Agent: Catch exceptions in cleanup function of signed script PBA

This commit is contained in:
Shreya Malviya 2022-04-01 18:16:38 +05:30
parent 9ac4d23f28
commit 7bd1ed4c67
1 changed files with 18 additions and 8 deletions

View File

@ -1,3 +1,4 @@
import logging
import subprocess
from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT
@ -8,6 +9,8 @@ from infection_monkey.post_breach.signed_script_proxy.windows.signed_script_prox
)
from infection_monkey.utils.environment import is_windows_os
logger = logging.getLogger(__name__)
def get_commands_to_proxy_execution_using_signed_script():
windows_cmds = get_windows_commands_to_proxy_execution_using_signed_script()
@ -16,11 +19,18 @@ def get_commands_to_proxy_execution_using_signed_script():
def cleanup_changes(original_comspec):
if is_windows_os():
subprocess.run( # noqa: DUO116
get_windows_commands_to_reset_comspec(original_comspec),
shell=True,
timeout=SHORT_REQUEST_TIMEOUT,
)
subprocess.run( # noqa: DUO116
get_windows_commands_to_delete_temp_comspec(), shell=True, timeout=SHORT_REQUEST_TIMEOUT
)
try:
subprocess.run( # noqa: DUO116
get_windows_commands_to_reset_comspec(original_comspec),
shell=True,
timeout=SHORT_REQUEST_TIMEOUT,
)
subprocess.run( # noqa: DUO116
get_windows_commands_to_delete_temp_comspec(),
shell=True,
timeout=SHORT_REQUEST_TIMEOUT,
)
except subprocess.CalledProcessError as err:
logger.error(err.output.decode())
except subprocess.TimeoutExpired as err:
logger.error(str(err))