Skip to content

SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.

Proper HTTP error code formatting and checking.

Steve4776854ca804
diff --git a/modules/sfp_accounts.py b/modules/sfp_accounts.py
index 8c1aef22..4be945d6 100644
--- a/modules/sfp_accounts.py
+++ b/modules/sfp_accounts.py
@@ -96,11 +96,12 @@ class sfp_accounts(SpiderFootPlugin):
try:
found = False
+ site['account_existence_code'] = str(site['account_existence_code'])
if site['account_existence_code']:
- if site['account_existence_code'] in [ res['code'], str(res['code']) ]:
+ if site['account_existence_code'] == res['code']:
found = True
if site['account_missing_code']:
- if site['account_missing_code'] in [ res['code'], str(res['code']) ]:
+ if site['account_missing_code'] == res['code']:
found = False
if site['account_existence_string']:
if site['account_existence_string'] in res['content']:
diff --git a/modules/sfp_censys.py b/modules/sfp_censys.py
index 4caa8b4c..722718ae 100644
--- a/modules/sfp_censys.py
+++ b/modules/sfp_censys.py
@@ -75,7 +75,7 @@ class sfp_censys(SpiderFootPlugin):
res = self.sf.fetchUrl(url , timeout=self.opts['_fetchtimeout'],
useragent="SpiderFoot", headers=headers)
- if res['code'] in [ "400", "429", "500", "403", 400, 429, 500, 403 ]:
+ if res['code'] in [ "400", "429", "500", "403" ]:
self.sf.error("Censys.io API key seems to have been rejected or you have exceeded usage limits for the month.", False)
self.errorState = True
return None
diff --git a/modules/sfp_clearbit.py b/modules/sfp_clearbit.py
index 83597559..dc36e284 100644
--- a/modules/sfp_clearbit.py
+++ b/modules/sfp_clearbit.py
@@ -61,7 +61,7 @@ class sfp_clearbit(SpiderFootPlugin):
res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],
useragent="SpiderFoot", headers=headers)
- if res['code'] not in [ 200, "200" ]:
+ if res['code'] != "200":
self.sf.error("Return code indicates no results or potential API key failure.",
False)
return None
diff --git a/modules/sfp_cymon.py b/modules/sfp_cymon.py
index 3bf95879..1a8348ef 100644
--- a/modules/sfp_cymon.py
+++ b/modules/sfp_cymon.py
@@ -82,7 +82,7 @@ class sfp_cymon(SpiderFootPlugin):
res = self.sf.fetchUrl(url , timeout=self.opts['_fetchtimeout'],
useragent="SpiderFoot", headers=headers)
- if res['code'] in [ "400", "429", "500", "403", 400, 429, 500, 403 ]:
+ if res['code'] in [ "400", "429", "500", "403" ]:
self.sf.error("Cymon.io API key seems to have been rejected or you have exceeded usage limits for the month.", False)
self.errorState = True
return None
diff --git a/modules/sfp_hunter.py b/modules/sfp_hunter.py
index 6135ad7d..efe01a26 100644
--- a/modules/sfp_hunter.py
+++ b/modules/sfp_hunter.py
@@ -58,7 +58,7 @@ class sfp_hunter(SpiderFootPlugin):
res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],
useragent="SpiderFoot")
- if res['code'] in [ 404, "404" ]:
+ if res['code'] == "404":
return None
try:
diff --git a/modules/sfp_junkfiles.py b/modules/sfp_junkfiles.py
index 6029ea55..7bd42064 100644
--- a/modules/sfp_junkfiles.py
+++ b/modules/sfp_junkfiles.py
@@ -85,7 +85,7 @@ class sfp_junkfiles(SpiderFootPlugin):
res = self.sf.fetchUrl(fetch, headOnly=True,
timeout=self.opts['_fetchtimeout'],
useragent=self.opts['_useragent'])
- if res['code'] not in [ 404, "404"]:
+ if res['code'] != "404":
self.skiphosts.append(host)
self.hosts.append(host)
@@ -113,7 +113,7 @@ class sfp_junkfiles(SpiderFootPlugin):
if res['realurl'] != fetch:
self.sf.debug("Skipping because " + res['realurl'] + " isn't the fetched URL of " + fetch)
continue
- if res['code'] in ["200", 200]:
+ if res['code'] != "200":
evt = SpiderFootEvent("JUNK_FILE", fetch,
self.__name__, event)
self.notifyListeners(evt)
@@ -151,7 +151,7 @@ class sfp_junkfiles(SpiderFootPlugin):
if res['realurl'] != fetch:
self.sf.debug("Skipping because " + res['realurl'] + " isn't the fetched URL of " + fetch)
continue
- if res['code'] in ["200", 200]:
+ if res['code'] != "200":
evt = SpiderFootEvent("JUNK_FILE", fetch,
self.__name__, event)
self.notifyListeners(evt)
@@ -174,7 +174,7 @@ class sfp_junkfiles(SpiderFootPlugin):
if res['realurl'] != fetch:
self.sf.debug("Skipping because " + res['realurl'] + " isn't the fetched URL of " + fetch)
continue
- if res['code'] in ["200", 200]:
+ if res['code'] != "200":
evt = SpiderFootEvent("JUNK_FILE", fetch,
self.__name__, event)
self.notifyListeners(evt)
diff --git a/modules/sfp_psbdmp.py b/modules/sfp_psbdmp.py
index 6ba73279..0cd992ef 100644
--- a/modules/sfp_psbdmp.py
+++ b/modules/sfp_psbdmp.py
@@ -63,7 +63,7 @@ class sfp_psbdmp(SpiderFootPlugin):
res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],
useragent="SpiderFoot")
- if res['code'] == 403:
+ if res['code'] == "403":
self.sf.info("Unable to fetch data from psbdmp.com right now.")
return None
diff --git a/modules/sfp_pwned.py b/modules/sfp_pwned.py
index 24fa4ae8..3bf1ed6c 100644
--- a/modules/sfp_pwned.py
+++ b/modules/sfp_pwned.py
@@ -60,10 +60,10 @@ class sfp_pwned(SpiderFootPlugin):
res = self.sf.fetchUrl(url, timeout=self.opts['_fetchtimeout'],
useragent="SpiderFoot", headers=hdrs)
- if res['code'] in [ 404, "404" ]:
+ if res['code'] == "404":
return None
- if res['code'] in [ 429, "429" ]:
+ if res['code'] == "429":
# Back off a little further
time.sleep(2)
retry += 1
diff --git a/modules/sfp_xforce.py b/modules/sfp_xforce.py
index f36b3d57..2098628e 100644
--- a/modules/sfp_xforce.py
+++ b/modules/sfp_xforce.py
@@ -78,7 +78,7 @@ class sfp_xforce(SpiderFootPlugin):
url = xforce_url + "/" + querytype + "/" + qry
res = self.sf.fetchUrl(url , timeout=self.opts['_fetchtimeout'], useragent="SpiderFoot", headers=headers)
- if res['code'] in [ "400", "401", "402", "403", 400, 401, 402, 403 ]:
+ if res['code'] in [ "400", "401", "402", "403" ]:
self.sf.error("XForce API key seems to have been rejected or you have exceeded usage limits for the month.", False)
self.errorState = True
return None
diff --git a/sflib.py b/sflib.py
index 4d35a484..15bd6908 100644
--- a/sflib.py
+++ b/sflib.py
@@ -987,7 +987,7 @@ class SpiderFoot:
hdr = requests.head(url, headers=header, verify=False)
size = int(hdr.headers.get('content-length', 0))
result['realurl'] = hdr.headers.get('location', url)
- result['code'] = hdr.status_code
+ result['code'] = str(hdr.status_code)
if headOnly:
return result
@@ -1004,7 +1004,7 @@ class SpiderFoot:
hdr = requests.head(result['realurl'], headers=header, verify=False)
size = int(hdr.headers.get('content-length', 0))
result['realurl'] = hdr.headers.get('location', result['realurl'])
- result['code'] = hdr.status_code
+ result['code'] = str(hdr.status_code)
if size > sizeLimit:
return result
@@ -1041,17 +1041,17 @@ class SpiderFoot:
#print "FOR: " + url
#print "HEADERS: " + str(result['headers'])
result['realurl'] = fullPage.geturl()
- result['code'] = fullPage.getcode()
+ result['code'] = str(fullPage.getcode())
result['status'] = 'OK'
except urllib2.HTTPError as h:
if not noLog:
self.info("HTTP code " + str(h.code) + " encountered for " + url)
# Capture the HTTP error code
- result['code'] = h.code
+ result['code'] = str(h.code)
for k, v in h.info().items():
result['headers'][k.lower()] = v
if fatal:
- self.fatal('URL could not be fetched (' + h.code + ')')
+ self.fatal('URL could not be fetched (' + str(h.code) + ')')
except urllib2.URLError as e:
if not noLog:
self.info("Error fetching " + url + "(" + str(e) + ")")
@@ -1107,7 +1107,7 @@ class SpiderFoot:
while attempts < 3:
firstPage = self.fetchUrl(seedUrl, timeout=opts['timeout'],
useragent=opts['useragent'])
- if firstPage['code'] == 403 or firstPage['code'] == 503:
+ if firstPage['code'] == "403" or firstPage['code'] == "503":
self.error("Google doesn't like us right now..", False)
failed = True
@@ -1157,7 +1157,7 @@ class SpiderFoot:
while attempts < 3:
nextPage = self.fetchUrl(u'https://www.google.com' + nextUrl,
timeout=opts['timeout'], useragent=opts['useragent'])
- if nextPage['code'] == 403 or nextPage['code'] == 503:
+ if nextPage['code'] == "403" or nextPage['code'] == "503":
self.error("Google doesn't like us right now..", False)
failed = True
@@ -1210,7 +1210,7 @@ class SpiderFoot:
while attempts < 3:
firstPage = self.fetchUrl(seedUrl, timeout=opts['timeout'],
useragent=opts['useragent'])
- if firstPage['code'] == 400:
+ if firstPage['code'] == "400":
self.error("Bing doesn't like us right now..", False)
failed = True
@@ -1258,7 +1258,7 @@ class SpiderFoot:
while attempts < 3:
nextPage = self.fetchUrl(u'https://www.bing.com' + nextUrl,
timeout=opts['timeout'], useragent=opts['useragent'])
- if nextPage['code'] == 400:
+ if nextPage['code'] == "400":
self.error("Bing doesn't like us any more..", False)
failed = True
@@ -1311,7 +1311,7 @@ class SpiderFoot:
while attempts < 3:
firstPage = self.fetchUrl(seedUrl, timeout=opts['timeout'],
useragent=opts['useragent'])
- if firstPage['code'] == 403:
+ if firstPage['code'] == "403":
self.error("Yahoo doesn't like us right now..", False)
failed = True
@@ -1357,7 +1357,7 @@ class SpiderFoot:
while attempts < 3:
nextPage = self.fetchUrl(nextUrl, timeout=opts['timeout'],
useragent=opts['useragent'])
- if nextPage['code'] == 403:
+ if nextPage['code'] == "403":
self.error("Yahoo doesn't like us any more..", False)
failed = True