From e70d1c714b5e4ce18a61a181ae2d277395d6fb89 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Wed, 25 Aug 2021 13:29:15 -0400 Subject: [PATCH] Agent: Remove context manager from _authenticate() Since the PowerShellExploiter's _authenticate() method returns the client object, it doesn't make sense for it to be constructed in a context manager. --- monkey/infection_monkey/exploit/powershell.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 134ae907c..6f0a27ac4 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -74,8 +74,7 @@ class PowerShellExploiter(HostExploiter): def _authenticate(self, username: Optional[str], password: Optional[str]) -> Client: (ssl, auth, encryption) = utils.get_powershell_client_params(password) - - with Client( + client = Client( self.host.ip_addr, username=username, password=password, @@ -83,10 +82,13 @@ class PowerShellExploiter(HostExploiter): ssl=ssl, auth=auth, encryption=encryption, - ) as client: - # attempt to execute dir command to know if authentication was successful - client.execute_cmd("dir") - return client + connection_timeout=3, + ) + + # attempt to execute dir command to know if authentication was successful + client.execute_cmd("dir") + + return client def _execute_monkey_agent_on_victim(self) -> bool: arch = self._get_host_arch()