From d861def86cfea2860c6770e27feea6c11e6822e8 Mon Sep 17 00:00:00 2001 From: Shreya Malviya Date: Tue, 21 Jun 2022 15:57:58 -0700 Subject: [PATCH] Island: Add logic to add metadata to config in new configuration resource's GET --- .../monkey_island/cc/resources/configuration.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/monkey/monkey_island/cc/resources/configuration.py b/monkey/monkey_island/cc/resources/configuration.py index 5ec163ded..7b8929ab9 100644 --- a/monkey/monkey_island/cc/resources/configuration.py +++ b/monkey/monkey_island/cc/resources/configuration.py @@ -7,6 +7,7 @@ import marshmallow from flask import jsonify, request from common.configuration.agent_configuration import AgentConfigurationSchema +from common.configuration.default_agent_configuration import DEFAULT_AGENT_CONFIGURATION from monkey_island.cc.repository import IAgentConfigurationRepository from monkey_island.cc.resources.AbstractResource import AbstractResource from monkey_island.cc.resources.request_authentication import jwt_required @@ -37,7 +38,21 @@ class AgentConfiguration(AbstractResource): @jwt_required def get(self): configuration = self._agent_configuration_repository.get_configuration() - return jsonify(configuration=configuration) + configuration_json = self._schema.dumps(configuration) + # for when the agent requests the config; it needs the exploiters' metadata + # Q: but this'll cause issues when the frontend requests the config? + AgentConfiguration._add_metadata_to_config(configuration_json) + return jsonify(configuration_json=configuration_json) + + @staticmethod + def _add_metadata_to_config(configuration_json): + for exploiter_type in ["brute_force", "vulnerability"]: + for exploiter in configuration_json["propagation"]["exploitation"][exploiter_type]: + # there has to be a better way to do this + if "supported_os" not in exploiter: + exploiter["supported_os"] = DEFAULT_AGENT_CONFIGURATION["propagation"][ + "exploitation" + ][exploiter_type]["supported_os"] @jwt_required def post(self):