summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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