Skip to content

Commit ecb23d0

Browse files
committed
Do initial fix
1 parent cc87df9 commit ecb23d0

File tree

1 file changed

+43
-5
lines changed

1 file changed

+43
-5
lines changed

lib/msf/core/exploit/file_dropper.rb

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
module Msf
44
module Exploit::FileDropper
55

6+
include Msf::Post::Common
7+
include Msf::Post::File
8+
69
def initialize(info = {})
710
super
811

@@ -22,6 +25,8 @@ def initialize(info = {})
2225
def on_new_session(session)
2326
super
2427

28+
@session = session
29+
2530
if session.type == "meterpreter"
2631
session.core.use("stdapi") unless session.ext.aliases.include?("stdapi")
2732
end
@@ -32,6 +37,8 @@ def on_new_session(session)
3237

3338
@dropped_files.delete_if do |file|
3439
win_file = file.gsub("/", "\\\\")
40+
exists_before = check_file(file, win_file)
41+
3542
if session.type == "meterpreter"
3643
begin
3744
# Meterpreter should do this automatically as part of
@@ -41,10 +48,9 @@ def on_new_session(session)
4148
session.shell_command_token(%Q|attrib.exe -r #{win_file}|)
4249
end
4350
session.fs.file.rm(file)
44-
print_good("Deleted #{file}")
45-
true
51+
file_deleted?(file, win_file, exists_before)
4652
rescue ::Rex::Post::Meterpreter::RequestError
47-
false
53+
return false
4854
end
4955
else
5056
win_cmds = [
@@ -59,8 +65,7 @@ def on_new_session(session)
5965
# succeed. Doing it this way saves us an extra round-trip.
6066
# Trick shared by @mihi42
6167
session.shell_command_token("rm -f \"#{file}\" >/dev/null ; echo ' & #{win_cmds.join(" & ")} & echo \" ' >/dev/null")
62-
print_good("Deleted #{file}")
63-
true
68+
file_deleted?(file, win_file, exists_before)
6469
end
6570
end
6671
end
@@ -125,6 +130,39 @@ def cleanup
125130
print_warning("This exploit may require manual cleanup of '#{f}' on the target")
126131
end
127132

133+
private
134+
135+
def session
136+
@session
137+
end
138+
139+
alias :client :session
140+
141+
def check_file(file, win_file)
142+
if session.platform =~ /win/
143+
res = file_exist?(win_file)
144+
else
145+
res = file_exist?(file)
146+
end
147+
148+
res
149+
end
150+
151+
def file_deleted?(file, win_file, exists_before)
152+
if exists_before
153+
if check_file(file, win_file)
154+
print_error("Unable to delete #{file}")
155+
false
156+
else
157+
print_good("Deleted #{file}")
158+
true
159+
end
160+
end
161+
162+
print_warning("Tried to delete #{file}, unknown result")
163+
true
164+
end
165+
128166
end
129167
end
130168
end

0 commit comments

Comments
 (0)