Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/documentation/modules/auxiliary/admin/scada/moxa_credentials_recovery.md
Views: 11787
Vulnerable Application
Many Moxa devices make use of a protocol that is vulnerable to unauthenticated credential retrieval via exploitation of CVE-2016-9361. The service is known to be used on Moxa devices in the NPort, OnCell, and MGate product lines.
This module leverages CVE-2016-9361 to retrieve admin passwords and SNMP community strings, as well as enumerate all possible function codes. The supporting research and Metasploit module are the work of Patrick DeSantis of Cisco Talos and K. Reid Wightman.
The module has been tested on Moxa NPort 6250 firmware v1.13, MGate MB3170 firmware v2.5, and NPort 5110 firmware v2.6.
The Moxa Protocol
The Moxa protocol listens on 4800/UDP and will respond to broadcast or direct traffic. The protocol is utilized by devices in several product lines and Moxa applications in order to manage and configure network-deployed devices.
Discovery / Identify
A discovery packet compels a Moxa device to respond to the sender with some basic device information that is needed for more advanced functions. The discovery data is 8 bytes in length and is the most basic example of the Moxa protocol. It may be sent out as a broadcast (destination 255.255.255.255) or to an individual device.
The discovery request contains the bytes:
Where the function code (first byte) 0x01 is Moxa discovery/identify and the fourth byte is the length of the full data payload.
Discovery Response
A valid response is 24 bytes, starts with 0x81, and contains the values 0x00, 0x90, 0xe8 (the Moxa OIU) in bytes 14, 15, and 16.
A response with a value of 0x04 for the second byte indicates that an invalid function code was used in the corresponding request.
The response can be broken down as follows:
Byte 0x0 identifies the packet as a response to the request. The first byte of a response will always be the FC + 0x80 (the most significant bit of the byte is set to 1, so 0b00000001 becomes 0b10000001, or 0x81 as response to identify 0x01).
Bytes 0x1-0x2 are unknown, may be padding
Byte 0x3 is the length of the datagram payload
Bytes 0x4-0x7 are unknown, may be padding
Bytes 0x8-0x9 may be the product line in little endian. For example, an NPort 6250 is part of the 6000 line, so bytes 8 and 9 will be 0x00 and 0x60 respectively.
Bytes 0xA-0xB are unknown but always seem to be 0x00 and 0x80 respectively.
Bytes 0xC-0xD are the model number in little endian, so the NPort 6250 is 0x50 and 0x62 respectively.
Bytes 0xE-0x13 are the MAC address of the device
Bytes 0x14-0x17 are the IP address
Here's a sample response from an NPort 6250 with the default IP address of 192.168.127.254 and a MAC of 00:90:e8:15:1c:22:
Other Functions
The values from the response are then used to craft a new request with the below format:
Byte 0x0 is the function code
Bytes 0x1-0x2 are unknown, may be padding
Byte 0x3 is the length of the datagram payload
Bytes 0x4-0x7 are unknown, may be padding
Bytes 0x8-0x9 are the product line in little endian
Bytes 0xA-0xB are the unknown 0x00 0x80
Bytes 0xC-0xD is the model number in big endian
Bytes 0xE-0x13 is the MAC
The module takes a valid response from discovery/ident and parses out the appropriate bytes to use as a "tail" which is appended to all subsequent requests.
The tail is then used as shown below:
For all function codes other than identify (0x01), as long as the "tail" values in the request match those of the target, the device will execute the function defined by the value in byte 0x0.
Other Known and Suspected Function Codes
Function codes fall in the range of 0x01 to 0x7F.
The below function codes are included in the module, even if unused. The intent is that the user may modify the module as needed to make use of other function codes.
Verification Steps
Start msfconsole
Do:
use auxiliary/admin/scada/moxa_credentials_recovery
Do:
set RHOST <target IP>
Do:
run
Any found credentials will be stored in loot (set VERBOSE to TRUE to have credentials output to console)
Options
RHOST
Target device.
FUNCTION
Either CREDS (default) or ENUM:
CREDS attempts to retrieve administrative password and SNMP community strings
ENUM will enumerate all function codes in the range 0x2..0x7F
Scenarios
Check
The module implements a check function to determine if a target "speaks" the Moxa protocol. It does this using the 0x01 function code and checking for a valid response of 24 bytes, starting with 0x81, and containing the values 0x00, 0x90, 0xe8 (the Moxa OIU) in bytes 14, 15, and 16.
Output Hexdump to Console
To output hexdump responses to console:
Sample verbose output:
Enumerate All Function Codes
To enumerate ALL function codes :
Sample ENUM output:
Note that the above response is an example of the utility of using ENUM. This function code (0x14) returns a netstat-type response. Output similar to the above will be displayed for every function code that does not return 'invalid' (0x4). This may also be useful for devices that do not "unlock" using the function codes supplied in this module; by running through all function codes in sequence, it is likely that an alternate "unlock" function will be sent prior to any function codes that request credentials.
NOTE: As the protocol is undocumented and the purpose of a majority of the function codes are unknown, undesired results are possible. Do NOT use on devices which are mission-critical!