2021-05-10 16:08:58 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
from flask import Blueprint, jsonify, Response, request
|
|
|
|
from app.decorators import require_header_token, require_get_token
|
2021-06-08 18:22:52 +02:00
|
|
|
from app.classes.misp import MISP
|
2021-05-10 16:08:58 +02:00
|
|
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
misp_bp = Blueprint("misp", __name__)
|
2021-06-08 18:22:52 +02:00
|
|
|
misp = MISP()
|
2021-05-10 16:08:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
@misp_bp.route('/add', methods=['POST'])
|
|
|
|
@require_header_token
|
2021-06-08 18:22:52 +02:00
|
|
|
def add():
|
2021-05-10 16:08:58 +02:00
|
|
|
"""
|
|
|
|
Parse and add a MISP instance to the database.
|
|
|
|
:return: status of the operation in JSON
|
|
|
|
"""
|
|
|
|
data = json.loads(request.data)
|
|
|
|
instance = data["data"]["instance"]
|
2021-06-08 18:22:52 +02:00
|
|
|
|
2021-05-10 16:08:58 +02:00
|
|
|
source = "backend"
|
2021-06-08 18:22:52 +02:00
|
|
|
res = MISP.add(instance["name"], instance["url"],
|
|
|
|
instance["key"], instance["ssl"], source)
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify(res)
|
|
|
|
|
2021-06-08 18:22:52 +02:00
|
|
|
|
2021-05-10 16:08:58 +02:00
|
|
|
@misp_bp.route('/delete/<misp_id>', methods=['GET'])
|
|
|
|
@require_header_token
|
|
|
|
def delete(misp_id):
|
|
|
|
"""
|
|
|
|
Delete a MISP instance by its id to the database.
|
|
|
|
:return: status of the operation in JSON
|
|
|
|
"""
|
2021-06-08 18:22:52 +02:00
|
|
|
res = MISP.delete(misp_id)
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify(res)
|
|
|
|
|
2021-06-08 18:22:52 +02:00
|
|
|
|
2021-05-10 16:08:58 +02:00
|
|
|
@misp_bp.route('/get_all', methods=['GET'])
|
|
|
|
@require_header_token
|
|
|
|
def get_all():
|
|
|
|
"""
|
|
|
|
Retreive a list of all MISP instances.
|
|
|
|
:return: list of MISP instances in JSON.
|
|
|
|
"""
|
2021-06-08 18:22:52 +02:00
|
|
|
res = MISP.get_all()
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify({"results": [i for i in res]})
|
|
|
|
|
|
|
|
|
|
|
|
@misp_bp.route('/get_iocs', methods=['POST'])
|
2021-06-08 18:22:52 +02:00
|
|
|
# @require_header_token
|
2021-05-10 16:08:58 +02:00
|
|
|
def get_iocs():
|
|
|
|
"""
|
|
|
|
Retreive a list of all MISP instances.
|
|
|
|
:return: list of MISP instances in JSON.
|
|
|
|
"""
|
|
|
|
|
|
|
|
data = json.loads(request.data)
|
|
|
|
data = data["data"]
|
|
|
|
|
2021-06-08 18:22:52 +02:00
|
|
|
res = MISP.get_iocs(data["misp_id"],
|
|
|
|
data["limit"],
|
|
|
|
data["page"])
|
2021-05-10 16:08:58 +02:00
|
|
|
return jsonify(res)
|
|
|
|
|
|
|
|
|
|
|
|
@misp_bp.route('/edit', methods=['POST'])
|
|
|
|
@require_header_token
|
2021-06-08 18:22:52 +02:00
|
|
|
def edit():
|
2021-05-10 16:08:58 +02:00
|
|
|
"""
|
|
|
|
Parse and edit the desired MISP instance.
|
|
|
|
:return: status of the operation in JSON
|
|
|
|
"""
|
|
|
|
data = json.loads(request.data)
|
|
|
|
instance = data["data"]["instance"]
|
2021-06-08 18:22:52 +02:00
|
|
|
res = MISP.edit(instance["id"],
|
|
|
|
instance["name"],
|
|
|
|
instance["url"],
|
|
|
|
instance["apikey"],
|
|
|
|
instance["verifycert"])
|
|
|
|
return jsonify(res)
|