From c43b676086f26edb1ea989b255e0eaf356c8ad5a Mon Sep 17 00:00:00 2001 From: dusoleil Date: Tue, 7 Sep 2021 02:36:54 -0400 Subject: Manually run garbage collection after exec Apparently python won't run garbage collection on stuff owned by the exec context if you define a function in the exec. This can lead to random leaks, but it is most impactful in daemon mode. If the globals dictionary given to exec isn't cleaned up, there will be a random reference to comm that still exists. This holds a reference to the Pipes object which prevents it from getting cleaned up before we try to make a new one. Making a new one needs the fifos to have been cleaned up, so it relies on the fact that the old one was supposed to be cleaned up. The most straightforward and non-intrusive way I could think to fix this was to just manually run the garbage collector after exec. This is able to find the leaked references and clean it all up. Signed-off-by: dusoleil --- tools/sploit/sploit/main.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tools') diff --git a/tools/sploit/sploit/main.py b/tools/sploit/sploit/main.py index f97e04e..77ef49e 100644 --- a/tools/sploit/sploit/main.py +++ b/tools/sploit/sploit/main.py @@ -1,6 +1,7 @@ import argparse import tempfile import traceback +import gc from sploit.comm import * @@ -55,4 +56,6 @@ def runscript(script, comm): pass except: traceback.print_exc() + finally: + gc.collect() print("Script Ended Early!") -- cgit v1.2.3