diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/__init__.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/__init__.py index e69de29bb..034f2e83b 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/__init__.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/__init__.py @@ -0,0 +1 @@ +from .credentials import Credentials diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py new file mode 100644 index 000000000..858f8e744 --- /dev/null +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/credentials.py @@ -0,0 +1,14 @@ +from __future__ import annotations + +from dataclasses import dataclass +from typing import Sequence + + +@dataclass(frozen=True) +class Credentials: + identities: Sequence[dict] + secrets: Sequence[dict] + + @staticmethod + def from_dict(cred_dict: dict) -> Credentials: + return Credentials(identities=cred_dict["identities"], secrets=cred_dict["secrets"]) 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 60264993d..d595300fb 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 @@ -3,10 +3,12 @@ from typing import Mapping from common.common_consts.credential_component_type import CredentialComponentType +from .credentials import Credentials from .identities.username_processor import process_username from .secrets.lm_hash_processor import process_lm_hash from .secrets.nt_hash_processor import process_nt_hash from .secrets.password_processor import process_password +from .secrets.ssh_key_processor import process_ssh_key logger = logging.getLogger(__name__) @@ -14,6 +16,7 @@ SECRET_PROCESSORS = { CredentialComponentType.PASSWORD: process_password, CredentialComponentType.NT_HASH: process_nt_hash, CredentialComponentType.LM_HASH: process_lm_hash, + CredentialComponentType.SSH_KEYPAIR: process_ssh_key, } IDENTITY_PROCESSORS = { @@ -21,11 +24,16 @@ IDENTITY_PROCESSORS = { } -def parse_credentials(credentials: Mapping): - for credential in credentials["data"]: - for identity in credential["identities"]: +def parse_credentials(credentials_dict: Mapping): + credentials = [ + Credentials(credential["identities"], credential["secrets"]) + for credential in credentials_dict["data"] + ] + + for credential in credentials: + for identity in credential.identities: credential_type = CredentialComponentType[identity["credential_type"]] - IDENTITY_PROCESSORS[credential_type](identity) - for secret in credential["secrets"]: + IDENTITY_PROCESSORS[credential_type](identity, credential) + for secret in credential.secrets: credential_type = CredentialComponentType[secret["credential_type"]] - SECRET_PROCESSORS[credential_type](secret) + SECRET_PROCESSORS[credential_type](secret, credential) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/identities/username_processor.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/identities/username_processor.py index 79b09901b..1b2febdb9 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/identities/username_processor.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/identities/username_processor.py @@ -1,5 +1,8 @@ +from typing import Mapping + from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.telemetry.processing.credentials import Credentials -def process_username(username: dict): +def process_username(username: Mapping, _: Credentials): ConfigService.creds_add_username(username["username"]) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/lm_hash_processor.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/lm_hash_processor.py index 7c5d5f3fa..4939c81bf 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/lm_hash_processor.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/lm_hash_processor.py @@ -1,5 +1,8 @@ +from typing import Mapping + from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.telemetry.processing.credentials import Credentials -def process_lm_hash(lm_hash: dict): +def process_lm_hash(lm_hash: Mapping, _: Credentials): ConfigService.creds_add_lm_hash(lm_hash["lm_hash"]) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/nt_hash_processor.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/nt_hash_processor.py index e29e2eef0..82f82af89 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/nt_hash_processor.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/nt_hash_processor.py @@ -1,5 +1,8 @@ +from typing import Mapping + from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.telemetry.processing.credentials import Credentials -def process_nt_hash(nt_hash: dict): +def process_nt_hash(nt_hash: Mapping, _: Credentials): ConfigService.creds_add_ntlm_hash(nt_hash["nt_hash"]) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/password_processor.py b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/password_processor.py index 6d3331db6..6df5a33ce 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/password_processor.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/credentials/secrets/password_processor.py @@ -1,5 +1,8 @@ +from typing import Mapping + from monkey_island.cc.services.config import ConfigService +from monkey_island.cc.services.telemetry.processing.credentials import Credentials -def process_password(password: dict): +def process_password(password: Mapping, _: Credentials): ConfigService.creds_add_password(password["password"])