From be30db885bd4385d0f85e986409e7b2259008c0b Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 22 Sep 2022 11:59:46 +0200 Subject: [PATCH 1/4] Island: Add TERMINATE_AGENTS to IslandEventTopic --- monkey/monkey_island/cc/event_queue/i_island_event_queue.py | 1 + 1 file changed, 1 insertion(+) diff --git a/monkey/monkey_island/cc/event_queue/i_island_event_queue.py b/monkey/monkey_island/cc/event_queue/i_island_event_queue.py index cf123c3e2..7ecf8c01b 100644 --- a/monkey/monkey_island/cc/event_queue/i_island_event_queue.py +++ b/monkey/monkey_island/cc/event_queue/i_island_event_queue.py @@ -9,6 +9,7 @@ class IslandEventTopic(Enum): CLEAR_SIMULATION_DATA = auto() RESET_AGENT_CONFIGURATION = auto() SET_ISLAND_MODE = auto() + TERMINATE_AGENTS = auto() class IIslandEventQueue(ABC): From 560d941885c9a30b10cae3f12d4b20eb7eeb629f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 22 Sep 2022 12:00:20 +0200 Subject: [PATCH 2/4] Island: Add terminate field to Simulation model --- monkey/monkey_island/cc/models/simulation.py | 3 +++ vulture_allowlist.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/models/simulation.py b/monkey/monkey_island/cc/models/simulation.py index d04bee76b..3f52ae370 100644 --- a/monkey/monkey_island/cc/models/simulation.py +++ b/monkey/monkey_island/cc/models/simulation.py @@ -1,6 +1,8 @@ from __future__ import annotations +from datetime import datetime from enum import Enum +from typing import Optional from common.base_models import InfectionMonkeyBaseModel @@ -13,3 +15,4 @@ class IslandMode(Enum): class Simulation(InfectionMonkeyBaseModel): mode: IslandMode = IslandMode.UNSET + terminate_signal_time: Optional[datetime] = None diff --git a/vulture_allowlist.py b/vulture_allowlist.py index ef9613fca..43292e49e 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -11,7 +11,7 @@ from common.credentials import Credentials, LMHash, NTHash from common.types import SocketAddress from infection_monkey.exploit.log4shell_utils.ldap_server import LDAPServerFactory from monkey_island.cc.event_queue import IslandEventTopic, PyPubSubIslandEventQueue -from monkey_island.cc.models import Report +from monkey_island.cc.models import Report, Simulation from monkey_island.cc.models.networkmap import Arc, NetworkMap from monkey_island.cc.repository import MongoAgentRepository, MongoMachineRepository from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository @@ -328,3 +328,5 @@ CC_TUNNEL # TODO: Remove after #2323 SocketAddress + +Simulation.terminate_signal_time From 721cc295591f75b06f091b994fa413facf67b987 Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 22 Sep 2022 12:02:47 +0200 Subject: [PATCH 3/4] Island: Add AgentSignals model --- monkey/monkey_island/cc/models/__init__.py | 1 + monkey/monkey_island/cc/models/agent_signals.py | 8 ++++++++ vulture_allowlist.py | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 monkey/monkey_island/cc/models/agent_signals.py diff --git a/monkey/monkey_island/cc/models/__init__.py b/monkey/monkey_island/cc/models/__init__.py index 65e63fe14..ca4078faa 100644 --- a/monkey/monkey_island/cc/models/__init__.py +++ b/monkey/monkey_island/cc/models/__init__.py @@ -15,3 +15,4 @@ from .communication_type import CommunicationType from .node import Node from common.types import AgentID from .agent import Agent +from .agent_signals import AgentSignals diff --git a/monkey/monkey_island/cc/models/agent_signals.py b/monkey/monkey_island/cc/models/agent_signals.py new file mode 100644 index 000000000..37af7b4c1 --- /dev/null +++ b/monkey/monkey_island/cc/models/agent_signals.py @@ -0,0 +1,8 @@ +from datetime import datetime +from typing import Optional + +from common.base_models import InfectionMonkeyBaseModel + + +class AgentSignals(InfectionMonkeyBaseModel): + terminate: Optional[datetime] diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 43292e49e..742450c50 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -11,7 +11,7 @@ from common.credentials import Credentials, LMHash, NTHash from common.types import SocketAddress from infection_monkey.exploit.log4shell_utils.ldap_server import LDAPServerFactory from monkey_island.cc.event_queue import IslandEventTopic, PyPubSubIslandEventQueue -from monkey_island.cc.models import Report, Simulation +from monkey_island.cc.models import AgentSignals, Report, Simulation from monkey_island.cc.models.networkmap import Arc, NetworkMap from monkey_island.cc.repository import MongoAgentRepository, MongoMachineRepository from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository From c0afae6dfada588b76c695c49d27ab5b5df8aade Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Thu, 22 Sep 2022 12:19:15 +0200 Subject: [PATCH 4/4] Island: Add stubbed AgentSignalsService --- monkey/monkey_island/cc/services/__init__.py | 1 + .../cc/services/agent_signals_service.py | 26 +++++++++++++++++++ vulture_allowlist.py | 21 ++++++++------- 3 files changed, 38 insertions(+), 10 deletions(-) create mode 100644 monkey/monkey_island/cc/services/agent_signals_service.py diff --git a/monkey/monkey_island/cc/services/__init__.py b/monkey/monkey_island/cc/services/__init__.py index d75734d59..c73aff356 100644 --- a/monkey/monkey_island/cc/services/__init__.py +++ b/monkey/monkey_island/cc/services/__init__.py @@ -1,3 +1,4 @@ from .authentication_service import AuthenticationService from .aws import AWSService +from .agent_signals_service import AgentSignalsService diff --git a/monkey/monkey_island/cc/services/agent_signals_service.py b/monkey/monkey_island/cc/services/agent_signals_service.py new file mode 100644 index 000000000..47c677271 --- /dev/null +++ b/monkey/monkey_island/cc/services/agent_signals_service.py @@ -0,0 +1,26 @@ +from datetime import datetime + +from monkey_island.cc.models import Agent, AgentSignals +from monkey_island.cc.repository import ISimulationRepository + + +class AgentSignalsService: + def __init__(self, simulation_repository: ISimulationRepository): + self._simulation_repository = simulation_repository + + def get_signals(self, agent: Agent) -> AgentSignals: + """ + Gets the signals sent to a particular agent + + :param agent: The agent whose signals need to be retrieved + :return: Signals sent to the relevant agent + """ + return AgentSignals(timestamp=datetime.now()) + + def on_terminate_agents_signal(self, timestamp: datetime): + """ + Updates the simulation repository with the terminate signal's timestamp + + :param timestamp: Timestamp of the terminate signal + """ + pass diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 742450c50..c63b26f3e 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -8,15 +8,14 @@ from common.agent_configuration.agent_sub_configurations import ( ScanTargetConfiguration, ) from common.credentials import Credentials, LMHash, NTHash -from common.types import SocketAddress from infection_monkey.exploit.log4shell_utils.ldap_server import LDAPServerFactory from monkey_island.cc.event_queue import IslandEventTopic, PyPubSubIslandEventQueue -from monkey_island.cc.models import AgentSignals, Report, Simulation +from monkey_island.cc.models import Report, Simulation +from monkey_island.cc.models import AgentSignals, Report from monkey_island.cc.models.networkmap import Arc, NetworkMap from monkey_island.cc.repository import MongoAgentRepository, MongoMachineRepository from monkey_island.cc.repository.attack.IMitigationsRepository import IMitigationsRepository from monkey_island.cc.repository.i_agent_event_repository import IAgentEventRepository -from monkey_island.cc.repository.i_agent_log_repository import IAgentLogRepository from monkey_island.cc.repository.i_agent_repository import IAgentRepository from monkey_island.cc.repository.i_attack_repository import IAttackRepository from monkey_island.cc.repository.i_config_repository import IConfigRepository @@ -27,6 +26,7 @@ from monkey_island.cc.repository.i_simulation_repository import ISimulationRepos from monkey_island.cc.repository.ICredentials import ICredentialsRepository from monkey_island.cc.repository.zero_trust.IEventRepository import IEventRepository from monkey_island.cc.repository.zero_trust.IFindingRepository import IFindingRepository +from monkey_island.cc.services import AgentSignalsService fake_monkey_dir_path # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:37) set_os_linux # unused variable (monkey/tests/infection_monkey/post_breach/actions/test_users_custom_pba.py:37) @@ -302,11 +302,6 @@ IAgentEventRepository.get_events_by_type IAgentEventRepository.get_events_by_tag IAgentEventRepository.get_events_by_source -# TODO: Remove once #2274 is closed -IAgentLogRepository -IAgentLogRepository.upsert_agent_log -IAgentLogRepository.get_agent_log - # pydantic base models underscore_attrs_are_private @@ -326,7 +321,13 @@ EXPLOITED CC CC_TUNNEL -# TODO: Remove after #2323 -SocketAddress +IslandEventTopic.AGENT_CONNECTED +IslandEventTopic.CLEAR_SIMULATION_DATA +IslandEventTopic.RESET_AGENT_CONFIGURATION +# TODO: Remove after #2261 is closed +IslandEventTopic.TERMINATE_AGENTS Simulation.terminate_signal_time + +AgentSignalsService.get_signals +AgentSignalsService.on_terminate_agents_signal