From 47375efe42fb0a01441e27496cce7796fbfc9c08 Mon Sep 17 00:00:00 2001 From: Shay Nehmad Date: Mon, 12 Aug 2019 18:21:55 +0300 Subject: [PATCH] Findings resource is now real data from the DB instead of mock data. --- .../cc/resources/reporting/report.py | 53 ++++++++----------- .../zerotrust/EventsTimeline.js | 20 +++---- 2 files changed, 33 insertions(+), 40 deletions(-) diff --git a/monkey/monkey_island/cc/resources/reporting/report.py b/monkey/monkey_island/cc/resources/reporting/report.py index 384ca09fe..61a034e45 100644 --- a/monkey/monkey_island/cc/resources/reporting/report.py +++ b/monkey/monkey_island/cc/resources/reporting/report.py @@ -1,9 +1,12 @@ import httplib +import json import flask_restful from flask import jsonify +from common.data.zero_trust_consts import TESTS_MAP, EXPLANATION_KEY, PILLARS_KEY from monkey_island.cc.auth import jwt_required +from monkey_island.cc.models.finding import Finding from monkey_island.cc.services.reporting.report import ReportService ZERO_TRUST_REPORT_TYPE = "zero_trust" @@ -35,37 +38,25 @@ class Report(flask_restful.Resource): def get_all_findings(): - return [ - { - "test": "Monkey 8 found a machine with no AV software active.", - "conclusive": False, - "pillars": ["Devices"], - "events": [ - { - "timestamp": "2019-08-01 14:48:46.112000", - "title": "Monkey performed an action", - "type": "MonkeyAction", - "message": "log1" - }, { - "timestamp": "2019-08-01 14:48:42.112000", - "title": "Analysis", - "type": "IslandAction", - "message": "log2" - }] - }, - { - "test": "Monkey 6 successfully exploited machine XXX with shellshock.", - "conclusive": True, - "pillars": ["Devices", "Networks"], - "events": [ - { - "timestamp": "2019-08-01 14:48:46.112000", - "title": "Analysis", - "type": "MonkeyAction", - "message": "log3" - }] - } - ] + all_findings = Finding.objects() + enriched_findings = [get_enriched_finding(f) for f in all_findings] + return enriched_findings + + +def get_events_as_dict(events): + return [json.loads(event.to_json()) for event in events] + + +def get_enriched_finding(finding): + test_info = TESTS_MAP[finding.test] + enriched_finding = { + # TODO add test explanation per status. + "test": test_info[EXPLANATION_KEY], + "pillars": test_info[PILLARS_KEY], + "status": finding.status, + "events": get_events_as_dict(finding.events) + } + return enriched_finding def get_recommendations_status(): diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/EventsTimeline.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/EventsTimeline.js index ec0842309..f70d5df31 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/EventsTimeline.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/EventsTimeline.js @@ -2,8 +2,9 @@ import React, {Component} from "react"; import {Timeline, TimelineEvent} from "react-event-timeline"; const eventTypeToIcon = { - "MonkeyAction": "fa fa-exclamation-circle fa-2x icon-warning", - "IslandAction": "fa fa-server fa-2x icon-info", + "monkey_local": "fa fa-exclamation-circle fa-2x icon-warning", + "monkey_network": "fa fa-exclamation-circle fa-2x icon-warning", + "island": "fa fa-server fa-2x icon-info", null: "fa fa-question-circle fa-2x icon-info", }; @@ -13,15 +14,16 @@ export class EventsTimeline extends Component {
{ - this.props["events"].map(event => ( - { + const event_time = new Date(event.timestamp['$date']).toString(); + return (}> + icon={}> {event.message} - - )) + ) + }) }