Skip to content

Commit 0fb21af

Browse files
committed
Verify deletion at on_new_session moment
1 parent a40af79 commit 0fb21af

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

lib/msf/core/exploit/file_dropper.rb

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Msf
44
module Exploit::FileDropper
55

6+
attr_accessor :session
7+
68
def initialize(info = {})
79
super
810

@@ -20,7 +22,18 @@ def initialize(info = {})
2022
# @return [void]
2123
#
2224
def on_new_session(session)
23-
super(session)
25+
super
26+
27+
print_status("new session...")
28+
on_new_session_job(session)
29+
end
30+
31+
def on_new_session_job(new_session)
32+
if session
33+
session_orig = session
34+
end
35+
36+
self.session = new_session
2437

2538
if session.type == 'meterpreter'
2639
session.core.use('stdapi') unless session.ext.aliases.include?('stdapi')
@@ -31,13 +44,20 @@ def on_new_session(session)
3144
end
3245

3346
@dropped_files.delete_if do |file|
47+
puts "Deleting #{file}"
3448
exists_before = file_dropper_check_file(file)
3549
if file_dropper_delete(file)
3650
file_dropper_deleted?(file, exists_before)
3751
else
3852
false
3953
end
4054
end
55+
56+
if session_orig
57+
self.session = session_orig
58+
else
59+
self.session = nil
60+
end
4161
end
4262

4363
#
@@ -108,6 +128,7 @@ def file_dropper_win_file(file)
108128
end
109129

110130
def file_dropper_delete(file)
131+
puts "Deleting #{file}"
111132
win_file = file_dropper_win_file(file)
112133

113134
if session.type == 'meterpreter'
@@ -124,6 +145,7 @@ def file_dropper_delete(file)
124145
false
125146
end
126147
else
148+
puts "Deleting with shell"
127149
win_cmds = [
128150
%Q|attrib.exe -r "#{win_file}"|,
129151
%Q|del.exe /f /q "#{win_file}"|
@@ -141,16 +163,19 @@ def file_dropper_delete(file)
141163
end
142164

143165
def file_dropper_check_file(file)
166+
puts "Checking file... #{file}"
144167
if session.platform =~ /win/
145168
normalized = file_dropper_win_file(file)
146169
else
147170
normalized = file
148171
end
149172

173+
puts "Checking normalized file... #{file}"
150174
Msf::Post::File.file_exist?(normalized)
151175
end
152176

153177
def file_dropper_deleted?(file, exists_before)
178+
puts "Deleted? ... #{file}"
154179
if exists_before && file_dropper_check_file(file)
155180
print_error("Unable to delete #{file}")
156181
false

modules/exploits/multi/http/struts_code_exec_classloader.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,7 @@ def class_loader_exploit
271271
fail_with(Failure::Unknown, "#{peer} - The log file hasn't been flushed")
272272
end
273273

274-
# This path depends on CWD. May require manual cleanup
275-
# See https://github.com/rapid7/metasploit-framework/issues/4667
276-
print_warning("This exploit requires manual cleanup of '#{@jsp_file}' on the target")
274+
register_files_for_cleanup(@jsp_file)
277275

278276
# Prepare the JSP
279277
print_status("#{peer} - Generating JSP...")

0 commit comments

Comments
 (0)