forked from p15670423/monkey
Refactor test_login_attemps_correctly_reported in test_powershell.py to address the changes in the flow of powershell and powershell client
This commit is contained in:
parent
e44e8f503e
commit
cc1c049ee9
|
@ -157,65 +157,28 @@ def test_failed_monkey_execution(monkeypatch, powershell_exploiter):
|
||||||
|
|
||||||
def test_login_attemps_correctly_reported(monkeypatch, powershell_exploiter):
|
def test_login_attemps_correctly_reported(monkeypatch, powershell_exploiter):
|
||||||
mock_client = MagicMock()
|
mock_client = MagicMock()
|
||||||
mock_client.get_host_architecture = lambda: WIN_ARCH_32
|
mock_client.return_value.get_host_architecture = lambda: WIN_ARCH_32
|
||||||
mock_client.copy_file = MagicMock(return_value=True)
|
mock_client.return_value.copy_file = MagicMock(return_value=True)
|
||||||
mock_client.execute_cmd_as_detached_process = MagicMock(side_effect=Exception)
|
|
||||||
|
|
||||||
def allow_ntlm(_, credentials: Credentials, auth_options: AuthOptions):
|
# execute_cmd method will throw exceptions for 5 first calls.
|
||||||
if credentials.username == USER_LIST[1] and credentials.secret == NT_HASH_LIST[1]:
|
# 6-th call doesn't throw an exception == credentials successful
|
||||||
return mock_client
|
execute_cmd_returns = [Exception, Exception, Exception, Exception, Exception, True]
|
||||||
|
mock_client.return_value.execute_cmd = MagicMock(side_effect=execute_cmd_returns)
|
||||||
|
|
||||||
raise TestAuthenticationError
|
monkeypatch.setattr(powershell, "PowerShellClient", mock_client)
|
||||||
|
|
||||||
mock_powershell_client = MagicMock(side_effect=allow_ntlm)
|
|
||||||
monkeypatch.setattr(powershell, "PowerShellClient", mock_powershell_client)
|
|
||||||
|
|
||||||
powershell_exploiter.exploit_host()
|
powershell_exploiter.exploit_host()
|
||||||
|
|
||||||
assert {
|
# Total 6 attempts reported, 5 failed and 1 succeeded
|
||||||
"result": False,
|
assert len(powershell_exploiter.exploit_attempts) == len(execute_cmd_returns)
|
||||||
"user": USER_LIST[1],
|
assert (
|
||||||
"password": None,
|
len([attempt for attempt in powershell_exploiter.exploit_attempts if not attempt["result"]])
|
||||||
"lm_hash": "",
|
== 5
|
||||||
"ntlm_hash": "",
|
)
|
||||||
"ssh_key": "",
|
assert (
|
||||||
} in powershell_exploiter.exploit_attempts
|
len([attempt for attempt in powershell_exploiter.exploit_attempts if attempt["result"]])
|
||||||
|
== 1
|
||||||
assert {
|
)
|
||||||
"result": False,
|
|
||||||
"user": USER_LIST[1],
|
|
||||||
"password": PASSWORD_LIST[0],
|
|
||||||
"lm_hash": "",
|
|
||||||
"ntlm_hash": "",
|
|
||||||
"ssh_key": "",
|
|
||||||
} in powershell_exploiter.exploit_attempts
|
|
||||||
|
|
||||||
assert {
|
|
||||||
"result": False,
|
|
||||||
"user": USER_LIST[0],
|
|
||||||
"password": "",
|
|
||||||
"lm_hash": LM_HASH_LIST[0],
|
|
||||||
"ntlm_hash": "",
|
|
||||||
"ssh_key": "",
|
|
||||||
} in powershell_exploiter.exploit_attempts
|
|
||||||
|
|
||||||
assert {
|
|
||||||
"result": False,
|
|
||||||
"user": USER_LIST[1],
|
|
||||||
"password": "",
|
|
||||||
"lm_hash": "",
|
|
||||||
"ntlm_hash": NT_HASH_LIST[0],
|
|
||||||
"ssh_key": "",
|
|
||||||
} in powershell_exploiter.exploit_attempts
|
|
||||||
|
|
||||||
assert {
|
|
||||||
"result": True,
|
|
||||||
"user": USER_LIST[1],
|
|
||||||
"password": "",
|
|
||||||
"lm_hash": "",
|
|
||||||
"ntlm_hash": NT_HASH_LIST[1],
|
|
||||||
"ssh_key": "",
|
|
||||||
} in powershell_exploiter.exploit_attempts
|
|
||||||
|
|
||||||
|
|
||||||
def test_build_monkey_execution_command():
|
def test_build_monkey_execution_command():
|
||||||
|
|
Loading…
Reference in New Issue