From 637053e6cd40270462dd6c11352749ba08abc198 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Thu, 16 Dec 2021 15:20:38 -0500 Subject: [PATCH] Agent: Integrate VictimHostFactory with monkey.py --- monkey/infection_monkey/monkey.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 50e3bc458..4d57369cf 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -168,14 +168,30 @@ class InfectionMonkey: return local_network_interfaces def _build_master(self, local_network_interfaces: List[NetworkInterface]): + victim_host_factory = self._build_victim_host_factory(local_network_interfaces) + self._master = AutomatedMaster( MockPuppet(), LegacyTelemetryMessengerAdapter(), - VictimHostFactory(), + victim_host_factory, ControlChannel(self._default_server, GUID), local_network_interfaces, ) + def _build_victim_host_factory( + self, local_network_interfaces: List[NetworkInterface] + ) -> VictimHostFactory: + on_island = self._running_on_island(local_network_interfaces) + logger.debug(f"This agent is running on the island: {on_island}") + + return VictimHostFactory( + self._monkey_inbound_tunnel, self._default_server, self._default_server_port, on_island + ) + + def _running_on_island(self, local_network_interfaces: List[NetworkInterface]) -> bool: + server_ip = self._default_server.split(":")[0] + return server_ip in {interface.address for interface in local_network_interfaces} + def _is_another_monkey_running(self): return not self._singleton.try_lock()