From dcd76ec5c4ffba2335d42068a3dc3b7fd21646d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 28 Sep 2016 18:50:05 +0200 Subject: [PATCH] Fix python 2.7 support, add missing test file --- pymisp/mispevent.py | 10 ++++++++-- tests/57c4445b-c548-4654-af0b-4be3950d210f.json | 1 + 2 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/57c4445b-c548-4654-af0b-4be3950d210f.json diff --git a/pymisp/mispevent.py b/pymisp/mispevent.py index 7697dcb..4812ac0 100644 --- a/pymisp/mispevent.py +++ b/pymisp/mispevent.py @@ -18,6 +18,12 @@ except ImportError: from .exceptions import PyMISPError, NewEventError, NewAttributeError +# Least dirty way to support python 2 and 3 +try: + basestring +except NameError: + basestring = str + class MISPAttribute(object): @@ -192,7 +198,7 @@ class MISPEvent(object): def load(self, json_event): self.new = False self.dump_full = True - if isinstance(json_event, str): + if isinstance(json_event, basestring): loaded = json.loads(json_event) if loaded.get('response'): event = loaded.get('response')[0] @@ -230,7 +236,7 @@ class MISPEvent(object): if kwargs.get('published') is not None: self.publish() if kwargs.get('date'): - if isinstance(kwargs['date'], str): + if isinstance(kwargs['date'], basestring): self.date = parse(kwargs['date']) elif isinstance(kwargs['date'], datetime.datetime): self.date = kwargs['date'].date() diff --git a/tests/57c4445b-c548-4654-af0b-4be3950d210f.json b/tests/57c4445b-c548-4654-af0b-4be3950d210f.json new file mode 100644 index 0000000..29bb02c --- /dev/null +++ b/tests/57c4445b-c548-4654-af0b-4be3950d210f.json @@ -0,0 +1 @@ +{"Event": {"info": "Ransomware - Xorist", "publish_timestamp": "1472548231", "timestamp": "1472541011", "analysis": "2", "Attribute": [{"category": "External analysis", "comment": "Imported via the Freetext Import Tool - Xchecked via VT: b3c4ae251f8094fa15b510051835c657eaef2a6cea46075d3aec964b14a99f68", "uuid": "57c5300c-0560-4146-bfaa-40e802de0b81", "timestamp": "1472540684", "to_ids": false, "value": "https://www.virustotal.com/file/b3c4ae251f8094fa15b510051835c657eaef2a6cea46075d3aec964b14a99f68/analysis/1469554268/", "type": "link"}, {"category": "External analysis", "comment": "", "uuid": "57c5310b-dc34-43cb-8b8e-4846950d210f", "timestamp": "1472541011", "to_ids": false, "value": "http://www.xylibox.com/2011/06/have-fun-with-trojan-ransomwin32xorist.html", "type": "link"}, {"category": "Other", "comment": "", "uuid": "57c444c0-8004-48fa-9c33-8aca950d210f", "timestamp": "1472480448", "to_ids": false, "value": "UPX packed", "type": "comment"}, {"category": "Other", "comment": "", "uuid": "57c44648-96f4-45d4-a8eb-453e950d210f", "timestamp": "1472480840", "to_ids": false, "value": "Key: 85350044dF4AC3518D185678A9414A7F,\r\nEncryption rounds:8,\r\nStart offset: 64,\r\nAlgorithm: TEA", "type": "text"}, {"category": "Payload delivery", "comment": "Imported via the Freetext Import Tool", "uuid": "57c4448a-fb04-457d-87e7-4127950d210f", "timestamp": "1472480394", "to_ids": true, "value": "3Z4wnG9603it23y.exe", "type": "filename"}, {"category": "Payload delivery", "comment": "Imported via the Freetext Import Tool", "uuid": "57c4448b-454c-4d17-90d1-4d2f950d210f", "timestamp": "1472480395", "to_ids": true, "value": "0749bae92ca336a02c83d126e04ec628", "type": "md5"}, {"category": "Payload delivery", "comment": "Imported via the Freetext Import Tool", "uuid": "57c4448a-bef0-4ba7-a071-444e950d210f", "timestamp": "1472480394", "to_ids": true, "value": "77b0c41b7d340b8a3d903f21347bbf06aa766b5b", "type": "sha1"}, {"category": "Payload delivery", "comment": "Imported via the Freetext Import Tool", "uuid": "57c4448b-3fa4-4d65-9ccc-4afa950d210f", "timestamp": "1472480395", "to_ids": true, "value": "b3c4ae251f8094fa15b510051835c657eaef2a6cea46075d3aec964b14a99f68", "type": "sha256"}, {"category": "Persistence mechanism", "comment": "", "uuid": "57c54b0f-27a4-458b-8e63-4455950d210f", "timestamp": "1472547599", "to_ids": true, "value": "Software\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Run|%TEMP%\\3Z4wnG9603it23y.exe", "type": "regkey|value"}], "Tag": [{"colour": "#ffffff", "exportable": true, "name": "tlp:white"}, {"colour": "#3d7a00", "exportable": true, "name": "circl:incident-classification=\"malware\""}, {"colour": "#420053", "exportable": true, "name": "ms-caro-malware:malware-type=\"Ransom\""}, {"colour": "#2c4f00", "exportable": true, "name": "malware_classification:malware-category=\"Ransomware\""}], "published": true, "date": "2016-08-29", "Orgc": {"name": "CIRCL", "uuid": "55f6ea5e-2c60-40e5-964f-47a8950d210f"}, "threat_level_id": "3", "uuid": "57c4445b-c548-4654-af0b-4be3950d210f"}} \ No newline at end of file