Skip to content

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

Support use of a HIBP API key.

smicallef83db7b66aea2
diff --git a/modules/sfp_haveibeenpwned.py b/modules/sfp_haveibeenpwned.py
index 9407cc13..a2040e21 100644
--- a/modules/sfp_haveibeenpwned.py
+++ b/modules/sfp_haveibeenpwned.py
@@ -15,25 +15,29 @@ import time
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
class sfp_haveibeenpwned(SpiderFootPlugin):
- """HaveIBeenPwned:Footprint,Investigate,Passive:Leaks, Dumps and Breaches::Check Have I Been Pwned? for hacked e-mail addresses identified."""
+ """HaveIBeenPwned:Footprint,Investigate,Passive:Leaks, Dumps and Breaches:apikey:Check HaveIBeenPwned.com for hacked e-mail addresses identified in breaches."""
# Default options
opts = {
+ "api_key": ""
}
# Option descriptions
optdescs = {
+ "api_key": "HaveIBeenPwned.com API key."
}
# Be sure to completely clear any class variables in setup()
# or you run the risk of data persisting between scan runs.
- results = dict()
+ results = None
+ errorState = False
def setup(self, sfc, userOpts=dict()):
self.sf = sfc
- self.results = dict()
+ self.results = self.tempStorage()
+ self.errorState = False
# Clear / reset any other class member variables here
# or you risk them persisting between threads.
@@ -51,10 +55,18 @@ class sfp_haveibeenpwned(SpiderFootPlugin):
def query(self, qry):
ret = None
- url = "https://haveibeenpwned.com/api/v2/breachedaccount/" + qry
- hdrs = { "Accept": "application/vnd.haveibeenpwned.v2+json" }
+ if self.opts['api_key']:
+ v = "3"
+ else:
+ v = "2"
+
+ url = "https://haveibeenpwned.com/api/v" + v + "/breachedaccount/" + qry
+ hdrs = { "Accept": "application/vnd.haveibeenpwned.v" + v + "+json" }
retry = 0
+ if self.opts['api_key']:
+ hdrs['hibp-api-key'] = self.opts['api_key']
+
while retry < 2:
# https://haveibeenpwned.com/API/v2#RateLimiting
time.sleep(1.5)
@@ -72,6 +84,11 @@ class sfp_haveibeenpwned(SpiderFootPlugin):
time.sleep(2)
retry += 1
+ if res['code'] == "401":
+ self.sf.error("Failed to authenticate key with HaveIBeenPwned.com.", False)
+ self.errorState = True
+ return None
+
try:
ret = json.loads(res['content'])
except Exception as e:
@@ -86,6 +103,9 @@ class sfp_haveibeenpwned(SpiderFootPlugin):
srcModuleName = event.module
eventData = event.data
+ if self.errorState:
+ return None
+
self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)
# Don't look up stuff twice
@@ -100,7 +120,10 @@ class sfp_haveibeenpwned(SpiderFootPlugin):
return None
for n in data:
- site = n["Title"]
+ if not self.opts['api_key']:
+ site = n["Title"]
+ else:
+ site = n["Name"]
evt = eventName + "_COMPROMISED"
# Notify other modules of what you've found
e = SpiderFootEvent(evt, eventData + " [" + site + "]",