forked from p15670423/monkey
Island: Fix credentials formatting to use simplified credentials object
This commit is contained in:
parent
c56b38f695
commit
57f2c7e058
|
@ -17,14 +17,17 @@ def format_creds_for_reporting(credentials: Sequence[Credentials]) -> Sequence[M
|
||||||
CredentialComponentType.SSH_KEYPAIR: "Clear SSH private key",
|
CredentialComponentType.SSH_KEYPAIR: "Clear SSH private key",
|
||||||
}
|
}
|
||||||
for cred in credentials:
|
for cred in credentials:
|
||||||
for secret_type in cred.secrets:
|
secret = cred.secret
|
||||||
if secret_type.credential_type not in cred_type_dict:
|
if secret is None:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if secret.credential_type not in cred_type_dict:
|
||||||
continue
|
continue
|
||||||
username = _get_username(cred)
|
username = _get_username(cred)
|
||||||
cred_row = {
|
cred_row = {
|
||||||
"username": username,
|
"username": username,
|
||||||
"_type": secret_type.credential_type.name,
|
"_type": secret.credential_type.name,
|
||||||
"type": cred_type_dict[secret_type.credential_type],
|
"type": cred_type_dict[secret.credential_type],
|
||||||
}
|
}
|
||||||
if cred_row not in formatted_creds:
|
if cred_row not in formatted_creds:
|
||||||
formatted_creds.append(cred_row)
|
formatted_creds.append(cred_row)
|
||||||
|
@ -32,4 +35,4 @@ def format_creds_for_reporting(credentials: Sequence[Credentials]) -> Sequence[M
|
||||||
|
|
||||||
|
|
||||||
def _get_username(credentials: Credentials) -> str:
|
def _get_username(credentials: Credentials) -> str:
|
||||||
return credentials.identities[0].username if credentials.identities else ""
|
return credentials.identity.username if credentials.identity else ""
|
||||||
|
|
|
@ -23,7 +23,14 @@ fake_ssh_key = SSHKeypair(fake_ssh_private_key, fake_ssh_public_key)
|
||||||
identities = (fake_username,)
|
identities = (fake_username,)
|
||||||
secrets = (fake_nt_hash, fake_lm_hash, fake_password, fake_ssh_key)
|
secrets = (fake_nt_hash, fake_lm_hash, fake_password, fake_ssh_key)
|
||||||
|
|
||||||
fake_credentials = [Credentials(identities, secrets)]
|
fake_credentials = [
|
||||||
|
Credentials(fake_username, fake_nt_hash),
|
||||||
|
Credentials(fake_username, fake_lm_hash),
|
||||||
|
Credentials(fake_username, fake_password),
|
||||||
|
Credentials(fake_username, fake_ssh_key),
|
||||||
|
Credentials(None, fake_ssh_key),
|
||||||
|
Credentials(fake_username, None),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def test_formatting_credentials_for_report():
|
def test_formatting_credentials_for_report():
|
||||||
|
@ -50,7 +57,13 @@ def test_formatting_credentials_for_report():
|
||||||
"type": "Clear SSH private key",
|
"type": "Clear SSH private key",
|
||||||
"username": fake_username.username,
|
"username": fake_username.username,
|
||||||
}
|
}
|
||||||
|
result5 = {
|
||||||
|
"_type": CredentialComponentType.SSH_KEYPAIR.name,
|
||||||
|
"type": "Clear SSH private key",
|
||||||
|
"username": "",
|
||||||
|
}
|
||||||
assert result1 in credentials
|
assert result1 in credentials
|
||||||
assert result2 in credentials
|
assert result2 in credentials
|
||||||
assert result3 in credentials
|
assert result3 in credentials
|
||||||
assert result4 in credentials
|
assert result4 in credentials
|
||||||
|
assert result5 in credentials
|
||||||
|
|
Loading…
Reference in New Issue