From f013d802088ede38389705c8b8591e8b26de221e Mon Sep 17 00:00:00 2001 From: Malfurious Date: Thu, 10 Mar 2022 04:47:04 -0500 Subject: sploit: Add function Comm.readall_nonblock() Function should consume all available incoming data from target and return it, however will return 'immediately' (according to a configurable timeout) if the pipe is empty. Signed-off-by: Malfurious Signed-off-by: dusoleil --- tools/sploit/sploit/comm.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/sploit/sploit/comm.py b/tools/sploit/sploit/comm.py index 604045c..4b1d487 100644 --- a/tools/sploit/sploit/comm.py +++ b/tools/sploit/sploit/comm.py @@ -11,6 +11,7 @@ class Comm: logonread = True logonwrite = False flushonwrite = True + timeout = 0.25 # seconds def __init__(self, backend): self.back = backend @@ -42,6 +43,16 @@ class Comm: pass return data + def readall_nonblock(self): + try: + os.set_blocking(self.back.stdin.fileno(), False) + poll = select.poll() + poll.register(self.back.stdin, select.POLLIN) + poll.poll(self.timeout) + return self.readall() + finally: + os.set_blocking(self.back.stdin.fileno(), True) + def readuntil(self, pred, /, *args, **kwargs): data = b'' pred = bind(pred, *args, **kwargs) -- cgit v1.2.3