From 944406725042daa6080ac3a3ae053a3d039b9d54 Mon Sep 17 00:00:00 2001 From: VakarisZ Date: Fri, 5 Feb 2021 11:05:22 +0200 Subject: [PATCH] Added comments, type hints and other minor changes in the scoutsuite code --- .../cc/resources/zero_trust/zero_trust_report.py | 1 + .../monkey_findings/monkey_zt_finding_service.py | 2 +- .../scoutsuite/consts/scoutsuite_findings.py | 2 +- .../zero_trust/test_common/monkey_finding_data.py | 2 +- .../zerotrust/scoutsuite/RuleDisplay.js | 4 ++++ .../zerotrust/scoutsuite/ScoutSuiteDataParser.js | 11 +++++++++++ 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/monkey/monkey_island/cc/resources/zero_trust/zero_trust_report.py b/monkey/monkey_island/cc/resources/zero_trust/zero_trust_report.py index a85499b2f..a69ea50c0 100644 --- a/monkey/monkey_island/cc/resources/zero_trust/zero_trust_report.py +++ b/monkey/monkey_island/cc/resources/zero_trust/zero_trust_report.py @@ -26,6 +26,7 @@ class ZeroTrustReport(flask_restful.Resource): elif report_data == REPORT_DATA_FINDINGS: return jsonify(FindingService.get_all_findings()) elif report_data == REPORT_DATA_SCOUTSUITE: + # Raw ScoutSuite data is already solved as json, no need to jsonify return Response(ScoutSuiteRawDataService.get_scoutsuite_data_json(), mimetype='application/json') diff --git a/monkey/monkey_island/cc/services/zero_trust/monkey_findings/monkey_zt_finding_service.py b/monkey/monkey_island/cc/services/zero_trust/monkey_findings/monkey_zt_finding_service.py index c3c45e69e..7ed184559 100644 --- a/monkey/monkey_island/cc/services/zero_trust/monkey_findings/monkey_zt_finding_service.py +++ b/monkey/monkey_island/cc/services/zero_trust/monkey_findings/monkey_zt_finding_service.py @@ -11,7 +11,7 @@ from monkey_island.cc.models.zero_trust.monkey_finding_details import MonkeyFind class MonkeyZTFindingService: @staticmethod - def create_or_add_to_existing(test, status, events): + def create_or_add_to_existing(test: str, status: str, events: str): """ Create a new finding or add the events to an existing one if it's the same (same meaning same status and same test). diff --git a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/scoutsuite_findings.py b/monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/scoutsuite_findings.py index 3368cbbdf..0881b4733 100644 --- a/monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/scoutsuite_findings.py +++ b/monkey/monkey_island/cc/services/zero_trust/scoutsuite/consts/scoutsuite_findings.py @@ -22,7 +22,7 @@ from .rule_names.vpc_rules import VPCRules class ScoutSuiteFinding(ABC): @property @abstractmethod - def rules(self) -> List[str]: + def rules(self) -> List[EC2Rules]: pass @property diff --git a/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py b/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py index d727ea9e8..b0050a8c9 100644 --- a/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py +++ b/monkey/monkey_island/cc/services/zero_trust/test_common/monkey_finding_data.py @@ -5,7 +5,7 @@ EVENTS = [ { "timestamp": "2021-01-20T15:40:28.357Z", "title": "Process list", - "message": "Monkey on gc-pc-244 scanned the process list", + "message": "Monkey on pc-24 scanned the process list", "event_type": "monkey_local" }, { diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/RuleDisplay.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/RuleDisplay.js index ac267e193..dc81ff183 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/RuleDisplay.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/RuleDisplay.js @@ -36,6 +36,8 @@ export default function RuleDisplay(props) {

References:

{references} ) + } else { + return null; } } @@ -56,6 +58,8 @@ export default function RuleDisplay(props) {

Flagged resources ({props.rule.flagged_items}):

{resources} ) + } else { + return null; } } } diff --git a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteDataParser.js b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteDataParser.js index 9657c0bba..be5599d99 100644 --- a/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteDataParser.js +++ b/monkey/monkey_island/cc/ui/src/components/report-components/zerotrust/scoutsuite/ScoutSuiteDataParser.js @@ -15,6 +15,12 @@ export default class ScoutSuiteDataParser { return this.getObjectValueByPath(resourcePath, this.runResults); } + /** + * Replaces id's in template path with id's from item path to form actual path to the object + * @param itemPath e.g. s3.buckets.da1e7081077ce92.secure_transport_enabled + * @param templatePath e.g. s3.buckets.id + * @returns {*} e.g. s3.buckets.da1e7081077ce92 + */ fillTemplatePath(itemPath, templatePath) { let itemPathArray = itemPath.split('.'); let templatePathArray = templatePath.split('.'); @@ -42,6 +48,11 @@ export default class ScoutSuiteDataParser { return source; } + /** + * Gets next key from the path + * @param path e.g. s3.buckets.id + * @returns {string|*} s3 + */ getNextKeyInPath(path) { if (path.indexOf('.') !== -1) { return path.substr(0, path.indexOf('.'));