Skip to content

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

Trumail module (#1091)

Krishnasis Mandal8efdf8bf41b3
diff --git a/modules/sfp_trumail.py b/modules/sfp_trumail.py
new file mode 100644
index 00000000..b7879687
--- /dev/null
+++ b/modules/sfp_trumail.py
@@ -0,0 +1,115 @@
+# -*- coding: utf-8 -*-
+# -------------------------------------------------------------------------------
+# Name: sfp_trumail
+# Purpose: Spiderfoot plugin to check if an email is
+# disposable using trumail.io API.
+#
+# Author: Krishnasis Mandal <[email protected]>
+#
+# Created: 2020-10-02
+# Copyright: (c) Steve Micallef
+# Licence: GPL
+# -------------------------------------------------------------------------------
+
+import json
+from spiderfoot import SpiderFootEvent, SpiderFootPlugin
+
+
+class sfp_trumail(SpiderFootPlugin):
+
+ meta = {
+ 'name': "Trumail",
+ 'summary': "Check whether an email is disposable",
+ 'flags': [""],
+ 'useCases': ["Footprint", "Investigate", "Passive"],
+ 'categories': ["Search Engines"],
+ 'dataSource': {
+ 'website': "https://trumail.io/",
+ 'model': "FREE_NOAUTH_UNLIMITED",
+ 'references': [
+ "https://trumail.io/documentation"
+ ],
+ 'favIcon': "https://trumail.io/assets/favicon-32x32.png",
+ 'logo': "https://trumail.io/assets/images/trumail100.png",
+ 'description': "Trumail is a product that was built with the intention of providing "
+ "an easy to use API to software professionals who value a quality audience. "
+ "Your apps registration workflow is one of the most important and complex parts of your software "
+ "and it's very important that you filter user credentials in a way that allows for future use. "
+ "Invalid user credentials, particularly email addresses, should be deemed valid "
+ "and deliverable at the time of signup - That's where we come in.",
+ }
+ }
+
+ opts = {
+ }
+
+ optdescs = {
+ }
+
+ results = None
+ errorState = False
+
+ def setup(self, sfc, userOpts=dict()):
+ self.sf = sfc
+ self.results = self.tempStorage()
+
+ for opt in list(userOpts.keys()):
+ self.opts[opt] = userOpts[opt]
+
+ def watchedEvents(self):
+ return [
+ "EMAILADDR"
+ ]
+
+ def producedEvents(self):
+ return [
+ "EMAILADDR_DISPOSABLE",
+ "RAW_RIR_DATA"
+ ]
+
+ def queryEmailAddr(self, qry):
+ res = self.sf.fetchUrl(
+ f"https://api.trumail.io/v2/lookups/json?email={qry}",
+ timeout=self.opts['_fetchtimeout'],
+ useragent="SpiderFoot"
+ )
+
+ if res['content'] is None:
+ self.sf.info(f"No Trumail info found for {qry}")
+ return None
+
+ try:
+ return json.loads(res['content'])
+ except Exception as e:
+ self.sf.error(f"Error processing JSON response from Trumail: {e}")
+
+ return None
+
+ # Handle events sent to this module
+ def handleEvent(self, event):
+ eventName = event.eventType
+ srcModuleName = event.module
+ eventData = event.data
+
+ if self.errorState:
+ return
+
+ self.sf.debug(f"Received event, {eventName}, from {srcModuleName}")
+
+ self.results[eventData] = True
+
+ data = self.queryEmailAddr(eventData)
+
+ if data is None:
+ return
+
+ isDisposable = data.get('disposable')
+
+ if isDisposable:
+ evt = SpiderFootEvent("RAW_RIR_DATA", str(data), self.__name__, event)
+ self.notifyListeners(evt)
+
+ evt = SpiderFootEvent("EMAILADDR_DISPOSABLE", eventData, self.__name__, event)
+ self.notifyListeners(evt)
+
+# End of sfp_trumail class
diff --git a/test/unit/modules/test_sfp_trumail.py b/test/unit/modules/test_sfp_trumail.py
new file mode 100644
index 00000000..82f48477
--- /dev/null
+++ b/test/unit/modules/test_sfp_trumail.py
@@ -0,0 +1,80 @@
+# test_sfp_trumail.py
+import unittest
+
+from modules.sfp_trumail import sfp_trumail
+from sflib import SpiderFoot
+from spiderfoot import SpiderFootEvent, SpiderFootTarget
+
+
+class TestModuletrumail(unittest.TestCase):
+ """
+ Test modules.sfp_trumail
+ """
+
+ default_options = {
+ '_debug': False, # Debug
+ '__logging': True, # Logging in general
+ '__outputfilter': None, # Event types to filter from modules' output
+ '_useragent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0', # User-Agent to use for HTTP requests
+ '_dnsserver': '', # Override the default resolver
+ '_fetchtimeout': 5, # number of seconds before giving up on a fetch
+ '_internettlds': 'https://publicsuffix.org/list/effective_tld_names.dat',
+ '_internettlds_cache': 72,
+ '_genericusers': "abuse,admin,billing,compliance,devnull,dns,ftp,hostmaster,inoc,ispfeedback,ispsupport,list-request,list,maildaemon,marketing,noc,no-reply,noreply,null,peering,peering-notify,peering-request,phish,phishing,postmaster,privacy,registrar,registry,root,routing-registry,rr,sales,security,spam,support,sysadmin,tech,undisclosed-recipients,unsubscribe,usenet,uucp,webmaster,www",
+ '__version__': '3.3-DEV',
+ '__database': 'spiderfoot.test.db', # note: test database file
+ '__modules__': None, # List of modules. Will be set after start-up.
+ '_socks1type': '',
+ '_socks2addr': '',
+ '_socks3port': '',
+ '_socks4user': '',
+ '_socks5pwd': '',
+ '_torctlport': 9051,
+ '__logstdout': False
+ }
+
+ def test_opts(self):
+ module = sfp_trumail()
+ self.assertEqual(len(module.opts), len(module.optdescs))
+
+ def test_setup(self):
+ """
+ Test setup(self, sfc, userOpts=dict())
+ """
+ sf = SpiderFoot(self.default_options)
+
+ module = sfp_trumail()
+ module.setup(sf, dict())
+
+ def test_watchedEvents_should_return_list(self):
+ module = sfp_trumail()
+ self.assertIsInstance(module.watchedEvents(), list)
+
+ def test_producedEvents_should_return_list(self):
+ module = sfp_trumail()
+ self.assertIsInstance(module.producedEvents(), list)
+
+ @unittest.skip("todo")
+ def test_handleEvent(self):
+ """
+ Test handleEvent(self, event)
+ """
+ sf = SpiderFoot(self.default_options)
+
+ module = sfp_trumail()
+ module.setup(sf, dict())
+
+ target_value = 'example target value'
+ target_type = 'EMAILADDR'
+ target = SpiderFootTarget(target_value, target_type)
+ module.setTarget(target)
+
+ event_type = 'ROOT'
+ event_data = 'example data'
+ event_module = ''
+ source_event = ''
+ evt = SpiderFootEvent(event_type, event_data, event_module, source_event)
+
+ result = module.handleEvent(evt)
+
+ self.assertIsNone(result)