ScoutSuite performance upgrades.

This commit is contained in:
VakarisZ 2021-03-17 10:02:13 +02:00
parent aaf6a33f92
commit 2c1e89c7b3
4 changed files with 18 additions and 8 deletions

View File

@ -1,5 +1,8 @@
# abstract, static method decorator # abstract, static method decorator
# noinspection PyPep8Naming # noinspection PyPep8Naming
from typing import List
class abstractstatic(staticmethod): class abstractstatic(staticmethod):
__slots__ = () __slots__ = ()
@ -8,3 +11,10 @@ class abstractstatic(staticmethod):
function.__isabstractmethod__ = True function.__isabstractmethod__ = True
__isabstractmethod__ = True __isabstractmethod__ = True
def get_value_from_dict(dict_data: dict, path: List[str]):
current_data = dict_data
for key in path:
current_data = current_data[key]
return current_data

View File

@ -3,6 +3,7 @@ import json
from monkey_island.cc.database import mongo from monkey_island.cc.database import mongo
from monkey_island.cc.models.zero_trust.scoutsuite_data_json import ScoutSuiteRawDataJson from monkey_island.cc.models.zero_trust.scoutsuite_data_json import ScoutSuiteRawDataJson
from monkey_island.cc.services.zero_trust.scoutsuite.consts.scoutsuite_findings_list import SCOUTSUITE_FINDINGS from monkey_island.cc.services.zero_trust.scoutsuite.consts.scoutsuite_findings_list import SCOUTSUITE_FINDINGS
from monkey_island.cc.services.zero_trust.scoutsuite.consts.service_consts import SERVICES
from monkey_island.cc.services.zero_trust.scoutsuite.data_parsing.rule_parser import RuleParser from monkey_island.cc.services.zero_trust.scoutsuite.data_parsing.rule_parser import RuleParser
from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_rule_service import ScoutSuiteRuleService from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_rule_service import ScoutSuiteRuleService
from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_zt_finding_service import ScoutSuiteZTFindingService from monkey_island.cc.services.zero_trust.scoutsuite.scoutsuite_zt_finding_service import ScoutSuiteZTFindingService
@ -13,14 +14,14 @@ def process_scoutsuite_telemetry(telemetry_json):
telemetry_json['data'] = json.dumps(telemetry_json['data']) telemetry_json['data'] = json.dumps(telemetry_json['data'])
ScoutSuiteRawDataJson.add_scoutsuite_data(telemetry_json['data']) ScoutSuiteRawDataJson.add_scoutsuite_data(telemetry_json['data'])
scoutsuite_data = json.loads(telemetry_json['data'])['data'] scoutsuite_data = json.loads(telemetry_json['data'])['data']
create_scoutsuite_findings(scoutsuite_data) create_scoutsuite_findings(scoutsuite_data[SERVICES])
update_data(telemetry_json) update_data(telemetry_json)
def create_scoutsuite_findings(scoutsuite_data): def create_scoutsuite_findings(cloud_services: dict):
for finding in SCOUTSUITE_FINDINGS: for finding in SCOUTSUITE_FINDINGS:
for rule in finding.rules: for rule in finding.rules:
rule_data = RuleParser.get_rule_data(scoutsuite_data, rule) rule_data = RuleParser.get_rule_data(cloud_services, rule)
rule = ScoutSuiteRuleService.get_rule_from_rule_data(rule_data) rule = ScoutSuiteRuleService.get_rule_from_rule_data(rule_data)
ScoutSuiteZTFindingService.process_rule(finding, rule) ScoutSuiteZTFindingService.process_rule(finding, rule)

View File

@ -1,7 +1,6 @@
from enum import Enum from enum import Enum
import dpath.util from common.utils.code_utils import get_value_from_dict
from common.utils.exceptions import RulePathCreatorNotFound from common.utils.exceptions import RulePathCreatorNotFound
from monkey_island.cc.services.zero_trust.scoutsuite.data_parsing.rule_path_building.rule_path_creators_list import \ from monkey_island.cc.services.zero_trust.scoutsuite.data_parsing.rule_path_building.rule_path_creators_list import \
RULE_PATH_CREATORS_LIST RULE_PATH_CREATORS_LIST
@ -23,7 +22,7 @@ class RuleParser:
@staticmethod @staticmethod
def get_rule_data(scoutsuite_data: dict, rule_name: Enum) -> dict: def get_rule_data(scoutsuite_data: dict, rule_name: Enum) -> dict:
rule_path = RuleParser._get_rule_path(rule_name) rule_path = RuleParser._get_rule_path(rule_name)
return dpath.util.get(scoutsuite_data, rule_path) return get_value_from_dict(scoutsuite_data, rule_path)
@staticmethod @staticmethod
def _get_rule_path(rule_name: Enum): def _get_rule_path(rule_name: Enum):

View File

@ -3,7 +3,7 @@ from enum import Enum
from typing import List, Type from typing import List, Type
from monkey_island.cc.services.zero_trust.scoutsuite.consts.rule_names.rule_name_enum import RuleNameEnum from monkey_island.cc.services.zero_trust.scoutsuite.consts.rule_names.rule_name_enum import RuleNameEnum
from monkey_island.cc.services.zero_trust.scoutsuite.consts.service_consts import FINDINGS, SERVICES, SERVICE_TYPES from monkey_island.cc.services.zero_trust.scoutsuite.consts.service_consts import FINDINGS, SERVICE_TYPES
class AbstractRulePathCreator(ABC): class AbstractRulePathCreator(ABC):
@ -21,4 +21,4 @@ class AbstractRulePathCreator(ABC):
@classmethod @classmethod
def build_rule_path(cls, rule_name: Enum) -> List[str]: def build_rule_path(cls, rule_name: Enum) -> List[str]:
assert(rule_name in cls.supported_rules) assert(rule_name in cls.supported_rules)
return [SERVICES, cls.service_type.value, FINDINGS, rule_name.value] return [cls.service_type.value, FINDINGS, rule_name.value]