Skip to content

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

sfp_emailrep: Add support for API key

Brendan Coles76ab075c2b27
diff --git a/modules/sfp_emailrep.py b/modules/sfp_emailrep.py
index 701de089..6c07d3c2 100644
--- a/modules/sfp_emailrep.py
+++ b/modules/sfp_emailrep.py
@@ -15,12 +15,14 @@ import time
from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent
class sfp_emailrep(SpiderFootPlugin):
- """EmailRep:Footprint,Investigate,Passive:Search Engines::Search EmailRep.io for email address reputation."""
+ """EmailRep:Footprint,Investigate,Passive:Search Engines:apikey:Search EmailRep.io for email address reputation."""
opts = {
+ 'api_key': '',
}
optdescs = {
+ 'api_key': 'EmailRep API key.',
}
results = None
@@ -42,11 +44,21 @@ class sfp_emailrep(SpiderFootPlugin):
# https://emailrep.io/docs/
def query(self, qry):
- res = self.sf.fetchUrl('https://emailrep.io/' + qry,
- useragent='curl', # cURL user-agent appears to be required
- timeout=self.opts['_fetchtimeout'])
+ headers = {
+ 'Accept': "application/json"
+ }
- # Documentation does not indicate rate limit
+ if self.opts['api_key'] != '':
+ headers['Key'] = self.opts['api_key']
+
+ res = self.sf.fetchUrl(
+ 'https://emailrep.io/' + qry,
+ headers=headers,
+ useragent='SpiderFoot',
+ timeout=self.opts['_fetchtimeout']
+ )
+
+ # Documentation does not indicate rate limit threshold (50 queries/day)
time.sleep(1)
if res['content'] is None:
@@ -57,6 +69,11 @@ class sfp_emailrep(SpiderFootPlugin):
self.errorState = True
return None
+ if res['code'] == '401':
+ self.sf.error('API error: Invalid API key', False)
+ self.errorState = True
+ return None
+
if res['code'] == '429':
self.sf.error('API error: Too Many Requests', False)
self.errorState = True
@@ -87,6 +104,9 @@ class sfp_emailrep(SpiderFootPlugin):
self.sf.debug("Received event, %s, from %s" % (eventName, srcModuleName))
+ if self.opts['api_key'] == '':
+ self.sf.error("Warning: You enabled sfp_emailrep but did not set an API key! Queries will be rate limited.", False)
+
res = self.query(eventData)
if res is None: