SpiderFoot automates OSINT for threat intelligence and mapping your attack surface.
Python attacksurfacecticybersecurityfootprintinghackinginformation-gatheringinformation-securityinfosecintelligence-gatheringosintosint-frameworkosint-reconnaissanceosint-toolpentestingpythonreconsecurity-toolsthreat-intelligencethreatintel
Add Module Shutdown Hook (#1390)
TheTechromancerc99cd43a3cdb
diff --git a/sfscan.py b/sfscan.pyindex 4420ad01..0c67007b 100644--- a/sfscan.py+++ b/sfscan.py@@ -423,6 +423,10 @@ class SpiderFootScanner():if threaded and not aborted:self.waitForThreads()+ if not threaded:+ for mod in list(self.__moduleInstances.values()):+ mod.finish()+if aborted:self.__sf.status(f"Scan [{self.__scanId}] aborted.")self.__setStatus("ABORTED", None, time.time() * 1000)@@ -449,6 +453,7 @@ class SpiderFootScanner():# start one thread for each modulefor mod in self.__moduleInstances.values():mod.start()+ modulesFinished = False# watch for newly-generated eventswhile True:@@ -466,7 +471,18 @@ class SpiderFootScanner():sleep(.1)# but are we really?if self.threadsFinished(log_status):- break+ if modulesFinished:+ break+ # Trigger module.finished()+ for mod in self.__moduleInstances.values():+ mod.incomingEventQueue.put('FINISHED')+ sleep(.1)+ while not self.threadsFinished(log_status):+ log_status = counter % 100 == 0+ counter += 1+ sleep(.01)+ modulesFinished = True+else:# save on CPUsleep(.01)diff --git a/spiderfoot/plugin.py b/spiderfoot/plugin.pyindex dcb8d81f..a4c95f79 100644--- a/spiderfoot/plugin.py+++ b/spiderfoot/plugin.py@@ -366,6 +366,13 @@ class SpiderFootPlugin():self.thread = threading.Thread(target=self.threadWorker)self.thread.start()+ def finish(self):+ """Perform final/cleanup functions before module exits+ Overridden by the implementer+ """++ return+def threadWorker(self):try:# create new database handle since we're in our own thread@@ -380,9 +387,13 @@ class SpiderFootPlugin():while not self.checkForStop():try:sfEvent = self.incomingEventQueue.get_nowait()- self.sf.debug(f"{self.__name__}.threadWorker() got event, {sfEvent.eventType}, from incomingEventQueue.")self.running = True- self.handleEvent(sfEvent)+ if sfEvent == 'FINISHED':+ self.sf.debug(f"{self.__name__}.threadWorker() got \"FINISHED\" from incomingEventQueue.")+ self.finish()+ else:+ self.sf.debug(f"{self.__name__}.threadWorker() got event, {sfEvent.eventType}, from incomingEventQueue.")+ self.handleEvent(sfEvent)self.running = Falseexcept queue.Empty:sleep(.3)