From c817415ef38bfb6eafd8dd16ff28b491078a9899 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 20 May 2020 11:25:24 +0300 Subject: [PATCH] Fixed "is monkey running on island" check by splitting port from ip string --- monkey/infection_monkey/monkey.py | 4 +++- monkey/monkey_island/cc/network_utils.py | 7 ++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 377440a76..6dd69e0eb 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -33,6 +33,7 @@ from infection_monkey.telemetry.attack.t1106_telem import T1106Telem from common.utils.attack_utils import ScanStatus, UsageEnum from common.version import get_version from infection_monkey.exploit.HostExploiter import HostExploiter +from monkey_island.cc.network_utils import remove_port_from_ip_string MAX_DEPTH_REACHED_MESSAGE = "Reached max depth, shutting down" @@ -384,4 +385,5 @@ class InfectionMonkey(object): LOG.debug("default server set to: %s" % self._default_server) def is_started_on_island(self): - return is_running_on_server(self._default_server) and WormConfiguration.depth == WormConfiguration.max_depth + island_ip = remove_port_from_ip_string(self._default_server) + return is_running_on_server(island_ip) and WormConfiguration.depth == WormConfiguration.max_depth diff --git a/monkey/monkey_island/cc/network_utils.py b/monkey/monkey_island/cc/network_utils.py index 1c4f59e34..903485723 100644 --- a/monkey/monkey_island/cc/network_utils.py +++ b/monkey/monkey_island/cc/network_utils.py @@ -5,7 +5,7 @@ import socket import struct import sys from typing import List -import collections +from urllib.parse import urlparse from netifaces import interfaces, ifaddresses, AF_INET from ring import lru @@ -86,3 +86,8 @@ def get_subnets(): ] ) return subnets + + +def remove_port_from_ip_string(ip_string: str) -> str: + url = urlparse("http://" + ip_string) + return str(url.hostname)