Agent: Set exploitation_success==True if powershell login successful

This commit is contained in:
Mike Salvatore 2022-03-14 12:16:48 -04:00 committed by Ilija Lazoroski
parent 3b094d0478
commit 020dbbf2fe
2 changed files with 17 additions and 5 deletions

View File

@ -78,15 +78,14 @@ class PowerShellExploiter(HostExploiter):
) )
return self.exploit_result return self.exploit_result
self.exploit_result.exploitation_success = True
try: try:
self._execute_monkey_agent_on_victim() self._execute_monkey_agent_on_victim()
self.exploit_result.propagation_success = True self.exploit_result.propagation_success = True
self.exploit_result.exploitation_success = True
except Exception as ex: except Exception as ex:
logger.error(f"Failed to propagate to the remote host: {ex}") logger.error(f"Failed to propagate to the remote host: {ex}")
self.exploit_result.error_message = str(ex) self.exploit_result.error_message = str(ex)
self.exploit_result.propagation_success = False
self.exploit_result.exploitation_success = False
return self.exploit_result return self.exploit_result

View File

@ -59,6 +59,7 @@ def test_powershell_disabled(monkeypatch, powershell_exploiter, powershell_argum
exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) exploit_result = powershell_exploiter.exploit_host(**powershell_arguments)
assert not exploit_result.exploitation_success assert not exploit_result.exploitation_success
assert not exploit_result.propagation_success
assert "disabled" in exploit_result.error_message 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) exploit_result = powershell_exploiter.exploit_host(**powershell_arguments)
assert not exploit_result.exploitation_success assert not exploit_result.exploitation_success
assert not exploit_result.propagation_success
assert "Unable to authenticate" in exploit_result.error_message 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) monkeypatch.setattr(powershell, "PowerShellClient", mock_client)
exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) 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 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) monkeypatch.setattr(powershell, "PowerShellClient", mock_powershell_client)
exploit_result = powershell_exploiter.exploit_host(**powershell_arguments) 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 exploit_result.propagation_success is False
assert "execute" in exploit_result.error_message 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): 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 # 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 # login attempt doesn't throw an exception, signifying that login with credentials was