@@ -61,13 +61,19 @@ def on_new_session(session)
61
61
62
62
@dropped_files . delete_if do |file |
63
63
exists_before = file_dropper_exist? ( session , file )
64
+
64
65
if file_dropper_delete_file ( session , file )
65
66
file_dropper_deleted? ( session , file , exists_before )
66
67
end
67
68
end
68
69
69
70
@dropped_dirs . delete_if do |dir |
71
+ if file_dropper_check_cwd? ( session , dir )
72
+ print_warning ( "Attempting to delete working directory #{ dir } " )
73
+ end
74
+
70
75
exists_before = file_dropper_exist? ( session , dir )
76
+
71
77
if file_dropper_delete_dir ( session , dir )
72
78
file_dropper_deleted? ( session , dir , exists_before )
73
79
end
@@ -110,6 +116,10 @@ def cleanup
110
116
# Check if dir_rm method is available (local exploit, mixin support, module support)
111
117
if respond_to? ( :dir_rm )
112
118
@dropped_dirs . delete_if do |dir |
119
+ if respond_to? ( :pwd ) && pwd . include? ( dir )
120
+ print_warning ( "Attempting to delete working directory #{ dir } " )
121
+ end
122
+
113
123
begin
114
124
dir_rm ( dir )
115
125
rescue ::Exception => e
@@ -201,10 +211,6 @@ def file_dropper_delete_file(session, file)
201
211
# @param [String] dir The directory to delete
202
212
# @return [Boolean] True if the delete command has been executed in the remote machine, otherwise false.
203
213
def file_dropper_delete_dir ( session , dir )
204
- if file_dropper_check_cwd? ( session , dir )
205
- print_warning ( "Attempting to delete working directory #{ dir } " )
206
- end
207
-
208
214
win_dir = file_dropper_win_path ( dir )
209
215
210
216
if session . type == 'meterpreter'
@@ -264,9 +270,9 @@ def file_dropper_check_cwd?(session, path)
264
270
else
265
271
pwd =
266
272
if session . platform == 'windows'
267
- session . shell_command_token ( 'echo %cd%' ) . strip
273
+ session . shell_command_token ( 'echo %cd%' )
268
274
else
269
- session . shell_command_token ( 'pwd' ) . strip
275
+ session . shell_command_token ( 'pwd' )
270
276
end
271
277
272
278
# Check for subdirectories and relative paths
0 commit comments