Merge branch 'new_module' of into new_module

chrisr3d 2019-06-07 15:30:19 +02:00
commit b7223abe78
1 changed files with 23 additions and 26 deletions

View File

@ -9,21 +9,7 @@ mispattributes = {'input': ['link'], 'format': 'misp_standard'}
moduleinfo = {'version': '0.1', 'author': 'Christian Studer',
'description': 'Query Joe Sandbox API with a report URL to get the parsed data.',
'module-type': ['expansion']}
moduleconfig = ['apiurl', 'apikey', 'accept-tac']
class _ParseError(Exception):
def _parse_bool(value, name="bool"):
if value is None or value == "":
return None
if value in ("true", "True"):
return True
if value in ("false", "False"):
return False
raise _ParseError("Cannot parse {}. Must be 'true' or 'false'".format(name))
moduleconfig = ['apiurl', 'apikey']
def handler(q=False):
@ -34,21 +20,32 @@ def handler(q=False):
apikey = request['config'].get('apikey')
if not apikey:
return {'error': 'No API key provided'}
url = request['attribute']['value']
if "/submissions/" not in url:
return {'error': "The URL does not point to a Joe Sandbox analysis."}
submission_id = url.split('/')[-1] # The URL has the format
joe = jbxapi.JoeSandbox(apiurl=apiurl, apikey=apikey, user_agent='MISP joesandbox_query')
accept_tac = _parse_bool(request['config'].get('accept-tac'), 'accept-tac')
except _ParseError as e:
joe_info = joe.submission_info(submission_id)
except jbxapi.ApiError as e:
return {'error': str(e)}
attribute = request['attribute']
joe = jbxapi.JoeSandbox(apiurl=apiurl, apikey=apikey, user_agent='MISP joesandbox_analysis', accept_tac=accept_tac)
joe_info = joe.submission_info(attribute['value'].split('/')[-1])
if joe_info["status"] != "finished":
return {'error': "The analysis has not finished yet."}
if joe_info['most_relevant_analysis'] is None:
return {'error': "No analysis belongs to this submission."}
analysis_webid = joe_info['most_relevant_analysis']['webid']
joe_parser = JoeParser()
most_relevant = joe_info['most_relevant_analysis']['webid']
for analyse in joe_info['analyses']:
if analyse['webid'] == most_relevant:
joe_data = json.loads(joe.analysis_download(most_relevant, 'jsonfixed')[1])
joe_data = json.loads(joe.analysis_download(analysis_webid, 'jsonfixed')[1])
return {'results': joe_parser.results}