From a8d6f936f1e268316c23ca2a88db1ff084d69069 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Wed, 17 Nov 2021 11:30:12 +0200 Subject: [PATCH] Agent, Island: remove hostname collector --- .../system_info_collectors_names.py | 1 - .../system_info/collectors/hostname_collector.py | 15 --------------- monkey/monkey_island/cc/models/monkey.py | 16 ++-------------- .../definitions/system_info_collector_classes.py | 9 --------- .../cc/services/config_schema/monkey.py | 2 -- .../system_info_collectors/hostname.py | 9 --------- .../system_info_telemetry_dispatcher.py | 10 +--------- .../monkey_island/cc/models/test_monkey.py | 3 --- vulture_allowlist.py | 1 - 9 files changed, 3 insertions(+), 63 deletions(-) delete mode 100644 monkey/infection_monkey/system_info/collectors/hostname_collector.py delete mode 100644 monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/hostname.py diff --git a/monkey/common/common_consts/system_info_collectors_names.py b/monkey/common/common_consts/system_info_collectors_names.py index f87fff4bd..d65c45b7b 100644 --- a/monkey/common/common_consts/system_info_collectors_names.py +++ b/monkey/common/common_consts/system_info_collectors_names.py @@ -1,4 +1,3 @@ AWS_COLLECTOR = "AwsCollector" -HOSTNAME_COLLECTOR = "HostnameCollector" PROCESS_LIST_COLLECTOR = "ProcessListCollector" MIMIKATZ_COLLECTOR = "MimikatzCollector" diff --git a/monkey/infection_monkey/system_info/collectors/hostname_collector.py b/monkey/infection_monkey/system_info/collectors/hostname_collector.py deleted file mode 100644 index 0aeecd9fb..000000000 --- a/monkey/infection_monkey/system_info/collectors/hostname_collector.py +++ /dev/null @@ -1,15 +0,0 @@ -import logging -import socket - -from common.common_consts.system_info_collectors_names import HOSTNAME_COLLECTOR -from infection_monkey.system_info.system_info_collector import SystemInfoCollector - -logger = logging.getLogger(__name__) - - -class HostnameCollector(SystemInfoCollector): - def __init__(self): - super().__init__(name=HOSTNAME_COLLECTOR) - - def collect(self) -> dict: - return {"hostname": socket.getfqdn()} diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index 888d1c569..24c8363d3 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -122,16 +122,6 @@ class Monkey(Document): """ return Monkey.get_single_monkey_by_id(object_id).hostname - def set_hostname(self, hostname): - """ - Sets a new hostname for a machine and clears the cache for getting it. - :param hostname: The new hostname for the machine. - """ - self.hostname = hostname - self.save() - Monkey.get_hostname_by_id.delete(self.id) - Monkey.get_label_by_id.delete(self.id) - def get_network_info(self): """ Formats network info from monkey's model @@ -139,10 +129,8 @@ class Monkey(Document): """ return {"ips": self.ip_addresses, "hostname": self.hostname} - @ring.lru( - # data has TTL of 1 second. This is useful for rapid calls for report generation. - expire=1 - ) + # data has TTL of 1 second. This is useful for rapid calls for report generation. + @ring.lru(expire=1) @staticmethod def is_monkey(object_id): try: diff --git a/monkey/monkey_island/cc/services/config_schema/definitions/system_info_collector_classes.py b/monkey/monkey_island/cc/services/config_schema/definitions/system_info_collector_classes.py index 514ee3183..b77087a48 100644 --- a/monkey/monkey_island/cc/services/config_schema/definitions/system_info_collector_classes.py +++ b/monkey/monkey_island/cc/services/config_schema/definitions/system_info_collector_classes.py @@ -1,6 +1,5 @@ from common.common_consts.system_info_collectors_names import ( AWS_COLLECTOR, - HOSTNAME_COLLECTOR, MIMIKATZ_COLLECTOR, PROCESS_LIST_COLLECTOR, ) @@ -27,14 +26,6 @@ SYSTEM_INFO_COLLECTOR_CLASSES = { "currently running on.", "attack_techniques": ["T1082"], }, - { - "type": "string", - "enum": [HOSTNAME_COLLECTOR], - "title": "Hostname Collector", - "safe": True, - "info": "Collects machine's hostname.", - "attack_techniques": ["T1082", "T1016"], - }, { "type": "string", "enum": [PROCESS_LIST_COLLECTOR], diff --git a/monkey/monkey_island/cc/services/config_schema/monkey.py b/monkey/monkey_island/cc/services/config_schema/monkey.py index 68155970f..97fdbd19b 100644 --- a/monkey/monkey_island/cc/services/config_schema/monkey.py +++ b/monkey/monkey_island/cc/services/config_schema/monkey.py @@ -1,6 +1,5 @@ from common.common_consts.system_info_collectors_names import ( AWS_COLLECTOR, - HOSTNAME_COLLECTOR, MIMIKATZ_COLLECTOR, PROCESS_LIST_COLLECTOR, ) @@ -88,7 +87,6 @@ MONKEY = { "items": {"$ref": "#/definitions/system_info_collector_classes"}, "default": [ AWS_COLLECTOR, - HOSTNAME_COLLECTOR, PROCESS_LIST_COLLECTOR, MIMIKATZ_COLLECTOR, ], diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/hostname.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/hostname.py deleted file mode 100644 index e2de4519c..000000000 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/hostname.py +++ /dev/null @@ -1,9 +0,0 @@ -import logging - -from monkey_island.cc.models.monkey import Monkey - -logger = logging.getLogger(__name__) - - -def process_hostname_telemetry(collector_results, monkey_guid): - Monkey.get_single_monkey_by_guid(monkey_guid).set_hostname(collector_results["hostname"]) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/system_info_telemetry_dispatcher.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/system_info_telemetry_dispatcher.py index 7683cac6f..702cffe2c 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/system_info_telemetry_dispatcher.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/system_info_telemetry_dispatcher.py @@ -1,17 +1,10 @@ import logging import typing -from common.common_consts.system_info_collectors_names import ( - AWS_COLLECTOR, - HOSTNAME_COLLECTOR, - PROCESS_LIST_COLLECTOR, -) +from common.common_consts.system_info_collectors_names import AWS_COLLECTOR, PROCESS_LIST_COLLECTOR from monkey_island.cc.services.telemetry.processing.system_info_collectors.aws import ( process_aws_telemetry, ) -from monkey_island.cc.services.telemetry.processing.system_info_collectors.hostname import ( - process_hostname_telemetry, -) from monkey_island.cc.services.telemetry.zero_trust_checks.antivirus_existence import ( check_antivirus_existence, ) @@ -20,7 +13,6 @@ logger = logging.getLogger(__name__) SYSTEM_INFO_COLLECTOR_TO_TELEMETRY_PROCESSORS = { AWS_COLLECTOR: [process_aws_telemetry], - HOSTNAME_COLLECTOR: [process_hostname_telemetry], PROCESS_LIST_COLLECTOR: [check_antivirus_existence], } diff --git a/monkey/tests/unit_tests/monkey_island/cc/models/test_monkey.py b/monkey/tests/unit_tests/monkey_island/cc/models/test_monkey.py index 90fd9032a..827a6631e 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/models/test_monkey.py +++ b/monkey/tests/unit_tests/monkey_island/cc/models/test_monkey.py @@ -134,9 +134,6 @@ class TestMonkey: assert cache_info_after_query_2.hits == 1 assert cache_info_after_query_2.misses == 1 - # set hostname deletes the id from the cache. - linux_monkey.set_hostname("Another hostname") - # should be a miss label = Monkey.get_label_by_id(linux_monkey.id) logger.debug("3) ID: {} label: {}".format(linux_monkey.id, label)) diff --git a/vulture_allowlist.py b/vulture_allowlist.py index ae4f95b55..b57fe73ab 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -97,7 +97,6 @@ Timestomping # unused class (monkey/infection_monkey/post_breach/actions/timest SignedScriptProxyExecution # unused class (monkey/infection_monkey/post_breach/actions/use_signed_scripts.py:15) AwsCollector # unused class (monkey/infection_monkey/system_info/collectors/aws_collector.py:15) EnvironmentCollector # unused class (monkey/infection_monkey/system_info/collectors/environment_collector.py:19) -HostnameCollector # unused class (monkey/infection_monkey/system_info/collectors/hostname_collector.py:10) ProcessListCollector # unused class (monkey/infection_monkey/system_info/collectors/process_list_collector.py:18) _.coinit_flags # unused attribute (monkey/infection_monkey/system_info/windows_info_collector.py:11) _.representations # unused attribute (monkey/monkey_island/cc/app.py:180)