Move data modification for PBA from frontend to backend

This commit is contained in:
Shreya 2020-07-22 01:08:31 +05:30
parent b2ef06ea01
commit 6698de3edb
2 changed files with 25 additions and 16 deletions

View File

@ -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']}})

View File

@ -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 <ReactTable