From df572d84c06f7a3c2562a372f34bc6baabe98371 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 14 Mar 2022 10:27:52 -0400 Subject: [PATCH] Agent: Set self.exploit_result.error_message in PowerShellExploiter --- monkey/infection_monkey/exploit/powershell.py | 8 ++++++-- .../infection_monkey/exploit/test_powershell.py | 4 ++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index 29120b478..7466a115e 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -56,7 +56,9 @@ class PowerShellExploiter(HostExploiter): use_ssl = self._is_client_using_https() except PowerShellRemotingDisabledError as e: logging.info(e) - # TODO: Set error message + self.exploit_result.error_message = ( + "PowerShell Remoting appears to be disabled on the remote host" + ) return self.exploit_result credentials = get_credentials( @@ -71,7 +73,9 @@ class PowerShellExploiter(HostExploiter): self._client = self._authenticate_via_brute_force(credentials, auth_options) if not self._client: - # TODO: Set error message + self.exploit_result.error_message = ( + "Unable to authenticate to the remote host using any of the available credentials" + ) return self.exploit_result try: diff --git a/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py b/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py index f039f6d9c..de1fa265a 100644 --- a/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py +++ b/monkey/tests/unit_tests/infection_monkey/exploit/test_powershell.py @@ -59,6 +59,7 @@ def test_powershell_disabled(monkeypatch, powershell_exploiter, powershell_argum exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) assert not exploit_result.exploitation_success + assert "disabled" in exploit_result.error_message def test_powershell_http(monkeypatch, powershell_exploiter, powershell_arguments): @@ -98,6 +99,7 @@ def test_no_valid_credentials(monkeypatch, powershell_exploiter, powershell_argu exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) assert not exploit_result.exploitation_success + assert "Unable to authenticate" in exploit_result.error_message def authenticate(mock_client): @@ -130,6 +132,7 @@ def test_failed_copy(monkeypatch, powershell_exploiter, powershell_arguments): exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) assert not exploit_result.exploitation_success + assert "copy" in exploit_result.error_message def test_failed_monkey_execution(monkeypatch, powershell_exploiter, powershell_arguments): @@ -145,6 +148,7 @@ def test_failed_monkey_execution(monkeypatch, powershell_exploiter, powershell_a exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) # assert exploit_result.exploitation_success is True assert exploit_result.propagation_success is False + assert "execute" in exploit_result.error_message def test_login_attemps_correctly_reported(monkeypatch, powershell_exploiter, powershell_arguments):