From 4d88efdd843a02b7b2d255369306f779d4330e74 Mon Sep 17 00:00:00 2001 From: Shreya Date: Sat, 24 Apr 2021 14:04:57 +0530 Subject: [PATCH] Fix DUO116 warnings in post breach actions by ignoring them --- .../post_breach/actions/clear_command_history.py | 4 ++-- .../post_breach/actions/modify_shell_startup_files.py | 4 ++-- .../post_breach/actions/use_signed_scripts.py | 5 ++--- monkey/infection_monkey/post_breach/pba.py | 2 +- .../windows/shell_startup_files_modification.py | 6 ++++-- .../post_breach/signed_script_proxy/signed_script_proxy.py | 4 ++-- monkey/infection_monkey/utils/hidden_files.py | 4 ++-- 7 files changed, 15 insertions(+), 14 deletions(-) diff --git a/monkey/infection_monkey/post_breach/actions/clear_command_history.py b/monkey/infection_monkey/post_breach/actions/clear_command_history.py index 412229ee5..f4aa5ad7b 100644 --- a/monkey/infection_monkey/post_breach/actions/clear_command_history.py +++ b/monkey/infection_monkey/post_breach/actions/clear_command_history.py @@ -46,8 +46,8 @@ class ClearCommandHistory(PBA): def run(self): if self.command: try: - output = subprocess.check_output( - self.command, stderr=subprocess.STDOUT, shell=True # noqa: DUO116 + output = subprocess.check_output( # noqa: DUO116 + self.command, stderr=subprocess.STDOUT, shell=True ).decode() return output, True except subprocess.CalledProcessError as e: diff --git a/monkey/infection_monkey/post_breach/actions/modify_shell_startup_files.py b/monkey/infection_monkey/post_breach/actions/modify_shell_startup_files.py index eea61ed2f..18990ab11 100644 --- a/monkey/infection_monkey/post_breach/actions/modify_shell_startup_files.py +++ b/monkey/infection_monkey/post_breach/actions/modify_shell_startup_files.py @@ -58,8 +58,8 @@ class ModifyShellStartupFiles(PBA): def run(self): if self.command: try: - output = subprocess.check_output( - self.command, stderr=subprocess.STDOUT, shell=True # noqa: DUO116 + output = subprocess.check_output( # noqa: DUO116 + self.command, stderr=subprocess.STDOUT, shell=True ).decode() return output, True except subprocess.CalledProcessError as e: diff --git a/monkey/infection_monkey/post_breach/actions/use_signed_scripts.py b/monkey/infection_monkey/post_breach/actions/use_signed_scripts.py index 782f85d13..ed9b1dc21 100644 --- a/monkey/infection_monkey/post_breach/actions/use_signed_scripts.py +++ b/monkey/infection_monkey/post_breach/actions/use_signed_scripts.py @@ -21,10 +21,9 @@ class SignedScriptProxyExecution(PBA): try: original_comspec = "" if is_windows_os(): - original_comspec = subprocess.check_output( + original_comspec = subprocess.check_output( # noqa: DUO116 "if defined COMSPEC echo %COMSPEC%", shell=True - ).decode() # noqa: DUO116 - + ).decode() super().run() except Exception as e: LOG.warning( diff --git a/monkey/infection_monkey/post_breach/pba.py b/monkey/infection_monkey/post_breach/pba.py index a87cfec48..bf0e66ed4 100644 --- a/monkey/infection_monkey/post_breach/pba.py +++ b/monkey/infection_monkey/post_breach/pba.py @@ -90,7 +90,7 @@ class PBA(Plugin): :return: Tuple of command's output string and boolean, indicating if it succeeded """ try: - output = subprocess.check_output( + output = subprocess.check_output( # noqa: DUO116 self.command, stderr=subprocess.STDOUT, shell=True ).decode() return output, True diff --git a/monkey/infection_monkey/post_breach/shell_startup_files/windows/shell_startup_files_modification.py b/monkey/infection_monkey/post_breach/shell_startup_files/windows/shell_startup_files_modification.py index e65893095..62fd9425e 100644 --- a/monkey/infection_monkey/post_breach/shell_startup_files/windows/shell_startup_files_modification.py +++ b/monkey/infection_monkey/post_breach/shell_startup_files/windows/shell_startup_files_modification.py @@ -13,8 +13,10 @@ def get_windows_commands_to_modify_shell_startup_files(): # get list of usernames USERS = ( - subprocess.check_output("dir C:\\Users /b", shell=True).decode().split("\r\n")[:-1] - ) # noqa: DUO116 + subprocess.check_output("dir C:\\Users /b", shell=True) # noqa: DUO116 + .decode() + .split("\r\n")[:-1] + ) USERS.remove("Public") STARTUP_FILES_PER_USER = [ diff --git a/monkey/infection_monkey/post_breach/signed_script_proxy/signed_script_proxy.py b/monkey/infection_monkey/post_breach/signed_script_proxy/signed_script_proxy.py index cfabaafec..12343d8cf 100644 --- a/monkey/infection_monkey/post_breach/signed_script_proxy/signed_script_proxy.py +++ b/monkey/infection_monkey/post_breach/signed_script_proxy/signed_script_proxy.py @@ -15,7 +15,7 @@ def get_commands_to_proxy_execution_using_signed_script(): def cleanup_changes(original_comspec): if is_windows_os(): - subprocess.run( + subprocess.run( # noqa: DUO116 get_windows_commands_to_reset_comspec(original_comspec), shell=True - ) # noqa: DUO116 + ) subprocess.run(get_windows_commands_to_delete_temp_comspec(), shell=True) # noqa: DUO116 diff --git a/monkey/infection_monkey/utils/hidden_files.py b/monkey/infection_monkey/utils/hidden_files.py index cc973cc5e..92391ecc9 100644 --- a/monkey/infection_monkey/utils/hidden_files.py +++ b/monkey/infection_monkey/utils/hidden_files.py @@ -26,9 +26,9 @@ def get_commands_to_hide_folders(): def cleanup_hidden_files(is_windows=is_windows_os()): - subprocess.run( + subprocess.run( # noqa: DUO116 get_windows_commands_to_delete() - if is_windows # noqa: DUO116 + if is_windows else " ".join(get_linux_commands_to_delete()), shell=True, )