From c21cf681a4bea4b33a1e2907389e645c8437b9f4 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Mon, 14 Feb 2022 11:41:47 +0200 Subject: [PATCH] Agent: define credential collector, credentials interfaces --- .../infection_monkey/credential_collectors/__init__.py | 0 .../credential_components/__init__.py | 0 .../credential_components/i_credential_component.py | 10 ++++++++++ .../credential_components/ntlm_hash.py | 8 ++++++++ .../credential_components/password.py | 8 ++++++++ .../credential_components/ssh_keypair.py | 8 ++++++++ .../credential_components/username.py | 8 ++++++++ .../credential_collectors/credential_types.py | 8 ++++++++ .../credential_collectors/credentials.py | 10 ++++++++++ .../credential_collectors/i_credential_collector.py | 9 +++++++++ 10 files changed, 69 insertions(+) create mode 100644 monkey/infection_monkey/credential_collectors/__init__.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_components/__init__.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_components/i_credential_component.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_components/ntlm_hash.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_components/password.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_components/username.py create mode 100644 monkey/infection_monkey/credential_collectors/credential_types.py create mode 100644 monkey/infection_monkey/credential_collectors/credentials.py create mode 100644 monkey/infection_monkey/credential_collectors/i_credential_collector.py diff --git a/monkey/infection_monkey/credential_collectors/__init__.py b/monkey/infection_monkey/credential_collectors/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/infection_monkey/credential_collectors/credential_components/__init__.py b/monkey/infection_monkey/credential_collectors/credential_components/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/infection_monkey/credential_collectors/credential_components/i_credential_component.py b/monkey/infection_monkey/credential_collectors/credential_components/i_credential_component.py new file mode 100644 index 000000000..566d3ed05 --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credential_components/i_credential_component.py @@ -0,0 +1,10 @@ +from abc import ABC +from dataclasses import dataclass + +from ..credential_types import CredentialTypes + + +@dataclass +class ICredentialComponent(ABC): + type: CredentialTypes + content: dict diff --git a/monkey/infection_monkey/credential_collectors/credential_components/ntlm_hash.py b/monkey/infection_monkey/credential_collectors/credential_components/ntlm_hash.py new file mode 100644 index 000000000..35ddae49b --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credential_components/ntlm_hash.py @@ -0,0 +1,8 @@ +from ..credential_types import CredentialTypes + +from .i_credential_component import ICredentialComponent + + +class NtlmHash(ICredentialComponent): + def __init__(self, content: dict): + super().__init__(type=CredentialTypes.NTLM_HASH, content=content) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/password.py b/monkey/infection_monkey/credential_collectors/credential_components/password.py new file mode 100644 index 000000000..fd5b71812 --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credential_components/password.py @@ -0,0 +1,8 @@ +from ..credential_types import CredentialTypes + +from .i_credential_component import ICredentialComponent + + +class Password(ICredentialComponent): + def __init__(self, content: dict): + super().__init__(type=CredentialTypes.PASSWORD, content=content) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py b/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py new file mode 100644 index 000000000..02390f781 --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py @@ -0,0 +1,8 @@ +from ..credential_types import CredentialTypes + +from .i_credential_component import ICredentialComponent + + +class SSHKeypair(ICredentialComponent): + def __init__(self, content: dict): + super().__init__(type=CredentialTypes.KEYPAIR, content=content) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/username.py b/monkey/infection_monkey/credential_collectors/credential_components/username.py new file mode 100644 index 000000000..348a6df47 --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credential_components/username.py @@ -0,0 +1,8 @@ +from ..credential_types import CredentialTypes + +from .i_credential_component import ICredentialComponent + + +class Username(ICredentialComponent): + def __init__(self, content: dict): + super().__init__(type=CredentialTypes.USERNAME, content=content) diff --git a/monkey/infection_monkey/credential_collectors/credential_types.py b/monkey/infection_monkey/credential_collectors/credential_types.py new file mode 100644 index 000000000..01b83797e --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credential_types.py @@ -0,0 +1,8 @@ +from enum import Enum + + +class CredentialTypes(Enum): + KEYPAIR = 1 + USERNAME = 2 + PASSWORD = 3 + NTLM_HASH = 4 diff --git a/monkey/infection_monkey/credential_collectors/credentials.py b/monkey/infection_monkey/credential_collectors/credentials.py new file mode 100644 index 000000000..dc7d9a375 --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/credentials.py @@ -0,0 +1,10 @@ +from dataclasses import dataclass +from typing import List + +from .credential_components.i_credential_component import ICredentialComponent + + +@dataclass +class Credentials: + identities: List[ICredentialComponent] + secrets: List[ICredentialComponent] diff --git a/monkey/infection_monkey/credential_collectors/i_credential_collector.py b/monkey/infection_monkey/credential_collectors/i_credential_collector.py new file mode 100644 index 000000000..79ef9cf8a --- /dev/null +++ b/monkey/infection_monkey/credential_collectors/i_credential_collector.py @@ -0,0 +1,9 @@ +from abc import ABC, abstractmethod + +from .credentials import Credentials + + +class ICredentialCollector(ABC): + @abstractmethod + def collect_credentials(self) -> Credentials: + pass