From d3de80feed658743893170e94d4563297c40436b Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Fri, 16 Jul 2021 19:23:18 +0530 Subject: [PATCH] island: Add filters for default config as per mode --- monkey/monkey_island/cc/services/config.py | 17 +++++++++++++++++ .../monkey_island/cc/services/config_filters.py | 3 +++ 2 files changed, 20 insertions(+) create mode 100644 monkey/monkey_island/cc/services/config_filters.py diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index acb12d48a..b29ac56e7 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -2,13 +2,16 @@ import collections import copy import functools import logging +from typing import Dict from jsonschema import Draft4Validator, validators import monkey_island.cc.environment.environment_singleton as env_singleton +from monkey.monkey_island.cc.services.config_filters import FILTER_PER_MODE from monkey_island.cc.database import mongo from monkey_island.cc.server_utils.encryptor import get_encryptor from monkey_island.cc.services.config_schema.config_schema import SCHEMA +from monkey_island.cc.services.mode.island_mode_service import get_mode from monkey_island.cc.services.post_breach_files import PostBreachFilesService from monkey_island.cc.services.utils.network_utils import local_ip_addresses @@ -235,11 +238,25 @@ class ConfigService: def get_default_config(should_encrypt=False): ConfigService.init_default_config() config = copy.deepcopy(ConfigService.default_config) + mode = get_mode() + config = ConfigService._set_default_config_values_per_mode(mode, config) if should_encrypt: ConfigService.encrypt_config(config) logger.info("Default config was called") return config + @staticmethod + def _set_default_config_values_per_mode(mode: str, config: Dict) -> Dict: + if mode == "advanced": + return config + config_filter = FILTER_PER_MODE[mode] + config = ConfigService._apply_config_filter(config, config_filter) + + @staticmethod + def _apply_config_filter(config: Dict, config_filter: Dict): + config.update(config_filter) + return config + @staticmethod def init_config(): if ConfigService.get_config(should_decrypt=False) != {}: diff --git a/monkey/monkey_island/cc/services/config_filters.py b/monkey/monkey_island/cc/services/config_filters.py new file mode 100644 index 000000000..51db21b93 --- /dev/null +++ b/monkey/monkey_island/cc/services/config_filters.py @@ -0,0 +1,3 @@ +from monkey_island.cc.services.mode.mode_enum import IslandModeEnum + +FILTER_PER_MODE = {IslandModeEnum.RANSOMWARE.value: {"basic.monkey.post_breach.post_breach_actions": []}}