From dec7d9021f719eb77c7b03d05888452601370a42 Mon Sep 17 00:00:00 2001 From: Shreya Date: Wed, 22 Jul 2020 01:08:31 +0530 Subject: [PATCH] Move data modification for PBA from frontend to backend --- .../telemetry/processing/post_breach.py | 30 +++++++++++++++---- .../report-components/security/PostBreach.js | 11 ------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/monkey/monkey_island/cc/services/telemetry/processing/post_breach.py b/monkey/monkey_island/cc/services/telemetry/processing/post_breach.py index 974a696d5..63cdfff48 100644 --- a/monkey/monkey_island/cc/services/telemetry/processing/post_breach.py +++ b/monkey/monkey_island/cc/services/telemetry/processing/post_breach.py @@ -1,4 +1,8 @@ -from common.data.post_breach_consts import POST_BREACH_COMMUNICATE_AS_NEW_USER +import copy + +from common.data.post_breach_consts import ( + POST_BREACH_COMMUNICATE_AS_NEW_USER, + POST_BREACH_SHELL_STARTUP_FILE_MODIFICATION) from monkey_island.cc.database import mongo from monkey_island.cc.models import Monkey from monkey_island.cc.services.telemetry.zero_trust_tests.communicate_as_new_user import \ @@ -12,16 +16,32 @@ def process_communicate_as_new_user_telemetry(telemetry_json): test_new_user_communication(current_monkey, success, message) +def process_shell_startup_file_modification_telemetry(telemetry_json): + modified_data = [] + for result in telemetry_json['data']['result']: + temp = copy.deepcopy(telemetry_json['data']) + temp['result'] = result + modified_data.append(temp) + telemetry_json['data'] = modified_data + + POST_BREACH_TELEMETRY_PROCESSING_FUNCS = { POST_BREACH_COMMUNICATE_AS_NEW_USER: process_communicate_as_new_user_telemetry, + POST_BREACH_SHELL_STARTUP_FILE_MODIFICATION: process_shell_startup_file_modification_telemetry, } def process_post_breach_telemetry(telemetry_json): - mongo.db.monkey.update( - {'guid': telemetry_json['monkey_guid']}, - {'$push': {'pba_results': telemetry_json['data']}}) - post_breach_action_name = telemetry_json["data"]["name"] if post_breach_action_name in POST_BREACH_TELEMETRY_PROCESSING_FUNCS: POST_BREACH_TELEMETRY_PROCESSING_FUNCS[post_breach_action_name](telemetry_json) + + if type(telemetry_json['data']) is list: + for pba_data in telemetry_json['data']: + mongo.db.monkey.update( + {'guid': telemetry_json['monkey_guid']}, + {'$push': {'pba_results': pba_data}}) + else: + mongo.db.monkey.update( + {'guid': telemetry_json['monkey_guid']}, + {'$push': {'pba_results': telemetry_json['data']}}) diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/security/PostBreach.js b/monkey/monkey_island/cc/ui/src/components/report-components/security/PostBreach.js index f49995b27..cc9ea1c20 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/security/PostBreach.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/security/PostBreach.js @@ -23,17 +23,6 @@ const subColumns = [ ]; let renderDetails = function (data) { - data.forEach(pba => { - if (typeof pba['result'][0] === "object") { // if `result` has more than one entry - let results = pba['result']; - let details = data.splice(data.indexOf(pba), 1); // remove that pba from `data` - results.forEach(result => { // add back those results to `data` as individual pba entries - let tempDetails = JSON.parse(JSON.stringify(details)); - tempDetails[0]['result'] = result; - data.push(tempDetails[0]); - }); - } - }); let defaultPageSize = data.length > pageSize ? pageSize : data.length; let showPagination = data.length > pageSize; return