Skip to content

Commit

Permalink
Fixes #94, some PEP8
Browse files Browse the repository at this point in the history
  • Loading branch information
3c7 authored and jeromeleonard committed Oct 18, 2017
1 parent 7d4e0a5 commit 0c12d3f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
13 changes: 9 additions & 4 deletions analyzers/MISP/misp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ class MISPAnalyzer(Analyzer):

def __init__(self):
Analyzer.__init__(self)

# Fixes #94. Instead of None, the string Unnamed should be passed to MISPClient constructor
name = self.getParam('config.name', None)
if not name:
name = 'Unnamed'

self.misp = MISPClient(url=self.getParam('config.url', None, 'No MISP url given.'),
key=self.getParam('config.key', None, 'No MISP api key given.'),
ssl=self.getParam('config.certpath', True),
name=self.getParam('config.name', None))
name=name)

def summary(self, raw):
taxonomies = []
Expand All @@ -27,7 +33,7 @@ def summary(self, raw):
data.append(res['uuid'])

# return number of unique events
if data == []:
if not data:
value = "\"0 event\""
taxonomies.append(self.build_taxonomy(level, namespace, predicate, value))
else:
Expand All @@ -36,8 +42,6 @@ def summary(self, raw):

return {"taxonomies": taxonomies}



def run(self):
if self.data_type == 'hash':
response = self.misp.search_hash(self.getData())
Expand All @@ -58,5 +62,6 @@ def run(self):

self.report({'results': response})


if __name__ == '__main__':
MISPAnalyzer().run()
18 changes: 12 additions & 6 deletions analyzers/MISP/mispclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,14 @@ def __clean_relatedevent(self, related_events):

response = []
for event in related_events:
ev = {}
ev['info'] = event['Event']['info']
ev['id'] = event['Event']['id']
ev = {
'info': event['Event']['info'],
'id': event['Event']['id']
}
response.append(ev)

return response


def __clean_event(self, misp_event):
"""
Strip event data for lighter output. Analyer report only contains useful data.
Expand Down Expand Up @@ -171,7 +171,6 @@ def __clean_event(self, misp_event):
if 'RelatedEvent' in misp_event:
misp_event['RelatedEvent'] = self.__clean_relatedevent(misp_event['RelatedEvent'])


return misp_event

def __clean(self, misp_response):
Expand Down Expand Up @@ -200,8 +199,15 @@ def __search(self, value, type_attribute):
raise EmptySearchtermError
for idx, connection in enumerate(self.misp_connections):
misp_response = connection.search(type_attribute=type_attribute, values=value)

# Fixes #94
if isinstance(self.misp_name, list):
name = self.misp_name[idx]
else:
name = self.misp_name

results.append({'url': connection.root_url,
'name': self.misp_name[idx],
'name': name,
'result': self.__clean(misp_response)})
return results

Expand Down

0 comments on commit 0c12d3f

Please sign in to comment.