|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Auxiliary |
| 7 | + include Msf::Exploit::Remote::Tcp |
| 8 | + include Msf::Auxiliary::Scanner |
| 9 | + include Msf::Auxiliary::Report |
| 10 | + |
| 11 | + def initialize(info = {}) |
| 12 | + super( |
| 13 | + update_info( |
| 14 | + info, |
| 15 | + 'Name' => 'Identify endpoints speaking the Remote Desktop Protocol (RDP)', |
| 16 | + 'Description' => %q( |
| 17 | + This module attempts to connect to the specified Remote Desktop Protocol port |
| 18 | + and determines if it speaks RDP. |
| 19 | + ), |
| 20 | + 'Author' => 'Jon Hart <jon_hart[at]rapid7.com>', |
| 21 | + 'References' => |
| 22 | + [ |
| 23 | + ['URL', 'https://msdn.microsoft.com/en-us/library/cc240445.aspx'] |
| 24 | + ], |
| 25 | + 'License' => MSF_LICENSE |
| 26 | + ) |
| 27 | + ) |
| 28 | + |
| 29 | + register_options( |
| 30 | + [ |
| 31 | + Opt::RPORT(3389), |
| 32 | + OptBool.new('TLS', [true, 'Wheter or not request TLS security', true]), |
| 33 | + OptBool.new('CredSSP', [true, 'Whether or not to request CredSSP', true]), |
| 34 | + OptBool.new('EarlyUser', [true, 'Whether to support Earlier User Authorization Result PDU', false]) |
| 35 | + ] |
| 36 | + ) |
| 37 | + end |
| 38 | + |
| 39 | + # any TPKT v3 + x.2224 COTP Connect Confirm |
| 40 | + RDP_RE = /^\x03\x00.{3}\xd0.{5}.*$/ |
| 41 | + def rdp? |
| 42 | + sock.put(@probe) |
| 43 | + response = sock.get_once(-1) |
| 44 | + if response |
| 45 | + if RDP_RE.match?(response) |
| 46 | + # XXX: it might be helpful to decode the response and show what was selected. |
| 47 | + print_good("Identified RDP") |
| 48 | + return true |
| 49 | + else |
| 50 | + vprint_status("No match for '#{Rex::Text.to_hex_ascii(response)}'") |
| 51 | + end |
| 52 | + else |
| 53 | + vprint_status("No response") |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + def setup |
| 58 | + # build a simple TPKT v3 + x.224 COTP Connect Request. optionally append |
| 59 | + # RDP negotiation request with TLS, CredSSP and Early User as requesteste |
| 60 | + requested_protocols = 0 |
| 61 | + if datastore['TLS'] |
| 62 | + requested_protocols = requested_protocols ^ 0b1 |
| 63 | + end |
| 64 | + if datastore['CredSSP'] |
| 65 | + requested_protocols = requested_protocols ^ 0b10 |
| 66 | + end |
| 67 | + if datastore['EarlyUser'] |
| 68 | + requested_protocols = requested_protocols ^ 0b1000 |
| 69 | + end |
| 70 | + |
| 71 | + if requested_protocols == 0 |
| 72 | + tpkt_len = 11 |
| 73 | + cotp_len = 6 |
| 74 | + pack = [ 3, 0, tpkt_len, cotp_len, 0xe0, 0, 0, 0 ] |
| 75 | + pack_string = "CCnCCnnC" |
| 76 | + else |
| 77 | + tpkt_len = 19 |
| 78 | + cotp_len = 14 |
| 79 | + pack = [ 3, 0, tpkt_len, cotp_len, 0xe0, 0, 0, 0, 1, 0, 8, 0, requested_protocols ] |
| 80 | + pack_string = "CCnCCnnCCCCCV" |
| 81 | + end |
| 82 | + @probe = pack.pack(pack_string) |
| 83 | + end |
| 84 | + |
| 85 | + def run_host(_ip) |
| 86 | + begin |
| 87 | + connect |
| 88 | + return unless rdp? |
| 89 | + rescue Rex::AddressInUse, Rex::HostUnreachable, Rex::ConnectionTimeout, Rex::ConnectionRefused, \ |
| 90 | + ::Errno::ETIMEDOUT, ::Timeout::Error, ::EOFError => e |
| 91 | + vprint_error("error while connecting and negotiating RDP: #{e}") |
| 92 | + return |
| 93 | + ensure |
| 94 | + disconnect |
| 95 | + end |
| 96 | + |
| 97 | + report_service( |
| 98 | + host: rhost, |
| 99 | + port: rport, |
| 100 | + proto: 'tcp', |
| 101 | + name: 'RDP' |
| 102 | + ) |
| 103 | + end |
| 104 | +end |
0 commit comments