From 1c602a3315f25a4aae7b95510f167132fa31bdca Mon Sep 17 00:00:00 2001 From: vakarisz Date: Mon, 28 Feb 2022 16:13:56 +0200 Subject: [PATCH] Agent, Island: send network information in monkey wakeup telemetry Network information is required for segmentation reports, that's why it gets sent in the wakeup telemetry. It could be joined with "ip_addresses", but that would require a bigger refactoring on the island side --- monkey/infection_monkey/control.py | 3 ++- monkey/monkey_island/cc/models/monkey.py | 1 + monkey/monkey_island/cc/services/reporting/report.py | 11 +++-------- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/monkey/infection_monkey/control.py b/monkey/infection_monkey/control.py index c4b4b9555..5abb99fdb 100644 --- a/monkey/infection_monkey/control.py +++ b/monkey/infection_monkey/control.py @@ -13,7 +13,7 @@ import infection_monkey.tunnel as tunnel from common.common_consts.api_url_consts import T1216_PBA_FILE_DOWNLOAD_PATH from common.common_consts.timeouts import LONG_REQUEST_TIMEOUT, MEDIUM_REQUEST_TIMEOUT from infection_monkey.config import GUID, WormConfiguration -from infection_monkey.network.info import local_ips +from infection_monkey.network.info import get_host_subnets, local_ips from infection_monkey.transport.http import HTTPConnectProxy from infection_monkey.transport.tcp import TcpProxy from infection_monkey.utils import agent_process @@ -48,6 +48,7 @@ class ControlClient(object): "guid": GUID, "hostname": hostname, "ip_addresses": local_ips(), + "networks": get_host_subnets(), "description": " ".join(platform.uname()), "config": WormConfiguration.as_dict(), "parent": parent, diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index c7fe734b6..3d941d512 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -42,6 +42,7 @@ class Monkey(Document): description = StringField() hostname = StringField() ip_addresses = ListField(StringField()) + networks = ListField() launch_time = FloatField() keepalive = DateTimeField() modifytime = DateTimeField() diff --git a/monkey/monkey_island/cc/services/reporting/report.py b/monkey/monkey_island/cc/services/reporting/report.py index 3ac0c0364..c2a7e7066 100644 --- a/monkey/monkey_island/cc/services/reporting/report.py +++ b/monkey/monkey_island/cc/services/reporting/report.py @@ -160,16 +160,11 @@ class ReportService: @staticmethod def get_monkey_subnets(monkey_guid): - network_info = mongo.db.telemetry.find_one( - {"telem_category": "system_info", "monkey_guid": monkey_guid}, - {"data.network_info.networks": 1}, - ) - if network_info is None or not network_info["data"]: - return [] + networks = Monkey.objects.get(guid=monkey_guid).networks return [ - ipaddress.ip_interface(str(network["addr"] + "/" + network["netmask"])).network - for network in network_info["data"]["network_info"]["networks"] + ipaddress.ip_interface(f"{network['addr']}/{network['netmask']}").network + for network in networks ] @staticmethod