From 6314ddd71ad0efbc6368e23e3a8b3270400cc17e Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 10 Jun 2022 13:48:05 +0200 Subject: [PATCH 1/2] Island: Remove PATCH method from api/agent * Remove config_error from monkey document --- monkey/monkey_island/cc/models/monkey.py | 1 - monkey/monkey_island/cc/resources/monkey.py | 23 --------------------- 2 files changed, 24 deletions(-) diff --git a/monkey/monkey_island/cc/models/monkey.py b/monkey/monkey_island/cc/models/monkey.py index 653972456..a106f9965 100644 --- a/monkey/monkey_island/cc/models/monkey.py +++ b/monkey/monkey_island/cc/models/monkey.py @@ -51,7 +51,6 @@ class Monkey(Document): # (even with required=False of null=True). # See relevant issue: https://github.com/MongoEngine/mongoengine/issues/1904 parent = ListField(ListField(DynamicField())) - config_error = BooleanField() critical_services = ListField(StringField()) pba_results = ListField() ttl_ref = ReferenceField(MonkeyTtl) diff --git a/monkey/monkey_island/cc/resources/monkey.py b/monkey/monkey_island/cc/resources/monkey.py index 4438733f6..411c383d2 100644 --- a/monkey/monkey_island/cc/resources/monkey.py +++ b/monkey/monkey_island/cc/resources/monkey.py @@ -27,29 +27,6 @@ class Monkey(AbstractResource): def get(self): return {"config": ConfigService.format_flat_config_for_agent()} - # Used by monkey. can't secure. - @TestTelemStore.store_exported_telem - def patch(self, guid): - - # TODO: This endpoint appears to be doing 3 things, although only one of them is used - # (config_error). The WormConfiguration will be removed in #1960. We should consider - # removing this endpoint - monkey_json = json.loads(request.data) - update = {"$set": {"modifytime": datetime.now()}} - monkey = NodeService.get_monkey_by_guid(guid) - if "config_error" in monkey_json: - update["$set"]["config_error"] = monkey_json["config_error"] - - if "tunnel" in monkey_json: - tunnel_host_ip = monkey_json["tunnel"].split(":")[-2].replace("//", "") - NodeService.set_monkey_tunnel(monkey["_id"], tunnel_host_ip) - - ttl = create_monkey_ttl_document(DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS) - update["$set"]["ttl_ref"] = ttl.id - - # API Spec: What is this returning? Check that it follows rules. - return mongo.db.monkey.update({"_id": monkey["_id"]}, update, upsert=False) - # Used by monkey. can't secure. # Called on monkey wakeup to initialize local configuration @TestTelemStore.store_exported_telem From 153436371b58b0a96d5c431d1e176664cb3d3f0f Mon Sep 17 00:00:00 2001 From: Ilija Lazoroski Date: Fri, 10 Jun 2022 14:44:27 +0200 Subject: [PATCH 2/2] Agent: Remove send_config_error from ControlClient --- monkey/infection_monkey/config.py | 4 ---- monkey/infection_monkey/control.py | 24 +----------------------- 2 files changed, 1 insertion(+), 27 deletions(-) diff --git a/monkey/infection_monkey/config.py b/monkey/infection_monkey/config.py index 0a64f51da..b26762fc5 100644 --- a/monkey/infection_monkey/config.py +++ b/monkey/infection_monkey/config.py @@ -14,7 +14,6 @@ HIDDEN_FIELD_REPLACEMENT_CONTENT = "hidden" class Configuration(object): def from_kv(self, formatted_data): - unknown_items = [] for key, value in list(formatted_data.items()): if key.startswith("_"): continue @@ -22,11 +21,8 @@ class Configuration(object): continue if hasattr(self, key): setattr(self, key, value) - else: - unknown_items.append(key) if not self.max_depth: self.max_depth = self.depth - return unknown_items @staticmethod def hide_sensitive_info(config_dict): diff --git a/monkey/infection_monkey/control.py b/monkey/infection_monkey/control.py index b6568a860..77b52fe3f 100644 --- a/monkey/infection_monkey/control.py +++ b/monkey/infection_monkey/control.py @@ -185,7 +185,7 @@ class ControlClient(object): return try: - unknown_variables = WormConfiguration.from_kv(reply.json().get("config")) + WormConfiguration.from_kv(reply.json().get("config")) formatted_config = pformat( WormConfiguration.hide_sensitive_info(WormConfiguration.as_dict()) ) @@ -200,28 +200,6 @@ class ControlClient(object): ) raise Exception("Couldn't load from from server's configuration, aborting. %s" % exc) - if unknown_variables: - ControlClient.send_config_error() - - @staticmethod - def send_config_error(): - if not WormConfiguration.current_server: - return - try: - requests.patch( # noqa: DUO123 - f"https://{WormConfiguration.current_server}/api/agent/{GUID}", - data=json.dumps({"config_error": True}), - headers={"content-type": "application/json"}, - verify=False, - proxies=ControlClient.proxies, - timeout=MEDIUM_REQUEST_TIMEOUT, - ) - except Exception as exc: - logger.warning( - "Error connecting to control server %s: %s", WormConfiguration.current_server, exc - ) - return {} - @staticmethod def create_control_tunnel(): if not WormConfiguration.current_server: