diff options
author | Malfurious <m@lfurio.us> | 2022-03-10 04:47:04 -0500 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2022-03-14 00:14:53 -0400 |
commit | 71b03b656540fbc135f2fc78b3c1104b7b05ee5a (patch) | |
tree | 0cc8fd6e2f7e4748d78d20b4ecaa52c9cc1097dc | |
parent | 9b0fafda616205b0fbc7cd5a6ee3259afd3b0e34 (diff) | |
download | sploit-71b03b656540fbc135f2fc78b3c1104b7b05ee5a.tar.gz sploit-71b03b656540fbc135f2fc78b3c1104b7b05ee5a.zip |
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 <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
-rw-r--r-- | sploit/comm.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/sploit/comm.py b/sploit/comm.py index 604045c..4b1d487 100644 --- a/sploit/comm.py +++ b/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) |