From 5bc061a6585d9e1ba29145cd1cdcf1833a0091b9 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Fri, 11 Oct 2019 21:09:34 +0300 Subject: [PATCH 1/2] Fixed cause for exception - bad JSON field access. Guid instead of id. --- .../cc/services/telemetry/processing/system_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py index a970c0cd4..17d494729 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py @@ -102,4 +102,4 @@ def process_aws_data(telemetry_json): def update_db_with_new_hostname(telemetry_json): - Monkey.get_single_monkey_by_id(telemetry_json['_id']).set_hostname(telemetry_json['data']['hostname']) + Monkey.get_single_monkey_by_guid(telemetry_json['monkey_guid']).set_hostname(telemetry_json['data']['hostname']) From ef04c341f52fae1cab5f9fd10e789402c4995214 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Fri, 11 Oct 2019 21:10:31 +0300 Subject: [PATCH 2/2] Added "safe_process_telemetry" so if one stage of processing fails (in the future), it won't fail the other stages. --- .../telemetry/processing/system_info.py | 32 +++++++++++++++---- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py index 17d494729..0af9a4315 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/system_info.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/system_info.py @@ -1,3 +1,5 @@ +import logging + from monkey_island.cc.database import mongo from monkey_island.cc.models import Monkey from monkey_island.cc.services import mimikatz_utils @@ -7,14 +9,32 @@ from monkey_island.cc.services.telemetry.zero_trust_tests.antivirus_existence im from monkey_island.cc.services.wmi_handler import WMIHandler from monkey_island.cc.encryptor import encryptor +logger = logging.getLogger(__name__) + def process_system_info_telemetry(telemetry_json): - process_ssh_info(telemetry_json) - process_credential_info(telemetry_json) - process_mimikatz_and_wmi_info(telemetry_json) - process_aws_data(telemetry_json) - update_db_with_new_hostname(telemetry_json) - test_antivirus_existence(telemetry_json) + telemetry_processing_stages = [ + process_ssh_info, + process_credential_info, + process_mimikatz_and_wmi_info, + process_aws_data, + update_db_with_new_hostname, + test_antivirus_existence, + ] + + # Calling safe_process_telemetry so if one of the stages fail, we log and move on instead of failing the rest of + # them, as they are independent. + for stage in telemetry_processing_stages: + safe_process_telemetry(stage, telemetry_json) + + +def safe_process_telemetry(processing_function, telemetry_json): + # noinspection PyBroadException + try: + processing_function(telemetry_json) + except Exception as err: + logger.error("Error while in {} stage of processing telemetry.".format(processing_function.func_name), + exc_info=True) def process_ssh_info(telemetry_json):