2020from __future__ import absolute_import , print_function , unicode_literals
2121import logging
2222
23+ try :
24+ import simplejson as json
25+ except ImportError :
26+ import json
27+
2328try :
2429 from modules import register
2530except ImportError :
@@ -55,7 +60,8 @@ def processor(conf, ipaddress, results):
5560"""
5661
5762
58- @register (processors , active = True )
63+ @register (processors , active = False )
64+ # TODO: to solve issue https://github.com/Parsely/streamparse/issues/368
5965def shodan (conf , ipaddress , results ):
6066 """This method updates the attachments results
6167 with the Tika reports.
@@ -75,8 +81,12 @@ def shodan(conf, ipaddress, results):
7581
7682 try :
7783 report = api .host (ipaddress )
84+ json .dumps (report , ensure_ascii = False )
7885 except shodan .APIError :
79- log .exception ("Shodan API error" )
86+ return
87+ except TypeError :
88+ log .error ("JSON TypeError in Shodan report for ip {!r}" .format (
89+ ipaddress ))
8090 else :
8191 if report :
8292 results ["shodan" ] = report
@@ -99,7 +109,17 @@ def virustotal(conf, ipaddress, results):
99109 if conf ["enabled" ]:
100110 from virus_total_apis import PublicApi as VirusTotalPublicApi
101111 vt = VirusTotalPublicApi (conf ["api_key" ])
102- report = vt .get_ip_report (ipaddress )
103112
104- if report :
105- results ["virustotal" ] = report
113+ # Error: {u'virustotal': {'error': SSLError(SSLEOFError(8, u'EOF
114+ # occurred in violation of protocol (_ssl.c:590)'),)}}')
115+ # TypeError: SSLError(SSLEOFError(8, u'EOF occurred in violation of
116+ # protocol (_ssl.c:590)'),) is not JSON serializable')
117+ try :
118+ report = vt .get_ip_report (ipaddress )
119+ json .dumps (report , ensure_ascii = False )
120+ except TypeError :
121+ log .error ("TypeError in VirusTotal report for ip {!r}" .format (
122+ ipaddress ))
123+ else :
124+ if report :
125+ results ["virustotal" ] = report
0 commit comments