forked from p15670423/monkey
Island: refactor credential parser to use Credentials object
This commit is contained in:
parent
3ff9bbe327
commit
8dd033c212
|
@ -0,0 +1 @@
|
||||||
|
from .credentials import Credentials
|
|
@ -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"])
|
|
@ -3,10 +3,12 @@ from typing import Mapping
|
||||||
|
|
||||||
from common.common_consts.credential_component_type import CredentialComponentType
|
from common.common_consts.credential_component_type import CredentialComponentType
|
||||||
|
|
||||||
|
from .credentials import Credentials
|
||||||
from .identities.username_processor import process_username
|
from .identities.username_processor import process_username
|
||||||
from .secrets.lm_hash_processor import process_lm_hash
|
from .secrets.lm_hash_processor import process_lm_hash
|
||||||
from .secrets.nt_hash_processor import process_nt_hash
|
from .secrets.nt_hash_processor import process_nt_hash
|
||||||
from .secrets.password_processor import process_password
|
from .secrets.password_processor import process_password
|
||||||
|
from .secrets.ssh_key_processor import process_ssh_key
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -14,6 +16,7 @@ SECRET_PROCESSORS = {
|
||||||
CredentialComponentType.PASSWORD: process_password,
|
CredentialComponentType.PASSWORD: process_password,
|
||||||
CredentialComponentType.NT_HASH: process_nt_hash,
|
CredentialComponentType.NT_HASH: process_nt_hash,
|
||||||
CredentialComponentType.LM_HASH: process_lm_hash,
|
CredentialComponentType.LM_HASH: process_lm_hash,
|
||||||
|
CredentialComponentType.SSH_KEYPAIR: process_ssh_key,
|
||||||
}
|
}
|
||||||
|
|
||||||
IDENTITY_PROCESSORS = {
|
IDENTITY_PROCESSORS = {
|
||||||
|
@ -21,11 +24,16 @@ IDENTITY_PROCESSORS = {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def parse_credentials(credentials: Mapping):
|
def parse_credentials(credentials_dict: Mapping):
|
||||||
for credential in credentials["data"]:
|
credentials = [
|
||||||
for identity in credential["identities"]:
|
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"]]
|
credential_type = CredentialComponentType[identity["credential_type"]]
|
||||||
IDENTITY_PROCESSORS[credential_type](identity)
|
IDENTITY_PROCESSORS[credential_type](identity, credential)
|
||||||
for secret in credential["secrets"]:
|
for secret in credential.secrets:
|
||||||
credential_type = CredentialComponentType[secret["credential_type"]]
|
credential_type = CredentialComponentType[secret["credential_type"]]
|
||||||
SECRET_PROCESSORS[credential_type](secret)
|
SECRET_PROCESSORS[credential_type](secret, credential)
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
from typing import Mapping
|
||||||
|
|
||||||
from monkey_island.cc.services.config import ConfigService
|
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"])
|
ConfigService.creds_add_username(username["username"])
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
from typing import Mapping
|
||||||
|
|
||||||
from monkey_island.cc.services.config import ConfigService
|
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"])
|
ConfigService.creds_add_lm_hash(lm_hash["lm_hash"])
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
from typing import Mapping
|
||||||
|
|
||||||
from monkey_island.cc.services.config import ConfigService
|
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"])
|
ConfigService.creds_add_ntlm_hash(nt_hash["nt_hash"])
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
from typing import Mapping
|
||||||
|
|
||||||
from monkey_island.cc.services.config import ConfigService
|
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"])
|
ConfigService.creds_add_password(password["password"])
|
||||||
|
|
Loading…
Reference in New Issue