From 6943f13dc906bdf411bcddebcaf243006addaceb Mon Sep 17 00:00:00 2001 From: dusoleil Date: Wed, 1 Sep 2021 00:25:47 -0400 Subject: Handle Exceptions in Daemon Mode If the user presses Ctrl+C while waiting on a connection, we want to gracefully exit. If the user presses Ctrl+C during the script, we want to stop executing the script and restart the loop. If any other exception happens during the script, we want to print out the stacktrace as normal, but continue the loop. Signed-off-by: dusoleil --- tools/sploit/sploit/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tools/sploit/sploit/main.py b/tools/sploit/sploit/main.py index 6c96104..bd01993 100644 --- a/tools/sploit/sploit/main.py +++ b/tools/sploit/sploit/main.py @@ -1,5 +1,6 @@ import argparse import tempfile +import traceback from sploit.comm import * @@ -30,7 +31,17 @@ def daemon(script): print("Running in Pipe Daemon Mode...") with tempfile.TemporaryDirectory() as tmpdir: while(True): - runscript(script,Comm(Pipes(tmpdir))); + try: + p = Pipes(tmpdir) + except KeyboardInterrupt: + break + try: + runscript(script,Comm(p)); + except KeyboardInterrupt: + pass + except: + traceback.print_exc() + del p def pipe(script): print("Running in Pipe Mode..."); -- cgit v1.2.3