From 44055b32f9c9fb4981d3f92b02595e06a7d6a857 Mon Sep 17 00:00:00 2001 From: Mike Salvatore Date: Fri, 3 Dec 2021 09:17:33 -0500 Subject: [PATCH] Island: Reformat "payloads" in config before sending to agent Allow the configuration to contain multiple payloads that can be run by the agent. --- monkey/monkey_island/cc/services/config.py | 6 +++++ .../monkey_configs/flat_config.json | 4 ++-- .../monkey_island/cc/services/test_config.py | 22 +++++++++++++++++++ 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/monkey/monkey_island/cc/services/config.py b/monkey/monkey_island/cc/services/config.py index 4e5290a19..80228c8e6 100644 --- a/monkey/monkey_island/cc/services/config.py +++ b/monkey/monkey_island/cc/services/config.py @@ -430,6 +430,7 @@ class ConfigService: @staticmethod def format_flat_config_for_agent(config: Dict): ConfigService._remove_credentials_from_flat_config(config) + ConfigService._format_payloads_from_flat_config(config) @staticmethod def _remove_credentials_from_flat_config(config: Dict): @@ -443,3 +444,8 @@ class ConfigService: for field in fields_to_remove: config.pop(field, None) + + @staticmethod + def _format_payloads_from_flat_config(config: Dict): + config.setdefault("payloads", {})["ransomware"] = config["ransomware"] + config.pop("ransomware", None) 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 82cc895a1..1f700d40f 100644 --- a/monkey/tests/data_for_tests/monkey_configs/flat_config.json +++ b/monkey/tests/data_for_tests/monkey_configs/flat_config.json @@ -93,8 +93,8 @@ "encryption": { "enabled": true, "directories": { - "linux_target_dir": "", - "windows_target_dir": "" + "linux_target_dir": "/tmp/ransomware-target", + "windows_target_dir": "C:\\windows\\temp\\ransomware-target" } }, "other_behaviors": { 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 30e56e05e..2f67c2f76 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 @@ -33,3 +33,25 @@ def test_format_config_for_agent__credentials_removed(flat_monkey_config): assert "exploit_password_list" not in flat_monkey_config assert "exploit_ssh_keys" not in flat_monkey_config assert "exploit_user_list" not in flat_monkey_config + + +def test_format_config_for_agent__ransomware_payload(flat_monkey_config): + expected_ransomware_config = { + "ransomware": { + "encryption": { + "enabled": True, + "directories": { + "linux_target_dir": "/tmp/ransomware-target", + "windows_target_dir": "C:\\windows\\temp\\ransomware-target", + }, + }, + "other_behaviors": {"readme": True}, + } + } + + ConfigService.format_flat_config_for_agent(flat_monkey_config) + + assert "payloads" in flat_monkey_config + assert flat_monkey_config["payloads"] == expected_ransomware_config + + assert "ransomware" not in flat_monkey_config