Skip to content

Commit

Permalink
#322 fix invalid output error. use the dirty solution submitted in th…
Browse files Browse the repository at this point in the history
…e issue, waiting for a better one
  • Loading branch information
jeromeleonard committed Jun 29, 2019
1 parent f6d2b4f commit 2bb08b2
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion analyzers/Shodan/shodan_analyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ def __init__(self):
self.service = self.get_param('config.service', None, 'Service parameter is missing')
self.shodan_client = None


def encode(self, x):
if isinstance(x, str):
return x.encode('utf-8', 'ignore').decode('utf-8', 'ignore')
elif isinstance(x, dict):
return {k: self.encode(v) for k, v in x.items()}
elif isinstance(x, list):
return [self.encode(k) for k in x]
else:
return x

def execute_shodan_service(self, data):
if self.service in ['host', 'host_history']:
results = {'host': self.shodan_client.host(data, history=True if self.service == 'host_history' else False)}
Expand Down Expand Up @@ -77,7 +88,7 @@ def run(self):
self.shodan_client = ShodanAPIPublic(self.shodan_key)
data = self.get_param('data', None, 'Data is missing')
results = self.execute_shodan_service(data)
self.report(results)
self.report(self.encode(results))

except APIError as e:
self.error(str(e))
Expand Down

0 comments on commit 2bb08b2

Please sign in to comment.