From 020dbbf2fe384e4bb93082e69be16bbee35cafee Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 14 Mar 2022 12:16:48 -0400 Subject: [PATCH] Agent: Set exploitation_success==True if powershell login successful --- monkey/infection_monkey/exploit/powershell.py | 5 ++--- .../infection_monkey/exploit/test_powershell.py | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/monkey/infection_monkey/exploit/powershell.py b/monkey/infection_monkey/exploit/powershell.py index e8999545a..9c34227ee 100644 --- a/monkey/infection_monkey/exploit/powershell.py +++ b/monkey/infection_monkey/exploit/powershell.py @@ -78,15 +78,14 @@ class PowerShellExploiter(HostExploiter): ) return self.exploit_result + self.exploit_result.exploitation_success = True + try: self._execute_monkey_agent_on_victim() self.exploit_result.propagation_success = True - self.exploit_result.exploitation_success = True except Exception as ex: logger.error(f"Failed to propagate to the remote host: {ex}") self.exploit_result.error_message = str(ex) - self.exploit_result.propagation_success = False - self.exploit_result.exploitation_success = False return self.exploit_result 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 5af0dd617..6d0aa6df3 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 not exploit_result.propagation_success assert "disabled" in exploit_result.error_message @@ -99,6 +100,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 not exploit_result.propagation_success assert "Unable to authenticate" in exploit_result.error_message @@ -130,7 +132,8 @@ def test_failed_copy(monkeypatch, powershell_exploiter, powershell_arguments): monkeypatch.setattr(powershell, "PowerShellClient", mock_client) exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) - assert not exploit_result.exploitation_success + assert exploit_result.exploitation_success + assert not exploit_result.propagation_success assert "copy" in exploit_result.error_message @@ -144,11 +147,21 @@ def test_failed_monkey_execution(monkeypatch, powershell_exploiter, powershell_a monkeypatch.setattr(powershell, "PowerShellClient", mock_powershell_client) exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) - # assert exploit_result.exploitation_success is True + assert exploit_result.exploitation_success is True assert exploit_result.propagation_success is False assert "execute" in exploit_result.error_message +def test_successful_propagation(monkeypatch, powershell_exploiter, powershell_arguments): + mock_client = MagicMock() + monkeypatch.setattr(powershell, "PowerShellClient", mock_client) + + exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) + + assert exploit_result.exploitation_success + assert exploit_result.propagation_success + + def test_login_attempts_correctly_reported(monkeypatch, powershell_exploiter, powershell_arguments): # 1st call is for determining HTTP/HTTPs. 6 remaining calls are actual login attempts. the 6th # login attempt doesn't throw an exception, signifying that login with credentials was