Skip to content

Commit

Permalink
fix: [objects] fix investigation + ail2ail + screenshot MISP export
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrtia committed Jun 4, 2023
1 parent 1eae92c commit f3c3cb5
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
25 changes: 20 additions & 5 deletions bin/core/ail_2_ail.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def is_server_client_sync_mode_connected(ail_uuid, sync_mode):
return res == 1

def is_server_client_connected(ail_uuid):
return r_cache.sismember('ail_2_ail:server:all_clients', ail_uuid)
try:
return r_cache.sismember('ail_2_ail:server:all_clients', ail_uuid)
except:
return False

def clear_server_connected_clients():
for ail_uuid in get_server_all_connected_clients():
Expand Down Expand Up @@ -398,7 +401,10 @@ def get_all_ail_instance_keys():
return r_serv_sync.smembers(f'ail:instance:key:all')

def is_allowed_ail_instance_key(key):
return r_serv_sync.sismember(f'ail:instance:key:all', key)
try:
return r_serv_sync.sismember(f'ail:instance:key:all', key)
except:
return False

def get_ail_instance_key(ail_uuid):
return r_serv_sync.hget(f'ail:instance:{ail_uuid}', 'api_key')
Expand Down Expand Up @@ -427,7 +433,10 @@ def get_ail_instance_all_sync_queue(ail_uuid):
return r_serv_sync.smembers(f'ail:instance:sync_queue:{ail_uuid}')

def is_ail_instance_queue(ail_uuid, queue_uuid):
return r_serv_sync.sismember(f'ail:instance:sync_queue:{ail_uuid}', queue_uuid)
try:
return r_serv_sync.sismember(f'ail:instance:sync_queue:{ail_uuid}', queue_uuid)
except:
return False

def exists_ail_instance(ail_uuid):
return r_serv_sync.exists(f'ail:instance:{ail_uuid}')
Expand All @@ -439,7 +448,10 @@ def get_ail_instance_description(ail_uuid):
return r_serv_sync.hget(f'ail:instance:{ail_uuid}', 'description')

def exists_ail_instance(ail_uuid):
return r_serv_sync.sismember('ail:instance:all', ail_uuid)
try:
return r_serv_sync.sismember('ail:instance:all', ail_uuid)
except:
return False

def is_ail_instance_push_enabled(ail_uuid):
res = r_serv_sync.hget(f'ail:instance:{ail_uuid}', 'push')
Expand Down Expand Up @@ -935,7 +947,10 @@ def get_all_sync_queue_dict():
return dict_sync_queues

def is_queue_registred_by_ail_instance(queue_uuid, ail_uuid):
return r_serv_sync.sismember(f'ail:instance:sync_queue:{ail_uuid}', queue_uuid)
try:
return r_serv_sync.sismember(f'ail:instance:sync_queue:{ail_uuid}', queue_uuid)
except:
return False

def register_ail_to_sync_queue(ail_uuid, queue_uuid):
is_linked = is_ail_instance_linked_to_sync_queue(ail_uuid)
Expand Down
3 changes: 2 additions & 1 deletion bin/lib/Investigations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
##################################
# Import Project packages
##################################
from lib import ail_core
from lib import ConfigLoader
from lib import Tag
from lib.exceptions import UpdateInvestigationError
Expand Down Expand Up @@ -445,7 +446,7 @@ def api_register_object(json_dict):
investigation = Investigation(investigation_uuid)

obj_type = json_dict.get('type', '').replace(' ', '')
if not exists_obj_type(obj_type):
if obj_type not in ail_core.get_all_objects():
return {"status": "error", "reason": f"Invalid Object Type: {obj_type}"}, 400

subtype = json_dict.get('subtype', '')
Expand Down
1 change: 1 addition & 0 deletions bin/lib/objects/Screenshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from hashlib import sha256
from io import BytesIO
from flask import url_for
from pymisp import MISPObject

sys.path.append(os.environ['AIL_BIN'])
##################################
Expand Down
5 changes: 4 additions & 1 deletion bin/lib/objects/abstract_subtype_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ def get_last_seen(self, r_int=False):
return last_seen

def get_nb_seen(self):
return int(r_object.zscore(f'{self.type}_all:{self.subtype}', self.id))
nb = r_object.zscore(f'{self.type}_all:{self.subtype}', self.id)
if not nb:
nb = 0
return int(nb)

# # TODO: CHECK RESULT
def get_nb_seen_by_date(self, date_day):
Expand Down
3 changes: 2 additions & 1 deletion var/www/blueprints/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from exporter import TheHiveExporter
from lib.exceptions import MISPConnectionError
from lib.objects import ail_objects
from lib import ail_core
from lib.Investigations import Investigation

# ============ BLUEPRINT ============
Expand Down Expand Up @@ -91,7 +92,7 @@ def import_object_file():
@login_analyst
def objects_misp_export():
user_id = current_user.get_id()
object_types = ail_objects.get_all_objects_with_subtypes_tuple()
object_types = ail_core.get_all_objects_with_subtypes_tuple()
to_export = MISPExporter.get_user_misp_objects_to_export(user_id)
return render_template("export_object.html", object_types=object_types, to_export=to_export)

Expand Down

0 comments on commit f3c3cb5

Please sign in to comment.