SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Implenting sfp_creditcard.py module
Krishnasis Mandalb4e309ec8668
diff --git a/modules/sfp_creditcard.py b/modules/sfp_creditcard.pynew file mode 100644index 00000000..7915949d--- /dev/null+++ b/modules/sfp_creditcard.py@@ -0,0 +1,90 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_creditcard+# Purpose: Example module to use for new modules.+#+# Author: Krishnasis Mandal <[email protected]>+#+# Created: 21/04/2020+# Copyright: (c) Steve Micallef+# Licence: GPL+# -------------------------------------------------------------------------------++from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent++class sfp_creditcard(SpiderFootPlugin):++ """Credit Card Extractor:Footprint,Investigate,Passive:Content Analysis::Identify Credit Card 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+ # Krishnasis - Note : What does self.tempStorage() return ?+ self.results = self.tempStorage()++ # Clear / reset any other class member variables here+ # or you risk them persisting between threads.++ for opt in list(userOpts.keys()):+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ # For a list of all events, check sfdb.py.+ def watchedEvents(self):+ return ["TARGET_WEB_CONTENT"]++ # What events this module produces+ def producedEvents(self):+ return ["CREDIT_CARD_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)++ creditCards=self.sf.parseCreditCards(eventData)++ myres=list()+ for creditCard in creditCards:+ evttype="CREDIT_CARD_NUMBER"++ self.sf.info("Found credit card number : "+creditCard)++ if creditCard in myres:+ self.sf.debug("Already found from this source")+ continue+ myres.append(creditCard)++ # Krishnasis Note : Need some understanding on this+ evt = SpiderFootEvent(evttype, mail, self.__name__, event)+ if event.moduleDataSource:+ evt.moduleDataSource = event.moduleDataSource+ else:+ evt.moduleDataSource = "Unknown"+ self.notifyListeners(evt)++ return None+# End of sfp_creditcard classdiff --git a/sfdb.py b/sfdb.pyindex f135b2a1..88ddffb4 100644--- a/sfdb.py+++ b/sfdb.py@@ -108,6 +108,7 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('CLOUD_STORAGE_BUCKET', 'Cloud Storage Bucket', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('CLOUD_STORAGE_BUCKET_OPEN', 'Cloud Storage Bucket Open', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('COMPANY_NAME', 'Company Name', 0, 'ENTITY')",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('CREDIT_CARD_NUMBER', 'Credit Card Number', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('BASE64_DATA', 'Base64-encoded Data', 1, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('BITCOIN_ADDRESS', 'Bitcoin Address', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('BITCOIN_BALANCE', 'Bitcoin Balance', 0, 'DESCRIPTOR')",diff --git a/sflib.py b/sflib.pyindex 37584be4..1fdcf9cd 100644--- a/sflib.py+++ b/sflib.py@@ -1102,7 +1102,27 @@ class SpiderFoot:emails.add(match)return list(emails)++ # Find all credit card numbers with the supplied content+ # Returns a list+ def parseCreditCards(self,data):+ credit_cards=set()+ credit_card_regex="^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\d{3})\d{11})$"++ # Krishnasis : Note+ # Potentially more effective alternative to using Regex :+ # 1. Extract numbers of length 13 - 16 digits+ # 2. Apply Luhn's algorithm to verify the credit card+ # Probable Feature : Identify the Credit Card provider++ matches=re.find_all(credit_card_regex,data)+ for match in matches:+ self.debug("Found possible credit card : "+match)++ credit_cards.add(match)+ return list(credit_cards)+# Return a PEM for a DERdef sslDerToPem(self, der):return ssl.DER_cert_to_PEM_cert(der)