SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
SpiderFootHelpers: move genScanInstanceId to SpiderFootHelpers (#1224)
bcolesea8b71cc598d
diff --git a/sf.py b/sf.pyindex 379dde7a..5f557f75 100755--- a/sf.py+++ b/sf.py@@ -419,7 +419,7 @@ def start_scan(sfConfig, sfModules, args):# Start running a new scanscanName = target- scanId = sf.genScanInstanceId()+ scanId = SpiderFootHelpers.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanName, scanId, target, targetType, modlist, cfg))p.daemon = Truediff --git a/sfscan.py b/sfscan.pyindex 80212e47..5b1bd0df 100644--- a/sfscan.py+++ b/sfscan.py@@ -21,7 +21,7 @@ from collections import OrderedDictimport dns.resolverfrom sflib import SpiderFoot-from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget+from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget, SpiderFootHelpersclass SpiderFootScanner():@@ -112,7 +112,7 @@ class SpiderFootScanner():if scanId:self.__scanId = scanIdelse:- self.__scanId = self.__sf.genScanInstanceId()+ self.__scanId = SpiderFootHelpers.genScanInstanceId()self.__sf.scanId = self.__scanIdself.__dbh.scanInstanceCreate(self.__scanId, self.__scanName, self.__targetValue)diff --git a/sfwebui.py b/sfwebui.pyindex d61cc7f6..375cf6ca 100644--- a/sfwebui.py+++ b/sfwebui.py@@ -529,7 +529,6 @@ class SpiderFootWebUi:# Snapshot the current configuration to be used by the scancfg = deepcopy(self.config)modlist = list()- sf = SpiderFoot(cfg)dbh = SpiderFootDb(cfg)info = dbh.scanInstanceGet(id)@@ -558,7 +557,7 @@ class SpiderFootWebUi:scantarget = scantarget.lower()# Start running a new scan- scanId = sf.genScanInstanceId()+ scanId = SpiderFootHelpers.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))p.daemon = True@@ -588,7 +587,6 @@ class SpiderFootWebUi:# Snapshot the current configuration to be used by the scancfg = deepcopy(self.config)modlist = list()- sf = SpiderFoot(cfg)dbh = SpiderFootDb(cfg)for id in ids.split(","):@@ -614,7 +612,7 @@ class SpiderFootWebUi:return self.error("Invalid target type. Could not recognize it as a target SpiderFoot supports.")# Start running a new scan- scanId = sf.genScanInstanceId()+ scanId = SpiderFootHelpers.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))p.daemon = True@@ -1189,7 +1187,7 @@ class SpiderFootWebUi:scantarget = scantarget.lower()# Start running a new scan- scanId = sf.genScanInstanceId()+ scanId = SpiderFootHelpers.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))p.daemon = Truediff --git a/spiderfoot/helpers.py b/spiderfoot/helpers.pyindex e0c48cf4..265fa98c 100644--- a/spiderfoot/helpers.py+++ b/spiderfoot/helpers.py@@ -1,6 +1,7 @@import jsonimport randomimport re+import uuidfrom networkx import nxfrom networkx.readwrite.gexf import GEXFWriter@@ -308,6 +309,17 @@ class SpiderFootHelpers():return True+ @staticmethod+ def genScanInstanceId():+ """Generate an globally unique ID for this scan.++ Returns:+ str: scan instance unique ID+ """++ return str(uuid.uuid4()).split("-")[0].upper()++ @staticmethoddef parseRobotsTxt(robotsTxtData):"""Parse the contents of robots.txt.diff --git a/test/unit/test_spiderfoot.py b/test/unit/test_spiderfoot.pyindex f2d13d49..8dc197a6 100644--- a/test/unit/test_spiderfoot.py+++ b/test/unit/test_spiderfoot.py@@ -97,15 +97,6 @@ class TestSpiderFoot(unittest.TestCase):opt_data = sf.optValueToData(invalid_type)self.assertEqual(opt_data, None)- def test_genScanInstanceId_should_return_a_string(self):- """- Test genScanInstanceId(self)- """- sf = SpiderFoot(dict())-- scan_instance_id = sf.genScanInstanceId()- self.assertIsInstance(scan_instance_id, str)-def test_dblog_invalid_dbh_should_raise(self):"""Test _dblog(self, level, message, component=None)diff --git a/test/unit/test_spiderfoothelpers.py b/test/unit/test_spiderfoothelpers.pyindex 2061284b..ba9c9140 100644--- a/test/unit/test_spiderfoothelpers.py+++ b/test/unit/test_spiderfoothelpers.py@@ -122,6 +122,13 @@ class TestSpiderFootHelpers(unittest.TestCase):tree = SpiderFootHelpers.dataParentChildToTree({"test": {"123": "456"}})self.assertIsInstance(tree, dict)+ def test_genScanInstanceId_should_return_a_string(self):+ """+ Test genScanInstanceId()+ """+ scan_instance_id = SpiderFootHelpers.genScanInstanceId()+ self.assertIsInstance(scan_instance_id, str)+def test_validLEI_should_return_a_boolean(self):"""Test validLEI(lei)