SNMP RCE
This post was copied from https://rioasmara.com/2021/02/05/snmp-arbitary-command-execution-and-shell/
SNMP is sometimes overseen by the administrator of the device or server where it is left in a default configuration. SNMP community with write permissions (rwcommunity) on the Linux operating system can be abused to let the attacker execute a command on the server.
Extending the Services
While you are not able to modify existing entries that were configured in snmpd.conf, it is possible to add additional commands over SNMP, because the “MAX-ACCESS” permission setting in the MIB definition is set to “read-create”
Adding a new command basically works by appending an additional row to the “nsExtendObjects” table.
Injecting a command to run on the SNMP service. NET-SNMP-EXTEND-MIB requires that you always provide the absolute path to the executable. The called binary/script must also exist and be executable.
Executing the command that we injected to the SNMP by enumerating it using snmpwalk
Showing that the command is /bin/echo.
The command will be executed when the it is read. run-on-read()
The command /bin/echo "hello rio is here" was executed during our snmpwalk read
Getting the Shell from Net-SNMP Extend
In this section, I would like to discuss how to gain a server shell to control the server.
You can use python script developed by mxrch that can be downloaded from https://github.com/mxrch/snmp-shell.git
You can install the pre-requisite to run this:
Creating reverse shell
You can also create reverse shell manually by injecting the command below into the SNMP
run the snmpwalk to trigger the command execution
Our netcat receives the reverseshell connection from the victim that allow us to gain control over the victim machine
Last updated