@@ -16,26 +16,33 @@ def on_new_session(session)
16
16
end
17
17
18
18
@dropped_files . delete_if do |file |
19
+ win_file = file . gsub ( "/" , "\\ \\ " )
19
20
if session . type == "meterpreter"
20
21
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 } "| )
21
26
session . fs . file . rm ( file )
22
27
print_good ( "Deleted #{ file } " )
23
28
true
24
29
rescue ::Rex ::Post ::Meterpreter ::RequestError
25
30
false
26
31
end
27
32
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
+ ]
31
38
32
39
# We need to be platform-independent here. Since we can't be
33
40
# certain that {#target} is accurate because exploits with
34
41
# automatic targets frequently change it, we just go ahead and
35
42
# run both a windows and a unixy command in the same line. One
36
43
# of them will definitely fail and the other will probably
37
44
# 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 ( " ; " ) )
39
46
print_good ( "Deleted #{ file } " )
40
47
true
41
48
end
0 commit comments