diff --git a/.swm/OwcKMnALpn7tuBaJY1US.swm b/.swm/OwcKMnALpn7tuBaJY1US.swm index a091073c5..5555018fa 100644 --- a/.swm/OwcKMnALpn7tuBaJY1US.swm +++ b/.swm/OwcKMnALpn7tuBaJY1US.swm @@ -5,7 +5,7 @@ "dod": "Add a system info collector that collects the machine hostname.", "tests": [], "hints": [ - "First thing you should do is take a look at a different collector (like EnvironmentCollector) and 100% understand how it runs, how results are relayed back to the server, and how the server processes the data.", + "First thing you should do is take a look at a different collector (like HostnameCollector) and 100% understand how it runs, how results are relayed back to the server, and how the server processes the data.", "Try to run \"socket.getfqdn()\".", "Take a look at SystemInfoCollector - that's the base class you'll need to implement.", "Make sure you add the new collector to the configuration in all relevant places, including making it ON by default!" @@ -25,7 +25,6 @@ " AWS_COLLECTOR = \"AwsCollector\"", "*HOSTNAME_COLLECTOR = \"HostnameCollector\"", "+# SWIMMER: Collector name goes here.", - " ENVIRONMENT_COLLECTOR = \"EnvironmentCollector\"", " PROCESS_LIST_COLLECTOR = \"ProcessListCollector\"", " MIMIKATZ_COLLECTOR = \"MimikatzCollector\"" ] @@ -60,7 +59,6 @@ "comments": [], "firstLineNumber": 4, "lines": [ - " ENVIRONMENT_COLLECTOR,", "* HOSTNAME_COLLECTOR,", " MIMIKATZ_COLLECTOR,", " PROCESS_LIST_COLLECTOR,", @@ -97,7 +95,6 @@ "lines": [ " from common.common_consts.system_info_collectors_names import (", " AWS_COLLECTOR,", - " ENVIRONMENT_COLLECTOR,", "* HOSTNAME_COLLECTOR,", " MIMIKATZ_COLLECTOR,", " PROCESS_LIST_COLLECTOR,", @@ -111,7 +108,6 @@ "firstLineNumber": 91, "lines": [ " \"default\": [", - " ENVIRONMENT_COLLECTOR,", " AWS_COLLECTOR,", "* HOSTNAME_COLLECTOR,", " PROCESS_LIST_COLLECTOR,", @@ -149,7 +145,6 @@ " ", " from common.common_consts.system_info_collectors_names import (", " AWS_COLLECTOR,", - " ENVIRONMENT_COLLECTOR,", "* HOSTNAME_COLLECTOR," ] }, @@ -161,7 +156,6 @@ "lines": [ " SYSTEM_INFO_COLLECTOR_TO_TELEMETRY_PROCESSORS = {", " AWS_COLLECTOR: [process_aws_telemetry],", - " ENVIRONMENT_COLLECTOR: [process_environment_telemetry],", "* HOSTNAME_COLLECTOR: [process_hostname_telemetry],", " PROCESS_LIST_COLLECTOR: [check_antivirus_existence],", " }", @@ -171,10 +165,6 @@ { "type": "snippet", "lines": [ - " )", - " from monkey_island.cc.services.telemetry.processing.system_info_collectors.environment import (", - " process_environment_telemetry,", - " )", "*from monkey_island.cc.services.telemetry.processing.system_info_collectors.hostname import (", "* process_hostname_telemetry,", "*)", diff --git a/docs/content/development/adding-system-info-collectors.md b/docs/content/development/adding-system-info-collectors.md index 71cea6000..3e924bd4e 100644 --- a/docs/content/development/adding-system-info-collectors.md +++ b/docs/content/development/adding-system-info-collectors.md @@ -39,7 +39,7 @@ class MyNewCollector(SystemInfoCollector): #### Implementation -Override the `collect` method with your own implementation. See the `EnvironmentCollector.py` System Info Collector for reference. You can log during collection as well. +Override the `collect` method with your own implementation. See the `hostname_collector.py` System Info Collector for reference. You can log during collection as well. ### Modify the Monkey Island @@ -57,7 +57,7 @@ You'll need to add your Sytem Info Collector to the `monkey_island/cc/services/c { "type": "string", "enum": [ - "EnvironmentCollector" + "HostnameCollector" ], "title": "Which Environment this machine is on (on prem/cloud)", "attack_techniques": [] @@ -87,7 +87,7 @@ Also, you can add the System Info Collector to be used by default by adding it t "$ref": "#/definitions/system_info_collectors_classes" }, "default": [ - "EnvironmentCollector", + "HostnameCollector", "MyNewCollector" <================================= ], "description": "Determines which system information collectors will collect information." diff --git a/monkey/infection_monkey/system_info/collectors/environment_collector.py b/monkey/infection_monkey/system_info/collectors/environment_collector.py deleted file mode 100644 index 039ede6f5..000000000 --- a/monkey/infection_monkey/system_info/collectors/environment_collector.py +++ /dev/null @@ -1,24 +0,0 @@ -from common.cloud.all_instances import get_all_cloud_instances -from common.cloud.environment_names import Environment -from common.common_consts.system_info_collectors_names import ENVIRONMENT_COLLECTOR -from infection_monkey.system_info.system_info_collector import SystemInfoCollector - - -def get_monkey_environment() -> str: - """ - Get the Monkey's running environment. - :return: One of the cloud providers if on cloud; otherwise, assumes "on premise". - """ - for instance in get_all_cloud_instances(): - if instance.is_instance(): - return instance.get_cloud_provider_name().value - - return Environment.ON_PREMISE.value - - -class EnvironmentCollector(SystemInfoCollector): - def __init__(self): - super().__init__(name=ENVIRONMENT_COLLECTOR) - - def collect(self) -> dict: - return {"environment": get_monkey_environment()} diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/environment.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/environment.py deleted file mode 100644 index 4c685a01b..000000000 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/environment.py +++ /dev/null @@ -1,12 +0,0 @@ -import logging - -from monkey_island.cc.models.monkey import Monkey - -logger = logging.getLogger(__name__) - - -def process_environment_telemetry(collector_results, monkey_guid): - relevant_monkey = Monkey.get_single_monkey_by_guid(monkey_guid) - relevant_monkey.environment = collector_results["environment"] - relevant_monkey.save() - logger.debug("Updated Monkey {} with env {}".format(str(relevant_monkey), collector_results)) 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 7ce4b6fcf..7683cac6f 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 @@ -3,16 +3,12 @@ import typing from common.common_consts.system_info_collectors_names import ( AWS_COLLECTOR, - ENVIRONMENT_COLLECTOR, HOSTNAME_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.environment import ( - process_environment_telemetry, -) from monkey_island.cc.services.telemetry.processing.system_info_collectors.hostname import ( process_hostname_telemetry, ) @@ -24,7 +20,6 @@ logger = logging.getLogger(__name__) SYSTEM_INFO_COLLECTOR_TO_TELEMETRY_PROCESSORS = { AWS_COLLECTOR: [process_aws_telemetry], - ENVIRONMENT_COLLECTOR: [process_environment_telemetry], HOSTNAME_COLLECTOR: [process_hostname_telemetry], PROCESS_LIST_COLLECTOR: [check_antivirus_existence], } diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py b/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py deleted file mode 100644 index 042f5b874..000000000 --- a/monkey/tests/unit_tests/monkey_island/cc/services/telemetry/processing/system_info_collectors/test_environment_telemetry_processing.py +++ /dev/null @@ -1,28 +0,0 @@ -import uuid - -from monkey_island.cc.models import Monkey -from monkey_island.cc.services.telemetry.processing.system_info_collectors.system_info_telemetry_dispatcher import ( # noqa: E501 - SystemInfoTelemetryDispatcher, -) - - -class TestEnvironmentTelemetryProcessing: - def test_process_environment_telemetry(self): - # Arrange - monkey_guid = str(uuid.uuid4()) - a_monkey = Monkey(guid=monkey_guid) - a_monkey.save() - dispatcher = SystemInfoTelemetryDispatcher() - - on_premise = "On Premise" - telem_json = { - "data": { - "collectors": { - "EnvironmentCollector": {"environment": on_premise}, - } - }, - "monkey_guid": monkey_guid, - } - dispatcher.dispatch_collector_results_to_relevant_processors(telem_json) - - assert Monkey.get_single_monkey_by_guid(monkey_guid).environment == on_premise diff --git a/vulture_allowlist.py b/vulture_allowlist.py index 114178ea7..ae4f95b55 100644 --- a/vulture_allowlist.py +++ b/vulture_allowlist.py @@ -199,7 +199,6 @@ LOG_DIR_NAME # unused variable (envs/monkey_zoo/blackbox/log_handlers/test_logs delete_logs # unused function (envs/monkey_zoo/blackbox/test_blackbox.py:85) MongoQueryJSONEncoder # unused class (envs/monkey_zoo/blackbox/utils/json_encoder.py:6) environment # unused variable (monkey/monkey_island/cc/models/monkey.py:59) -_.environment # unused attribute (monkey/monkey_island/cc/services/telemetry/processing/system_info_collectors/environment.py:10) _.instance_name # unused attribute (monkey/common/cloud/azure/azure_instance.py:35) _.instance_name # unused attribute (monkey/common/cloud/azure/azure_instance.py:64) GCPHandler # unused function (envs/monkey_zoo/blackbox/test_blackbox.py:57)