def try_add_aws_exporter_to_manager(manager): # noinspection PyBroadException try: RemoteRunAwsService.init() if RemoteRunAwsService.is_running_on_aws() and ('aws' == env_singleton.env.get_deployment()): manager.add_exporter_to_list(AWSExporter) except Exception: logger.error("Failed adding aws exporter to manager. Exception info:", exc_info=True)
def init_app(mongo_url): app = Flask(__name__) api = flask_restful.Api(app) api.representations = {'application/json': output_json} app.config['MONGO_URI'] = mongo_url app.config['SECRET_KEY'] = str(uuid.getnode()) app.config['JWT_AUTH_URL_RULE'] = '/api/auth' app.config['JWT_EXPIRATION_DELTA'] = env.get_auth_expiration_time() init_jwt(app) mongo.init_app(app) with app.app_context(): database.init() ConfigService.init_config() # If running on AWS, this will initialize the instance data, which is used "later" in the execution of the island. RemoteRunAwsService.init() app.add_url_rule('/', 'serve_home', serve_home) app.add_url_rule('/<path:static_path>', 'serve_static_file', serve_static_file) api.add_resource(Root, '/api') api.add_resource(Monkey, '/api/monkey', '/api/monkey/', '/api/monkey/<string:guid>') api.add_resource(LocalRun, '/api/local-monkey', '/api/local-monkey/') api.add_resource(ClientRun, '/api/client-monkey', '/api/client-monkey/') api.add_resource(Telemetry, '/api/telemetry', '/api/telemetry/', '/api/telemetry/<string:monkey_guid>') api.add_resource(MonkeyConfiguration, '/api/configuration', '/api/configuration/') api.add_resource(IslandConfiguration, '/api/configuration/island', '/api/configuration/island/') api.add_resource(MonkeyDownload, '/api/monkey/download', '/api/monkey/download/', '/api/monkey/download/<string:path>') api.add_resource(NetMap, '/api/netmap', '/api/netmap/') api.add_resource(Edge, '/api/netmap/edge', '/api/netmap/edge/') api.add_resource(Node, '/api/netmap/node', '/api/netmap/node/') api.add_resource(Report, '/api/report', '/api/report/') api.add_resource(TelemetryFeed, '/api/telemetry-feed', '/api/telemetry-feed/') api.add_resource(Log, '/api/log', '/api/log/') api.add_resource(IslandLog, '/api/log/island/download', '/api/log/island/download/') api.add_resource(PBAFileDownload, '/api/pba/download/<string:path>') api.add_resource( FileUpload, '/api/fileUpload/<string:file_type>', '/api/fileUpload/<string:file_type>?load=<string:filename>', '/api/fileUpload/<string:file_type>?restore=<string:filename>') api.add_resource(RemoteRun, '/api/remote-monkey', '/api/remote-monkey/') api.add_resource(AttackTelem, '/api/attack/<string:technique>') return app
def init_app_services(app): init_jwt(app) mongo.init_app(app) with app.app_context(): database.init() Database.init_db() # If running on AWS, this will initialize the instance data, which is used "later" in the execution of the island. RemoteRunAwsService.init()
def populate_exporter_list(): manager = ReportExporterManager() RemoteRunAwsService.init() if RemoteRunAwsService.is_running_on_aws(): manager.add_exporter_to_list(AWSExporter) if len(manager.get_exporters_list()) != 0: logger.debug( "Populated exporters list with the following exporters: {0}". format(str(manager.get_exporters_list())))
def post(self): body = json.loads(request.data) resp = {} if body.get("type") == "aws": RemoteRunAwsService.update_aws_region_authless() result = self.run_aws_monkeys(body) resp["result"] = result return jsonify(resp) # default action return make_response({"error": "Invalid action"}, 500)
def post(self): body = json.loads(request.data) resp = {} if body.get('type') == 'aws': RemoteRunAwsService.update_aws_region_authless() result = self.run_aws_monkeys(body) resp['result'] = result return jsonify(resp) # default action return make_response({'error': 'Invalid action'}, 500)
def get(self): action = request.args.get('action') if action == 'list_aws': is_aws = RemoteRunAwsService.is_running_on_aws() resp = {'is_aws': is_aws} if is_aws: is_auth = RemoteRunAwsService.update_aws_auth_params() resp['auth'] = is_auth if is_auth: resp['instances'] = AwsService.get_instances() return jsonify(resp) return {}
def get(self): action = request.args.get("action") if action == "list_aws": is_aws = RemoteRunAwsService.is_running_on_aws() resp = {"is_aws": is_aws} if is_aws: try: resp["instances"] = AwsService.get_instances() except NoCredentialsError as e: resp["error"] = NO_CREDS_ERROR_FORMAT.format(e) return jsonify(resp) except ClientError as e: resp["error"] = CLIENT_ERROR_FORMAT.format(e) return jsonify(resp) return jsonify(resp) return {}
def get(self): action = request.args.get('action') if action == 'list_aws': is_aws = RemoteRunAwsService.is_running_on_aws() resp = {'is_aws': is_aws} if is_aws: try: resp['instances'] = AwsService.get_instances() except NoCredentialsError as e: resp['error'] = NO_CREDS_ERROR_FORMAT.format(e.message) return jsonify(resp) except ClientError as e: resp['error'] = CLIENT_ERROR_FORMAT.format(e.message) return jsonify(resp) return jsonify(resp) return {}
def run_aws_monkeys(self, request_body): instances = request_body.get("instances") island_ip = request_body.get("island_ip") return RemoteRunAwsService.run_aws_monkeys(instances, island_ip)
def __init__(self): super(RemoteRun, self).__init__() RemoteRunAwsService.init()