From 61c6bf2567c7879a7760886bda0daf319c7750ec Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 1 Sep 2021 13:52:55 -0400 Subject: [PATCH] Agent: Reduce code duplication in _try_http(s)() methods --- monkey/infection_monkey/exploit/powershell.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 6361165c1..26d01be8e 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -94,27 +94,23 @@ class PowerShellExploiter(HostExploiter): raise PowerShellRemotingDisabledError("Powershell remoting seems to be disabled.") def _try_http(self): - credentials = Credentials( - username=self._config.exploit_user_list[0], - password=self._config.exploit_password_list[0], - ) - auth_options = AuthOptions( - auth_type=AUTH_NEGOTIATE, - encryption=ENCRYPTION_AUTO, - ssl=False, - ) - self._authenticate(credentials, auth_options) + self._try_ssl_login(self, use_ssl=False) def _try_https(self): + self._try_ssl_login(self, use_ssl=True) + + def _try_ssl_login(self, use_ssl: bool): credentials = Credentials( username=self._config.exploit_user_list[0], password=self._config.exploit_password_list[0], ) + auth_options = AuthOptions( auth_type=AUTH_NEGOTIATE, encryption=ENCRYPTION_AUTO, - ssl=True, + ssl=use_ssl, ) + self._authenticate(credentials, auth_options) def _authenticate_via_brute_force(