fix: Fixed input & output of the module

pull/168/head
chrisr3d 2018-03-02 11:03:21 +01:00
parent 0a96d44810
commit 82fe8ba78c
No known key found for this signature in database
GPG Key ID: 6BBED1B63A6D639F
1 changed files with 9 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import json, datetime, time import json, datetime, time, base64
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from collections import defaultdict from collections import defaultdict
from pymisp import MISPEvent, MISPObject from pymisp import MISPEvent, MISPObject
@ -8,7 +8,7 @@ moduleinfo = {'version': 1, 'author': 'Christian Studer',
'description': 'Import from GoAML', 'description': 'Import from GoAML',
'module-type': ['import']} 'module-type': ['import']}
moduleconfig = [] moduleconfig = []
mispattributes = {'input': ['xml file'], 'output': ['MISPEvent']} mispattributes = {'inputSource': ['file'], 'output': ['MISP objects']}
t_from_objects = {'nodes': ['from_person', 'from_account', 'from_entity'], t_from_objects = {'nodes': ['from_person', 'from_account', 'from_entity'],
'leaves': ['from_funds_code', 'from_country']} 'leaves': ['from_funds_code', 'from_country']}
@ -76,8 +76,8 @@ class GoAmlParser():
def __init__(self): def __init__(self):
self.misp_event = MISPEvent() self.misp_event = MISPEvent()
def readFile(self, filename): def read_xml(self, data):
self.tree = ET.parse(filename).getroot() self.tree = ET.fromstring(data)
def parse_xml(self): def parse_xml(self):
self.first_itteration() self.first_itteration()
@ -138,19 +138,19 @@ def handler(q=False):
if q is False: if q is False:
return False return False
request = json.loads(q) request = json.loads(q)
if request.get('file'): if request.get('data'):
filename = request['file'] data = base64.b64decode(request['data']).decode('utf-8')
else: else:
misperrors['error'] = "Unsupported attributes type" misperrors['error'] = "Unsupported attributes type"
return misperrors return misperrors
aml_parser = GoAmlParser() aml_parser = GoAmlParser()
try: try:
aml_parser.readFile(filename) aml_parser.read_xml(data)
except: except:
misperrors['error'] = "Impossible to read the file" misperrors['error'] = "Impossible to read XML data"
return misperrors return misperrors
aml_parser.parse_xml() aml_parser.parse_xml()
r = {'results': [{'types': mispattributes['output'], 'values': aml_parser.misp_event.to_json()}]} r = {'results': [obj.to_json() for obj in aml_parser.misp_event.objects]}
return r return r
def introspection(): def introspection():