From 93c6adcbc97f6cdd9b45b78b95279abb82e8a05c Mon Sep 17 00:00:00 2001
From: Malfurious <m@lfurio.us>
Date: Wed, 23 Mar 2022 07:09:11 -0400
Subject: sploit: Allow multiple reads in Comm.readall_nonblock()

Due to line buffering, we may often trigger a burst of data to be sent
by the target, but resolve the non-blocking read only after the first
line is received.  We would like to wait just a little longer to receive
the entire burst instead.

readall_nonblock() will now reset its timeout period whenever any data
becomes readable and will not return until we go an entire period of
silence.  Under normal conditions, the full duration of readall_nonblock
should barely be any longer than the defined period itself.

Signed-off-by: Malfurious <m@lfurio.us>
Signed-off-by: dusoleil <howcansocksbereal@gmail.com>
---
 tools/sploit/sploit/comm.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

(limited to 'tools/sploit')

diff --git a/tools/sploit/sploit/comm.py b/tools/sploit/sploit/comm.py
index b373762..67c97bc 100644
--- a/tools/sploit/sploit/comm.py
+++ b/tools/sploit/sploit/comm.py
@@ -46,11 +46,15 @@ class Comm:
 
     def readall_nonblock(self):
         try:
+            data = b''
             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()
+            while True:
+                poll.poll(self.timeout)
+                d = self.readall()
+                if len(d) == 0: return data
+                data += d
         finally:
             os.set_blocking(self.back.stdin.fileno(), True)
 
-- 
cgit v1.2.3