Island: Fix all references to 'local' IPs which may not always be local
This commit is contained in:
parent
4095e130f9
commit
2be0e088e0
|
@ -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 get_local_ip_addresses
|
||||
from monkey_island.cc.services.utils.network_utils import get_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(get_local_ip_addresses())) > 0:
|
||||
if len(set(current_monkey.ip_addresses).intersection(get_ip_addresses())) > 0:
|
||||
label = "MonkeyIsland - " + label
|
||||
return label
|
||||
|
||||
|
|
|
@ -6,20 +6,20 @@ from monkey_island.cc.resources.request_authentication import jwt_required
|
|||
|
||||
class IPAddresses(AbstractResource):
|
||||
"""
|
||||
Endpoint for the Monkey Island's local IP addresses
|
||||
Endpoint for the Monkey Island's IP addresses
|
||||
"""
|
||||
|
||||
urls = ["/api/island/ip-addresses"]
|
||||
|
||||
def __init__(self, local_ip_addresses: Sequence[str]):
|
||||
self._local_ips = local_ip_addresses
|
||||
def __init__(self, ip_addresses: Sequence[str]):
|
||||
self._ips = ip_addresses
|
||||
|
||||
@jwt_required
|
||||
def get(self) -> Sequence[str]:
|
||||
"""
|
||||
Sends the local IP addresses of the Island
|
||||
Sends the IP addresses of the Island
|
||||
|
||||
:return: Local IPs
|
||||
:return: IP addresses
|
||||
"""
|
||||
|
||||
return self._local_ips
|
||||
return self._ips
|
||||
|
|
|
@ -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 get_local_ip_addresses # noqa: E402
|
||||
from monkey_island.cc.services.utils.network_utils import get_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,9 +168,7 @@ def _log_init_info():
|
|||
|
||||
|
||||
def _log_web_interface_access_urls():
|
||||
web_interface_urls = ", ".join(
|
||||
[f"https://{ip}:{ISLAND_PORT}" for ip in get_local_ip_addresses()]
|
||||
)
|
||||
web_interface_urls = ", ".join([f"https://{ip}:{ISLAND_PORT}" for ip in get_ip_addresses()])
|
||||
logger.info(
|
||||
"To access the web interface, navigate to one of the the following URLs using your "
|
||||
f"browser: {web_interface_urls}"
|
||||
|
|
|
@ -46,7 +46,7 @@ from monkey_island.cc.services.telemetry.processing.credentials.credentials_pars
|
|||
from monkey_island.cc.services.telemetry.processing.processing import (
|
||||
TELEMETRY_CATEGORY_TO_PROCESSING_FUNC,
|
||||
)
|
||||
from monkey_island.cc.services.utils.network_utils import get_local_ip_addresses
|
||||
from monkey_island.cc.services.utils.network_utils import get_ip_addresses
|
||||
from monkey_island.cc.setup.mongo.mongo_setup import MONGO_URL
|
||||
from monkey_island.cc.version import Version
|
||||
|
||||
|
@ -98,7 +98,7 @@ def _register_conventions(container: DIContainer, data_dir: Path):
|
|||
)
|
||||
container.register_convention(Path, "island_log_file_path", get_log_file_path(data_dir))
|
||||
container.register_convention(str, "version_number", get_version())
|
||||
container.register_convention(Sequence[str], "local_ip_addresses", get_local_ip_addresses())
|
||||
container.register_convention(Sequence[str], "ip_addresses", get_ip_addresses())
|
||||
|
||||
|
||||
def _register_repositories(container: DIContainer, data_dir: Path):
|
||||
|
|
|
@ -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 get_local_ip_addresses
|
||||
from monkey_island.cc.services.utils.network_utils import get_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 = get_local_ip_addresses()
|
||||
ip_addresses = get_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(get_local_ip_addresses())) != 0:
|
||||
if len(set(monkey["ip_addresses"]).intersection(get_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 = get_local_ip_addresses()
|
||||
ip_addresses = get_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"] = get_local_ip_addresses()
|
||||
island_node["ip_addresses"] = get_ip_addresses()
|
||||
island_node["domain_name"] = socket.gethostname()
|
||||
return island_node
|
||||
|
||||
|
|
|
@ -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_local_ip_addresses, get_subnets
|
||||
from monkey_island.cc.services.utils.network_utils import get_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 = get_local_ip_addresses()
|
||||
island_ips = get_ip_addresses()
|
||||
for monkey in mongo.db.monkey.find(
|
||||
{"tunnel": {"$exists": False}}, {"tunnel": 1, "guid": 1, "hostname": 1}
|
||||
):
|
||||
|
|
|
@ -19,11 +19,11 @@ class LocalMonkeyRunService:
|
|||
self,
|
||||
data_dir: Path,
|
||||
agent_binary_repository: IAgentBinaryRepository,
|
||||
local_ip_addresses: Sequence[str],
|
||||
ip_addresses: Sequence[str],
|
||||
):
|
||||
self._data_dir = data_dir
|
||||
self._agent_binary_repository = agent_binary_repository
|
||||
self._local_ips = local_ip_addresses
|
||||
self._ips = ip_addresses
|
||||
|
||||
def run_local_monkey(self):
|
||||
# get the monkey executable suitable to run on the server
|
||||
|
@ -65,7 +65,7 @@ class LocalMonkeyRunService:
|
|||
|
||||
# run the monkey
|
||||
try:
|
||||
ip = self._local_ips[0]
|
||||
ip = self._ips[0]
|
||||
port = ISLAND_PORT
|
||||
|
||||
args = [str(dest_path), "m0nk3y", "-s", f"{ip}:{port}"]
|
||||
|
|
|
@ -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 get_local_ip_addresses() -> Sequence[str]:
|
||||
def get_ip_addresses() -> Sequence[str]:
|
||||
ip_list = []
|
||||
for interface in interfaces():
|
||||
addresses = ifaddresses(interface).get(AF_INET, [])
|
||||
|
|
Loading…
Reference in New Issue