From 52d0e6f655c64bda06a03856122f02e5636d0afe Mon Sep 17 00:00:00 2001 From: vakarisz Date: Fri, 23 Sep 2022 12:25:00 +0300 Subject: [PATCH] Agent, Island: Rename get_my_ip_address to legacy --- monkey/common/network/network_utils.py | 2 +- monkey/infection_monkey/control.py | 4 ++-- monkey/infection_monkey/monkey.py | 4 ++-- monkey/monkey_island/cc/models/monkey.py | 4 ++-- monkey/monkey_island/cc/server_setup.py | 4 ++-- monkey/monkey_island/cc/services/node.py | 10 +++++----- monkey/monkey_island/cc/services/reporting/report.py | 4 ++-- 7 files changed, 16 insertions(+), 16 deletions(-) diff --git a/monkey/common/network/network_utils.py b/monkey/common/network/network_utils.py index f04e5a64e..ce8002d0c 100644 --- a/monkey/common/network/network_utils.py +++ b/monkey/common/network/network_utils.py @@ -5,7 +5,7 @@ from typing import List, Optional, Sequence, Tuple from netifaces import AF_INET, ifaddresses, interfaces -def get_my_ip_addresses() -> Sequence[str]: +def get_my_ip_addresses_legacy() -> Sequence[str]: return [str(interface.ip) for interface in get_network_interfaces()] diff --git a/monkey/infection_monkey/control.py b/monkey/infection_monkey/control.py index 440f58712..4b0361608 100644 --- a/monkey/infection_monkey/control.py +++ b/monkey/infection_monkey/control.py @@ -7,7 +7,7 @@ import requests from urllib3 import disable_warnings from common.common_consts.timeouts import MEDIUM_REQUEST_TIMEOUT -from common.network.network_utils import get_my_ip_addresses +from common.network.network_utils import get_my_ip_addresses_legacy from infection_monkey.config import GUID from infection_monkey.island_api_client import IIslandAPIClient from infection_monkey.network.info import get_host_subnets @@ -39,7 +39,7 @@ class ControlClient: monkey = { "guid": GUID, "hostname": hostname, - "ip_addresses": get_my_ip_addresses(), + "ip_addresses": get_my_ip_addresses_legacy(), "networks": get_host_subnets(), "description": " ".join(platform.uname()), "parent": parent, diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 3bb75bc7e..c4b8d8871 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -18,7 +18,7 @@ from common.agent_registration_data import AgentRegistrationData from common.event_queue import IAgentEventQueue, PyPubSubAgentEventQueue from common.network.network_utils import ( address_to_ip_port, - get_my_ip_addresses, + get_my_ip_addresses_legacy, get_network_interfaces, ) from common.utils.argparse_types import positive_int @@ -236,7 +236,7 @@ class InfectionMonkey: self._cmd_island_port, client_disconnect_timeout=config.keep_tunnel_open_time, ) - relay_servers = [f"{ip}:{relay_port}" for ip in get_my_ip_addresses()] + relay_servers = [f"{ip}:{relay_port}" for ip in get_my_ip_addresses_legacy()] if not maximum_depth_reached(config.propagation.maximum_depth, self._current_depth): self._relay.start() diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index a3e96baca..f1732ed66 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -16,7 +16,7 @@ from mongoengine import ( StringField, ) -from common.network.network_utils import get_my_ip_addresses +from common.network.network_utils import get_my_ip_addresses_legacy from monkey_island.cc.models.command_control_channel import CommandControlChannel from monkey_island.cc.models.monkey_ttl import MonkeyTtl, create_monkey_ttl_document from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS @@ -123,7 +123,7 @@ class Monkey(Document): def get_label_by_id(object_id): current_monkey = Monkey.get_single_monkey_by_id(object_id) label = Monkey.get_hostname_by_id(object_id) + " : " + current_monkey.ip_addresses[0] - local_ips = map(str, get_my_ip_addresses()) + local_ips = map(str, get_my_ip_addresses_legacy()) if len(set(current_monkey.ip_addresses).intersection(local_ips)) > 0: label = "MonkeyIsland - " + label return label diff --git a/monkey/monkey_island/cc/server_setup.py b/monkey/monkey_island/cc/server_setup.py index 7b1216419..f488eff2e 100644 --- a/monkey/monkey_island/cc/server_setup.py +++ b/monkey/monkey_island/cc/server_setup.py @@ -23,7 +23,7 @@ if str(MONKEY_ISLAND_DIR_BASE_PATH) not in sys.path: sys.path.insert(0, MONKEY_ISLAND_DIR_BASE_PATH) from common import DIContainer # noqa: E402 -from common.network.network_utils import get_my_ip_addresses # noqa: E402 +from common.network.network_utils import get_my_ip_addresses_legacy # noqa: E402 from common.version import get_version # noqa: E402 from monkey_island.cc.app import init_app # noqa: E402 from monkey_island.cc.arg_parser import IslandCmdArgs # noqa: E402 @@ -103,7 +103,7 @@ def _configure_logging(config_options): def _collect_system_info() -> Tuple[Sequence[str], Deployment, Version]: deployment = _get_deployment() version = Version(get_version(), deployment) - return (get_my_ip_addresses(), deployment, version) + return (get_my_ip_addresses_legacy(), deployment, version) def _get_deployment() -> Deployment: diff --git a/monkey/monkey_island/cc/services/node.py b/monkey/monkey_island/cc/services/node.py index 0bacb53b8..d4ecd17e8 100644 --- a/monkey/monkey_island/cc/services/node.py +++ b/monkey/monkey_island/cc/services/node.py @@ -4,7 +4,7 @@ from datetime import datetime from bson import ObjectId import monkey_island.cc.services.log -from common.network.network_utils import get_my_ip_addresses +from common.network.network_utils import get_my_ip_addresses_legacy from monkey_island.cc import models from monkey_island.cc.database import mongo from monkey_island.cc.models import Monkey @@ -110,7 +110,7 @@ class NodeService: def get_monkey_label(monkey): # todo label = monkey["hostname"] + " : " + monkey["ip_addresses"][0] - ip_addresses = get_my_ip_addresses() + ip_addresses = get_my_ip_addresses_legacy() if len(set(monkey["ip_addresses"]).intersection(ip_addresses)) > 0: label = "MonkeyIsland - " + label return label @@ -118,7 +118,7 @@ class NodeService: @staticmethod def get_monkey_group(monkey): keywords = [] - if len(set(monkey["ip_addresses"]).intersection(get_my_ip_addresses())) != 0: + if len(set(monkey["ip_addresses"]).intersection(get_my_ip_addresses_legacy())) != 0: keywords.extend(["island", "monkey"]) else: monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey" @@ -275,7 +275,7 @@ class NodeService: # It's better to just initialize the island machine on reset I think @staticmethod def get_monkey_island_monkey(): - ip_addresses = get_my_ip_addresses() + ip_addresses = get_my_ip_addresses_legacy() for ip_address in ip_addresses: monkey = NodeService.get_monkey_by_ip(ip_address) if monkey is not None: @@ -297,7 +297,7 @@ class NodeService: @staticmethod def get_monkey_island_node(): island_node = NodeService.get_monkey_island_pseudo_net_node() - island_node["ip_addresses"] = get_my_ip_addresses() + island_node["ip_addresses"] = get_my_ip_addresses_legacy() island_node["domain_name"] = socket.gethostname() return island_node diff --git a/monkey/monkey_island/cc/services/reporting/report.py b/monkey/monkey_island/cc/services/reporting/report.py index b80f3c3b6..656b55da2 100644 --- a/monkey/monkey_island/cc/services/reporting/report.py +++ b/monkey/monkey_island/cc/services/reporting/report.py @@ -5,7 +5,7 @@ from itertools import chain, product from typing import List from common.network.network_range import NetworkRange -from common.network.network_utils import get_my_ip_addresses, get_network_interfaces +from common.network.network_utils import get_my_ip_addresses_legacy, get_network_interfaces from common.network.segmentation_utils import get_ip_in_src_and_not_in_dst from monkey_island.cc.database import mongo from monkey_island.cc.models import Monkey @@ -175,7 +175,7 @@ class ReportService: @staticmethod def get_island_cross_segment_issues(): issues = [] - island_ips = get_my_ip_addresses() + island_ips = get_my_ip_addresses_legacy() for monkey in mongo.db.monkey.find( {"tunnel": {"$exists": False}}, {"tunnel": 1, "guid": 1, "hostname": 1} ):