SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Support use of a HIBP API key.
smicallef83db7b66aea2
diff --git a/modules/sfp_haveibeenpwned.py b/modules/sfp_haveibeenpwned.pyindex 9407cc13..a2040e21 100644--- a/modules/sfp_haveibeenpwned.py+++ b/modules/sfp_haveibeenpwned.py@@ -15,25 +15,29 @@ import timefrom sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEventclass 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 optionsopts = {+ "api_key": ""}# Option descriptionsoptdescs = {+ "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 = Falsedef 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#RateLimitingtime.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.moduleeventData = 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 Nonefor 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 founde = SpiderFootEvent(evt, eventData + " [" + site + "]",