fixed rev_shell deadlock when shell instantly closes

This commit is contained in:
Roman Hergenreder 2023-12-13 00:49:06 +01:00
parent 67045c6ba0
commit 2d708619b8
2 changed files with 8 additions and 4 deletions

@ -98,6 +98,7 @@ class ShellListener:
print("[-] Disconnected") print("[-] Disconnected")
self.connection = None self.connection = None
self.running = False
def close(self): def close(self):
self.running = False self.running = False
@ -432,7 +433,7 @@ def wait_for_connection(listener, timeout=None, prompt=True):
else: else:
print(prompt) print(prompt)
while listener.connection is None: while listener.connection is None and listener.running:
time.sleep(0.5) time.sleep(0.5)
if timeout is not None: if timeout is not None:
diff = time.time() - start diff = time.time() - start

@ -321,7 +321,7 @@ def pad(x, n, b=b"\x00", s="r"):
x = (n-(len(x)%n))*b + x x = (n-(len(x)%n))*b + x
return x return x
def xor(a, b): def xor(a, b, *args):
if isinstance(a, int): if isinstance(a, int):
a = a.to_bytes(math.ceil(math.log(a)/math.log(2)/8.0)) a = a.to_bytes(math.ceil(math.log(a)/math.log(2)/8.0))
if isinstance(b, int): if isinstance(b, int):
@ -345,9 +345,12 @@ def xor(a, b):
if type(b) not in (bytes, bytearray): if type(b) not in (bytes, bytearray):
b = b.encode() b = b.encode()
result = b"".join([bytes([c1 ^ c2]) for (c1,c2) in zip(a, b) ])
return b"".join([bytes([c1 ^ c2]) for (c1,c2) in zip(a, b) ]) if len(args) > 0:
result = xor(result, *args)
return result
def base64urldecode(data): def base64urldecode(data):
if isinstance(data, str): if isinstance(data, str):