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/CHANGELOG.md b/CHANGELOG.md index 02a9d386d..f9b9ee010 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Changelog](https://keepachangelog.com/en/1.0.0/). - Remove serialization of config. #1537 - Checkbox that gave the option to not try to first move the dropper file. #1537 - Custom singleton mutex name config option. #1589 +- Removed environment system info collector #1535 - Azure credential collector, because it was broken (not gathering credentials). #1535 - Custom monkey directory name config option. #1537 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/common/cloud/all_instances.py b/monkey/common/cloud/all_instances.py deleted file mode 100644 index 6387730f6..000000000 --- a/monkey/common/cloud/all_instances.py +++ /dev/null @@ -1,12 +0,0 @@ -from typing import List - -from common.cloud.aws.aws_instance import AwsInstance -from common.cloud.azure.azure_instance import AzureInstance -from common.cloud.gcp.gcp_instance import GcpInstance -from common.cloud.instance import CloudInstance - -all_cloud_instances = [AwsInstance(), AzureInstance(), GcpInstance()] - - -def get_all_cloud_instances() -> List[CloudInstance]: - return all_cloud_instances diff --git a/monkey/common/cloud/aws/aws_instance.py b/monkey/common/cloud/aws/aws_instance.py index 09d112480..4bdc89bf3 100644 --- a/monkey/common/cloud/aws/aws_instance.py +++ b/monkey/common/cloud/aws/aws_instance.py @@ -4,7 +4,6 @@ import re import requests -from common.cloud.environment_names import Environment from common.cloud.instance import CloudInstance AWS_INSTANCE_METADATA_LOCAL_IP_ADDRESS = "169.254.169.254" @@ -22,9 +21,6 @@ class AwsInstance(CloudInstance): def is_instance(self): return self.instance_id is not None - def get_cloud_provider_name(self) -> Environment: - return Environment.AWS - def __init__(self): self.instance_id = None self.region = None diff --git a/monkey/common/cloud/azure/__init__.py b/monkey/common/cloud/azure/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/monkey/common/cloud/azure/azure_instance.py b/monkey/common/cloud/azure/azure_instance.py deleted file mode 100644 index 859ab279f..000000000 --- a/monkey/common/cloud/azure/azure_instance.py +++ /dev/null @@ -1,69 +0,0 @@ -import logging - -import requests -import simplejson - -from common.cloud.environment_names import Environment -from common.cloud.instance import CloudInstance -from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT - -LATEST_AZURE_METADATA_API_VERSION = "2019-04-30" -AZURE_METADATA_SERVICE_URL = ( - "http://169.254.169.254/metadata/instance?api-version=%s" % LATEST_AZURE_METADATA_API_VERSION -) - -logger = logging.getLogger(__name__) - - -class AzureInstance(CloudInstance): - """ - Access to useful information about the current machine if it's an Azure VM. - Based on Azure metadata service: - https://docs.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service - """ - - def is_instance(self): - return self._on_azure - - def get_cloud_provider_name(self) -> Environment: - return Environment.AZURE - - def __init__(self): - """ - Determines if on Azure and if so, gets some basic metadata on this instance. - """ - self.instance_name = None - self.instance_id = None - self.location = None - self._on_azure = False - - try: - response = requests.get( - AZURE_METADATA_SERVICE_URL, - headers={"Metadata": "true"}, - timeout=SHORT_REQUEST_TIMEOUT, - ) - - # If not on cloud, the metadata URL is non-routable and the connection will fail. - # If on AWS, should get 404 since the metadata service URL is different, - # so bool(response) will be false. - if response: - logger.debug("Trying to parse Azure metadata.") - self.try_parse_response(response) - else: - logger.warning(f"Metadata response not ok: {response.status_code}") - except requests.RequestException: - logger.debug( - "Failed to get response from Azure metadata service: This instance is not on " - "Azure." - ) - - def try_parse_response(self, response): - try: - response_data = response.json() - self.instance_name = response_data["compute"]["name"] - self.instance_id = response_data["compute"]["vmId"] - self.location = response_data["compute"]["location"] - self._on_azure = True - except (KeyError, simplejson.errors.JSONDecodeError) as e: - logger.exception(f"Error while parsing response from Azure metadata service: {e}") diff --git a/monkey/common/cloud/environment_names.py b/monkey/common/cloud/environment_names.py index 945d438ce..438c64379 100644 --- a/monkey/common/cloud/environment_names.py +++ b/monkey/common/cloud/environment_names.py @@ -2,14 +2,4 @@ from enum import Enum class Environment(Enum): - UNKNOWN = "Unknown" - ON_PREMISE = "On Premise" - AZURE = "Azure" AWS = "AWS" - GCP = "GCP" - ALIBABA = "Alibaba Cloud" - IBM = "IBM Cloud" - DigitalOcean = "Digital Ocean" - - -ALL_ENVIRONMENTS_NAMES = [x.value for x in Environment] diff --git a/monkey/common/cloud/gcp/__init__.py b/monkey/common/cloud/gcp/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/monkey/common/cloud/gcp/gcp_instance.py b/monkey/common/cloud/gcp/gcp_instance.py deleted file mode 100644 index 1fc208165..000000000 --- a/monkey/common/cloud/gcp/gcp_instance.py +++ /dev/null @@ -1,54 +0,0 @@ -import logging - -import requests - -from common.cloud.environment_names import Environment -from common.cloud.instance import CloudInstance -from common.common_consts.timeouts import SHORT_REQUEST_TIMEOUT - -logger = logging.getLogger(__name__) - -GCP_METADATA_SERVICE_URL = "http://metadata.google.internal/" - - -class GcpInstance(CloudInstance): - """ - Used to determine if on GCP. See https://cloud.google.com/compute/docs/storing-retrieving - -metadata#runninggce - """ - - def is_instance(self): - return self._on_gcp - - def get_cloud_provider_name(self) -> Environment: - return Environment.GCP - - def __init__(self): - self._on_gcp = False - - try: - # If not on GCP, this domain shouldn't resolve. - response = requests.get(GCP_METADATA_SERVICE_URL, timeout=SHORT_REQUEST_TIMEOUT) - - if response: - logger.debug("Got ok metadata response: on GCP") - self._on_gcp = True - - if "Metadata-Flavor" not in response.headers: - logger.warning("Got unexpected GCP Metadata format") - else: - if not response.headers["Metadata-Flavor"] == "Google": - logger.warning( - "Got unexpected Metadata flavor: {}".format( - response.headers["Metadata-Flavor"] - ) - ) - else: - logger.warning( - "On GCP, but metadata response not ok: {}".format(response.status_code) - ) - except requests.RequestException: - logger.debug( - "Failed to get response from GCP metadata service: This instance is not on GCP" - ) - self._on_gcp = False diff --git a/monkey/common/cloud/instance.py b/monkey/common/cloud/instance.py index f0da19359..77376ee8e 100644 --- a/monkey/common/cloud/instance.py +++ b/monkey/common/cloud/instance.py @@ -1,6 +1,3 @@ -from common.cloud.environment_names import Environment - - class CloudInstance(object): """ This is an abstract class which represents a cloud instance. @@ -10,6 +7,3 @@ class CloudInstance(object): def is_instance(self) -> bool: raise NotImplementedError() - - def get_cloud_provider_name(self) -> Environment: - raise NotImplementedError() diff --git a/monkey/common/cloud/scoutsuite_consts.py b/monkey/common/cloud/scoutsuite_consts.py index 091b51114..e2d0c1664 100644 --- a/monkey/common/cloud/scoutsuite_consts.py +++ b/monkey/common/cloud/scoutsuite_consts.py @@ -3,7 +3,3 @@ from enum import Enum class CloudProviders(Enum): AWS = "aws" - AZURE = "azure" - GCP = "gcp" - ALIBABA = "aliyun" - ORACLE = "oci" diff --git a/monkey/common/common_consts/system_info_collectors_names.py b/monkey/common/common_consts/system_info_collectors_names.py index afd9e3321..f87fff4bd 100644 --- a/monkey/common/common_consts/system_info_collectors_names.py +++ b/monkey/common/common_consts/system_info_collectors_names.py @@ -1,5 +1,4 @@ AWS_COLLECTOR = "AwsCollector" HOSTNAME_COLLECTOR = "HostnameCollector" -ENVIRONMENT_COLLECTOR = "EnvironmentCollector" PROCESS_LIST_COLLECTOR = "ProcessListCollector" MIMIKATZ_COLLECTOR = "MimikatzCollector" 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/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index 4bfaa1759..888d1c569 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -14,7 +14,6 @@ from mongoengine import ( StringField, ) -from common.cloud import environment_names 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 @@ -55,14 +54,8 @@ class Monkey(Document): tunnel = ReferenceField("self") command_control_channel = EmbeddedDocumentField(CommandControlChannel) - # Environment related fields - environment = StringField( - default=environment_names.Environment.UNKNOWN.value, - choices=environment_names.ALL_ENVIRONMENTS_NAMES, - ) - aws_instance_id = StringField( - required=False - ) # This field only exists when the monkey is running on an AWS + # This field only exists when the monkey is running on an AWS + aws_instance_id = StringField(required=False) # instance. See https://github.com/guardicore/monkey/issues/426. 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 128503078..514ee3183 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, - ENVIRONMENT_COLLECTOR, HOSTNAME_COLLECTOR, MIMIKATZ_COLLECTOR, PROCESS_LIST_COLLECTOR, @@ -11,14 +10,6 @@ SYSTEM_INFO_COLLECTOR_CLASSES = { "description": "Click on a system info collector to find out what it collects.", "type": "string", "anyOf": [ - { - "type": "string", - "enum": [ENVIRONMENT_COLLECTOR], - "title": "Environment Collector", - "safe": True, - "info": "Collects information about machine's environment (on " "premise/GCP/AWS).", - "attack_techniques": ["T1082"], - }, { "type": "string", "enum": [MIMIKATZ_COLLECTOR], diff --git a/monkey/monkey_island/cc/services/config_schema/monkey.py b/monkey/monkey_island/cc/services/config_schema/monkey.py index ddd14a3d0..68155970f 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, - ENVIRONMENT_COLLECTOR, HOSTNAME_COLLECTOR, MIMIKATZ_COLLECTOR, PROCESS_LIST_COLLECTOR, @@ -88,7 +87,6 @@ MONKEY = { "uniqueItems": True, "items": {"$ref": "#/definitions/system_info_collector_classes"}, "default": [ - ENVIRONMENT_COLLECTOR, AWS_COLLECTOR, HOSTNAME_COLLECTOR, PROCESS_LIST_COLLECTOR, 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/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js index a1c3cb491..e6c2290b2 100644 --- a/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js +++ b/monkey/monkey_island/cc/ui/src/components/pages/RunMonkeyPage/RunOnAWS/AWSRunOptions.js @@ -81,7 +81,7 @@ const getContents = (props) => {