SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Module to find base64-encoded strings in content and URLs.
Steve2f35e8364f7f
diff --git a/modules/sfp_base64.py b/modules/sfp_base64.pynew file mode 100644index 00000000..a2f9eb58--- /dev/null+++ b/modules/sfp_base64.py@@ -0,0 +1,78 @@+# -*- coding: utf-8 -*-+# -------------------------------------------------------------------------------+# Name: sfp_base64+# Purpose: Identifies (best-effort) Base64-encoded strings in content and URLs.+#+# Author: Steve Micallef <[email protected]>+#+# Created: 31/01/2017+# Copyright: (c) Steve Micallef 2017+# -------------------------------------------------------------------------------++import base64+import re+from sflib import SpiderFoot, SpiderFootPlugin, SpiderFootEvent+++class sfp_base64(SpiderFootPlugin):+ """Base64:Investigate:Data Analysis::Identify Base64-encoded strings in any content and URLs, often revealing interesting hidden information."""++ # Default options+ opts = {+ 'minlength': 10+ }++ # Option descriptions+ optdescs = {+ 'minlength': "The minimum length a string that looks like a base64-encoded string needs to be."+ }++ def setup(self, sfc, userOpts=dict()):+ self.sf = sfc++ for opt in userOpts.keys():+ self.opts[opt] = userOpts[opt]++ # What events is this module interested in for input+ def watchedEvents(self):+ return ["LINKED_URL_INTERNAL", "TARGET_WEB_CONTENT"]++ # What events this module produces+ # This is to support the end user in selecting modules based on events+ # produced.+ def producedEvents(self):+ return ["BASE64_DATA"]++ # Handle events sent to this module+ def handleEvent(self, event):+ eventName = event.eventType+ srcModuleName = event.module+ eventData = event.data++ self.sf.debug("Received event, " + eventName + ", from " + srcModuleName)++ pat = re.compile("([A-Za-z0-9+\/]+\=\=|[A-Za-z0-9+\/]+\=)")+ m = re.findall(pat, eventData)+ for match in m:+ minlen = int(self.opts['minlength'])+ if len(match) >= minlen:+ caps = sum(1 for c in match if c.isupper())+ # Base64-encoded strings don't look like normal strings+ if caps < (minlen/4):+ return None+ self.sf.info("Found Base64 string: " + match)+ if type(match) == str:+ string = unicode(match, 'utf-8', errors='replace')+ else:+ string = match++ try:+ string += " (" + base64.b64decode(match) + ")"+ evt = SpiderFootEvent("BASE64_DATA", string, self.__name__, event)+ self.notifyListeners(evt)+ except BaseException as e:+ self.sf.debug("Unable to base64-decode a string.")++ return None++# End of sfp_base64 classdiff --git a/sfdb.py b/sfdb.pyindex 367a5313..83df464a 100644--- a/sfdb.py+++ b/sfdb.py@@ -96,7 +96,9 @@ class SpiderFootDb:"INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('AFFILIATE_WEB_CONTENT', 'Affiliate - Web Content', 1, 'DATA')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('AFFILIATE_DESCRIPTION_CATEGORY', 'Affiliate Description - Category', 0, 'DESCRIPTOR')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('AFFILIATE_DESCRIPTION_ABSTRACT', 'Affiliate Description - Abstract', 0, 'DESCRIPTOR')",+ "INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('APPSTORE_ENTRY', 'App Store Entry', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('AMAZON_S3_BUCKET', 'Amazon S3 Bucket', 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 ('BGP_AS_OWNER', 'BGP AS Ownership', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('BGP_AS_MEMBER', 'BGP AS Membership', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('BGP_AS_PEER', 'BGP AS Peer', 0, 'ENTITY')",@@ -126,7 +128,7 @@ class SpiderFootDb:"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 ('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 ('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')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('INTERNET_NAME', 'Internet Name', 0, 'ENTITY')","INSERT INTO tbl_event_types (event, event_descr, event_raw, event_type) VALUES ('IP_ADDRESS', 'IP Address', 0, 'ENTITY')",