From b73c3d10e157f066214049f8cb1b6f413bfb61d7 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Mon, 28 Mar 2022 14:23:04 -0400 Subject: [PATCH] Island: Add a list of supported OSs to exploiters --- monkey/monkey_island/cc/services/config.py | 24 ++++++++++++++- .../monkey_configs/flat_config.json | 3 +- .../monkey_island/cc/services/test_config.py | 29 ++++++++++++------- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index f90df6847..c5f78e62d 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -3,6 +3,7 @@ import copy import functools import logging import re +from itertools import chain from typing import Any, Dict, List from jsonschema import Draft4Validator, validators @@ -629,9 +630,10 @@ class ConfigService: config.pop(flat_config_exploiter_classes_field, None) - return ConfigService._add_smb_download_timeout_to_exploiters( + formatted_exploiters_config = ConfigService._add_smb_download_timeout_to_exploiters( config, formatted_exploiters_config ) + return ConfigService._add_supported_os_to_exploiters(formatted_exploiters_config) @staticmethod def _add_smb_download_timeout_to_exploiters( @@ -644,3 +646,23 @@ class ConfigService: exploiter["options"]["smb_download_timeout"] = flat_config["smb_download_timeout"] return new_config + + @staticmethod + def _add_supported_os_to_exploiters( + formatted_config: Dict, + ) -> Dict[str, List[Dict[str, Any]]]: + supported_os = { + "HadoopExploiter": ["linux", "windows"], + "Log4ShellExploiter": ["linux", "windows"], + "MSSQLExploiter": ["windows"], + "PowerShellExploiter": ["windows"], + "SSHExploiter": ["linux"], + "SmbExploiter": ["windows"], + "WmiExploiter": ["windows"], + "ZerologonExploiter": ["windows"], + } + new_config = copy.deepcopy(formatted_config) + for exploiter in chain(new_config["brute_force"], new_config["vulnerability"]): + exploiter["supported_os"] = supported_os.get(exploiter["name"], []) + + return new_config diff --git a/monkey/tests/data_for_tests/monkey_configs/flat_config.json b/monkey/tests/data_for_tests/monkey_configs/flat_config.json index f36bc5d18..b9dae9453 100644 --- a/monkey/tests/data_for_tests/monkey_configs/flat_config.json +++ b/monkey/tests/data_for_tests/monkey_configs/flat_config.json @@ -55,7 +55,8 @@ "HadoopExploiter", "MSSQLExploiter", "DrupalExploiter", - "PowerShellExploiter" + "PowerShellExploiter", + "Log4ShellExploiter" ], "export_monkey_telems": false, "finger_classes": [ diff --git a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py index 72dafd168..ae0a44cdc 100644 --- a/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py +++ b/monkey/tests/unit_tests/monkey_island/cc/services/test_config.py @@ -177,18 +177,27 @@ def test_format_config_for_agent__exploiters(flat_monkey_config): "http_ports": [80, 443, 7001, 8008, 8080, 9200], }, "brute_force": [ - {"name": "MSSQLExploiter", "options": {}}, - {"name": "PowerShellExploiter", "options": {}}, - {"name": "SSHExploiter", "options": {}}, - {"name": "SmbExploiter", "options": {"smb_download_timeout": 300}}, - {"name": "WmiExploiter", "options": {"smb_download_timeout": 300}}, + {"name": "MSSQLExploiter", "supported_os": ["windows"], "options": {}}, + {"name": "PowerShellExploiter", "supported_os": ["windows"], "options": {}}, + {"name": "SSHExploiter", "supported_os": ["linux"], "options": {}}, + { + "name": "SmbExploiter", + "supported_os": ["windows"], + "options": {"smb_download_timeout": 300}, + }, + { + "name": "WmiExploiter", + "supported_os": ["windows"], + "options": {"smb_download_timeout": 300}, + }, ], "vulnerability": [ - {"name": "DrupalExploiter", "options": {}}, - {"name": "HadoopExploiter", "options": {}}, - {"name": "Struts2Exploiter", "options": {}}, - {"name": "WebLogicExploiter", "options": {}}, - {"name": "ZerologonExploiter", "options": {}}, + {"name": "DrupalExploiter", "supported_os": [], "options": {}}, + {"name": "HadoopExploiter", "supported_os": ["linux", "windows"], "options": {}}, + {"name": "Log4ShellExploiter", "supported_os": ["linux", "windows"], "options": {}}, + {"name": "Struts2Exploiter", "supported_os": [], "options": {}}, + {"name": "WebLogicExploiter", "supported_os": [], "options": {}}, + {"name": "ZerologonExploiter", "supported_os": ["windows"], "options": {}}, ], } ConfigService.format_flat_config_for_agent(flat_monkey_config)