From 67d08c443fcf32b86c79e20332583e238bd64d56 Mon Sep 17 00:00:00 2001 From: haraksin Date: Tue, 16 Jun 2020 01:12:23 -0700 Subject: [PATCH] try/except on pymisp loading stix failing --- misp_taxii_hooks/hooks.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/misp_taxii_hooks/hooks.py b/misp_taxii_hooks/hooks.py index 1c79021..a6f94fb 100644 --- a/misp_taxii_hooks/hooks.py +++ b/misp_taxii_hooks/hooks.py @@ -113,8 +113,12 @@ def post_stix(manager, content_block, collection_ids, service_id): block = content_block.content if isinstance(block, bytes): block = block.decode() - - package = pymisp.tools.stix.load_stix(StringIO(block)) + + try: + package = pymisp.tools.stix.load_stix(StringIO(block)) + except: + log.error('Could not load stix into MISP format; exiting.') + return 0 log.info("STIX loaded succesfully.") values = [x.value for x in package.attributes] log.info("Extracted %s", values) @@ -130,6 +134,8 @@ def post_stix(manager, content_block, collection_ids, service_id): search = '' if MISP: search = MISP.search("attributes", values=str(attrib)) + else: + return 0 if 'response' in search: if search["response"]["Attribute"] != []: # This means we have it!