From 4b3750076a8a7c8110cd001eb832c282e322f2ae Mon Sep 17 00:00:00 2001 From: vakaris_zilius Date: Mon, 21 Feb 2022 12:40:11 +0000 Subject: [PATCH] Agent, Island, Common: change code to process CredentialType value Island: rename credentials_type.py --- monkey/common/common_consts/credentials_type.py | 10 +++++----- .../credential_components/lm_hash.py | 2 +- .../credential_components/nt_hash.py | 2 +- .../credential_components/password.py | 2 +- .../credential_components/ssh_keypair.py | 2 +- .../credential_components/username.py | 2 +- .../processing/credentials/credentials_parser.py | 14 +++++++------- .../credentials/secrets/ssh_key_processor.py | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) diff --git a/monkey/common/common_consts/credentials_type.py b/monkey/common/common_consts/credentials_type.py index e818b1e5c..0aeb79630 100644 --- a/monkey/common/common_consts/credentials_type.py +++ b/monkey/common/common_consts/credentials_type.py @@ -2,8 +2,8 @@ from enum import Enum class CredentialsType(Enum): - USERNAME = 1 - PASSWORD = 2 - NT_HASH = 3 - LM_HASH = 4 - SSH_KEYPAIR = 5 + USERNAME = "username" + PASSWORD = "password" + NT_HASH = "nt_hash" + LM_HASH = "lm_hash" + SSH_KEYPAIR = "ssh_keypair" diff --git a/monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py b/monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py index a7be177a8..721e5a822 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py +++ b/monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py @@ -6,5 +6,5 @@ from infection_monkey.i_puppet import ICredentialComponent @dataclass(frozen=True) class LMHash(ICredentialComponent): - credential_type: CredentialsType = field(default=CredentialsType.LM_HASH, init=False) + credential_type: CredentialsType = field(default=CredentialsType.LM_HASH.value, init=False) lm_hash: str diff --git a/monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py b/monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py index d23f42a1d..c7d0de042 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py +++ b/monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py @@ -6,5 +6,5 @@ from infection_monkey.i_puppet import ICredentialComponent @dataclass(frozen=True) class NTHash(ICredentialComponent): - credential_type: CredentialsType = field(default=CredentialsType.NT_HASH, init=False) + credential_type: CredentialsType = field(default=CredentialsType.NT_HASH.value, init=False) nt_hash: str diff --git a/monkey/infection_monkey/credential_collectors/credential_components/password.py b/monkey/infection_monkey/credential_collectors/credential_components/password.py index 19477ab18..5615c20f7 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/password.py +++ b/monkey/infection_monkey/credential_collectors/credential_components/password.py @@ -6,5 +6,5 @@ from infection_monkey.i_puppet import ICredentialComponent @dataclass(frozen=True) class Password(ICredentialComponent): - credential_type: CredentialsType = field(default=CredentialsType.PASSWORD, init=False) + credential_type: CredentialsType = field(default=CredentialsType.PASSWORD.value, init=False) password: str diff --git a/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py b/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py index 6d54dafe4..29f91a15d 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py +++ b/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py @@ -6,6 +6,6 @@ from infection_monkey.i_puppet import ICredentialComponent @dataclass(frozen=True) class SSHKeypair(ICredentialComponent): - credential_type: CredentialsType = field(default=CredentialsType.SSH_KEYPAIR, init=False) + credential_type: CredentialsType = field(default=CredentialsType.SSH_KEYPAIR.value, init=False) private_key: str public_key: str diff --git a/monkey/infection_monkey/credential_collectors/credential_components/username.py b/monkey/infection_monkey/credential_collectors/credential_components/username.py index f1587955f..7ed37e89c 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/username.py +++ b/monkey/infection_monkey/credential_collectors/credential_components/username.py @@ -6,5 +6,5 @@ from infection_monkey.i_puppet import ICredentialComponent @dataclass(frozen=True) class Username(ICredentialComponent): - credential_type: CredentialsType = field(default=CredentialsType.USERNAME, init=False) + credential_type: CredentialsType = field(default=CredentialsType.USERNAME.value, init=False) username: str diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py index cd738f4b4..47be30a63 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials_parser.py @@ -11,14 +11,14 @@ from .secrets.ssh_key_processor import process_ssh_key logger = logging.getLogger(__name__) SECRET_PROCESSORS = { - CredentialsType.PASSWORD: process_password, - CredentialsType.NT_HASH: process_nt_hash, - CredentialsType.LM_HASH: process_lm_hash, - CredentialsType.SSH_KEYPAIR: process_ssh_key, + CredentialsType.PASSWORD.value: process_password, + CredentialsType.NT_HASH.value: process_nt_hash, + CredentialsType.LM_HASH.value: process_lm_hash, + CredentialsType.SSH_KEYPAIR.value: process_ssh_key, } IDENTITY_PROCESSORS = { - CredentialsType.USERNAME: process_username, + CredentialsType.USERNAME.value: process_username, } @@ -26,7 +26,7 @@ def parse_credentials(credentials: dict): for credential in credentials["data"]: if is_ssh_keypair(credential): - SECRET_PROCESSORS[CredentialsType.SSH_KEYPAIR](credential, credentials["monkey_guid"]) + SECRET_PROCESSORS[CredentialsType.SSH_KEYPAIR.value](credential, credentials["monkey_guid"]) else: for identity in credential["identities"]: IDENTITY_PROCESSORS[identity["credential_type"]](identity) @@ -39,6 +39,6 @@ def is_ssh_keypair(credential: dict) -> bool: [ secret for secret in credential["secrets"] - if secret["credential_type"] == CredentialsType.SSH_KEYPAIR + if secret["credential_type"] == CredentialsType.SSH_KEYPAIR.value ] ) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py index 47ecc265a..61d03b2d1 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/ssh_key_processor.py @@ -17,7 +17,7 @@ def process_ssh_key(credentials: dict, monkey_guid: str): ) for ssh_key in credentials["secrets"]: - if not ssh_key["credential_type"] == CredentialsType.SSH_KEYPAIR.name: + if not ssh_key["credential_type"] == CredentialsType.SSH_KEYPAIR.value: raise SSHKeyProcessingError("SSH credentials contain secrets that are not keypairs") if not ssh_key["public_key"] or not ssh_key["private_key"]: