SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Implemented sfp_iban.py
Krishnasis Mandal48a1ff56b7b7
diff --git a/modules/sfp_iban.py b/modules/sfp_iban.pynew file mode 100644index 00000000..374e3c8e--- /dev/null+++ b/modules/sfp_iban.py@@ -0,0 +1,93 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_iban+# Purpose: SpiderFoot plug-in for scanning retreived content by other+# modules (such as sfp_spider) and identifying IBAN numbers.+#+# Author: Krishnasis Mandal <[email protected]>+#+# Created: 26/04/2020+# Copyright: (c) Steve Micallef+# Licence: GPL+# -------------------------------------------------------------------------------++from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++class sfp_iban(SpiderFootPlugin):++ """IBAN Number Extractor:Footprint,Investigate,Passive:Content Analysis::Identify IBAN Numbers in any data"""++ # Default options.+ opts = {+ # Options specific to this module+ }++ # Option descriptions.+ optdescs = {+ }++ # Tracking results can be helpful to avoid reporting/processing duplicates+ results = None++ # Tracking the error state of the module can be useful to detect when a third party+ # has failed and you don't wish to process any more events.+ errorState = False++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc+ self.results = self.tempStorage()++ # Clear / reset any other class member variables here+ # or you risk them persisting between threads.++ # Override datasource for sfp_iban module+ self.__dataSource__ = "Target Website"++ for opt in list(userOpts.keys()):+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return ["TARGET_WEB_CONTENT", "DARKNET_MENTION_CONTENT",+ "LEAKSITE_CONTENT"]++ # What events this module produces+ def producedEvents(self):+ return ["IBAN_NUMBER"]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ # Once we are in this state, return immediately.+ if self.errorState:+ return None++ # event was received.+ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ # Extract IBAN Card numbers+ ibanNumbers = self.sf.parseIBANNumbers(eventData)++ myres = list()+ for ibanNumber in ibanNumbers:+ evttype = "IBAN_NUMBER"++ self.sf.info("Found IBAN number : " + ibanNumber)++ if ibanNumber in myres:+ self.sf.debug("Already found from this source")+ continue+ myres.append(ibanNumber)++ evt = SpiderFootEvent(evttype, ibanNumber, self.__name__, event)+ if event.moduleDataSource:+ evt.moduleDataSource = event.moduleDataSource+ else:+ evt.moduleDataSource = "Unknown"+ self.notifyListeners(evt)++ return None+# End of sfp_iban classdiff --git a/sfdb.py b/sfdb.pyindex 88ddffb4..b3aa8bfb 100644--- a/sfdb.py+++ b/sfdb.py@@ -149,6 +149,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HASH_COMPROMISED', 'Compromised Password Hash', 0, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HTTP_CODE', 'HTTP Status Code', 0, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('HUMAN_NAME', 'Human Name', 0, 'ENTITY')",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('IBAN_NUMBER', 'IBAN Number', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('INTERESTING_FILE', 'Interesting File', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('INTERESTING_FILE_HISTORIC', 'Historic Interesting File', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('JUNK_FILE', 'Junk File', 0, 'DESCRIPTOR')",diff --git a/sflib.py b/sflib.pyindex c52dd131..01cf2335 100644--- a/sflib.py+++ b/sflib.py@@ -1150,6 +1150,92 @@ class SpiderFoot:self.debug("Skipped invalid credit card number: " + match)return list(creditCards)+ # Find all IBAN numbers with the supplied content+ #+ # Extracts possible IBAN Numbers using a generic regex+ #+ # Checks whether the possible IBAN number is valid or not+ # Country-wise length check and Mod 97 algorithm+ #+ # Returns a list+ def parseIBANNumbers(self, data):+ ibanNumbers = set()++ # Dictionary of country codes and their respective IBAN lengths+ ibanCountryLengths = {+ "AL" : 28, "AD" : 24, "AT" : 20, "AZ" : 28,+ "ME" : 22, "BH" : 22, "BY" : 28, "BE" : 16,+ "BA" : 20, "BR" : 29, "BG" : 22, "CR" : 22,+ "HR" : 21, "CY" : 28, "CZ" : 24, "DK" : 18,+ "DO" : 28, "EG" : 29, "SV" : 28, "FO" : 18,+ "FI" : 18, "FR" : 27, "GE" : 22, "DE" : 22,+ "GI" : 23, "GR" : 27, "GL" : 18, "GT" : 28,+ "VA" : 22, "HU" : 28, "IS" : 26, "IQ" : 23,+ "IE" : 22, "IL" : 27, "JO" : 30, "KZ" : 20,+ "XK" : 20, "KW" : 30, "LV" : 21, "LB" : 28,+ "LI" : 21, "LT" : 20, "LU" : 20, "MT" : 31,+ "MR" : 27, "MU" : 30, "MD" : 24, "MC" : 27,+ "DZ" : 24, "AO" : 25, "BJ" : 28, "VG" : 24,+ "BF" : 27, "BI" : 16, "CM" : 27, "CV" : 25,+ "CG" : 27, "EE" : 20, "GA" : 27, "GG" : 22,+ "IR" : 26, "IM" : 22, "IT" : 27, "CI" : 28,+ "JE" : 22, "MK" : 19, "MG" : 27, "ML" : 28,+ "MZ" : 25, "NL" : 18, "NO" : 15, "PK" : 24,+ "PS" : 29, "PL" : 28, "PT" : 25, "QA" : 29,+ "RO" : 24, "LC" : 32, "SM" : 27, "ST" : 25,+ "SA" : 24, "SN" : 28, "RS" : 22, "SC" : 31,+ "SK" : 24, "SI" : 19, "ES" : 24, "CH" : 21,+ "TL" : 23, "TN" : 24, "TR" : 26, "UA" : 29,+ "AE" : 23, "GB" : 22, "SE" : 24+ }++ # Remove whitespace from data.+ # Credit cards might contain spaces between them+ # which will cause regex mismatch+ data = data.replace(" ", "")++ # Extract alphanumeric characters of lengths ranging from 16 to 31+ possibleIBANRegex = "[A-Za-z0-9]{16,31}"+ matches = re.findall(possibleIBANRegex, data)++ for match in matches:+ match = match.upper()+ ibanNumber = match++ countryCode = ibanNumber[0:2]++ # Country code not in dictionary+ if countryCode not in ibanCountryLengths.keys():+ self.debug("Skipped invalid IBAN number: " + ibanNumber)+ continue++ if len(ibanNumber) == ibanCountryLengths[countryCode]:+ # Move the first 4 characters to the end of the string+ match = match[4:] + match[0:4]++ for character in match:+ # Check if character is an alphabet+ if character.isalpha():+ # Replace alphabet to number+ # where A = 10, B = 11, ...., Z = 35+ match = match.replace(character, str((ord(character) - 65) + 10))++ if int(match) % 97 == 1:+ # IBAN Number is valid+ self.debug("Found IBAN number: " + match)+ ibanNumbers.add(ibanNumber)+ else:+ # Invalid IBAN Number due to failed Mod 97 operation+ self.debug("Skipped invalid IBAN number: " + ibanNumber)+ continue+ else:+ # Invalid IBAN Number due to length mismatch+ self.debug("Skipped invalid IBAN number: " + ibanNumber)+ continue++ return list(ibanNumbers)++# Return a PEM for a DERdef sslDerToPem(self, der):return ssl.DER_cert_to_PEM_cert(der)