diff --git a/monkey/common/credentials/__init__.py b/monkey/common/credentials/__init__.py new file mode 100644 index 000000000..92a778886 --- /dev/null +++ b/monkey/common/credentials/__init__.py @@ -0,0 +1,8 @@ +from .credential_component_type import CredentialComponentType +from .i_credential_component import ICredentialComponent +from .credentials import Credentials +from .lm_hash import LMHash +from .nt_hash import NTHash +from .password import Password +from .ssh_keypair import SSHKeypair +from .username import Username diff --git a/monkey/common/common_consts/credential_component_type.py b/monkey/common/credentials/credential_component_type.py similarity index 100% rename from monkey/common/common_consts/credential_component_type.py rename to monkey/common/credentials/credential_component_type.py diff --git a/monkey/infection_monkey/i_puppet/credential_collection/credentials.py b/monkey/common/credentials/credentials.py similarity index 100% rename from monkey/infection_monkey/i_puppet/credential_collection/credentials.py rename to monkey/common/credentials/credentials.py diff --git a/monkey/infection_monkey/i_puppet/credential_collection/i_credential_component.py b/monkey/common/credentials/i_credential_component.py similarity index 68% rename from monkey/infection_monkey/i_puppet/credential_collection/i_credential_component.py rename to monkey/common/credentials/i_credential_component.py index c4471ebfb..03dc75604 100644 --- a/monkey/infection_monkey/i_puppet/credential_collection/i_credential_component.py +++ b/monkey/common/credentials/i_credential_component.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod -from common.common_consts.credential_component_type import CredentialComponentType +from . import CredentialComponentType class ICredentialComponent(ABC): diff --git a/monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py b/monkey/common/credentials/lm_hash.py similarity index 62% rename from monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py rename to monkey/common/credentials/lm_hash.py index 5e89891ec..818999244 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/lm_hash.py +++ b/monkey/common/credentials/lm_hash.py @@ -1,7 +1,6 @@ from dataclasses import dataclass, field -from common.common_consts.credential_component_type import CredentialComponentType -from infection_monkey.i_puppet import ICredentialComponent +from . import CredentialComponentType, ICredentialComponent @dataclass(frozen=True) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py b/monkey/common/credentials/nt_hash.py similarity index 62% rename from monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py rename to monkey/common/credentials/nt_hash.py index 7e2328699..67246f695 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/nt_hash.py +++ b/monkey/common/credentials/nt_hash.py @@ -1,7 +1,6 @@ from dataclasses import dataclass, field -from common.common_consts.credential_component_type import CredentialComponentType -from infection_monkey.i_puppet import ICredentialComponent +from . import CredentialComponentType, ICredentialComponent @dataclass(frozen=True) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/password.py b/monkey/common/credentials/password.py similarity index 63% rename from monkey/infection_monkey/credential_collectors/credential_components/password.py rename to monkey/common/credentials/password.py index 3601511af..ff6da0eae 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/password.py +++ b/monkey/common/credentials/password.py @@ -1,7 +1,6 @@ from dataclasses import dataclass, field -from common.common_consts.credential_component_type import CredentialComponentType -from infection_monkey.i_puppet import ICredentialComponent +from . import CredentialComponentType, ICredentialComponent @dataclass(frozen=True) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py b/monkey/common/credentials/ssh_keypair.py similarity index 65% rename from monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py rename to monkey/common/credentials/ssh_keypair.py index 16b943ea6..897acba8a 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/ssh_keypair.py +++ b/monkey/common/credentials/ssh_keypair.py @@ -1,7 +1,6 @@ from dataclasses import dataclass, field -from common.common_consts.credential_component_type import CredentialComponentType -from infection_monkey.i_puppet import ICredentialComponent +from . import CredentialComponentType, ICredentialComponent @dataclass(frozen=True) diff --git a/monkey/infection_monkey/credential_collectors/credential_components/username.py b/monkey/common/credentials/username.py similarity index 63% rename from monkey/infection_monkey/credential_collectors/credential_components/username.py rename to monkey/common/credentials/username.py index e7d55aa6f..c3249058e 100644 --- a/monkey/infection_monkey/credential_collectors/credential_components/username.py +++ b/monkey/common/credentials/username.py @@ -1,7 +1,6 @@ from dataclasses import dataclass, field -from common.common_consts.credential_component_type import CredentialComponentType -from infection_monkey.i_puppet import ICredentialComponent +from . import CredentialComponentType, ICredentialComponent @dataclass(frozen=True) diff --git a/monkey/infection_monkey/credential_collectors/__init__.py b/monkey/infection_monkey/credential_collectors/__init__.py index 1f259949d..9048197b3 100644 --- a/monkey/infection_monkey/credential_collectors/__init__.py +++ b/monkey/infection_monkey/credential_collectors/__init__.py @@ -1,7 +1,2 @@ -from .credential_components.nt_hash import NTHash -from .credential_components.lm_hash import LMHash -from .credential_components.password import Password -from .credential_components.username import Username -from .credential_components.ssh_keypair import SSHKeypair from .mimikatz_collector import MimikatzCredentialCollector from .ssh_collector import SSHCredentialCollector diff --git a/monkey/infection_monkey/credential_collectors/credential_components/__init__.py b/monkey/infection_monkey/credential_collectors/credential_components/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/monkey/infection_monkey/credential_collectors/mimikatz_collector/mimikatz_credential_collector.py b/monkey/infection_monkey/credential_collectors/mimikatz_collector/mimikatz_credential_collector.py index 27fb26498..9dc590aeb 100644 --- a/monkey/infection_monkey/credential_collectors/mimikatz_collector/mimikatz_credential_collector.py +++ b/monkey/infection_monkey/credential_collectors/mimikatz_collector/mimikatz_credential_collector.py @@ -1,8 +1,8 @@ import logging from typing import Sequence -from infection_monkey.credential_collectors import LMHash, NTHash, Password, Username -from infection_monkey.i_puppet.credential_collection import Credentials, ICredentialCollector +from common.credentials import Credentials, LMHash, NTHash, Password, Username +from infection_monkey.i_puppet.credential_collection import ICredentialCollector from infection_monkey.model import USERNAME_PREFIX from . import pypykatz_handler diff --git a/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_credential_collector.py b/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_credential_collector.py index 69afd68f6..35bd401f4 100644 --- a/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_credential_collector.py +++ b/monkey/infection_monkey/credential_collectors/ssh_collector/ssh_credential_collector.py @@ -1,9 +1,9 @@ import logging from typing import Dict, Iterable, Sequence -from infection_monkey.credential_collectors import SSHKeypair, Username +from common.credentials import Credentials, SSHKeypair, Username from infection_monkey.credential_collectors.ssh_collector import ssh_handler -from infection_monkey.i_puppet.credential_collection import Credentials, ICredentialCollector +from infection_monkey.i_puppet.credential_collection import ICredentialCollector from infection_monkey.telemetry.messengers.i_telemetry_messenger import ITelemetryMessenger logger = logging.getLogger(__name__) diff --git a/monkey/infection_monkey/credential_store/aggregating_credentials_store.py b/monkey/infection_monkey/credential_store/aggregating_credentials_store.py index 47f097dad..6ff6bb288 100644 --- a/monkey/infection_monkey/credential_store/aggregating_credentials_store.py +++ b/monkey/infection_monkey/credential_store/aggregating_credentials_store.py @@ -1,10 +1,9 @@ import logging from typing import Any, Iterable, Mapping -from common.common_consts.credential_component_type import CredentialComponentType +from common.credentials import CredentialComponentType, Credentials from infection_monkey.custom_types import PropagationCredentials from infection_monkey.i_control_channel import IControlChannel -from infection_monkey.i_puppet import Credentials from infection_monkey.utils.decorators import request_cache from .i_credentials_store import ICredentialsStore diff --git a/monkey/infection_monkey/credential_store/i_credentials_store.py b/monkey/infection_monkey/credential_store/i_credentials_store.py index 711c77a89..15486afb4 100644 --- a/monkey/infection_monkey/credential_store/i_credentials_store.py +++ b/monkey/infection_monkey/credential_store/i_credentials_store.py @@ -1,8 +1,8 @@ import abc from typing import Iterable +from common.credentials import Credentials from infection_monkey.custom_types import PropagationCredentials -from infection_monkey.i_puppet import Credentials class ICredentialsStore(metaclass=abc.ABCMeta): diff --git a/monkey/infection_monkey/exploit/zerologon.py b/monkey/infection_monkey/exploit/zerologon.py index 9be006d8e..1665d551c 100644 --- a/monkey/infection_monkey/exploit/zerologon.py +++ b/monkey/infection_monkey/exploit/zerologon.py @@ -16,7 +16,7 @@ from impacket.dcerpc.v5 import epm, nrpc, rpcrt, transport from impacket.dcerpc.v5.dtypes import NULL from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT -from infection_monkey.credential_collectors import LMHash, NTHash, Username +from common.credentials import Credentials, LMHash, NTHash, Username from infection_monkey.exploit.HostExploiter import HostExploiter from infection_monkey.exploit.tools.wmi_tools import WmiTools from infection_monkey.exploit.zerologon_utils.dump_secrets import DumpSecrets @@ -24,7 +24,6 @@ from infection_monkey.exploit.zerologon_utils.options import OptionsForSecretsdu from infection_monkey.exploit.zerologon_utils.vuln_assessment import get_dc_details, is_exploitable from infection_monkey.exploit.zerologon_utils.wmiexec import Wmiexec from infection_monkey.i_puppet import ExploiterResultData -from infection_monkey.i_puppet.credential_collection import Credentials from infection_monkey.telemetry.credentials_telem import CredentialsTelem from infection_monkey.utils.capture_output import StdoutCapture from infection_monkey.utils.threading import interruptible_iter diff --git a/monkey/infection_monkey/i_puppet/__init__.py b/monkey/infection_monkey/i_puppet/__init__.py index 767826297..c4e6b5b1c 100644 --- a/monkey/infection_monkey/i_puppet/__init__.py +++ b/monkey/infection_monkey/i_puppet/__init__.py @@ -10,8 +10,3 @@ from .i_puppet import ( UnknownPluginError, ) from .i_fingerprinter import IFingerprinter -from .credential_collection import ( - Credentials, - ICredentialCollector, - ICredentialComponent, -) diff --git a/monkey/infection_monkey/i_puppet/credential_collection/__init__.py b/monkey/infection_monkey/i_puppet/credential_collection/__init__.py index a97d8373f..ba2c18466 100644 --- a/monkey/infection_monkey/i_puppet/credential_collection/__init__.py +++ b/monkey/infection_monkey/i_puppet/credential_collection/__init__.py @@ -1,3 +1 @@ from .i_credential_collector import ICredentialCollector -from .credentials import Credentials -from .i_credential_component import ICredentialComponent diff --git a/monkey/infection_monkey/i_puppet/credential_collection/i_credential_collector.py b/monkey/infection_monkey/i_puppet/credential_collection/i_credential_collector.py index 0cbd2578b..02d7677ac 100644 --- a/monkey/infection_monkey/i_puppet/credential_collection/i_credential_collector.py +++ b/monkey/infection_monkey/i_puppet/credential_collection/i_credential_collector.py @@ -1,7 +1,7 @@ from abc import ABC, abstractmethod from typing import Mapping, Optional, Sequence -from .credentials import Credentials +from common.credentials import Credentials class ICredentialCollector(ABC): diff --git a/monkey/infection_monkey/i_puppet/i_puppet.py b/monkey/infection_monkey/i_puppet/i_puppet.py index 7a755e41f..e949ac373 100644 --- a/monkey/infection_monkey/i_puppet/i_puppet.py +++ b/monkey/infection_monkey/i_puppet/i_puppet.py @@ -5,10 +5,10 @@ from dataclasses import dataclass from enum import Enum from typing import Dict, Iterable, List, Mapping, Sequence +from common.credentials import Credentials from infection_monkey.model import VictimHost from . import PluginType -from .credential_collection import Credentials class PortStatus(Enum): diff --git a/monkey/infection_monkey/puppet/puppet.py b/monkey/infection_monkey/puppet/puppet.py index c7953d83c..ec77ffa35 100644 --- a/monkey/infection_monkey/puppet/puppet.py +++ b/monkey/infection_monkey/puppet/puppet.py @@ -3,9 +3,9 @@ import threading from typing import Dict, Iterable, List, Sequence from common.common_consts.timeouts import CONNECTION_TIMEOUT +from common.credentials import Credentials from infection_monkey import network_scanning from infection_monkey.i_puppet import ( - Credentials, ExploiterResultData, FingerprintData, IPuppet, diff --git a/monkey/infection_monkey/telemetry/credentials_telem.py b/monkey/infection_monkey/telemetry/credentials_telem.py index 4f5c43aa4..11e2bbb6d 100644 --- a/monkey/infection_monkey/telemetry/credentials_telem.py +++ b/monkey/infection_monkey/telemetry/credentials_telem.py @@ -3,7 +3,7 @@ import json from typing import Dict, Iterable from common.common_consts.telem_categories import TelemCategoryEnum -from infection_monkey.i_puppet.credential_collection import Credentials, ICredentialComponent +from common.credentials import Credentials, ICredentialComponent from infection_monkey.telemetry.base_telem import BaseTelem diff --git a/monkey/monkey_island/cc/services/reporting/stolen_credentials.py b/monkey/monkey_island/cc/services/reporting/stolen_credentials.py index a1f596ad5..2a817ac75 100644 --- a/monkey/monkey_island/cc/services/reporting/stolen_credentials.py +++ b/monkey/monkey_island/cc/services/reporting/stolen_credentials.py @@ -1,7 +1,7 @@ import logging from typing import Mapping, Sequence -from common.common_consts.credential_component_type import CredentialComponentType +from common.credentials import CredentialComponentType from monkey_island.cc.models import StolenCredentials logger = logging.getLogger(__name__) 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 5c6d15631..8ab905ce6 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 @@ -2,7 +2,7 @@ import logging from itertools import chain from typing import Mapping -from common.common_consts.credential_component_type import CredentialComponentType +from common.credentials import CredentialComponentType from monkey_island.cc.models import StolenCredentials from .credentials import Credentials diff --git a/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_mimikatz_collector.py b/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_mimikatz_collector.py index 20eca62c7..f87dea93c 100644 --- a/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_mimikatz_collector.py +++ b/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_mimikatz_collector.py @@ -2,17 +2,11 @@ from typing import Sequence import pytest -from infection_monkey.credential_collectors import ( - LMHash, - MimikatzCredentialCollector, - NTHash, - Password, - Username, -) +from common.credentials import Credentials, LMHash, NTHash, Password, Username +from infection_monkey.credential_collectors import MimikatzCredentialCollector from infection_monkey.credential_collectors.mimikatz_collector.windows_credentials import ( WindowsCredentials, ) -from infection_monkey.i_puppet import Credentials def patch_pypykatz(win_creds: [WindowsCredentials], monkeypatch): diff --git a/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_ssh_credentials_collector.py b/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_ssh_credentials_collector.py index 4b344d9b0..17ca7ddc7 100644 --- a/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_ssh_credentials_collector.py +++ b/monkey/tests/unit_tests/infection_monkey/credential_collectors/test_ssh_credentials_collector.py @@ -2,8 +2,8 @@ from unittest.mock import MagicMock import pytest -from infection_monkey.credential_collectors import SSHCredentialCollector, SSHKeypair, Username -from infection_monkey.i_puppet.credential_collection import Credentials +from common.credentials import Credentials, SSHKeypair, Username +from infection_monkey.credential_collectors import SSHCredentialCollector @pytest.fixture diff --git a/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py b/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py index d2c1746e4..baff7df65 100644 --- a/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py +++ b/monkey/tests/unit_tests/infection_monkey/credential_store/test_aggregating_credentials_store.py @@ -2,9 +2,8 @@ from unittest.mock import MagicMock import pytest -from infection_monkey.credential_collectors import Password, SSHKeypair, Username +from common.credentials import Credentials, Password, SSHKeypair, Username from infection_monkey.credential_store import AggregatingCredentialsStore -from infection_monkey.i_puppet import Credentials CONTROL_CHANNEL_CREDENTIALS = { "exploit_user_list": ["Administrator", "root", "user1"], diff --git a/monkey/tests/unit_tests/infection_monkey/master/mock_puppet.py b/monkey/tests/unit_tests/infection_monkey/master/mock_puppet.py index 4d77bd0b3..624d79471 100644 --- a/monkey/tests/unit_tests/infection_monkey/master/mock_puppet.py +++ b/monkey/tests/unit_tests/infection_monkey/master/mock_puppet.py @@ -3,9 +3,8 @@ import threading from typing import Dict, Iterable, List, Sequence from common import OperatingSystems -from infection_monkey.credential_collectors import LMHash, Password, SSHKeypair, Username +from common.credentials import Credentials, LMHash, Password, SSHKeypair, Username from infection_monkey.i_puppet import ( - Credentials, ExploiterResultData, FingerprintData, IPuppet, diff --git a/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_credentials_intercepting_telemetry_messenger.py b/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_credentials_intercepting_telemetry_messenger.py index 7481bff34..e516baab8 100644 --- a/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_credentials_intercepting_telemetry_messenger.py +++ b/monkey/tests/unit_tests/infection_monkey/telemetry/messengers/test_credentials_intercepting_telemetry_messenger.py @@ -1,7 +1,6 @@ from unittest.mock import MagicMock -from infection_monkey.credential_collectors import Password, SSHKeypair, Username -from infection_monkey.i_puppet import Credentials +from common.credentials import Credentials, Password, SSHKeypair, Username from infection_monkey.telemetry.credentials_telem import CredentialsTelem from infection_monkey.telemetry.messengers.credentials_intercepting_telemetry_messenger import ( CredentialsInterceptingTelemetryMessenger, diff --git a/monkey/tests/unit_tests/infection_monkey/telemetry/test_credentials_telem.py b/monkey/tests/unit_tests/infection_monkey/telemetry/test_credentials_telem.py index 13c93f60f..5fca80eff 100644 --- a/monkey/tests/unit_tests/infection_monkey/telemetry/test_credentials_telem.py +++ b/monkey/tests/unit_tests/infection_monkey/telemetry/test_credentials_telem.py @@ -2,8 +2,7 @@ import json import pytest -from infection_monkey.credential_collectors import Password, SSHKeypair, Username -from infection_monkey.i_puppet import Credentials +from common.credentials import Credentials, Password, SSHKeypair, Username from infection_monkey.telemetry.credentials_telem import CredentialsTelem USERNAME = "m0nkey" diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/reporting/test_stolen_credentials.py b/monkey/tests/unit_tests/monkey_island/cc/services/reporting/test_stolen_credentials.py index 7a0e0aeca..d7c2386c9 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/reporting/test_stolen_credentials.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/reporting/test_stolen_credentials.py @@ -1,6 +1,6 @@ import pytest -from common.common_consts.credential_component_type import CredentialComponentType +from common.credentials import CredentialComponentType from monkey_island.cc.models import Monkey, StolenCredentials from monkey_island.cc.services.reporting.stolen_credentials import ( extract_ssh_keys, diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py index 5fcccc7a0..d12ba15e4 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/credentials/test_credential_processing.py @@ -6,13 +6,13 @@ from tests.unit_tests.monkey_island.cc.services.telemetry.processing.credentials CREDENTIAL_TELEM_TEMPLATE, ) -from common.common_consts.credential_component_type import CredentialComponentType from common.config_value_paths import ( LM_HASH_LIST_PATH, NTLM_HASH_LIST_PATH, PASSWORD_LIST_PATH, USER_LIST_PATH, ) +from common.credentials import CredentialComponentType from monkey_island.cc.models import StolenCredentials from monkey_island.cc.services.config import ConfigService from monkey_island.cc.services.telemetry.processing.credentials.credentials_parser import (