Skip to content

Commit

Permalink
Fixes #209: PyMISP need to get proxy setting explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
3c7 committed Mar 21, 2018
1 parent 96b862e commit 008b271
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
27 changes: 14 additions & 13 deletions analyzers/MISP/misp.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ 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)
name = self.get_param('config.name', None)
if not name:
name = 'Unnamed'
try:
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=name)
self.misp = MISPClient(url=self.get_param('config.url', None, 'No MISP url given.'),
key=self.get_param('config.key', None, 'No MISP api key given.'),
ssl=self.get_param('config.certpath', True),
name=name,
proxies={'http': self.http_proxy, 'https': self.https_proxy})
except MISPClientError as e:
self.error(str(e))
except TypeError as te:
Expand Down Expand Up @@ -48,21 +49,21 @@ def summary(self, raw):

def run(self):
if self.data_type == 'hash':
response = self.misp.search_hash(self.getData())
response = self.misp.search_hash(self.get_data())
elif self.data_type == 'url':
response = self.misp.search_url(self.getData())
response = self.misp.search_url(self.get_data())
elif self.data_type == 'domain' or self.data_type == 'fqdn':
response = self.misp.search_domain(self.getData())
response = self.misp.search_domain(self.get_data())
elif self.data_type == 'mail' or self.data_type == 'mail_subject':
response = self.misp.search_mail(self.getData())
response = self.misp.search_mail(self.get_data())
elif self.data_type == 'ip':
response = self.misp.search_ip(self.getData())
response = self.misp.search_ip(self.get_data())
elif self.data_type == 'registry':
response = self.misp.search_registry(self.getData())
response = self.misp.search_registry(self.get_data())
elif self.data_type == 'filename':
response = self.misp.search_filename(self.getData())
response = self.misp.search_filename(self.get_data())
else:
response = self.misp.searchall(self.getData())
response = self.misp.searchall(self.get_data())

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

Expand Down
14 changes: 9 additions & 5 deletions analyzers/MISP/mispclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ class MISPClient:
:type ssl: [bool, list, str]
:param name: Name of the MISP instance, is sent back in the report for matching the results.
:type name: [str, list]
:param proxies: Proxy to use for pymisp instances
:type proxies: dict
"""

def __init__(self, url, key, ssl=True, name='Unnamed'):
def __init__(self, url, key, ssl=True, name='Unnamed', proxies=None):
self.misp_connections = []
if type(url) is list:
for idx, server in enumerate(url):
Expand All @@ -58,7 +60,8 @@ def __init__(self, url, key, ssl=True, name='Unnamed'):
raise TypeError('SSL parameter is a not expected type.')
self.misp_connections.append(pymisp.PyMISP(url=server,
key=key[idx],
ssl=verify))
ssl=verify,
proxies=proxies))
else:
verify = True
if isinstance(ssl, str):
Expand All @@ -68,7 +71,8 @@ def __init__(self, url, key, ssl=True, name='Unnamed'):
verify = ssl
self.misp_connections.append(pymisp.PyMISP(url=url,
key=key,
ssl=verify))
ssl=verify,
proxies=proxies))
self.misp_name = name

@staticmethod
Expand Down Expand Up @@ -131,7 +135,7 @@ def __mispregistrytypes():
:rtype: list
"""
return ['regkey', 'regkey|value']

@staticmethod
def __mispfilenametypes():
"""Just for better readability, all __misp*type methods return just a list of misp data types
Expand Down Expand Up @@ -279,7 +283,7 @@ def search_registry(self, searchterm):
:rtype: list
"""
return self.__search(type_attribute=self.__mispregistrytypes(), value=searchterm)

def search_filename(self, searchterm):
"""Search for filenames
Expand Down

0 comments on commit 008b271

Please sign in to comment.