cc: Process exploit data on backend for ransomware stats reporting

This commit is contained in:
Shreya 2021-07-12 13:11:44 +05:30
parent a95adfb5b6
commit 2212029f0b
2 changed files with 24 additions and 4 deletions

View File

@ -2,10 +2,10 @@ import flask_restful
from flask import jsonify from flask import jsonify
from monkey_island.cc.resources.auth.auth import jwt_required 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): class RansomwareReport(flask_restful.Resource):
@jwt_required @jwt_required
def get(self): def get(self):
return jsonify({"report": None, "propagation": get_exploitation_details()}) return jsonify({"report": None, "propagation_stats": get_propagation_stats()})

View File

@ -1,8 +1,28 @@
from typing import Dict, List
from monkey_island.cc.services.reporting.report import ReportService from monkey_island.cc.services.reporting.report import ReportService
def get_exploitation_details(): def get_propagation_stats() -> Dict:
scanned = ReportService.get_scanned() scanned = ReportService.get_scanned()
exploited = ReportService.get_exploited() 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