forked from p15670423/monkey
Added an endpoint on the island for telemetry tests. This allows for tests like blackbox tests to send queries and check whether a certain telemetry is in the database or not
This commit is contained in:
parent
f6b0682297
commit
263fa53ea5
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import logging
|
||||
from time import sleep
|
||||
from typing import Union
|
||||
|
||||
from bson import json_util
|
||||
|
||||
|
@ -8,6 +9,7 @@ from envs.monkey_zoo.blackbox.island_client.monkey_island_requests import Monkey
|
|||
|
||||
SLEEP_BETWEEN_REQUESTS_SECONDS = 0.5
|
||||
MONKEY_TEST_ENDPOINT = 'api/test/monkey'
|
||||
TELEMETRY_TEST_ENDPOINT = 'api/test/telemetry'
|
||||
LOG_TEST_ENDPOINT = 'api/test/log'
|
||||
LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -67,6 +69,13 @@ class MonkeyIslandClient(object):
|
|||
MonkeyIslandClient.form_find_query_for_request(query))
|
||||
return MonkeyIslandClient.get_test_query_results(response)
|
||||
|
||||
def find_telems_in_db(self, query: dict):
|
||||
if query is None:
|
||||
raise TypeError
|
||||
response = self.requests.get(TELEMETRY_TEST_ENDPOINT,
|
||||
MonkeyIslandClient.form_find_query_for_request(query))
|
||||
return MonkeyIslandClient.get_test_query_results(response)
|
||||
|
||||
def get_all_monkeys_from_db(self):
|
||||
response = self.requests.get(MONKEY_TEST_ENDPOINT,
|
||||
MonkeyIslandClient.form_find_query_for_request(None))
|
||||
|
@ -78,7 +87,7 @@ class MonkeyIslandClient(object):
|
|||
return MonkeyIslandClient.get_test_query_results(response)
|
||||
|
||||
@staticmethod
|
||||
def form_find_query_for_request(query):
|
||||
def form_find_query_for_request(query: Union[dict, None]) -> dict:
|
||||
return {'find_query': json_util.dumps(query)}
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -7,6 +7,7 @@ from werkzeug.exceptions import NotFound
|
|||
|
||||
import monkey_island.cc.environment.environment_singleton as env_singleton
|
||||
from common.common_consts.api_url_consts import T1216_PBA_FILE_DOWNLOAD_PATH
|
||||
from monkey_island.cc.resources.test.telemetry_test import TelemetryTest
|
||||
from monkey_island.cc.resources.zero_trust.zero_trust_report import ZeroTrustReport
|
||||
from monkey_island.cc.server_utils.consts import MONKEY_ISLAND_ABS_PATH
|
||||
from monkey_island.cc.server_utils.custom_json_encoder import CustomJSONEncoder
|
||||
|
@ -145,9 +146,11 @@ def init_api_resources(api):
|
|||
api.add_resource(ScoutSuiteAuth, '/api/scoutsuite_auth/<string:provider>')
|
||||
api.add_resource(AWSKeys, '/api/aws_keys')
|
||||
|
||||
# Resources used by black box tests
|
||||
api.add_resource(MonkeyTest, '/api/test/monkey')
|
||||
api.add_resource(ClearCaches, '/api/test/clear_caches')
|
||||
api.add_resource(LogTest, '/api/test/log')
|
||||
api.add_resource(TelemetryTest, '/api/test/telemetry')
|
||||
|
||||
|
||||
def init_app(mongo_url):
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
import flask_restful
|
||||
from bson import json_util
|
||||
from flask import request
|
||||
|
||||
from monkey_island.cc.database import mongo
|
||||
from monkey_island.cc.resources.auth.auth import jwt_required
|
||||
|
||||
|
||||
class TelemetryTest(flask_restful.Resource):
|
||||
@jwt_required
|
||||
def get(self, **kw):
|
||||
find_query = json_util.loads(request.args.get('find_query'))
|
||||
return {'results': list(mongo.db.telemetry.find(find_query))}
|
Loading…
Reference in New Issue