From 2b9d54408abd74cb46754ffd0779001f17596ada Mon Sep 17 00:00:00 2001 From: Shreya Date: Thu, 4 Jun 2020 23:29:27 +0530 Subject: [PATCH] Tweak PBA logic Don't need to use winAPI to delete file --- monkey/infection_monkey/utils/hidden_files.py | 5 +---- monkey/infection_monkey/utils/windows/hidden_files.py | 10 ++-------- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/monkey/infection_monkey/utils/hidden_files.py b/monkey/infection_monkey/utils/hidden_files.py index 186c03fd0..cf37a0b1a 100644 --- a/monkey/infection_monkey/utils/hidden_files.py +++ b/monkey/infection_monkey/utils/hidden_files.py @@ -7,8 +7,7 @@ from infection_monkey.utils.windows.hidden_files import\ get_windows_commands_to_hide_files,\ get_windows_commands_to_hide_folders,\ get_winAPI_to_hide_files,\ - get_windows_commands_to_delete,\ - get_winAPI_to_delete_files + get_windows_commands_to_delete from infection_monkey.utils.environment import is_windows_os @@ -29,7 +28,5 @@ def get_winAPI_to_hide_files(): def cleanup_hidden_files(is_windows=is_windows_os()): - if is_windows: - get_winAPI_to_delete_files() subprocess.run(get_windows_commands_to_delete() if is_windows else get_linux_commands_to_delete()) diff --git a/monkey/infection_monkey/utils/windows/hidden_files.py b/monkey/infection_monkey/utils/windows/hidden_files.py index 157e09f45..0a527d167 100644 --- a/monkey/infection_monkey/utils/windows/hidden_files.py +++ b/monkey/infection_monkey/utils/windows/hidden_files.py @@ -1,6 +1,3 @@ -import win32file - - HIDDEN_FILE = 'C:\\monkey-hidden-file' HIDDEN_FILE_WINAPI = 'C:\\monkey-hidden-file-winAPI' HIDDEN_FOLDER = 'C:\\monkey-hidden-folder' @@ -29,6 +26,7 @@ def get_windows_commands_to_hide_folders(): def get_winAPI_to_hide_files(): + import win32file try: fileAccess = win32file.GENERIC_READ | win32file.GENERIC_WRITE # read-write access fileCreation = win32file.CREATE_ALWAYS # overwrite existing file @@ -43,20 +41,16 @@ def get_winAPI_to_hide_files(): 0) return "Created hidden file: {}".format(HIDDEN_FILE_WINAPI), True - except Exception as err: return str(err), False -def get_winAPI_to_delete_files(): - win32file.DeleteFile(HIDDEN_FILE_WINAPI) - - def get_windows_commands_to_delete(): return [ 'del', # delete file '/f', # force delete HIDDEN_FILE, + HIDDEN_FILE_WINAPI, '&& rmdir', # delete folder HIDDEN_FOLDER ]