SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Handle gzip-compressed HTTP responses.
smicallef6bc77a523488
diff --git a/sflib.py b/sflib.pyindex 0c478b58..650399cc 100644--- a/sflib.py+++ b/sflib.py@@ -12,6 +12,7 @@import inspectimport hashlib+import gzipimport reimport osimport random@@ -19,6 +20,7 @@ import socketimport sysimport timeimport urllib2+import StringIOclass SpiderFoot:dbh = None@@ -425,8 +427,13 @@ class SpiderFoot:# Extract the FQDN from a URLdef urlFQDN(self, url):baseurl = self.urlBaseUrl(url)+ if '://' not in baseurl:+ count = 0+ else:+ count = 2+# http://abc.com will split to ['http:', '', 'abc.com']- return baseurl.split('/')[2].lower()+ return baseurl.split('/')[count].lower()# Extract the keyword (the domain without the TLD or any subdomains)# from a domain.@@ -642,10 +649,18 @@ class SpiderFoot:opener = urllib2.build_opener(SmartRedirectHandler())fullPage = opener.open(req, timeout=timeout)+ content = fullPage.read()++ result['headers'] = dict()+ for k, v in fullPage.info().items():+ result['headers'][k.lower()] = v++ # Content is compressed+ if 'gzip' in result['headers'].get('content-encoding', ''):+ content = gzip.GzipFile(fileobj=StringIO.StringIO(content)).read()++ result['content'] = unicode(content, 'utf-8', errors='replace')- # Prepare result to return- result['content'] = unicode(fullPage.read(), 'utf-8', errors='replace')- result['headers'] = fullPage.info()#print "FOR: " + url#print "HEADERS: " + str(result['headers'])result['realurl'] = fullPage.geturl()@@ -664,7 +679,7 @@ class SpiderFoot:if fatal:self.fatal('URL could not be fetched (' + str(e) + ')')except Exception as x:- self.info("Unexpected exception occurred fetching: " + url + "(" + str(x) + ")")+ self.info("Unexpected exception occurred fetching: " + url + " (" + str(x) + ")")result['content'] = Noneresult['status'] = str(x)if fatal: