Island: Rename local_ip_addresses() -> get_local_ip_addresses()

This commit is contained in:
Shreya Malviya 2022-08-04 12:31:21 +05:30
parent 867135b358
commit d189a94e9c
8 changed files with 20 additions and 18 deletions

View File

@ -19,7 +19,7 @@ from mongoengine import (
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
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
class ParentNotFoundError(Exception):
@ -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]
if len(set(current_monkey.ip_addresses).intersection(local_ip_addresses())) > 0:
if len(set(current_monkey.ip_addresses).intersection(get_local_ip_addresses())) > 0:
label = "MonkeyIsland - " + label
return label

View File

@ -2,7 +2,7 @@ from typing import Mapping, Sequence
from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.request_authentication import jwt_required
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
class IpAddresses(AbstractResource):
@ -15,6 +15,6 @@ class IpAddresses(AbstractResource):
:return: a dictionary with "ip_addresses" key that points to a list of IP's
"""
local_ips = local_ip_addresses()
local_ips = get_local_ip_addresses()
return {"ip_addresses": local_ips}

View File

@ -6,7 +6,7 @@ from monkey_island.cc.database import mongo
from monkey_island.cc.resources.AbstractResource import AbstractResource
from monkey_island.cc.resources.request_authentication import jwt_required
from monkey_island.cc.services.infection_lifecycle import get_completed_steps
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
logger = logging.getLogger(__name__)
@ -29,7 +29,7 @@ class Root(AbstractResource):
@jwt_required
def get_server_info(self):
return jsonify(
ip_addresses=local_ip_addresses(),
ip_addresses=get_local_ip_addresses(),
mongo=str(mongo.db),
completed_steps=get_completed_steps(),
)

View File

@ -27,7 +27,7 @@ from monkey_island.cc.server_utils.consts import ( # noqa: E402
)
from monkey_island.cc.server_utils.island_logger import reset_logger, setup_logging # noqa: E402
from monkey_island.cc.services.initialize import initialize_services # noqa: E402
from monkey_island.cc.services.utils.network_utils import local_ip_addresses # noqa: E402
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses # noqa: E402
from monkey_island.cc.setup import PyWSGILoggingFilter # noqa: E402
from monkey_island.cc.setup import island_config_options_validator # noqa: E402
from monkey_island.cc.setup.data_dir import IncompatibleDataDirectory, setup_data_dir # noqa: E402
@ -168,7 +168,9 @@ def _log_init_info():
def _log_web_interface_access_urls():
web_interface_urls = ", ".join([f"https://{ip}:{ISLAND_PORT}" for ip in local_ip_addresses()])
web_interface_urls = ", ".join(
[f"https://{ip}:{ISLAND_PORT}" for ip in get_local_ip_addresses()]
)
logger.info(
"To access the web interface, navigate to one of the the following URLs using your "
f"browser: {web_interface_urls}"

View File

@ -9,7 +9,7 @@ from monkey_island.cc.database import mongo
from monkey_island.cc.models import Monkey
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
from monkey_island.cc.services.edge.edge import EdgeService
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
from monkey_island.cc.services.utils.node_states import NodeStates
@ -110,7 +110,7 @@ class NodeService:
def get_monkey_label(monkey):
# todo
label = monkey["hostname"] + " : " + monkey["ip_addresses"][0]
ip_addresses = local_ip_addresses()
ip_addresses = get_local_ip_addresses()
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(local_ip_addresses())) != 0:
if len(set(monkey["ip_addresses"]).intersection(get_local_ip_addresses())) != 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 = local_ip_addresses()
ip_addresses = get_local_ip_addresses()
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"] = local_ip_addresses()
island_node["ip_addresses"] = get_local_ip_addresses()
island_node["domain_name"] = socket.gethostname()
return island_node

View File

@ -19,7 +19,7 @@ from monkey_island.cc.services.reporting.pth_report import PTHReportService
from monkey_island.cc.services.reporting.report_generation_synchronisation import (
safe_generate_regular_report,
)
from monkey_island.cc.services.utils.network_utils import get_subnets, local_ip_addresses
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses, get_subnets
from .. import AWSService
from . import aws_exporter
@ -175,7 +175,7 @@ class ReportService:
@staticmethod
def get_island_cross_segment_issues():
issues = []
island_ips = local_ip_addresses()
island_ips = get_local_ip_addresses()
for monkey in mongo.db.monkey.find(
{"tunnel": {"$exists": False}}, {"tunnel": 1, "guid": 1, "hostname": 1}
):

View File

@ -7,7 +7,7 @@ from shutil import copyfileobj
from monkey_island.cc.repository import IAgentBinaryRepository, RetrievalError
from monkey_island.cc.server_utils.consts import ISLAND_PORT
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
logger = logging.getLogger(__name__)
@ -59,7 +59,7 @@ class LocalMonkeyRunService:
# run the monkey
try:
ip = local_ip_addresses()[0]
ip = get_local_ip_addresses()[0]
port = ISLAND_PORT
args = [str(dest_path), "m0nk3y", "-s", f"{ip}:{port}"]

View File

@ -58,7 +58,7 @@ else:
# lot of times during the report generation. This means that if the interfaces of the Island machine
# change, the Island process needs to be restarted.
@lru(maxsize=1)
def local_ip_addresses() -> Sequence[str]:
def get_local_ip_addresses() -> Sequence[str]:
ip_list = []
for interface in interfaces():
addresses = ifaddresses(interface).get(AF_INET, [])