From 9c41556cb0a2ce034e400df230e3da1c0a351903 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 3 Jul 2019 14:11:15 +0300 Subject: [PATCH] Fixed tunneling bug where local machine gets set as island. --- monkey/infection_monkey/monkey.py | 7 +++++-- monkey/infection_monkey/network/network_scanner.py | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 06e0f267b..572b527df 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -175,8 +175,11 @@ class InfectionMonkey(object): if monkey_tunnel: monkey_tunnel.set_tunnel_for_host(machine) if self._default_server: - machine.set_default_server(get_interface_to_target(machine.ip_addr) + - (':'+self._default_server_port if self._default_server_port else '')) + if self._network.on_island(self._default_server): + machine.set_default_server(get_interface_to_target(machine.ip_addr) + + (':'+self._default_server_port if self._default_server_port else '')) + else: + machine.set_default_server(self._default_server) LOG.debug("Default server: %s set to machine: %r" % (self._default_server, machine)) # Order exploits according to their type diff --git a/monkey/infection_monkey/network/network_scanner.py b/monkey/infection_monkey/network/network_scanner.py index 5f65e4228..837add48a 100644 --- a/monkey/infection_monkey/network/network_scanner.py +++ b/monkey/infection_monkey/network/network_scanner.py @@ -118,3 +118,6 @@ class NetworkScanner(object): if NetworkRange.get_range_obj(subnet_str).is_in_range(ip_address): return True return False + + def on_island(self, server): + return bool([x for x in self._ip_addresses if x in server])