2023-05-16 14:34:22 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
|
|
|
|
"""
|
|
|
|
module
|
|
|
|
====================
|
|
|
|
|
|
|
|
This module send tagged pastes to MISP or THE HIVE Project
|
|
|
|
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
sys.path.append(os.environ['AIL_BIN'])
|
|
|
|
##################################
|
|
|
|
# Import Project packages
|
|
|
|
##################################
|
|
|
|
from modules.abstract_module import AbstractModule
|
|
|
|
from lib.exceptions import MISPConnectionError
|
|
|
|
from lib.objects.Items import Item
|
|
|
|
from lib import Tag
|
|
|
|
from exporter.MISPExporter import MISPExporterAutoDaily
|
|
|
|
from exporter.TheHiveExporter import TheHiveExporterAlertTag
|
|
|
|
|
|
|
|
class MISP_Thehive_Auto_Push(AbstractModule):
|
|
|
|
"""MISP_Hive_Feeder module for AIL framework"""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(MISP_Thehive_Auto_Push, self).__init__()
|
|
|
|
|
|
|
|
# refresh Tracked Regex
|
|
|
|
self.tags = Tag.refresh_auto_push()
|
|
|
|
self.last_refresh = time.time()
|
|
|
|
|
|
|
|
self.misp_exporter = MISPExporterAutoDaily()
|
|
|
|
self.the_hive_exporter = TheHiveExporterAlertTag()
|
|
|
|
|
|
|
|
# Send module state to logs
|
|
|
|
self.logger.info(f"Module {self.module_name} initialized")
|
|
|
|
|
|
|
|
def compute(self, message):
|
|
|
|
if self.last_refresh < Tag.get_last_auto_push_refreshed() < 0:
|
|
|
|
self.tags = Tag.refresh_auto_push()
|
|
|
|
self.last_refresh = time.time()
|
|
|
|
self.redis_logger.info('Tags Auto Push refreshed')
|
|
|
|
|
2023-06-22 13:38:04 +00:00
|
|
|
tag = message
|
|
|
|
item = self.get_obj()
|
|
|
|
item_id = item.get_id()
|
2023-05-16 14:34:22 +00:00
|
|
|
|
|
|
|
# enabled
|
|
|
|
if 'misp' in self.tags:
|
|
|
|
if tag in self.tags['misp']:
|
|
|
|
r = self.misp_exporter.export(item, tag)
|
|
|
|
if r == -1:
|
|
|
|
Tag.set_auto_push_status('misp', 'ConnectionError')
|
|
|
|
else:
|
|
|
|
Tag.set_auto_push_status('misp', '')
|
2024-04-02 07:35:35 +00:00
|
|
|
self.logger.info(f'MISP Pushed: {tag} -> {item_id}')
|
2023-05-16 14:34:22 +00:00
|
|
|
|
|
|
|
if 'thehive' in self.tags:
|
|
|
|
if tag in self.tags['thehive']:
|
|
|
|
r = self.the_hive_exporter.export(item, tag)
|
|
|
|
if r == -1:
|
|
|
|
Tag.set_auto_push_status('thehive', 'ConnectionError')
|
|
|
|
elif r == -2:
|
|
|
|
Tag.set_auto_push_status('thehive', 'Request Entity Too Large')
|
|
|
|
else:
|
|
|
|
Tag.set_auto_push_status('thehive', '')
|
2024-04-02 07:35:35 +00:00
|
|
|
self.logger.info(f'thehive Pushed: {tag} -> {item_id}')
|
2023-05-16 14:34:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
module = MISP_Thehive_Auto_Push()
|
|
|
|
module.run()
|