diff --git a/sf.py b/sf.py index 379dde7abc..5f557f754a 100755 --- a/sf.py +++ b/sf.py @@ -419,7 +419,7 @@ def start_scan(sfConfig, sfModules, args): # Start running a new scan scanName = target - scanId = sf.genScanInstanceId() + scanId = SpiderFootHelpers.genScanInstanceId() try: p = mp.Process(target=SpiderFootScanner, args=(scanName, scanId, target, targetType, modlist, cfg)) p.daemon = True diff --git a/sfscan.py b/sfscan.py index 80212e47e5..5b1bd0dfe6 100644 --- a/sfscan.py +++ b/sfscan.py @@ -21,7 +21,7 @@ import dns.resolver from sflib import SpiderFoot -from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget +from spiderfoot import SpiderFootDb, SpiderFootEvent, SpiderFootPlugin, SpiderFootTarget, SpiderFootHelpers class SpiderFootScanner(): @@ -112,7 +112,7 @@ def __init__(self, scanName, scanId, targetValue, targetType, moduleList, global if scanId: self.__scanId = scanId else: - self.__scanId = self.__sf.genScanInstanceId() + self.__scanId = SpiderFootHelpers.genScanInstanceId() self.__sf.scanId = self.__scanId self.__dbh.scanInstanceCreate(self.__scanId, self.__scanName, self.__targetValue) diff --git a/sfwebui.py b/sfwebui.py index d61cc7f67c..375cf6ca2d 100644 --- a/sfwebui.py +++ b/sfwebui.py @@ -529,7 +529,6 @@ def rerunscan(self, id): # Snapshot the current configuration to be used by the scan cfg = deepcopy(self.config) modlist = list() - sf = SpiderFoot(cfg) dbh = SpiderFootDb(cfg) info = dbh.scanInstanceGet(id) @@ -558,7 +557,7 @@ def rerunscan(self, id): 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 @@ def rerunscanmulti(self, ids): # Snapshot the current configuration to be used by the scan cfg = deepcopy(self.config) modlist = list() - sf = SpiderFoot(cfg) dbh = SpiderFootDb(cfg) for id in ids.split(","): @@ -614,7 +612,7 @@ def rerunscanmulti(self, ids): 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 @@ def startscan(self, scanname, scantarget, modulelist, typelist, usecase): 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 diff --git a/spiderfoot/helpers.py b/spiderfoot/helpers.py index e0c48cf497..265fa98cc7 100644 --- a/spiderfoot/helpers.py +++ b/spiderfoot/helpers.py @@ -1,6 +1,7 @@ import json import random import re +import uuid from networkx import nx from networkx.readwrite.gexf import GEXFWriter @@ -308,6 +309,17 @@ def validLEI(lei): 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() + + @staticmethod def parseRobotsTxt(robotsTxtData): """Parse the contents of robots.txt. diff --git a/test/unit/test_spiderfoot.py b/test/unit/test_spiderfoot.py index f2d13d49d4..8dc197a69d 100644 --- a/test/unit/test_spiderfoot.py +++ b/test/unit/test_spiderfoot.py @@ -97,15 +97,6 @@ def test_optValueToData_argument_val_invalid_type_should_return_None(self): 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.py index 2061284b3e..ba9c914010 100644 --- a/test/unit/test_spiderfoothelpers.py +++ b/test/unit/test_spiderfoothelpers.py @@ -122,6 +122,13 @@ def test_dataParentChildToTree_should_return_dict(self): 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)