Agent: Return credentials when credentials propagation fails

This commit is contained in:
Kekoa Kaaikala 2022-08-15 19:17:37 +00:00
parent 9e6a569393
commit e4f7707b66
2 changed files with 15 additions and 3 deletions

View File

@ -63,12 +63,11 @@ class AggregatingPropagationCredentialsRepository(IPropagationCredentialsReposit
try:
propagation_credentials = self._get_credentials_from_control_channel()
self.add_credentials(propagation_credentials)
return self._stored_credentials
except Exception as ex:
self._stored_credentials = {}
logger.error(f"Error while attempting to retrieve credentials for propagation: {ex}")
return self._stored_credentials
def _set_attribute(self, attribute_to_be_set: str, credentials_values: Iterable[Any]):
if not credentials_values:
return

View File

@ -122,3 +122,16 @@ def test_all_keys_if_credentials_empty():
assert "exploit_password_list" in actual_stored_credentials
assert "exploit_ntlm_hash_list" in actual_stored_credentials
assert "exploit_ssh_keys" in actual_stored_credentials
def test_credentials_obtained_if_propagation_credentials_fails():
control_channel = MagicMock()
control_channel.get_credentials_for_propagation.return_value = EMPTY_CHANNEL_CREDENTIALS
control_channel.get_credentials_for_propagation.side_effect = Exception(
"No credentials for you!"
)
credentials_repository = AggregatingPropagationCredentialsRepository(control_channel)
credentials = credentials_repository.get_credentials()
assert credentials is not None