From b82f4e157ae59627e29a14b5812e4383d2a9dc51 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 1 Sep 2021 15:25:13 +0300 Subject: [PATCH] Add logging to powershell exploiter in the case where powershell remoting seems to be disabled --- monkey/infection_monkey/exploit/powershell.py | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 8a6aa9927..8a86f8c39 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -28,6 +28,10 @@ LOG = logging.getLogger(__name__) TEMP_MONKEY_BINARY_FILEPATH = "./monkey_temp_bin" +class PowerShellRemotingDisabledError(Exception): + pass + + class PowerShellExploiter(HostExploiter): _TARGET_OS_TYPE = ["windows"] EXPLOIT_TYPE = ExploitType.BRUTE_FORCE @@ -47,7 +51,12 @@ class PowerShellExploiter(HostExploiter): logging.getLogger(package.__name__).setLevel(logging.ERROR) def _exploit_host(self): - is_https = self._is_client_using_https() + try: + is_https = self._is_client_using_https() + except PowerShellRemotingDisabledError as e: + logging.info(e) + return False + credentials = CredentialGenerator( self.host.ip_addr, self._config.exploit_user_list, @@ -63,20 +72,23 @@ class PowerShellExploiter(HostExploiter): def _is_client_using_https(self) -> bool: try: + logging.debug("Checking if powershell remoting is enabled over HTTP.") self._try_http() return False except AuthenticationError: return False - except Exception: - pass + except Exception as e: + logging.debug(f"Powershell remoting over HTTP seems disabled: {e}") try: + logging.debug("Checking if powershell remoting is enabled over HTTPS.") self._try_https() return True except AuthenticationError: return True - except Exception: - raise Exception("Powershell remoting seems to be disabled.") + except Exception as e: + logging.debug(f"Powershell remoting over HTTPS seems disabled: {e}") + raise PowerShellRemotingDisabledError("Powershell remoting seems to be disabled.") def _try_http(self): auth_options_http = AuthOptions(