Skip to content

Commit 527ba0e

Browse files
committed
Merge branch 'feature/automatic-fs-cleanup' of git://github.com/jlee-r7/metasploit-framework into jlee-r7-feature/automatic-fs-cleanup
2 parents d4749ff + 2526dce commit 527ba0e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/msf/core/exploit/file_dropper.rb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,33 @@ def on_new_session(session)
1616
end
1717

1818
@dropped_files.delete_if do |file|
19+
win_file = file.gsub("/", "\\\\")
1920
if session.type == "meterpreter"
2021
begin
22+
# Meterpreter should do this automatically as part of
23+
# fs.file.rm(). Until that has been implemented, remove the
24+
# read-only flag with a command.
25+
session.shell_command_token(%Q|attrib.exe -r "#{win_file}"|)
2126
session.fs.file.rm(file)
2227
print_good("Deleted #{file}")
2328
true
2429
rescue ::Rex::Post::Meterpreter::RequestError
2530
false
2631
end
2732
else
28-
win_file = file.gsub("/", "\\\\")
29-
win_cmd = %Q|del.exe /f /q "#{win_file}"|
30-
unix_cmd = %Q|rm -f "#{file}" >/dev/null|
33+
cmds = [
34+
%Q|attrib.exe -r "#{win_file}"|,
35+
%Q|del.exe /f /q "#{win_file}"|,
36+
%Q|rm -f "#{file}" >/dev/null|,
37+
]
3138

3239
# We need to be platform-independent here. Since we can't be
3340
# certain that {#target} is accurate because exploits with
3441
# automatic targets frequently change it, we just go ahead and
3542
# run both a windows and a unixy command in the same line. One
3643
# of them will definitely fail and the other will probably
3744
# succeed. Doing it this way saves us an extra round-trip.
38-
session.shell_command_token(%Q|#{win_cmd} ; #{unix_cmd}|)
45+
session.shell_command_token(cmds.join(" ; "))
3946
print_good("Deleted #{file}")
4047
true
4148
end

0 commit comments

Comments
 (0)