SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Correlation functionality fully integrated.
smicallef6fd8e50a4ff5
diff --git a/sf.py b/sf.pyindex 1984cbaf..90f67e58 100755--- a/sf.py+++ b/sf.py@@ -31,6 +31,7 @@ from sfscan import startSpiderFootScannerfrom sfwebui import SpiderFootWebUifrom spiderfoot import SpiderFootHelpersfrom spiderfoot import SpiderFootDb+from spiderfoot import SpiderFootCorrelatorfrom spiderfoot.logger import logListenerSetup, logWorkerSetupfrom spiderfoot import __version__@@ -133,11 +134,16 @@ def main():log = logging.getLogger(f"spiderfoot.{__name__}")sfModules = dict()+ correlationRulesRaw = dict()sft = SpiderFoot(sfConfig)# Load each module in the modules directory with a .py extensionmod_dir = sft.myPath() + '/modules/'+ # Load each correlation rule in the correlations directory with+ # a .yaml extension+ corr_dir = sft.myPath() + '/correlations/'+if not os.path.isdir(mod_dir):log.critical(f"Modules directory does not exist: {mod_dir}")sys.exit(-1)@@ -167,8 +173,34 @@ def main():log.critical(f"No modules found in modules directory: {mod_dir}")sys.exit(-1)- # Add module info to sfConfig so it can be used by the UI+ if not os.path.isdir(corr_dir):+ log.critical(f"Correlation rules directory does not exist: {corr_dir}")+ sys.exit(-1)++ for filename in os.listdir(corr_dir):+ if not filename.endswith(".yaml"):+ continue+ if filename in ('template.yaml'):+ continue++ ruleName = filename.split('.')[0]+ correlationRulesRaw[ruleName] = open(corr_dir + filename, 'r').read()++ # Sanity-check the rules and parse them+ dbh = SpiderFootDb(sfConfig)+ correlator = None+ if not correlationRulesRaw:+ log.error(f"No correlation rules found in the directory: {corr_dir}. Maybe this was intended?")+ sfCorrelationRules = list()+ else:+ correlator = SpiderFootCorrelator(dbh, correlationRulesRaw)+ if not correlator:+ log.fatal("Failure initializing correlation rules, aborting.")+ sfCorrelationRules = correlator.get_ruleset()++ # Add modules and the correlator to sfConfig so they can be used elsewheresfConfig['__modules__'] = sfModules+ sfConfig['__correlationrules__'] = sfCorrelationRules# Add descriptions of the global config optionssfConfig['__globaloptdescs__'] = sfOptdescsdiff --git a/sfscan.py b/sfscan.pyindex 925e3c07..bb258e7a 100644--- a/sfscan.py+++ b/sfscan.py@@ -22,7 +22,7 @@ from collections import OrderedDictimport dns.resolverfrom sflib import SpiderFoot-from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget, SpiderFootHelpers, SpiderFootThreadPool, logger+from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget, SpiderFootHelpers, SpiderFootThreadPool, SpiderFootCorrelator, loggerdef startSpiderFootScanner(loggingQueue, *args, **kwargs):@@ -110,7 +110,6 @@ class SpiderFootScanner():raise ValueError("moduleList is empty")self.__moduleList = moduleList-self.__sf = SpiderFoot(self.__config)self.__sf.dbh = self.__dbh@@ -422,10 +421,19 @@ class SpiderFootScanner():finally:if not failed:+ self.runCorrelations()self.__sf.status(f"Scan [{self.__scanId}] completed.")self.__setStatus("FINISHED", None, time.time() * 1000)self.__dbh.close()+ def runCorrelations(self):+ self.__sf.status(f"Running {len(self.__config['__correlationrules__'])} correlation rules.")+ ruleset = dict()+ for rule in self.__config['__correlationrules__']:+ ruleset[rule['id']] = rule['rawYaml']+ corr = SpiderFootCorrelator(self.__dbh, ruleset, self.__scanId)+ corr.run_correlations()+def waitForThreads(self):counter = 0