Tweak PBA logic

Don't need to use winAPI to delete file
This commit is contained in:
Shreya 2020-06-04 23:29:27 +05:30
parent 1d952a4781
commit 2b9d54408a
2 changed files with 3 additions and 12 deletions

View File

@ -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())

View File

@ -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
]