summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordusoleil <howcansocksbereal@gmail.com>2021-08-31 19:35:35 -0400
committerdusoleil <howcansocksbereal@gmail.com>2021-08-31 19:35:35 -0400
commit3c2e0b235b5df6004abb1c583316a370835c5570 (patch)
tree4e8ab391b9ee966a4a6221b7e6ad2d5f0fee619f
parent72b8043524620f1bb48259002d777b28680c9008 (diff)
downloadsploit-3c2e0b235b5df6004abb1c583316a370835c5570.tar.gz
sploit-3c2e0b235b5df6004abb1c583316a370835c5570.zip
Add Interactive Mode to Comms
comm.interact() will drop the user into an "interactive" mode where they can directly control what is sent. A SIGINT (Ctrl+C) will drop the script out of interactive mode and continue executing the rest of the script. If the output of the program (input into our script) goes into a broken state (such as when the target program exits), interactive mode will automatically exit. Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r--sploit/comm.py50
1 files changed, 49 insertions, 1 deletions
diff --git a/sploit/comm.py b/sploit/comm.py
index 9b68c38..0b5bc2a 100644
--- a/sploit/comm.py
+++ b/sploit/comm.py
@@ -1,6 +1,10 @@
import subprocess
+import threading
import tempfile
import os
+import sys
+import select
+import signal
from sploit.log import log
@@ -43,13 +47,57 @@ class Comm:
def writeline(self, data):
self.write(data + b'\n')
+ def interact(self):
+ print("Interact Mode")
+ syncstop = threading.Event()
+ def readloop():
+ poll = select.poll()
+ poll.register(self.back.stdin)
+ def readall():
+ while(True):
+ data = self.back.stdin.readline()
+ if(data == b''):
+ break
+ log(data)
+ while not syncstop.isSet():
+ readall()
+ dat = poll.poll(100)
+ if(len(dat)>0):
+ if(dat[0][1] & select.POLLIN):
+ readall()
+ else:
+ syncstop.set()
+ os.set_blocking(self.back.stdin.fileno(),False)
+ readthread = threading.Thread(target=readloop,daemon=True)
+ readthread.start()
+ stdin = sys.stdin.buffer
+ signal.signal(signal.SIGALRM,lambda: 0)
+ while not syncstop.isSet():
+ try:
+ signal.alarm(1)
+ data = stdin.readline()
+ if(data and not syncstop.isSet()):
+ self.write(data)
+ else:
+ break
+ except TypeError:
+ pass
+ except KeyboardInterrupt:
+ break
+ signal.alarm(0)
+ syncstop.set()
+ readthread.join()
+ os.set_blocking(self.back.stdin.fileno(),True)
+ print("Interact Mode Done")
+
class Process:
def __init__(self, args):
print(f"Running: {' '.join(args)}")
self.proc = subprocess.Popen(args,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT)
+ stderr=subprocess.STDOUT,
+ preexec_fn=lambda : os.setpgrp())
print(f"PID: {self.proc.pid}")
self.stdin = self.proc.stdout
self.stdout = self.proc.stdin