forked from p15670423/monkey
Island: Move URL definitions to resource classes
This commit is contained in:
parent
ce12d46012
commit
f0a613eb75
|
@ -143,65 +143,49 @@ class FlaskDIWrapper:
|
|||
|
||||
|
||||
def init_api_resources(api: FlaskDIWrapper):
|
||||
api.add_resource(Root, "/api")
|
||||
api.add_resource(Registration, "/api/registration")
|
||||
api.add_resource(Authenticate, "/api/auth")
|
||||
api.add_resource(
|
||||
Monkey,
|
||||
"/api/agent",
|
||||
"/api/agent/<string:guid>",
|
||||
"/api/agent/<string:guid>/<string:config_format>",
|
||||
)
|
||||
api.add_resource(LocalRun, "/api/local-monkey")
|
||||
api.add_resource(Telemetry, "/api/telemetry", "/api/telemetry/<string:monkey_guid>")
|
||||
api.add_resource(Root)
|
||||
api.add_resource(Registration)
|
||||
api.add_resource(Authenticate)
|
||||
api.add_resource(Monkey)
|
||||
api.add_resource(LocalRun)
|
||||
api.add_resource(Telemetry)
|
||||
|
||||
api.add_resource(IslandMode, "/api/island-mode")
|
||||
api.add_resource(IslandConfiguration, "/api/configuration/island")
|
||||
api.add_resource(ConfigurationExport, "/api/configuration/export")
|
||||
api.add_resource(ConfigurationImport, "/api/configuration/import")
|
||||
api.add_resource(
|
||||
MonkeyDownload,
|
||||
"/api/agent/download/<string:host_os>",
|
||||
)
|
||||
api.add_resource(NetMap, "/api/netmap")
|
||||
api.add_resource(Edge, "/api/netmap/edge")
|
||||
api.add_resource(Node, "/api/netmap/node")
|
||||
api.add_resource(NodeStates, "/api/netmap/node-states")
|
||||
api.add_resource(IslandMode)
|
||||
api.add_resource(IslandConfiguration)
|
||||
api.add_resource(ConfigurationExport)
|
||||
api.add_resource(ConfigurationImport)
|
||||
api.add_resource(MonkeyDownload)
|
||||
api.add_resource(NetMap)
|
||||
api.add_resource(Edge)
|
||||
api.add_resource(Node)
|
||||
api.add_resource(NodeStates)
|
||||
|
||||
api.add_resource(SecurityReport, "/api/report/security")
|
||||
api.add_resource(ZeroTrustReport, "/api/report/zero-trust/<string:report_data>")
|
||||
api.add_resource(AttackReport, "/api/report/attack")
|
||||
api.add_resource(RansomwareReport, "/api/report/ransomware")
|
||||
api.add_resource(ManualExploitation, "/api/exploitations/manual")
|
||||
api.add_resource(MonkeyExploitation, "/api/exploitations/monkey")
|
||||
api.add_resource(SecurityReport)
|
||||
api.add_resource(ZeroTrustReport)
|
||||
api.add_resource(AttackReport)
|
||||
api.add_resource(RansomwareReport)
|
||||
api.add_resource(ManualExploitation)
|
||||
api.add_resource(MonkeyExploitation)
|
||||
|
||||
api.add_resource(ZeroTrustFindingEvent, "/api/zero-trust/finding-event/<string:finding_id>")
|
||||
api.add_resource(TelemetryFeed, "/api/telemetry-feed")
|
||||
api.add_resource(Log, "/api/log")
|
||||
api.add_resource(IslandLog, "/api/log/island/download")
|
||||
api.add_resource(ZeroTrustFindingEvent)
|
||||
api.add_resource(TelemetryFeed)
|
||||
api.add_resource(Log)
|
||||
api.add_resource(IslandLog)
|
||||
|
||||
api.add_resource(
|
||||
PBAFileDownload,
|
||||
"/api/pba/download/<string:filename>",
|
||||
)
|
||||
api.add_resource(
|
||||
FileUpload,
|
||||
"/api/file-upload/<string:target_os>",
|
||||
"/api/file-upload/<string:target_os>?load=<string:filename>",
|
||||
"/api/file-upload/<string:target_os>?restore=<string:filename>",
|
||||
)
|
||||
api.add_resource(PBAFileDownload)
|
||||
api.add_resource(FileUpload)
|
||||
|
||||
api.add_resource(PropagationCredentials, "/api/propagation-credentials/<string:guid>")
|
||||
api.add_resource(RemoteRun, "/api/remote-monkey")
|
||||
api.add_resource(VersionUpdate, "/api/version-update")
|
||||
api.add_resource(StopAgentCheck, "/api/monkey-control/needs-to-stop/<int:monkey_guid>")
|
||||
api.add_resource(StopAllAgents, "/api/monkey-control/stop-all-agents")
|
||||
api.add_resource(PropagationCredentials)
|
||||
api.add_resource(RemoteRun)
|
||||
api.add_resource(VersionUpdate)
|
||||
api.add_resource(StopAgentCheck)
|
||||
api.add_resource(StopAllAgents)
|
||||
|
||||
# Resources used by black box tests
|
||||
api.add_resource(MonkeyBlackboxEndpoint, "/api/test/monkey")
|
||||
api.add_resource(ClearCaches, "/api/test/clear-caches")
|
||||
api.add_resource(LogBlackboxEndpoint, "/api/test/log")
|
||||
api.add_resource(TelemetryBlackboxEndpoint, "/api/test/telemetry")
|
||||
api.add_resource(MonkeyBlackboxEndpoint)
|
||||
api.add_resource(ClearCaches)
|
||||
api.add_resource(LogBlackboxEndpoint)
|
||||
api.add_resource(TelemetryBlackboxEndpoint)
|
||||
|
||||
|
||||
def init_app(mongo_url: str, container: DIContainer):
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.infection_lifecycle import should_agent_die
|
||||
|
||||
|
||||
class StopAgentCheck(flask_restful.Resource):
|
||||
class StopAgentCheck(flask_restful.Resource, IResource):
|
||||
urls = ["/api/monkey-control/needs-to-stop/<int:monkey_guid>"]
|
||||
|
||||
def get(self, monkey_guid: int):
|
||||
return {"stop_agent": should_agent_die(monkey_guid)}
|
||||
|
|
|
@ -4,11 +4,14 @@ import flask_restful
|
|||
from flask import make_response, request
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.resources.utils.semaphores import agent_killing_mutex
|
||||
from monkey_island.cc.services.infection_lifecycle import set_stop_all, should_agent_die
|
||||
|
||||
|
||||
class StopAllAgents(flask_restful.Resource):
|
||||
class StopAllAgents(flask_restful.Resource, IResource):
|
||||
urls = ["/api/monkey-control/stop-all-agents"]
|
||||
|
||||
@jwt_required
|
||||
def post(self):
|
||||
with agent_killing_mutex:
|
||||
|
|
|
@ -2,11 +2,14 @@ import flask_restful
|
|||
from flask import current_app, json
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.attack.attack_report import AttackReportService
|
||||
from monkey_island.cc.services.attack.attack_schema import SCHEMA
|
||||
|
||||
|
||||
class AttackReport(flask_restful.Resource):
|
||||
class AttackReport(flask_restful.Resource, IResource):
|
||||
urls = ["/api/report/attack"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
response_content = {
|
||||
|
|
|
@ -9,6 +9,7 @@ from jwt import PyJWTError
|
|||
|
||||
from common.utils.exceptions import IncorrectCredentialsError
|
||||
from monkey_island.cc.resources.auth.credential_utils import get_username_password_from_request
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services import AuthenticationService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -21,13 +22,15 @@ def init_jwt(app):
|
|||
)
|
||||
|
||||
|
||||
class Authenticate(flask_restful.Resource):
|
||||
class Authenticate(flask_restful.Resource, IResource):
|
||||
"""
|
||||
Resource for user authentication. The user provides the username and password and we
|
||||
give them a JWT.
|
||||
See `AuthService.js` file for the frontend counterpart for this code.
|
||||
"""
|
||||
|
||||
urls = ["/api/auth"]
|
||||
|
||||
def post(self):
|
||||
"""
|
||||
Example request:
|
||||
|
|
|
@ -5,12 +5,16 @@ from flask import make_response, request
|
|||
|
||||
from common.utils.exceptions import AlreadyRegisteredError, InvalidRegistrationCredentialsError
|
||||
from monkey_island.cc.resources.auth.credential_utils import get_username_password_from_request
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services import AuthenticationService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Registration(flask_restful.Resource):
|
||||
class Registration(flask_restful.Resource, IResource):
|
||||
|
||||
urls = ["/api/registration"]
|
||||
|
||||
def get(self):
|
||||
return {"needs_registration": AuthenticationService.needs_registration()}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import logging
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.attack.attack_report import AttackReportService
|
||||
from monkey_island.cc.services.reporting.report import ReportService
|
||||
|
||||
|
@ -11,7 +12,8 @@ NOT_ALL_REPORTS_DELETED = "Not all reports have been cleared from the DB!"
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ClearCaches(flask_restful.Resource):
|
||||
class ClearCaches(flask_restful.Resource, IResource):
|
||||
urls = ["/api/test/clear-caches"]
|
||||
"""
|
||||
Used for timing tests - we want to get actual execution time of functions in BlackBox without
|
||||
caching -
|
||||
|
|
|
@ -4,9 +4,12 @@ from flask import request
|
|||
|
||||
from monkey_island.cc.database import database, mongo
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
|
||||
|
||||
class LogBlackboxEndpoint(flask_restful.Resource):
|
||||
class LogBlackboxEndpoint(flask_restful.Resource, IResource):
|
||||
urls = ["/api/test/log"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
find_query = json_util.loads(request.args.get("find_query"))
|
||||
|
|
|
@ -4,9 +4,12 @@ from flask import request
|
|||
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
|
||||
|
||||
class MonkeyBlackboxEndpoint(flask_restful.Resource):
|
||||
class MonkeyBlackboxEndpoint(flask_restful.Resource, IResource):
|
||||
urls = ["/api/test/monkey"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, **kw):
|
||||
find_query = json_util.loads(request.args.get("find_query"))
|
||||
|
|
|
@ -4,9 +4,12 @@ from flask import request
|
|||
|
||||
from monkey_island.cc.models.telemetries import get_telemetry_by_query
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
|
||||
|
||||
class TelemetryBlackboxEndpoint(flask_restful.Resource):
|
||||
class TelemetryBlackboxEndpoint(flask_restful.Resource, IResource):
|
||||
urls = ["/api/test/telemetry"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, **kw):
|
||||
find_query = json_util.loads(request.args.get("find_query"))
|
||||
|
|
|
@ -4,11 +4,14 @@ import flask_restful
|
|||
from flask import request
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.server_utils.encryption import PasswordBasedStringEncryptor
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
|
||||
|
||||
class ConfigurationExport(flask_restful.Resource):
|
||||
class ConfigurationExport(flask_restful.Resource, IResource):
|
||||
urls = ["/api/configuration/export"]
|
||||
|
||||
@jwt_required
|
||||
def post(self):
|
||||
data = json.loads(request.data)
|
||||
|
|
|
@ -8,6 +8,7 @@ from flask import request
|
|||
|
||||
from common.utils.exceptions import InvalidConfigurationError
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.server_utils.encryption import (
|
||||
InvalidCiphertextError,
|
||||
InvalidCredentialsError,
|
||||
|
@ -38,7 +39,8 @@ class ResponseContents:
|
|||
return self.__dict__
|
||||
|
||||
|
||||
class ConfigurationImport(flask_restful.Resource):
|
||||
class ConfigurationImport(flask_restful.Resource, IResource):
|
||||
urls = ["/api/configuration/import"]
|
||||
SUCCESS = False
|
||||
|
||||
@jwt_required
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import flask_restful
|
||||
from flask import request
|
||||
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.edge.displayed_edge import DisplayedEdgeService
|
||||
|
||||
|
||||
class Edge(flask_restful.Resource):
|
||||
class Edge(flask_restful.Resource, IResource):
|
||||
urls = ["/api/netmap/edge"]
|
||||
|
||||
def get(self):
|
||||
edge_id = request.args.get("id")
|
||||
displayed_edge = DisplayedEdgeService.get_displayed_edge_by_id(edge_id)
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.reporting.exploitations.manual_exploitation import (
|
||||
get_manual_exploitations,
|
||||
)
|
||||
|
||||
|
||||
class ManualExploitation(flask_restful.Resource):
|
||||
class ManualExploitation(flask_restful.Resource, IResource):
|
||||
urls = ["/api/exploitations/manual"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
manual_exploitations = [
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.reporting.exploitations.monkey_exploitation import (
|
||||
get_monkey_exploited,
|
||||
)
|
||||
|
||||
|
||||
class MonkeyExploitation(flask_restful.Resource):
|
||||
class MonkeyExploitation(flask_restful.Resource, IResource):
|
||||
urls = ["/api/exploitations/monkey"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
monkey_exploitations = [exploitation.__dict__ for exploitation in get_monkey_exploited()]
|
||||
|
|
|
@ -4,10 +4,14 @@ import flask_restful
|
|||
from flask import abort, jsonify, request
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
|
||||
|
||||
class IslandConfiguration(flask_restful.Resource):
|
||||
class IslandConfiguration(flask_restful.Resource, IResource):
|
||||
|
||||
urls = ["/api/configuration/island"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
return jsonify(
|
||||
|
|
|
@ -3,12 +3,15 @@ import logging
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.island_logs import IslandLogService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IslandLog(flask_restful.Resource):
|
||||
class IslandLog(flask_restful.Resource, IResource):
|
||||
urls = ["/api/log/island/download"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
try:
|
||||
|
|
|
@ -5,6 +5,7 @@ import flask_restful
|
|||
from flask import make_response, request
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.config_manipulator import update_config_on_mode_set
|
||||
from monkey_island.cc.services.mode.island_mode_service import ModeNotSetError, get_mode, set_mode
|
||||
from monkey_island.cc.services.mode.mode_enum import IslandModeEnum
|
||||
|
@ -12,7 +13,9 @@ from monkey_island.cc.services.mode.mode_enum import IslandModeEnum
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class IslandMode(flask_restful.Resource):
|
||||
class IslandMode(flask_restful.Resource, IResource):
|
||||
urls = ["/api/island-mode"]
|
||||
|
||||
@jwt_required
|
||||
def post(self):
|
||||
try:
|
||||
|
|
|
@ -5,11 +5,15 @@ from flask import jsonify, make_response, request
|
|||
|
||||
from monkey_island.cc.models import Monkey
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
from monkey_island.cc.services.run_local_monkey import LocalMonkeyRunService
|
||||
|
||||
|
||||
class LocalRun(flask_restful.Resource):
|
||||
class LocalRun(flask_restful.Resource, IResource):
|
||||
|
||||
urls = ["/api/local-monkey"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
island_monkey = NodeService.get_monkey_island_monkey()
|
||||
|
|
|
@ -7,11 +7,14 @@ from flask import request
|
|||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.log import LogService
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
|
||||
|
||||
class Log(flask_restful.Resource):
|
||||
class Log(flask_restful.Resource, IResource):
|
||||
urls = ["/api/log"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
monkey_id = request.args.get("id")
|
||||
|
|
|
@ -7,6 +7,7 @@ from flask import request
|
|||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.models.monkey_ttl import create_monkey_ttl_document
|
||||
from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.resources.utils.semaphores import agent_killing_mutex
|
||||
from monkey_island.cc.server_utils.consts import DEFAULT_MONKEY_TTL_EXPIRY_DURATION_IN_SECONDS
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
|
@ -16,7 +17,12 @@ from monkey_island.cc.services.node import NodeService
|
|||
# TODO: separate logic from interface
|
||||
|
||||
|
||||
class Monkey(flask_restful.Resource):
|
||||
class Monkey(flask_restful.Resource, IResource):
|
||||
urls = [
|
||||
"/api/agent",
|
||||
"/api/agent/<string:guid>",
|
||||
"/api/agent/<string:guid>/<string:config_format>",
|
||||
]
|
||||
|
||||
# Used by monkey. can't secure.
|
||||
def get(self, guid=None, config_format=None, **kw):
|
||||
|
|
|
@ -5,6 +5,7 @@ from pathlib import Path
|
|||
import flask_restful
|
||||
from flask import make_response, send_from_directory
|
||||
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
@ -19,7 +20,8 @@ class UnsupportedOSError(Exception):
|
|||
pass
|
||||
|
||||
|
||||
class MonkeyDownload(flask_restful.Resource):
|
||||
class MonkeyDownload(flask_restful.Resource, IResource):
|
||||
urls = ["/api/agent/download/<string:host_os>"]
|
||||
|
||||
# Used by monkey. can't secure.
|
||||
def get(self, host_os):
|
||||
|
|
|
@ -1,11 +1,14 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.netmap.net_edge import NetEdgeService
|
||||
from monkey_island.cc.services.netmap.net_node import NetNodeService
|
||||
|
||||
|
||||
class NetMap(flask_restful.Resource):
|
||||
class NetMap(flask_restful.Resource, IResource):
|
||||
urls = ["/api/netmap"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, **kw):
|
||||
net_nodes = NetNodeService.get_all_net_nodes()
|
||||
|
|
|
@ -2,10 +2,13 @@ import flask_restful
|
|||
from flask import request
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
|
||||
|
||||
class Node(flask_restful.Resource):
|
||||
class Node(flask_restful.Resource, IResource):
|
||||
urls = ["/api/netmap/node"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
node_id = request.args.get("id")
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.utils.node_states import NodeStates as NodeStateList
|
||||
|
||||
|
||||
class NodeStates(flask_restful.Resource):
|
||||
class NodeStates(flask_restful.Resource, IResource):
|
||||
urls = ["/api/netmap/node-states"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
return {"node_states": [state.value for state in NodeStateList]}
|
||||
|
|
|
@ -3,12 +3,14 @@ import logging
|
|||
import flask_restful
|
||||
from flask import make_response, send_file
|
||||
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services import FileRetrievalError, IFileStorageService
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
|
||||
|
||||
class PBAFileDownload(flask_restful.Resource):
|
||||
class PBAFileDownload(flask_restful.Resource, IResource):
|
||||
urls = ["/api/pba/download/<string:filename>"]
|
||||
"""
|
||||
File download endpoint used by monkey to download user's PBA file
|
||||
"""
|
||||
|
|
|
@ -7,22 +7,28 @@ from werkzeug.utils import secure_filename as sanitize_filename
|
|||
|
||||
from common.config_value_paths import PBA_LINUX_FILENAME_PATH, PBA_WINDOWS_FILENAME_PATH
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services import FileRetrievalError, IFileStorageService
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
|
||||
|
||||
# Front end uses these strings to identify which files to work with (linux or windows)
|
||||
LINUX_PBA_TYPE = "PBAlinux"
|
||||
WINDOWS_PBA_TYPE = "PBAwindows"
|
||||
|
||||
|
||||
class FileUpload(flask_restful.Resource):
|
||||
class FileUpload(flask_restful.Resource, IResource):
|
||||
"""
|
||||
File upload endpoint used to send/receive Custom PBA files
|
||||
"""
|
||||
|
||||
urls = [
|
||||
"/api/file-upload/<string:target_os>",
|
||||
"/api/file-upload/<string:target_os>?load=<string:filename>",
|
||||
"/api/file-upload/<string:target_os>?restore=<string:filename>",
|
||||
]
|
||||
|
||||
def __init__(self, file_storage_service: IFileStorageService):
|
||||
self._file_storage_service = file_storage_service
|
||||
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.config import ConfigService
|
||||
|
||||
|
||||
class PropagationCredentials(flask_restful.Resource):
|
||||
class PropagationCredentials(flask_restful.Resource, IResource):
|
||||
urls = ["/api/propagation-credentials/<string:guid>"]
|
||||
|
||||
def get(self, guid: str):
|
||||
monkey_json = mongo.db.monkey.find_one_or_404({"guid": guid})
|
||||
ConfigService.decrypt_flat_config(monkey_json["config"])
|
||||
|
|
|
@ -2,10 +2,13 @@ import flask_restful
|
|||
from flask import jsonify
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.ransomware import ransomware_report
|
||||
|
||||
|
||||
class RansomwareReport(flask_restful.Resource):
|
||||
class RansomwareReport(flask_restful.Resource, IResource):
|
||||
urls = ["/api/report/ransomware"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
return jsonify(
|
||||
|
|
|
@ -6,6 +6,7 @@ from botocore.exceptions import ClientError, NoCredentialsError
|
|||
from flask import jsonify, make_response, request
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services import AWSService
|
||||
from monkey_island.cc.services.aws import AWSCommandResults
|
||||
|
||||
|
@ -19,7 +20,9 @@ NO_CREDS_ERROR_FORMAT = (
|
|||
)
|
||||
|
||||
|
||||
class RemoteRun(flask_restful.Resource):
|
||||
class RemoteRun(flask_restful.Resource, IResource):
|
||||
urls = ["/api/remote-monkey"]
|
||||
|
||||
def __init__(self, aws_service: AWSService):
|
||||
self._aws_service = aws_service
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from flask import jsonify, make_response, request
|
|||
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.database import Database
|
||||
from monkey_island.cc.services.infection_lifecycle import get_completed_steps
|
||||
from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
||||
|
@ -12,7 +13,10 @@ from monkey_island.cc.services.utils.network_utils import local_ip_addresses
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Root(flask_restful.Resource):
|
||||
class Root(IResource, flask_restful.Resource):
|
||||
|
||||
urls = ["/api"]
|
||||
|
||||
def get(self, action=None):
|
||||
if not action:
|
||||
action = request.args.get("action")
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.reporting.report import ReportService
|
||||
|
||||
|
||||
class SecurityReport(flask_restful.Resource):
|
||||
class SecurityReport(flask_restful.Resource, IResource):
|
||||
urls = ["/api/report/security"]
|
||||
|
||||
@jwt_required
|
||||
def get(self):
|
||||
return ReportService.get_report()
|
||||
|
|
|
@ -11,13 +11,16 @@ from monkey_island.cc.models.monkey import Monkey
|
|||
from monkey_island.cc.models.telemetries import get_telemetry_by_query
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.blackbox.utils.telem_store import TestTelemStore
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
from monkey_island.cc.services.telemetry.processing.processing import process_telemetry
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Telemetry(flask_restful.Resource):
|
||||
class Telemetry(flask_restful.Resource, IResource):
|
||||
urls = ["/api/telemetry", "/api/telemetry/<string:monkey_guid>"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, **kw):
|
||||
monkey_guid = request.args.get("monkey_guid")
|
||||
|
|
|
@ -9,12 +9,15 @@ from flask import request
|
|||
from common.common_consts.telem_categories import TelemCategoryEnum
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.node import NodeService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class TelemetryFeed(flask_restful.Resource):
|
||||
class TelemetryFeed(flask_restful.Resource, IResource):
|
||||
urls = ["/api/telemetry-feed"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, **kw):
|
||||
timestamp = request.args.get("timestamp")
|
||||
|
|
|
@ -3,12 +3,15 @@ import logging
|
|||
import flask_restful
|
||||
|
||||
from common.version import get_version
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.version_update import VersionUpdateService
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class VersionUpdate(flask_restful.Resource):
|
||||
class VersionUpdate(flask_restful.Resource, IResource):
|
||||
urls = ["/api/version-update"]
|
||||
|
||||
def __init__(self):
|
||||
super(VersionUpdate, self).__init__()
|
||||
|
||||
|
|
|
@ -3,12 +3,15 @@ import json
|
|||
import flask_restful
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.zero_trust.monkey_findings.monkey_zt_finding_service import (
|
||||
MonkeyZTFindingService,
|
||||
)
|
||||
|
||||
|
||||
class ZeroTrustFindingEvent(flask_restful.Resource):
|
||||
class ZeroTrustFindingEvent(flask_restful.Resource, IResource):
|
||||
urls = ["/api/zero-trust/finding-event/<string:finding_id>"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, finding_id: str):
|
||||
return {
|
||||
|
|
|
@ -4,6 +4,7 @@ import flask_restful
|
|||
from flask import jsonify
|
||||
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
from monkey_island.cc.resources.i_resource import IResource
|
||||
from monkey_island.cc.services.zero_trust.zero_trust_report.finding_service import FindingService
|
||||
from monkey_island.cc.services.zero_trust.zero_trust_report.pillar_service import PillarService
|
||||
from monkey_island.cc.services.zero_trust.zero_trust_report.principle_service import (
|
||||
|
@ -15,7 +16,9 @@ REPORT_DATA_FINDINGS = "findings"
|
|||
REPORT_DATA_PRINCIPLES_STATUS = "principles"
|
||||
|
||||
|
||||
class ZeroTrustReport(flask_restful.Resource):
|
||||
class ZeroTrustReport(flask_restful.Resource, IResource):
|
||||
urls = ["/api/report/zero-trust/<string:report_data>"]
|
||||
|
||||
@jwt_required
|
||||
def get(self, report_data=None):
|
||||
if report_data == REPORT_DATA_PILLARS:
|
||||
|
|
Loading…
Reference in New Issue