From 2212029f0bd07648a0eab5ae44d706e3fb869f39 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 12 Jul 2021 13:11:44 +0530 Subject: [PATCH] cc: Process exploit data on backend for ransomware stats reporting --- .../cc/resources/ransomware_report.py | 4 ++-- .../cc/services/ransomware_report.py | 24 +++++++++++++++++-- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/monkey/monkey_island/cc/resources/ransomware_report.py b/monkey/monkey_island/cc/resources/ransomware_report.py index c5dfef3a8..93a318114 100644 --- a/monkey/monkey_island/cc/resources/ransomware_report.py +++ b/monkey/monkey_island/cc/resources/ransomware_report.py @@ -2,10 +2,10 @@ import flask_restful from flask import jsonify from monkey_island.cc.resources.auth.auth import jwt_required -from monkey_island.cc.services.ransomware_report import get_exploitation_details +from monkey_island.cc.services.ransomware_report import get_propagation_stats class RansomwareReport(flask_restful.Resource): @jwt_required def get(self): - return jsonify({"report": None, "propagation": get_exploitation_details()}) + return jsonify({"report": None, "propagation_stats": get_propagation_stats()}) diff --git a/monkey/monkey_island/cc/services/ransomware_report.py b/monkey/monkey_island/cc/services/ransomware_report.py index 74d30cf93..691ae1fd3 100644 --- a/monkey/monkey_island/cc/services/ransomware_report.py +++ b/monkey/monkey_island/cc/services/ransomware_report.py @@ -1,8 +1,28 @@ +from typing import Dict, List + from monkey_island.cc.services.reporting.report import ReportService -def get_exploitation_details(): +def get_propagation_stats() -> Dict: scanned = ReportService.get_scanned() exploited = ReportService.get_exploited() - return {"scanned": scanned, "exploited": exploited} + return { + "num_scanned_nodes": len(scanned), + "num_exploited_nodes": len(exploited), + "count_per_exploit": _get_exploit_counts(exploited), + } + + +def _get_exploit_counts(exploited: List[Dict]) -> Dict: + exploit_counts = {} + + for node in exploited: + exploits = node["exploits"] + for exploit in exploits: + if exploit in exploit_counts: + exploit_counts[exploit] += 1 + else: + exploit_counts[exploit] = 1 + + return exploit_counts