Agent, Island: Rename get_my_ip_address to legacy

This commit is contained in:
vakarisz 2022-09-23 12:25:00 +03:00 committed by VakarisZ
parent 2c4625eb1c
commit 52d0e6f655
7 changed files with 16 additions and 16 deletions

View File

@ -5,7 +5,7 @@ from typing import List, Optional, Sequence, Tuple
from netifaces import AF_INET, ifaddresses, interfaces 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()] return [str(interface.ip) for interface in get_network_interfaces()]

View File

@ -7,7 +7,7 @@ import requests
from urllib3 import disable_warnings from urllib3 import disable_warnings
from common.common_consts.timeouts import MEDIUM_REQUEST_TIMEOUT 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.config import GUID
from infection_monkey.island_api_client import IIslandAPIClient from infection_monkey.island_api_client import IIslandAPIClient
from infection_monkey.network.info import get_host_subnets from infection_monkey.network.info import get_host_subnets
@ -39,7 +39,7 @@ class ControlClient:
monkey = { monkey = {
"guid": GUID, "guid": GUID,
"hostname": hostname, "hostname": hostname,
"ip_addresses": get_my_ip_addresses(), "ip_addresses": get_my_ip_addresses_legacy(),
"networks": get_host_subnets(), "networks": get_host_subnets(),
"description": " ".join(platform.uname()), "description": " ".join(platform.uname()),
"parent": parent, "parent": parent,

View File

@ -18,7 +18,7 @@ from common.agent_registration_data import AgentRegistrationData
from common.event_queue import IAgentEventQueue, PyPubSubAgentEventQueue from common.event_queue import IAgentEventQueue, PyPubSubAgentEventQueue
from common.network.network_utils import ( from common.network.network_utils import (
address_to_ip_port, address_to_ip_port,
get_my_ip_addresses, get_my_ip_addresses_legacy,
get_network_interfaces, get_network_interfaces,
) )
from common.utils.argparse_types import positive_int from common.utils.argparse_types import positive_int
@ -236,7 +236,7 @@ class InfectionMonkey:
self._cmd_island_port, self._cmd_island_port,
client_disconnect_timeout=config.keep_tunnel_open_time, 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): if not maximum_depth_reached(config.propagation.maximum_depth, self._current_depth):
self._relay.start() self._relay.start()

View File

@ -16,7 +16,7 @@ from mongoengine import (
StringField, 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.command_control_channel import CommandControlChannel
from monkey_island.cc.models.monkey_ttl import MonkeyTtl, create_monkey_ttl_document 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 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): def get_label_by_id(object_id):
current_monkey = Monkey.get_single_monkey_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] 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: if len(set(current_monkey.ip_addresses).intersection(local_ips)) > 0:
label = "MonkeyIsland - " + label label = "MonkeyIsland - " + label
return label return label

View File

@ -23,7 +23,7 @@ if str(MONKEY_ISLAND_DIR_BASE_PATH) not in sys.path:
sys.path.insert(0, MONKEY_ISLAND_DIR_BASE_PATH) sys.path.insert(0, MONKEY_ISLAND_DIR_BASE_PATH)
from common import DIContainer # noqa: E402 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 common.version import get_version # noqa: E402
from monkey_island.cc.app import init_app # noqa: E402 from monkey_island.cc.app import init_app # noqa: E402
from monkey_island.cc.arg_parser import IslandCmdArgs # 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]: def _collect_system_info() -> Tuple[Sequence[str], Deployment, Version]:
deployment = _get_deployment() deployment = _get_deployment()
version = Version(get_version(), 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: def _get_deployment() -> Deployment:

View File

@ -4,7 +4,7 @@ from datetime import datetime
from bson import ObjectId from bson import ObjectId
import monkey_island.cc.services.log 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 import models
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.models import Monkey from monkey_island.cc.models import Monkey
@ -110,7 +110,7 @@ class NodeService:
def get_monkey_label(monkey): def get_monkey_label(monkey):
# todo # todo
label = monkey["hostname"] + " : " + monkey["ip_addresses"][0] 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: if len(set(monkey["ip_addresses"]).intersection(ip_addresses)) > 0:
label = "MonkeyIsland - " + label label = "MonkeyIsland - " + label
return label return label
@ -118,7 +118,7 @@ class NodeService:
@staticmethod @staticmethod
def get_monkey_group(monkey): def get_monkey_group(monkey):
keywords = [] 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"]) keywords.extend(["island", "monkey"])
else: else:
monkey_type = "manual" if NodeService.get_monkey_manual_run(monkey) else "monkey" 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 # It's better to just initialize the island machine on reset I think
@staticmethod @staticmethod
def get_monkey_island_monkey(): def get_monkey_island_monkey():
ip_addresses = get_my_ip_addresses() ip_addresses = get_my_ip_addresses_legacy()
for ip_address in ip_addresses: for ip_address in ip_addresses:
monkey = NodeService.get_monkey_by_ip(ip_address) monkey = NodeService.get_monkey_by_ip(ip_address)
if monkey is not None: if monkey is not None:
@ -297,7 +297,7 @@ class NodeService:
@staticmethod @staticmethod
def get_monkey_island_node(): def get_monkey_island_node():
island_node = NodeService.get_monkey_island_pseudo_net_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() island_node["domain_name"] = socket.gethostname()
return island_node return island_node

View File

@ -5,7 +5,7 @@ from itertools import chain, product
from typing import List from typing import List
from common.network.network_range import NetworkRange 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 common.network.segmentation_utils import get_ip_in_src_and_not_in_dst
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.models import Monkey from monkey_island.cc.models import Monkey
@ -175,7 +175,7 @@ class ReportService:
@staticmethod @staticmethod
def get_island_cross_segment_issues(): def get_island_cross_segment_issues():
issues = [] issues = []
island_ips = get_my_ip_addresses() island_ips = get_my_ip_addresses_legacy()
for monkey in mongo.db.monkey.find( for monkey in mongo.db.monkey.find(
{"tunnel": {"$exists": False}}, {"tunnel": 1, "guid": 1, "hostname": 1} {"tunnel": {"$exists": False}}, {"tunnel": 1, "guid": 1, "hostname": 1}
): ):