From 5c6a5aba81037ca276d2cf6fae53d2e9647524c4 Mon Sep 17 00:00:00 2001 From: dusoleil Date: Wed, 1 Sep 2021 00:12:30 -0400 Subject: Better Shutdown Process for Pipes Handle all of the edge cases when shutting down in Pipes mode. e.g. If the pipes are broken (tried to write after the program died) If the fifos don't exist anymore (sometimes tempfile cleans them up before the destructor finishes when certain errors happen) If the object attributes for the streams and fifo paths aren't set (this can happen if the constructor didn't finish. e.g. the user cancels while waiting on a connection) Signed-off-by: dusoleil --- sploit/comm.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/sploit/comm.py b/sploit/comm.py index d3b1395..040ddd6 100644 --- a/sploit/comm.py +++ b/sploit/comm.py @@ -132,8 +132,11 @@ class Pipes: print("Connected!") def __del__(self): - self.stdout.close() - self.stdin.close() - os.unlink(self.pathin) - os.unlink(self.pathout) + try: + if getattr(self,'stdout',None) : self.stdout.close() + if getattr(self,'stdin',None) : self.stdin.close() + except BrokenPipeError: + pass + if getattr(self,'pathin',None) and os.path.exists(self.pathin) : os.unlink(self.pathin) + if getattr(self,'pathout',None) and os.path.exists(self.pathout) : os.unlink(self.pathout) -- cgit v1.2.3