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
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()]

View File

@ -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,

View File

@ -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()

View File

@ -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

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)
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:

View File

@ -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

View File

@ -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}
):