From 7807a46769f2abeca3c74cb20e127eb1c3213f66 Mon Sep 17 00:00:00 2001 From: Itay Mizeretz Date: Wed, 18 Oct 2017 16:06:03 +0300 Subject: [PATCH] Add all known telemetry types to dict + don't except when unknown telem_type is received telem_type + data don't have default value --- chaos_monkey/control.py | 4 ++-- monkey_island/cc/resources/telemetry.py | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/chaos_monkey/control.py b/chaos_monkey/control.py index ab5abec83..b4f2769cd 100644 --- a/chaos_monkey/control.py +++ b/chaos_monkey/control.py @@ -97,11 +97,11 @@ class ControlClient(object): return {} @staticmethod - def send_telemetry(tele_type='general', data=''): + def send_telemetry(telem_type, data): if not WormConfiguration.current_server: return try: - telemetry = {'monkey_guid': GUID, 'telem_type': tele_type, 'data': data} + telemetry = {'monkey_guid': GUID, 'telem_type': telem_type, 'data': data} reply = requests.post("https://%s/api/telemetry" % (WormConfiguration.current_server,), data=json.dumps(telemetry), headers={'content-type': 'application/json'}, diff --git a/monkey_island/cc/resources/telemetry.py b/monkey_island/cc/resources/telemetry.py index a5e9bac5b..88b144333 100644 --- a/monkey_island/cc/resources/telemetry.py +++ b/monkey_island/cc/resources/telemetry.py @@ -43,8 +43,12 @@ class Telemetry(flask_restful.Resource): monkey = NodeService.get_monkey_by_guid(telemetry_json['monkey_guid']) try: - TELEM_PROCESS_DICT[telemetry_json.get('telem_type')](telemetry_json) NodeService.update_monkey_modify_time(monkey["_id"]) + telem_type = telemetry_json.get('telem_type') + if telem_type in TELEM_PROCESS_DICT: + TELEM_PROCESS_DICT[telem_type](telemetry_json) + else: + print('Got unknown type of telemetry: %s' % telem_type) except StandardError as ex: print("Exception caught while processing telemetry: %s" % str(ex)) traceback.print_exc() @@ -154,6 +158,10 @@ class Telemetry(flask_restful.Resource): if 'ntlm_hash' in creds[user]: ConfigService.creds_add_ntlm_hash(creds[user]['ntlm_hash']) + @staticmethod + def process_trace_telemetry(telemetry_json): + # Nothing to do + return TELEM_PROCESS_DICT = \ { @@ -162,4 +170,5 @@ TELEM_PROCESS_DICT = \ 'exploit': Telemetry.process_exploit_telemetry, 'scan': Telemetry.process_scan_telemetry, 'system_info_collection': Telemetry.process_system_info_telemetry, + 'trace': Telemetry.process_trace_telemetry } \ No newline at end of file