|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class MetasploitModule < Msf::Auxiliary |
| 9 | + |
| 10 | + include Msf::Auxiliary::Report |
| 11 | + include Msf::Auxiliary::UDPScanner |
| 12 | + |
| 13 | + def initialize(info = {}) |
| 14 | + super( |
| 15 | + update_info( |
| 16 | + info, |
| 17 | + 'Name' => 'Moxa UDP Device Discovery', |
| 18 | + 'Description' => %q( |
| 19 | + The Moxa protocol listens on 4800/UDP and will respond to broadcast |
| 20 | + or direct traffic. The service is known to be used on Moxa devices |
| 21 | + in the NPort, OnCell, and MGate product lines. |
| 22 | +
|
| 23 | + A discovery packet compels a Moxa device to respond to the sender |
| 24 | + with some basic device information that is needed for more advanced |
| 25 | + functions. The discovery data is 8 bytes in length and is the most |
| 26 | + basic example of the Moxa protocol. It may be sent out as a |
| 27 | + broadcast (destination 255.255.255.255) or to an individual device. |
| 28 | +
|
| 29 | + Devices that respond to this query may be vulnerable to serious |
| 30 | + information disclosure vulnerabilities, such as CVE-2016-9361. |
| 31 | +
|
| 32 | + The module is the work of Patrick DeSantis of Cisco Talos and is |
| 33 | + derived from original work by K. Reid Wightman. Tested and validated |
| 34 | + on a Moxa NPort 6250 with firmware versions 1.13 and 1.15. |
| 35 | + ), |
| 36 | + 'Author' => 'Patrick DeSantis <p[at]t-r10t.com>', |
| 37 | + 'License' => MSF_LICENSE, |
| 38 | + 'References' => |
| 39 | + [ |
| 40 | + [ 'URL', 'https://www.digitalbond.com/blog/2016/10/25/serial-killers/'], |
| 41 | + [ 'URL', 'http://www.moxa.com/support/faq/faq_detail.aspx?id=646' ], |
| 42 | + ] |
| 43 | + ) |
| 44 | + ) |
| 45 | + |
| 46 | + register_options( |
| 47 | + [ |
| 48 | + # Moxa protocol listens on 4800/UDP by default |
| 49 | + Opt::RPORT(4800) |
| 50 | + ], self.class) |
| 51 | + end |
| 52 | + |
| 53 | + # The data to be sent via UDP |
| 54 | + def build_probe |
| 55 | + # Function Code (first byte) 0x01: Moxa discovery/identify |
| 56 | + # The fourth byte is the length of the full data payload |
| 57 | + @probe ||= "\x01\x00\x00\x08\x00\x00\x00\x00" |
| 58 | + end |
| 59 | + |
| 60 | + # Called for each response packet |
| 61 | + def scanner_process(response, src_host, _src_port) |
| 62 | + # The first byte of a response will always be the func code + 0x80 |
| 63 | + # (the most significant bit of the byte is set to 1, so 0b00000001 |
| 64 | + # becomes 0b10000001, or 0x81). |
| 65 | + # A valid response is 24 bytes, starts with 0x81, and contains the values |
| 66 | + # 0x00, 0x90, 0xe8 (the Moxa OIU) in bytes 14, 15, and 16. |
| 67 | + return unless response[0] == "\x81" && response[14..16] == "\x00\x90\xe8" && response.length == 24 |
| 68 | + @results[src_host] ||= [] |
| 69 | + @results[src_host] << response |
| 70 | + end |
| 71 | + |
| 72 | + # Called after the scan block |
| 73 | + def scanner_postscan(_batch) |
| 74 | + @results.each_pair do |host, response| |
| 75 | + peer = "#{host}:#{rport}" |
| 76 | + |
| 77 | + # Report the host |
| 78 | + report_host( |
| 79 | + :host => host, |
| 80 | + :info => "Moxa Device", |
| 81 | + ) |
| 82 | + |
| 83 | + # Report the service |
| 84 | + report_service( |
| 85 | + host: host, |
| 86 | + proto: 'udp', |
| 87 | + port: rport, |
| 88 | + name: 'Moxa Protocol', |
| 89 | + ) |
| 90 | + |
| 91 | + if response.empty? |
| 92 | + vprint_status("#{peer} No Moxa Devices Found.") |
| 93 | + else |
| 94 | + print_good("#{peer} Moxa Device Found!") |
| 95 | + |
| 96 | + # Report vuln |
| 97 | + report_vuln( |
| 98 | + host: host, |
| 99 | + port: rport, |
| 100 | + proto: 'udp', |
| 101 | + name: 'Moxa Protocol Use', |
| 102 | + refs: references |
| 103 | + ) |
| 104 | + end |
| 105 | + end |
| 106 | + end |
| 107 | +end |
0 commit comments