Add logging to powershell exploiter in the case where powershell remoting seems to be disabled

This commit is contained in:
VakarisZ 2021-09-01 15:25:13 +03:00
parent b2e1b28059
commit b82f4e157a
1 changed files with 17 additions and 5 deletions

View File

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