2019-05-08 12:58:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
2023-07-25 13:57:11 +00:00
|
|
|
"""
|
2019-05-08 12:58:41 +00:00
|
|
|
Flask functions and routes for the rest api
|
2023-07-25 13:57:11 +00:00
|
|
|
"""
|
2019-05-08 12:58:41 +00:00
|
|
|
|
2024-02-26 14:35:48 +00:00
|
|
|
# import os
|
|
|
|
# import re
|
|
|
|
# import sys
|
|
|
|
# import uuid
|
|
|
|
# import json
|
|
|
|
|
|
|
|
# sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
# ##################################
|
|
|
|
# # Import Project packages
|
|
|
|
# ##################################
|
|
|
|
# from lib.ConfigLoader import ConfigLoader
|
|
|
|
# from lib import Users
|
|
|
|
# from lib.objects import Items
|
|
|
|
# from lib import Tag
|
|
|
|
#
|
|
|
|
# from packages import Import_helper
|
|
|
|
#
|
|
|
|
# from importer.FeederImporter import api_add_json_feeder_to_queue
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# from flask import jsonify, request, Blueprint, redirect, url_for, Response
|
|
|
|
#
|
|
|
|
# from functools import wraps
|
2019-05-08 12:58:41 +00:00
|
|
|
|
|
|
|
# ============ VARIABLES ============
|
|
|
|
|
2019-08-07 10:08:24 +00:00
|
|
|
|
2019-07-11 11:58:15 +00:00
|
|
|
|
2019-05-08 12:58:41 +00:00
|
|
|
# ============ DECORATOR ============
|
|
|
|
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2019-12-11 12:58:43 +00:00
|
|
|
|
2019-12-16 13:31:31 +00:00
|
|
|
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2019-05-08 12:58:41 +00:00
|
|
|
# ============= ROUTES ==============
|
|
|
|
|
2019-06-20 12:47:59 +00:00
|
|
|
# @restApi.route("/api", methods=['GET'])
|
|
|
|
# @login_required
|
|
|
|
# def api():
|
|
|
|
# return 'api doc'
|
2019-05-08 12:58:41 +00:00
|
|
|
|
2024-02-26 14:35:48 +00:00
|
|
|
|
|
|
|
'''
|
2019-08-01 11:16:57 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# POST
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "id": item_id, mandatory
|
|
|
|
# "content": true,
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {
|
|
|
|
# "id": "item_id",
|
|
|
|
# "tags": [],
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2019-08-06 09:29:12 +00:00
|
|
|
@restApi.route("api/v1/get/item", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-01 11:16:57 +00:00
|
|
|
def get_item_id():
|
2019-08-06 09:29:12 +00:00
|
|
|
data = request.get_json()
|
2023-04-21 14:16:10 +00:00
|
|
|
res = Items.api_get_item(data)
|
2019-08-06 09:29:12 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2019-07-26 13:44:29 +00:00
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# GET
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "id": item_id, mandatory
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {
|
|
|
|
# "id": "item_id",
|
2023-04-21 14:16:10 +00:00
|
|
|
# "date": "date",
|
2019-07-26 13:44:29 +00:00
|
|
|
# "tags": [],
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2019-08-05 14:00:23 +00:00
|
|
|
@restApi.route("api/v1/get/item/tag", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-05 14:00:23 +00:00
|
|
|
def get_item_tag():
|
|
|
|
data = request.get_json()
|
|
|
|
item_id = data.get('id', None)
|
|
|
|
req_data = {'id': item_id, 'date': False, 'tags': True}
|
|
|
|
res = Item.get_item(req_data)
|
2019-08-01 11:16:57 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2019-07-26 13:44:29 +00:00
|
|
|
|
2019-07-30 11:49:21 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# POST
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "id": item_id, mandatory
|
|
|
|
# "tags": [tags to add],
|
|
|
|
# "galaxy": [galaxy to add],
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {
|
|
|
|
# "id": "item_id",
|
|
|
|
# "tags": [tags added],
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2019-08-05 07:46:56 +00:00
|
|
|
@restApi.route("api/v1/add/item/tag", methods=['POST'])
|
2019-08-06 08:37:56 +00:00
|
|
|
@token_required('analyst')
|
2019-07-30 11:49:21 +00:00
|
|
|
def add_item_tags():
|
|
|
|
|
|
|
|
data = request.get_json()
|
|
|
|
if not data:
|
|
|
|
return Response(json.dumps({'status': 'error', 'reason': 'Malformed JSON'}, indent=2, sort_keys=True), mimetype='application/json'), 400
|
|
|
|
|
2020-01-07 13:30:52 +00:00
|
|
|
object_id = data.get('id', None)
|
2019-07-30 11:49:21 +00:00
|
|
|
tags = data.get('tags', [])
|
|
|
|
galaxy = data.get('galaxy', [])
|
|
|
|
|
2023-01-18 15:28:08 +00:00
|
|
|
# res = Tag.api_add_obj_tags(tags=tags, galaxy_tags=galaxy, object_id=object_id, object_type="item")
|
|
|
|
res = {'error': 'disabled endpoint'}, 500
|
2019-07-30 11:49:21 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# DELETE
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "id": item_id, mandatory
|
|
|
|
# "tags": [tags to delete],
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {
|
|
|
|
# "id": "item_id",
|
|
|
|
# "tags": [tags deleted],
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2019-08-05 07:46:56 +00:00
|
|
|
@restApi.route("api/v1/delete/item/tag", methods=['DELETE'])
|
2019-08-06 08:37:56 +00:00
|
|
|
@token_required('analyst')
|
2019-07-30 11:49:21 +00:00
|
|
|
def delete_item_tags():
|
|
|
|
|
|
|
|
data = request.get_json()
|
|
|
|
if not data:
|
|
|
|
return Response(json.dumps({'status': 'error', 'reason': 'Malformed JSON'}, indent=2, sort_keys=True), mimetype='application/json'), 400
|
|
|
|
|
2020-01-07 13:30:52 +00:00
|
|
|
object_id = data.get('id', None)
|
2019-07-30 11:49:21 +00:00
|
|
|
tags = data.get('tags', [])
|
|
|
|
|
2020-01-07 13:30:52 +00:00
|
|
|
res = Tag.api_delete_obj_tags(tags=tags, object_id=object_id, object_type="item")
|
2019-07-30 11:49:21 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
2019-07-26 13:44:29 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# GET
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "id": item_id, mandatory
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {
|
|
|
|
# "id": "item_id",
|
|
|
|
# "content": "item content"
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2019-08-05 14:00:23 +00:00
|
|
|
@restApi.route("api/v1/get/item/content", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-05 14:00:23 +00:00
|
|
|
def get_item_content():
|
|
|
|
data = request.get_json()
|
|
|
|
item_id = data.get('id', None)
|
|
|
|
req_data = {'id': item_id, 'date': False, 'content': True, 'tags': False}
|
|
|
|
res = Item.get_item(req_data)
|
2019-08-01 11:16:57 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2019-08-16 15:59:44 +00:00
|
|
|
|
2021-11-26 16:54:15 +00:00
|
|
|
@restApi.route("api/v1/get/item/content/utf8/base64", methods=['POST'])
|
2021-10-04 13:01:14 +00:00
|
|
|
@token_required('read_only')
|
2021-10-05 12:17:39 +00:00
|
|
|
def get_item_content_encoded_text():
|
2021-10-04 13:01:14 +00:00
|
|
|
data = request.get_json()
|
|
|
|
item_id = data.get('id', None)
|
|
|
|
req_data = {'id': item_id}
|
2021-11-26 16:54:15 +00:00
|
|
|
res = Item.api_get_item_content_base64_utf8(req_data)
|
2021-10-06 09:12:43 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
|
2021-11-26 16:54:15 +00:00
|
|
|
@restApi.route("api/v1/get/items/sources", methods=['GET'])
|
2021-10-06 09:12:43 +00:00
|
|
|
@token_required('read_only')
|
|
|
|
def get_item_sources():
|
2021-11-26 16:54:15 +00:00
|
|
|
res = Item.api_get_items_sources()
|
2021-10-06 09:12:43 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|
2021-10-06 09:12:43 +00:00
|
|
|
|
2019-08-01 12:36:52 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # TAGS # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|
2019-08-05 14:00:23 +00:00
|
|
|
@restApi.route("api/v1/get/tag/metadata", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-05 14:00:23 +00:00
|
|
|
def get_tag_metadata():
|
|
|
|
data = request.get_json()
|
|
|
|
tag = data.get('tag', None)
|
2019-08-01 12:36:52 +00:00
|
|
|
if not Tag.is_tag_in_all_tag(tag):
|
|
|
|
return Response(json.dumps({'status': 'error', 'reason':'Tag not found'}, indent=2, sort_keys=True), mimetype='application/json'), 404
|
|
|
|
metadata = Tag.get_tag_metadata(tag)
|
|
|
|
return Response(json.dumps(metadata, indent=2, sort_keys=True), mimetype='application/json'), 200
|
|
|
|
|
2019-08-05 14:00:23 +00:00
|
|
|
@restApi.route("api/v1/get/tag/all", methods=['GET'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-01 12:36:52 +00:00
|
|
|
def get_all_tags():
|
|
|
|
res = {'tags': Tag.get_all_tags()}
|
|
|
|
return Response(json.dumps(res, indent=2, sort_keys=True), mimetype='application/json'), 200
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|
2019-08-01 12:36:52 +00:00
|
|
|
|
2023-05-04 14:35:56 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # TODO
|
|
|
|
# # # # # # # # # # # # # # TRACKER # # # # # # # # # # # # # # # # # TODO
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # TODO
|
|
|
|
'''
|
2019-09-13 09:40:09 +00:00
|
|
|
@restApi.route("api/v1/add/tracker", methods=['POST'])
|
2019-08-07 10:08:24 +00:00
|
|
|
@token_required('analyst')
|
2019-08-06 15:03:49 +00:00
|
|
|
def add_tracker_term():
|
2019-08-09 13:22:57 +00:00
|
|
|
data = request.get_json()
|
2019-08-07 10:08:24 +00:00
|
|
|
user_token = get_auth_from_header()
|
2023-02-03 15:13:57 +00:00
|
|
|
user_id = Users.get_token_user(user_token)
|
2021-11-19 09:55:47 +00:00
|
|
|
res = Tracker.api_add_tracker(data, user_id)
|
2019-08-07 10:08:24 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2019-08-06 15:03:49 +00:00
|
|
|
|
2019-09-13 09:40:09 +00:00
|
|
|
@restApi.route("api/v1/delete/tracker", methods=['DELETE'])
|
2019-08-09 13:22:57 +00:00
|
|
|
@token_required('analyst')
|
|
|
|
def delete_tracker_term():
|
|
|
|
data = request.get_json()
|
|
|
|
user_token = get_auth_from_header()
|
2023-02-03 15:13:57 +00:00
|
|
|
user_id = Users.get_token_user(user_token)
|
2019-08-09 13:22:57 +00:00
|
|
|
res = Term.parse_tracked_term_to_delete(data, user_id)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
2019-09-13 09:40:09 +00:00
|
|
|
@restApi.route("api/v1/get/tracker/item", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-09 15:07:54 +00:00
|
|
|
def get_tracker_term_item():
|
|
|
|
data = request.get_json()
|
|
|
|
user_token = get_auth_from_header()
|
2023-02-03 15:13:57 +00:00
|
|
|
user_id = Users.get_token_user(user_token)
|
2019-08-09 15:07:54 +00:00
|
|
|
res = Term.parse_get_tracker_term_item(data, user_id)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2019-08-09 13:22:57 +00:00
|
|
|
|
2019-09-04 08:24:46 +00:00
|
|
|
|
2021-10-06 09:12:43 +00:00
|
|
|
@restApi.route("api/v1/get/tracker/yara/content", methods=['POST'])
|
|
|
|
@token_required('read_only')
|
|
|
|
def get_default_yara_rule_content():
|
|
|
|
data = request.get_json()
|
|
|
|
rule_name = data.get('rule_name', None)
|
2021-11-26 16:54:15 +00:00
|
|
|
rule_name = escape(rule_name)
|
2021-10-06 09:12:43 +00:00
|
|
|
req_data = {'rule_name': rule_name}
|
|
|
|
res = Tracker.get_yara_rule_content_restapi(req_data)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
2021-10-06 12:32:45 +00:00
|
|
|
|
|
|
|
@restApi.route("api/v1/get/tracker/metadata", methods=['POST'])
|
|
|
|
@token_required('read_only')
|
|
|
|
def get_tracker_metadata_api():
|
|
|
|
data = request.get_json()
|
|
|
|
tracker_uuid = data.get('tracker_uuid', None)
|
|
|
|
req_data = {'tracker_uuid': tracker_uuid}
|
2023-05-04 14:35:56 +00:00
|
|
|
|
|
|
|
tracker_uuid = request_dict.get('tracker_uuid', None)
|
|
|
|
if not request_dict:
|
|
|
|
return {'status': 'error', 'reason': 'Malformed JSON'}, 400
|
|
|
|
if not tracker_uuid:
|
|
|
|
return {'status': 'error', 'reason': 'Mandatory parameter(s) not provided'}, 400
|
|
|
|
if not is_valid_uuid_v4(tracker_uuid):
|
|
|
|
return {"status": "error", "reason": "Invalid Tracker UUID"}, 400
|
|
|
|
if not r_serv_tracker.exists(f'tracker:{tracker_uuid}'):
|
|
|
|
return {'status': 'error', 'reason': 'Tracker not found'}, 404
|
|
|
|
|
2021-10-06 12:32:45 +00:00
|
|
|
res = Tracker.get_tracker_metadata_api(req_data)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=False), mimetype='application/json'), res[1]
|
2023-05-04 14:35:56 +00:00
|
|
|
|
|
|
|
'''
|
2021-11-26 16:54:15 +00:00
|
|
|
|
2023-04-21 14:16:10 +00:00
|
|
|
'''
|
|
|
|
|
2019-08-16 15:59:44 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # CRYPTOCURRENCY # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
@restApi.route("api/v1/get/cryptocurrency/bitcoin/metadata", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_cryptocurrency_bitcoin_metadata():
|
|
|
|
data = request.get_json()
|
|
|
|
crypto_address = data.get('bitcoin', None)
|
|
|
|
req_data = {'bitcoin': crypto_address, 'metadata': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/cryptocurrency/bitcoin/item", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_cryptocurrency_bitcoin_item():
|
|
|
|
data = request.get_json()
|
|
|
|
bitcoin_address = data.get('bitcoin', None)
|
|
|
|
req_data = {'bitcoin': bitcoin_address, 'items': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # # PGP # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
@restApi.route("api/v1/get/pgp/key/metadata", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_pgp_key_metadata():
|
|
|
|
data = request.get_json()
|
|
|
|
pgp_field = data.get('key', None)
|
|
|
|
req_data = {'key': pgp_field, 'metadata': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/pgp/mail/metadata", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_pgp_mail_metadata():
|
|
|
|
data = request.get_json()
|
|
|
|
pgp_field = data.get('mail', None)
|
|
|
|
req_data = {'mail': pgp_field, 'metadata': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/pgp/name/metadata", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_pgp_name_metadata():
|
|
|
|
data = request.get_json()
|
|
|
|
pgp_field = data.get('name', None)
|
|
|
|
req_data = {'name': pgp_field, 'metadata': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/pgp/key/item", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_pgp_key_item():
|
|
|
|
data = request.get_json()
|
|
|
|
pgp_field = data.get('key', None)
|
|
|
|
req_data = {'key': pgp_field, 'items': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
res = 0
|
|
|
|
raise Exception('TO MIGRATE')
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/pgp/mail/item", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_pgp_mail_item():
|
|
|
|
data = request.get_json()
|
|
|
|
pgp_mail = data.get('mail', None)
|
|
|
|
req_data = {'mail': pgp_mail, 'items': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/pgp/name/item", methods=['POST'])
|
2021-02-23 13:07:57 +00:00
|
|
|
@token_required('read_only')
|
2019-08-16 15:59:44 +00:00
|
|
|
def get_pgp_name_item():
|
|
|
|
data = request.get_json()
|
|
|
|
pgp_name = data.get('name', None)
|
|
|
|
req_data = {'name': pgp_name, 'items': True}
|
2022-11-28 14:01:40 +00:00
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
res = 0
|
2019-08-16 15:59:44 +00:00
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/item/cryptocurrency/key", methods=['POST'])
|
|
|
|
@token_required('analyst')
|
|
|
|
def get_item_cryptocurrency_bitcoin():
|
|
|
|
data = request.get_json()
|
|
|
|
item_id = data.get('id', None)
|
|
|
|
req_data = {'id': item_id, 'date': False, 'tags': False, 'pgp': {'key': True}}
|
|
|
|
res = Item.get_item(req_data)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/item/pgp/mail", methods=['POST'])
|
|
|
|
@token_required('analyst')
|
|
|
|
def get_item_cryptocurrency_bitcoin():
|
|
|
|
data = request.get_json()
|
|
|
|
item_id = data.get('id', None)
|
|
|
|
req_data = {'id': item_id, 'date': False, 'tags': False, 'pgp': {'mail': True}}
|
|
|
|
res = Item.get_item(req_data)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
|
|
|
|
@restApi.route("api/v1/get/item/pgp/name", methods=['POST'])
|
|
|
|
@token_required('analyst')
|
|
|
|
def get_item_cryptocurrency_bitcoin():
|
|
|
|
data = request.get_json()
|
|
|
|
item_id = data.get('id', None)
|
|
|
|
req_data = {'id': item_id, 'date': False, 'tags': False, 'pgp': {'name': True}}
|
|
|
|
res = Item.get_item(req_data)
|
|
|
|
return Response(json.dumps(res[0], indent=2, sort_keys=True), mimetype='application/json'), res[1]
|
|
|
|
'''
|
|
|
|
|
2023-12-07 10:28:35 +00:00
|
|
|
|
2022-08-19 14:53:31 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # DOMAIN # # # # # # # # # # # # # # # #
|
2019-12-11 12:58:43 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|
2019-12-16 13:36:34 +00:00
|
|
|
@restApi.route("api/v1/get/domain/status/minimal", methods=['POST'])
|
2019-12-11 12:58:43 +00:00
|
|
|
@token_required('analyst')
|
2019-12-16 13:36:34 +00:00
|
|
|
def get_domain_status_minimal():
|
2019-12-11 12:58:43 +00:00
|
|
|
data = request.get_json()
|
|
|
|
domain = data.get('domain', None)
|
|
|
|
# error handler
|
2022-11-28 14:01:40 +00:00
|
|
|
# TODO TO MIGRATE
|
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
# res = Domain.api_verify_if_domain_exist(domain)
|
2019-12-11 12:58:43 +00:00
|
|
|
if res:
|
|
|
|
return create_json_response(res[0], res[1])
|
2022-11-28 14:01:40 +00:00
|
|
|
# TODO TO MIGRATE
|
|
|
|
raise Exception('TO MIGRATE')
|
|
|
|
# res = Domain.api_get_domain_up_range(domain)
|
2019-12-16 13:31:31 +00:00
|
|
|
res[0]['domain'] = domain
|
|
|
|
return create_json_response(res[0], res[1])
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|
2019-12-16 13:31:31 +00:00
|
|
|
|
2023-05-04 14:35:56 +00:00
|
|
|
# @restApi.route("api/v1/get/crawled/domain/list", methods=['POST'])
|
|
|
|
# @token_required('analyst')
|
|
|
|
# def get_crawled_domain_list():
|
|
|
|
# data = request.get_json()
|
|
|
|
# res = get_mandatory_fields(data, ['date_from', 'date_to'])
|
|
|
|
# if res:
|
|
|
|
# return create_json_response(res[0], res[1])
|
|
|
|
#
|
|
|
|
# date_from = data.get('date_from', None)
|
|
|
|
# date_to = data.get('date_to', None)
|
|
|
|
# domain_type = data.get('domain_type', None)
|
|
|
|
# domain_status = 'UP'
|
|
|
|
# # TODO TO MIGRATE
|
|
|
|
# raise Exception('TO MIGRATE')
|
|
|
|
# # res = Domain.api_get_domains_by_status_daterange(date_from, date_to, domain_type)
|
|
|
|
# dict_res = res[0]
|
|
|
|
# dict_res['date_from'] = date_from
|
|
|
|
# dict_res['date_to'] = date_to
|
|
|
|
# dict_res['domain_status'] = domain_status
|
|
|
|
# dict_res['domain_type'] = domain_type
|
|
|
|
# return create_json_response(dict_res, res[1])
|
2019-12-11 12:58:43 +00:00
|
|
|
|
2019-08-01 12:36:52 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # IMPORT # # # # # # # # # # # # # # # # # #
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
|
|
|
|
|
2019-07-25 15:26:32 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
#
|
|
|
|
# POST JSON FORMAT
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "type": "text", (default value)
|
|
|
|
# "tags": [], (default value)
|
2019-07-26 12:28:02 +00:00
|
|
|
# "default_tags": True, (default value)
|
2019-07-25 15:26:32 +00:00
|
|
|
# "galaxy" [], (default value)
|
|
|
|
# "text": "", mandatory if type = text
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {"uuid": "uuid"}
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|
2019-08-05 07:46:56 +00:00
|
|
|
@restApi.route("api/v1/import/item", methods=['POST'])
|
2019-08-06 08:37:56 +00:00
|
|
|
@token_required('analyst')
|
2019-07-25 15:26:32 +00:00
|
|
|
def import_item():
|
2019-07-30 11:49:21 +00:00
|
|
|
|
2019-07-25 15:26:32 +00:00
|
|
|
data = request.get_json()
|
|
|
|
if not data:
|
2023-04-21 14:16:10 +00:00
|
|
|
return create_json_response({'status': 'error', 'reason': 'Malformed JSON'}, 400)
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2019-07-26 12:28:02 +00:00
|
|
|
# unpack json
|
|
|
|
text_to_import = data.get('text', None)
|
|
|
|
if not text_to_import:
|
2023-04-21 14:16:10 +00:00
|
|
|
return create_json_response({'status': 'error', 'reason': 'No text supplied'}, 400)
|
2019-07-26 12:28:02 +00:00
|
|
|
|
|
|
|
tags = data.get('tags', [])
|
|
|
|
if not type(tags) is list:
|
|
|
|
tags = []
|
|
|
|
galaxy = data.get('galaxy', [])
|
|
|
|
if not type(galaxy) is list:
|
|
|
|
galaxy = []
|
|
|
|
|
2019-07-30 11:49:21 +00:00
|
|
|
if not Tag.is_valid_tags_taxonomies_galaxy(tags, galaxy):
|
2023-04-21 14:16:10 +00:00
|
|
|
return create_json_response({'status': 'error', 'reason': 'Tags or Galaxy not enabled'}, 400)
|
2019-07-26 12:28:02 +00:00
|
|
|
|
|
|
|
default_tags = data.get('default_tags', True)
|
|
|
|
if default_tags:
|
|
|
|
tags.append('infoleak:submission="manual"')
|
|
|
|
|
|
|
|
if sys.getsizeof(text_to_import) > 900000:
|
2023-04-21 14:16:10 +00:00
|
|
|
return create_json_response({'status': 'error', 'reason': 'Size exceeds default'}, 413)
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2023-04-21 14:16:10 +00:00
|
|
|
import_uuid = str(uuid.uuid4())
|
|
|
|
Import_helper.create_import_queue(tags, galaxy, text_to_import, import_uuid)
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2023-04-21 14:16:10 +00:00
|
|
|
return Response(json.dumps({'uuid': import_uuid}, indent=2, sort_keys=True), mimetype='application/json')
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2019-07-26 12:28:02 +00:00
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
|
|
|
# GET
|
|
|
|
#
|
|
|
|
# {
|
|
|
|
# "uuid": "uuid", mandatory
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# response: {
|
|
|
|
# "status": "in queue"/"in progress"/"imported",
|
|
|
|
# "items": [all item id]
|
|
|
|
# }
|
|
|
|
#
|
|
|
|
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
2019-08-05 14:00:23 +00:00
|
|
|
@restApi.route("api/v1/get/import/item", methods=['POST'])
|
2019-08-06 08:37:56 +00:00
|
|
|
@token_required('analyst')
|
2019-08-05 14:00:23 +00:00
|
|
|
def import_item_uuid():
|
|
|
|
data = request.get_json()
|
2023-04-21 14:16:10 +00:00
|
|
|
import_uuid = data.get('uuid', None)
|
2019-07-25 15:26:32 +00:00
|
|
|
|
|
|
|
# Verify uuid
|
2023-04-21 14:16:10 +00:00
|
|
|
if not is_valid_uuid_v4(import_uuid):
|
2019-07-26 12:28:02 +00:00
|
|
|
return Response(json.dumps({'status': 'error', 'reason': 'Invalid uuid'}), mimetype='application/json'), 400
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2023-04-21 14:16:10 +00:00
|
|
|
data = Import_helper.check_import_status(import_uuid)
|
2019-07-26 12:28:02 +00:00
|
|
|
if data:
|
|
|
|
return Response(json.dumps(data[0]), mimetype='application/json'), data[1]
|
2019-07-25 15:26:32 +00:00
|
|
|
|
2019-07-26 12:28:02 +00:00
|
|
|
return Response(json.dumps({'status': 'error', 'reason': 'Invalid response'}), mimetype='application/json'), 400
|
2024-02-26 14:35:48 +00:00
|
|
|
'''
|