Skip to content

Commit

Permalink
Merge branch '3167-pluralize-credential-collectors' into develop
Browse files Browse the repository at this point in the history
Issue #3167
PR #3250
  • Loading branch information
ilija-lazoroski committed Apr 25, 2023
2 parents 40db19a + f5c7818 commit 3fbca17
Show file tree
Hide file tree
Showing 32 changed files with 97 additions and 100 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ Changelog](https://keepachangelog.com/en/1.0.0/).
### Added
- `PortScanData.open` property. #3238

### Changed
- Renamed "Credential collector" to "Credentials collector". #3167

## [2.1.0] - 2023-04-19
### Added
- Logout button. #3063
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .noop import noop_test_configuration
from .utils import (
add_credential_collectors,
add_credentials_collectors,
add_exploiters,
add_subnets,
add_tcp_ports,
Expand All @@ -33,13 +33,13 @@ def _add_subnets(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_subnets(agent_configuration, subnets)


def _add_credential_collectors(agent_configuration: AgentConfiguration) -> AgentConfiguration:
credential_collectors = [
def _add_credentials_collectors(agent_configuration: AgentConfiguration) -> AgentConfiguration:
credentials_collectors = [
PluginConfiguration(name="SSHCollector", options={}),
]

return add_credential_collectors(
agent_configuration, credential_collectors=credential_collectors
return add_credentials_collectors(
agent_configuration, credentials_collectors=credentials_collectors
)


Expand All @@ -52,7 +52,7 @@ def _add_tcp_ports(agent_configuration: AgentConfiguration) -> AgentConfiguratio
test_agent_configuration = set_keep_tunnel_open_time(test_agent_configuration, 20)
test_agent_configuration = _add_exploiters(test_agent_configuration)
test_agent_configuration = _add_subnets(test_agent_configuration)
test_agent_configuration = _add_credential_collectors(test_agent_configuration)
test_agent_configuration = _add_credentials_collectors(test_agent_configuration)
test_agent_configuration = _add_tcp_ports(test_agent_configuration)

CREDENTIALS = (
Expand Down
8 changes: 4 additions & 4 deletions envs/monkey_zoo/blackbox/test_configurations/depth_1_a.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .noop import noop_test_configuration
from .utils import (
add_credential_collectors,
add_credentials_collectors,
add_exploiters,
add_fingerprinters,
add_http_ports,
Expand Down Expand Up @@ -63,8 +63,8 @@ def _add_subnets(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_subnets(agent_configuration, subnets)


def _add_credential_collectors(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_credential_collectors(
def _add_credentials_collectors(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_credentials_collectors(
agent_configuration, [PluginConfiguration(name="MimikatzCollector", options={})]
)

Expand All @@ -86,7 +86,7 @@ def _add_http_ports(agent_configuration: AgentConfiguration) -> AgentConfigurati
test_agent_configuration = _add_fingerprinters(test_agent_configuration)
test_agent_configuration = _add_subnets(test_agent_configuration)
test_agent_configuration = _add_tcp_ports(test_agent_configuration)
test_agent_configuration = _add_credential_collectors(test_agent_configuration)
test_agent_configuration = _add_credentials_collectors(test_agent_configuration)
test_agent_configuration = _add_http_ports(test_agent_configuration)

CREDENTIALS = (
Expand Down
2 changes: 1 addition & 1 deletion envs/monkey_zoo/blackbox/test_configurations/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

_agent_configuration = AgentConfiguration(
keep_tunnel_open_time=0,
credential_collectors=[],
credentials_collectors=[],
payloads={},
propagation=_propagation_configuration,
)
Expand Down
14 changes: 3 additions & 11 deletions envs/monkey_zoo/blackbox/test_configurations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def add_exploiters(
agent_configuration: AgentConfiguration,
exploiters: Optional[Dict[str, Mapping]],
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
if not exploiters:
exploiters = {}
Expand All @@ -21,7 +20,6 @@ def add_exploiters(
def add_fingerprinters(
agent_configuration: AgentConfiguration, fingerprinters: Sequence[PluginConfiguration]
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.propagation.network_scan.fingerprinters = fingerprinters

Expand All @@ -31,7 +29,6 @@ def add_fingerprinters(
def add_tcp_ports(
agent_configuration: AgentConfiguration, tcp_ports: Sequence[int]
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.propagation.network_scan.tcp.ports = tuple(tcp_ports)

Expand All @@ -41,27 +38,24 @@ def add_tcp_ports(
def add_subnets(
agent_configuration: AgentConfiguration, subnets: Sequence[str]
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.propagation.network_scan.targets.subnets = subnets

return agent_configuration_copy


def add_credential_collectors(
agent_configuration: AgentConfiguration, credential_collectors: Sequence[PluginConfiguration]
def add_credentials_collectors(
agent_configuration: AgentConfiguration, credentials_collectors: Sequence[PluginConfiguration]
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.credential_collectors = tuple(credential_collectors)
agent_configuration_copy.credentials_collectors = tuple(credentials_collectors)

return agent_configuration_copy


def add_http_ports(
agent_configuration: AgentConfiguration, http_ports: Sequence[int]
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.propagation.exploitation.options.http_ports = http_ports

Expand All @@ -71,7 +65,6 @@ def add_http_ports(
def set_keep_tunnel_open_time(
agent_configuration: AgentConfiguration, keep_tunnel_open_time: int
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.keep_tunnel_open_time = keep_tunnel_open_time

Expand All @@ -81,7 +74,6 @@ def set_keep_tunnel_open_time(
def set_maximum_depth(
agent_configuration: AgentConfiguration, maximum_depth: int
) -> AgentConfiguration:

agent_configuration_copy = agent_configuration.copy(deep=True)
agent_configuration_copy.propagation.maximum_depth = maximum_depth

Expand Down
10 changes: 5 additions & 5 deletions envs/monkey_zoo/blackbox/test_configurations/wmi_mimikatz.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from .noop import noop_test_configuration
from .utils import (
add_credential_collectors,
add_credentials_collectors,
add_exploiters,
add_subnets,
add_tcp_ports,
Expand All @@ -32,8 +32,8 @@ def _add_subnets(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_subnets(agent_configuration, subnets)


def _add_credential_collectors(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_credential_collectors(
def _add_credentials_collectors(agent_configuration: AgentConfiguration) -> AgentConfiguration:
return add_credentials_collectors(
agent_configuration, [PluginConfiguration(name="MimikatzCollector", options={})]
)

Expand All @@ -46,9 +46,9 @@ def _add_tcp_ports(agent_configuration: AgentConfiguration) -> AgentConfiguratio
test_agent_configuration = set_maximum_depth(noop_test_configuration.agent_configuration, 1)
test_agent_configuration = _add_exploiters(test_agent_configuration)
test_agent_configuration = _add_subnets(test_agent_configuration)
test_agent_configuration = _add_credential_collectors(test_agent_configuration)
test_agent_configuration = _add_credentials_collectors(test_agent_configuration)
test_agent_configuration = _add_tcp_ports(test_agent_configuration)
test_agent_configuration = _add_credential_collectors(test_agent_configuration)
test_agent_configuration = _add_credentials_collectors(test_agent_configuration)

CREDENTIALS = (
Credentials(identity=Username(username="Administrator"), secret=None),
Expand Down
6 changes: 3 additions & 3 deletions monkey/common/agent_configuration/agent_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ class AgentConfiguration(MutableInfectionMonkeyBaseModel):
"seconds)",
default=30,
)
credential_collectors: Tuple[PluginConfiguration, ...] = Field(
title="Credential collectors",
description="Configure options for the attack’s credential collection stage",
credentials_collectors: Tuple[PluginConfiguration, ...] = Field(
title="Credentials collectors",
description="Configure options for the attack’s credentials collection stage",
)
payloads: Dict[str, Dict] = Field(
title="Payloads", description="Configure payloads that Agents will execute"
Expand Down
10 changes: 5 additions & 5 deletions monkey/common/agent_configuration/default_agent_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
TCPScanConfiguration,
)

CREDENTIAL_COLLECTORS = ("MimikatzCollector", "SSHCollector")
CREDENTIALS_COLLECTORS = ("MimikatzCollector", "SSHCollector")

CREDENTIAL_COLLECTOR_CONFIGURATION = tuple(
PluginConfiguration(name=collector, options={}) for collector in CREDENTIAL_COLLECTORS
CREDENTIALS_COLLECTOR_CONFIGURATION = tuple(
PluginConfiguration(name=collector, options={}) for collector in CREDENTIALS_COLLECTORS
)

RANSOMWARE_OPTIONS = {
Expand Down Expand Up @@ -93,10 +93,10 @@

DEFAULT_AGENT_CONFIGURATION = AgentConfiguration(
keep_tunnel_open_time=30,
credential_collectors=CREDENTIAL_COLLECTOR_CONFIGURATION,
credentials_collectors=CREDENTIALS_COLLECTOR_CONFIGURATION,
payloads=PAYLOAD_CONFIGURATION,
propagation=PROPAGATION_CONFIGURATION,
)

DEFAULT_RANSOMWARE_AGENT_CONFIGURATION = deepcopy(DEFAULT_AGENT_CONFIGURATION)
DEFAULT_RANSOMWARE_AGENT_CONFIGURATION.credential_collectors = tuple()
DEFAULT_RANSOMWARE_AGENT_CONFIGURATION.credentials_collectors = tuple()
2 changes: 1 addition & 1 deletion monkey/common/agent_plugins/agent_plugin_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class AgentPluginManifest(InfectionMonkeyBaseModel):
Attributes:
:param name: Plugin name in snake case
:param plugin_type: Type of the plugin (exploiter, fingerprinter,
credential collector, etc.)
credentials collector, etc.)
:param supported_operating_systems: Operating systems that the plugin can run on
:param target_operating_systems: Operating systems that the plugin can target
:param title: Human readable name for the plugin
Expand Down
2 changes: 1 addition & 1 deletion monkey/common/agent_plugins/agent_plugin_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


class AgentPluginType(Enum):
CREDENTIAL_COLLECTOR = "CredentialCollector"
CREDENTIALS_COLLECTOR = "Credentials_Collector"
EXPLOITER = "Exploiter"
FINGERPRINTER = "Fingerprinter"
PAYLOAD = "Payload"
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from common.agent_plugins import AgentPluginManifest, AgentPluginType
from common.operating_system import OperatingSystem

HARD_CODED_CREDENTIAL_COLLECTOR_MANIFESTS = {
HARD_CODED_CREDENTIALS_COLLECTOR_MANIFESTS = {
"MimikatzCollector": AgentPluginManifest(
name="MimikatzCollector",
plugin_type=AgentPluginType.CREDENTIAL_COLLECTOR,
plugin_type=AgentPluginType.CREDENTIALS_COLLECTOR,
supported_operating_systems=(OperatingSystem.LINUX, OperatingSystem.WINDOWS),
target_operating_systems=(OperatingSystem.WINDOWS,),
title="Mimikatz Credentials Collector",
Expand All @@ -14,7 +14,7 @@
),
"SSHCollector": AgentPluginManifest(
name="SSHCollector",
plugin_type=AgentPluginType.CREDENTIAL_COLLECTOR,
plugin_type=AgentPluginType.CREDENTIALS_COLLECTOR,
supported_operating_systems=(OperatingSystem.LINUX, OperatingSystem.WINDOWS),
target_operating_systems=(OperatingSystem.LINUX,),
title="SSH Credentials Collector",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from common.event_queue import IAgentEventQueue
from common.tags import DATA_FROM_LOCAL_SYSTEM_T1005_TAG, OS_CREDENTIAL_DUMPING_T1003_TAG
from common.types import AgentID
from infection_monkey.i_puppet import ICredentialCollector
from infection_monkey.i_puppet import ICredentialsCollector
from infection_monkey.model import USERNAME_PREFIX

from . import pypykatz_handler
Expand All @@ -26,7 +26,7 @@
)


class MimikatzCredentialCollector(ICredentialCollector):
class MimikatzCredentialCollector(ICredentialsCollector):
def __init__(self, agent_event_queue: IAgentEventQueue, agent_id: AgentID):
self._agent_event_queue = agent_event_queue
self._agent_id = agent_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
from common.event_queue import IAgentEventQueue
from common.types import AgentID
from infection_monkey.credential_collectors.ssh_collector import ssh_handler
from infection_monkey.i_puppet import ICredentialCollector
from infection_monkey.i_puppet import ICredentialsCollector

logger = logging.getLogger(__name__)


class SSHCredentialCollector(ICredentialCollector):
class SSHCredentialCollector(ICredentialsCollector):
"""
SSH keys credential collector
"""
Expand Down
2 changes: 1 addition & 1 deletion monkey/infection_monkey/i_puppet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
IncompatibleOperatingSystemError,
)
from .i_fingerprinter import IFingerprinter
from .i_credential_collector import ICredentialCollector
from .i_credentials_collector import ICredentialsCollector
from .target_host import TargetHost, TargetHostPorts, PortScanDataDict
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from common.credentials import Credentials


class ICredentialCollector(ABC):
class ICredentialsCollector(ABC):
@abstractmethod
def collect_credentials(self, options: Optional[Mapping]) -> Sequence[Credentials]:
pass
8 changes: 4 additions & 4 deletions monkey/infection_monkey/i_puppet/i_puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def load_plugin(self, plugin_type: AgentPluginType, plugin_name: str, plugin: ob
"""

@abc.abstractmethod
def run_credential_collector(self, name: str, options: Dict) -> Sequence[Credentials]:
def run_credentials_collector(self, name: str, options: Dict) -> Sequence[Credentials]:
"""
Runs a credential collector
Runs a credentials collector
:param str name: The name of the credential collector to run
:param str name: The name of the credentials collector to run
:param Dict options: A dictionary containing options that modify the behavior of the
Credential collector
Credentials collector
:return: A sequence of Credentials that have been collected from the system
:rtype: Sequence[Credentials]
"""
Expand Down
14 changes: 7 additions & 7 deletions monkey/infection_monkey/master/automated_master.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,19 +126,19 @@ def _run_simulation(self):
logger.error(f"An error occurred while fetching configuration: {e}")
return

credential_collector_thread = create_daemon_thread(
credentials_collector_thread = create_daemon_thread(
target=self._run_plugins_legacy,
name="CredentialCollectorThread",
name="CredentialsCollectorThread",
args=(
config.credential_collectors,
"credential collector",
config.credentials_collectors,
"credentials collector",
self._collect_credentials,
),
)
# We don't need to use multithreading here, but it's likely that in the
# future we'll like to run other tasks while credentials are being collected
credential_collector_thread.start()
credential_collector_thread.join()
credentials_collector_thread.start()
credentials_collector_thread.join()

current_depth = self._current_depth if self._current_depth is not None else 0
logger.info(f"Current depth is {current_depth}")
Expand All @@ -157,7 +157,7 @@ def _run_simulation(self):
payload_thread.join()

def _collect_credentials(self, collector: PluginConfiguration):
credentials = self._puppet.run_credential_collector(collector.name, collector.options)
credentials = self._puppet.run_credentials_collector(collector.name, collector.options)

if not credentials:
logger.debug(f"No credentials were collected by {collector}")
Expand Down
4 changes: 2 additions & 2 deletions monkey/infection_monkey/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,12 +406,12 @@ def _build_puppet(self, operating_system: OperatingSystem) -> IPuppet:
)

puppet.load_plugin(
AgentPluginType.CREDENTIAL_COLLECTOR,
AgentPluginType.CREDENTIALS_COLLECTOR,
"MimikatzCollector",
MimikatzCredentialCollector(self._agent_event_queue, self._agent_id),
)
puppet.load_plugin(
AgentPluginType.CREDENTIAL_COLLECTOR,
AgentPluginType.CREDENTIALS_COLLECTOR,
"SSHCollector",
SSHCredentialCollector(self._agent_event_queue, self._agent_id),
)
Expand Down
8 changes: 4 additions & 4 deletions monkey/infection_monkey/puppet/puppet.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ def __init__(
def load_plugin(self, plugin_type: AgentPluginType, plugin_name: str, plugin: object) -> None:
self._plugin_registry.load_plugin(plugin_type, plugin_name, plugin)

def run_credential_collector(self, name: str, options: Dict) -> Sequence[Credentials]:
credential_collector = self._plugin_registry.get_plugin(
AgentPluginType.CREDENTIAL_COLLECTOR, name
def run_credentials_collector(self, name: str, options: Dict) -> Sequence[Credentials]:
credentials_collector = self._plugin_registry.get_plugin(
AgentPluginType.CREDENTIALS_COLLECTOR, name
)
return credential_collector.collect_credentials(options)
return credentials_collector.collect_credentials(options)

def ping(self, host: str, timeout: float = CONNECTION_TIMEOUT) -> PingScanData:
return network_scanning.ping(host, timeout, self._agent_event_queue, self._agent_id)
Expand Down
Loading

0 comments on commit 3fbca17

Please sign in to comment.