Skip to content

Commit 15ff70f

Browse files
committed
Add warning to FileDropper for deleting CWD
1 parent 8be2b1f commit 15ff70f

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/msf/core/exploit/file_dropper.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ def file_dropper_delete_file(session, file)
201201
# @param [String] dir The directory to delete
202202
# @return [Boolean] True if the delete command has been executed in the remote machine, otherwise false.
203203
def file_dropper_delete_dir(session, dir)
204+
if file_dropper_check_cwd?(dir)
205+
print_warning("Attempting to delete working directory #{dir}")
206+
end
207+
204208
win_dir = file_dropper_win_path(dir)
205209

206210
if session.type == 'meterpreter'
@@ -250,6 +254,26 @@ def file_dropper_deleted?(session, path, exists_before)
250254
end
251255
end
252256

257+
# Check if the path being removed is the same as the working directory
258+
#
259+
# @param [String] path The path to check
260+
# @return [Boolean] true if the path is the same, otherwise false
261+
def file_dropper_check_cwd?(path)
262+
if session.type == 'meterpreter'
263+
return true if path == session.fs.dir.pwd
264+
else
265+
pwd = if session.platform == 'windows'
266+
session.shell_command_token('echo %cd%').strip
267+
else
268+
session.shell_command_token('pwd').strip
269+
end
270+
271+
return true if path == pwd
272+
end
273+
274+
false
275+
end
276+
253277
# Converts a path to use the windows separator '\'
254278
#
255279
# @param [String] path The path to convert

0 commit comments

Comments
 (0)