From e62f89acb4f8e07c758a0d7e31f96a41776f95c6 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 --- sploit/main.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/sploit/main.py b/sploit/main.py index 6c96104..bd01993 100644 --- a/sploit/main.py +++ b/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