Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3244 enable random hash in agent #3345

Merged
merged 3 commits into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions envs/monkey_zoo/blackbox/test_configurations/noop.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
ExploitationOptionsConfiguration,
ICMPScanConfiguration,
NetworkScanConfiguration,
PolymorphismConfiguration,
PropagationConfiguration,
ScanTargetConfiguration,
TCPScanConfiguration,
Expand Down Expand Up @@ -37,11 +38,16 @@
exploitation=_exploitation_configuration,
)

_polymorphism_configuration = PolymorphismConfiguration(
randomize_agent_hash=False,
)

_agent_configuration = AgentConfiguration(
keep_tunnel_open_time=0,
credentials_collectors={},
payloads={},
propagation=_propagation_configuration,
polymorphism=_polymorphism_configuration,
)
_propagation_credentials: Tuple[Credentials, ...] = tuple()

Expand Down
11 changes: 6 additions & 5 deletions monkey/common/agent_configuration/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from .agent_configuration import AgentConfiguration
from .agent_sub_configurations import (
PluginConfiguration,
ScanTargetConfiguration,
ExploitationConfiguration,
ExploitationOptionsConfiguration,
ICMPScanConfiguration,
TCPScanConfiguration,
NetworkScanConfiguration,
ExploitationOptionsConfiguration,
ExploitationConfiguration,
PluginConfiguration,
PolymorphismConfiguration,
PropagationConfiguration,
ScanTargetConfiguration,
TCPScanConfiguration,
)
from .default_agent_configuration import (
DEFAULT_AGENT_CONFIGURATION,
Expand Down
4 changes: 2 additions & 2 deletions monkey/common/agent_configuration/agent_sub_configurations.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ class PolymorphismConfiguration(MutableInfectionMonkeyBaseModel):
A configuration for polymorphism

Attributes:
:param randomized_agent_hash: If true, the Agent will emulate the property of polymorphism
:param randomize_agent_hash: If true, the Agent will emulate the property of polymorphism
that all copies have unique hashes
"""

randomized_agent_hash: bool = Field(
randomize_agent_hash: bool = Field(
title="Randomize Agent hash",
description="Emulate the property of polymorphic (or metamorphic) malware that all "
"copies have unique hashes.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
credentials_collectors=CREDENTIALS_COLLECTORS,
payloads=PAYLOAD_CONFIGURATION,
propagation=PROPAGATION_CONFIGURATION,
polymorphism=PolymorphismConfiguration(randomized_agent_hash=False),
polymorphism=PolymorphismConfiguration(randomize_agent_hash=False),
)

DEFAULT_RANSOMWARE_AGENT_CONFIGURATION = deepcopy(DEFAULT_AGENT_CONFIGURATION)
Expand Down
21 changes: 17 additions & 4 deletions monkey/infection_monkey/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
from infection_monkey.exploit import (
CachingAgentBinaryRepository,
ExploiterWrapper,
IAgentBinaryRepository,
IslandAPIAgentOTPProvider,
PolymorphicAgentBinaryRepositoryDecorator,
)
from infection_monkey.exploit.log4shell import Log4ShellExploiter
from infection_monkey.exploit.mssqlexec import MSSQLExploiter
Expand Down Expand Up @@ -378,10 +380,7 @@ def _build_puppet(self, operating_system: OperatingSystem) -> IPuppet:
# insecure permissions.
logger.debug(f"Created {self._plugin_dir} to store agent plugins")

agent_binary_repository = CachingAgentBinaryRepository(
island_api_client=self._island_api_client,
manager=self._manager,
)
agent_binary_repository = self._build_agent_binary_repository()

plugin_source_extractor = PluginSourceExtractor(self._plugin_dir)
plugin_loader = PluginLoader(
Expand Down Expand Up @@ -461,6 +460,20 @@ def _build_puppet(self, operating_system: OperatingSystem) -> IPuppet:

return puppet

def _build_agent_binary_repository(self) -> IAgentBinaryRepository:
agent_configuration = self._island_api_client.get_config()
agent_binary_repository: IAgentBinaryRepository = CachingAgentBinaryRepository(
island_api_client=self._island_api_client,
manager=self._manager,
)

if agent_configuration.polymorphism.randomize_agent_hash:
agent_binary_repository = PolymorphicAgentBinaryRepositoryDecorator(
agent_binary_repository
)

return agent_binary_repository

def _subscribe_events(self):
self._agent_event_queue.subscribe_type(
CredentialsStolenEvent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export default function UiSchema(props) {
}
},
polymorphism: {
randomized_agent_hash: {
randomize_agent_hash: {
'ui:widget': CheckboxWithMessage
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const POLYMORPHISM_SCHEMA = {
'title': 'Polymorphism',
'properties': {
'randomized_agent_hash': {
'randomize_agent_hash': {
'title': 'Randomize Agent hash',
'type': 'boolean',
'default': false
Expand Down
2 changes: 1 addition & 1 deletion monkey/tests/common/example_agent_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"credentials_collectors": {"SSHCollector": {}, "MimikatzCollector": {}}
}

POLYMORPHISM_CONFIGURATION = {"randomized_agent_hash": False}
POLYMORPHISM_CONFIGURATION = {"randomize_agent_hash": False}

AGENT_CONFIGURATION = {
"keep_tunnel_open_time": 30,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,15 @@
},
"PolymorphismConfiguration": {
"title": "PolymorphismConfiguration",
"description": "A configuration for polymorphism\n\nAttributes:\n :param randomized_agent_hash: If true, the Agent will emulate the property of polymorphism that all copies have unique hashes",
"description": "A configuration for polymorphism\n\nAttributes:\n :param randomize_agent_hash: If true, the Agent will emulate the property of polymorphism that all copies have unique hashes",
"type": "object",
"properties": {
"randomized_agent_hash": {
"randomize_agent_hash": {
"title": "Randomize Agent hash",
"default": False,
},
},
"required": ["randomized_agent_hash"],
"required": ["randomize_agent_hash"],
"additionalProperties": False,
},
},
Expand Down