From 2bb08b2f28457b310a2ec7ff16717bf801f0743b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Leonard?= Date: Sat, 29 Jun 2019 08:02:00 +0200 Subject: [PATCH] #322 fix invalid output error. use the dirty solution submitted in the issue, waiting for a better one --- analyzers/Shodan/shodan_analyzer.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/analyzers/Shodan/shodan_analyzer.py b/analyzers/Shodan/shodan_analyzer.py index 078f80c54..af74b8481 100755 --- a/analyzers/Shodan/shodan_analyzer.py +++ b/analyzers/Shodan/shodan_analyzer.py @@ -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)} @@ -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))