Island: Add logic to add metadata to config in new configuration resource's GET

This commit is contained in:
Shreya Malviya 2022-06-21 15:57:58 -07:00
parent 922495785c
commit d861def86c
1 changed files with 16 additions and 1 deletions

View File

@ -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):