From 90b8b3fc4e966e79d01f3a12e7a1b1e5bda45790 Mon Sep 17 00:00:00 2001 From: vakarisz Date: Fri, 8 Jul 2022 17:09:44 +0300 Subject: [PATCH] Island: Add StolenPropagationCredentials resource --- monkey/monkey_island/cc/app.py | 4 +++ .../cc/resources/credentials/__init__.py | 0 .../stolen_propagation_credentials.py | 27 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 monkey/monkey_island/cc/resources/credentials/__init__.py create mode 100644 monkey/monkey_island/cc/resources/credentials/stolen_propagation_credentials.py diff --git a/monkey/monkey_island/cc/app.py b/monkey/monkey_island/cc/app.py index df8497f65..d9874b460 100644 --- a/monkey/monkey_island/cc/app.py +++ b/monkey/monkey_island/cc/app.py @@ -31,6 +31,9 @@ from monkey_island.cc.resources.blackbox.telemetry_blackbox_endpoint import ( from monkey_island.cc.resources.credentials.configured_propagation_credentials import ( ConfiguredPropagationCredentials, ) +from monkey_island.cc.resources.credentials.stolen_propagation_credentials import ( + StolenPropagationCredentials, +) from monkey_island.cc.resources.edge import Edge from monkey_island.cc.resources.exploitations.manual_exploitation import ManualExploitation from monkey_island.cc.resources.exploitations.monkey_exploitation import MonkeyExploitation @@ -189,6 +192,7 @@ def init_restful_endpoints(api: FlaskDIWrapper): api.add_resource(PropagationCredentials) api.add_resource(ConfiguredPropagationCredentials) + api.add_resource(StolenPropagationCredentials) api.add_resource(RemoteRun) api.add_resource(VersionUpdate) diff --git a/monkey/monkey_island/cc/resources/credentials/__init__.py b/monkey/monkey_island/cc/resources/credentials/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/monkey/monkey_island/cc/resources/credentials/stolen_propagation_credentials.py b/monkey/monkey_island/cc/resources/credentials/stolen_propagation_credentials.py new file mode 100644 index 000000000..2ebda8302 --- /dev/null +++ b/monkey/monkey_island/cc/resources/credentials/stolen_propagation_credentials.py @@ -0,0 +1,27 @@ +import logging + +from flask import jsonify, request + +from common.credentials import Credentials +from monkey_island.cc.repository import ICredentialsRepository +from monkey_island.cc.resources.AbstractResource import AbstractResource + +logger = logging.getLogger(__name__) + + +class StolenPropagationCredentials(AbstractResource): + # API Spec: Resource name should be plural + urls = ["/api/propagation-credentials/stolen"] + + def __init__(self, credentials_repository: ICredentialsRepository): + self._credentials_repository = credentials_repository + + def get(self): + return jsonify(self._credentials_repository.get_stolen_credentials()) + + def post(self): + credentials = Credentials.from_mapping(request.json) + self._credentials_repository.save_stolen_credentials(credentials) + + def delete(self): + self._credentials_repository.remove_stolen_credentials()