SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
sflib: set attributes protected
Brendan Colesdf92f7db6bab
diff --git a/sf.py b/sf.pyindex 9c0887d1..902a7681 100755--- a/sf.py+++ b/sf.py@@ -344,7 +344,7 @@ if __name__ == '__main__':# Start running a new scanscanName = target- scanId = sf.genScanInstanceGUID()+ scanId = sf.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanName, scanId, target, targetType, modlist, cfg))p.daemon = Truediff --git a/sflib.py b/sflib.pyindex 64912380..d15e6cb7 100644--- a/sflib.py+++ b/sflib.py@@ -41,10 +41,9 @@ from datetime import datetimefrom bs4 import BeautifulSoup, SoupStrainerfrom copy import deepcopyimport io-+import urllib3# For hiding the SSL warnings coming from the requests lib-import urllib3urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)@@ -52,16 +51,16 @@ class SpiderFoot:"""SpiderFootAttributes:- dbh: TBD- GUID: TBD- savedSock: TBD- socksProxy: TBD+ dbh (SpiderFootDb): database handle+ scanId (str): scan ID this instance of SpiderFoot is being used in+ socksProxy (str): SOCKS proxy+ opts (dict): configuration options"""- dbh = None- GUID = None- savedsock = socket- socksProxy = None+ _dbh = None+ _scanId = None+ _socksProxy = None+ opts = dict()def __init__(self, options):"""Initialize SpiderFoot object.@@ -83,30 +82,40 @@ class SpiderFoot:res.nameservers = [self.opts['_dnsserver']]dns.resolver.override_system_resolver(res)- def updateSocket(self, socksProxy):- """Update socket.+ @property+ def dbh(self):+ return self._dbh- Bit of a hack to support SOCKS because of the loading order of- modules. sfscan will call this to update the socket reference- to the SOCKS one.+ @property+ def scanId(self):+ return self._scanId- Args:- socksProxy (str): TBD+ @property+ def socksProxy(self):+ return self._socksProxy- Returns:- None+ @dbh.setter+ def dbh(self, dbh):+ """Called usually some time after instantiation+ to set up a database handle and scan ID, used+ for logging events to the database about a scan."""+ self._dbh = dbh- self.socksProxy = socksProxy+ @scanId.setter+ def scanId(self, scanId):+ """Set the scan ID this instance of SpiderFoot is being used in."""+ self._scanId = scanId- def revertSocket(self):- """Revert socket.+ @socksProxy.setter+ def socksProxy(self, socksProxy):+ """SOCKS proxy- Returns:- None+ Bit of a hack to support SOCKS because of the loading order of+ modules. sfscan will call this to update the socket reference+ to the SOCKS one."""-- self.socksProxy = None+ self._socksProxy = socksProxydef refreshTorIdent(self):"""Tell TOR to re-circuit.@@ -361,22 +370,11 @@ class SpiderFoot:return json.dumps(ret)- def setDbh(self, handle):- """Called usually some time after instantiation- to set up a database handle and scan GUID, used- for logging events to the database about a scan.- """- self.dbh = handle-- def setGUID(self, uid):- """Set the GUID this instance of SpiderFoot is being used in."""- self.GUID = uid-- def genScanInstanceGUID(self):+ def genScanInstanceId(self):"""Generate an globally unique ID for this scan.Returns:- str: scan instance unique GUID+ str: scan instance unique ID"""return str(uuid.uuid4()).split("-")[0].upper()@@ -397,7 +395,7 @@ class SpiderFoot:self.error("No database handle. Could not log event to database: %s" % message, True)return False- return self.dbh.scanLogEvent(self.GUID, level, message, component)+ return self.dbh.scanLogEvent(self.scanId, level, message, component)def error(self, message, exception=True):"""Print an error message and optionally also raise an exception.diff --git a/sfscan.py b/sfscan.pyindex 327c209a..b8274ff0 100644--- a/sfscan.py+++ b/sfscan.py@@ -101,7 +101,7 @@ class SpiderFootScanner():self.__moduleList = moduleListself.__sf = SpiderFoot(self.__config)- self.__sf.setDbh(self.__dbh)+ self.__sf.dbh = self.__dbh# Create a unique ID for this scan in the back-end DB.if not isinstance(scanId, str):@@ -110,9 +110,9 @@ class SpiderFootScanner():if scanId:self.__scanId = scanIdelse:- self.__scanId = self.__sf.genScanInstanceGUID()+ self.__scanId = self.__sf.genScanInstanceId()- self.__sf.setGUID(self.__scanId)+ self.__sf.scanId = self.__scanIdself.__dbh.scanInstanceCreate(self.__scanId, self.__scanName, self.__targetValue)# Create our target@@ -155,9 +155,9 @@ class SpiderFootScanner():self.__sf.debug(f"SOCKS: {socksAddr}:{socksPort} ({socksUsername}:{socksPassword})")- self.__sf.updateSocket(proxy)+ self.__sf.socksProxy = proxyelse:- self.__sf.revertSocket()+ self.__sf.socksProxy = None# Override the default DNS serverif self.__config['_dnsserver']:diff --git a/sfwebui.py b/sfwebui.pyindex b006038f..47e20858 100644--- a/sfwebui.py+++ b/sfwebui.py@@ -450,7 +450,7 @@ class SpiderFootWebUi:scantarget = scantarget.lower()# Start running a new scan- scanId = sf.genScanInstanceGUID()+ scanId = sf.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))p.daemon = True@@ -501,7 +501,7 @@ class SpiderFootWebUi:return self.error("Invalid target type. Could not recognize it as a human name, IP address, IP subnet, ASN, domain name or host name.")# Start running a new scan- scanId = sf.genScanInstanceGUID()+ scanId = sf.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))p.daemon = True@@ -1075,7 +1075,7 @@ class SpiderFootWebUi:scantarget = scantarget.lower()# Start running a new scan- scanId = sf.genScanInstanceGUID()+ scanId = sf.genScanInstanceId()try:p = mp.Process(target=SpiderFootScanner, args=(scanname, scanId, scantarget, targetType, modlist, cfg))p.daemon = Truediff --git a/test/unit/test_spiderfoot.py b/test/unit/test_spiderfoot.pyindex 3e4194b7..868fdab9 100644--- a/test/unit/test_spiderfoot.py+++ b/test/unit/test_spiderfoot.py@@ -37,7 +37,7 @@ class TestSpiderFoot(unittest.TestCase):test_tlds = "// ===BEGIN ICANN DOMAINS===\n\ncom\nnet\norg\n\n// // ===END ICANN DOMAINS===\n"- def test_init_argument_invalid_options_should_raise(self):+ def test_init_argument_options_of_invalid_type_should_raise_TypeError(self):"""Test __init__(self, options):"""@@ -47,37 +47,37 @@ class TestSpiderFoot(unittest.TestCase):with self.assertRaises(TypeError) as cm:sf = SpiderFoot(invalid_type)- def test_init_no_options(self):+ def test_init_argument_options_with_empty_dict(self):"""Test __init__(self, options):"""sf = SpiderFoot(dict())self.assertIsInstance(sf, SpiderFoot)- def test_init(self):+ def test_init_argument_options_with_default_options(self):"""Test __init__(self, options):"""sf = SpiderFoot(self.default_options)self.assertIsInstance(sf, SpiderFoot)- def test_update_socket(self):- """- Test updateSocket(self, sock)- """+ def test_attribute_dbh(self):sf = SpiderFoot(dict())- sf.updateSocket('new socket')- self.assertEqual('new socket', sf.socksProxy)+ sf.dbh = 'new handle'+ self.assertEqual('new handle', sf.dbh)- def test_revert_socket(self):- """- Test revertSocket(self)- """+ def test_attribute_scanId(self):sf = SpiderFoot(dict())- sf.revertSocket()- self.assertEqual(None, sf.socksProxy)+ sf.scanId = 'new guid'+ self.assertEqual('new guid', sf.scanId)++ def test_attribute_socksProxy(self):+ sf = SpiderFoot(dict())++ sf.socksProxy = 'new socket'+ self.assertEqual('new socket', sf.socksProxy)def test_refresh_tor_ident_should_return_none(self):"""@@ -150,31 +150,13 @@ class TestSpiderFoot(unittest.TestCase):json = sf.buildGraphJson('', '')self.assertIsInstance(json, str)- def test_set_dbh(self):- """- Test setDbh(self, handle)- """- sf = SpiderFoot(dict())-- sf.setDbh('new handle')- self.assertEqual('new handle', sf.dbh)-- def test_set_guid(self):- """- Test setGUID(self, uid)- """- sf = SpiderFoot(dict())-- sf.setGUID('new guid')- self.assertEqual('new guid', sf.GUID)-- def test_gen_scan_instance_guid_should_return_a_string(self):+ def test_genScanInstanceId_should_return_a_string(self):"""- Test genScanInstanceGUID(self)+ Test genScanInstanceId(self)"""sf = SpiderFoot(dict())- scan_instance_id = sf.genScanInstanceGUID()+ scan_instance_id = sf.genScanInstanceId()self.assertIsInstance(scan_instance_id, str)def test_dblog_invalid_dbh_should_raise(self):