mirror of
https://github.com/calebstewart/pwncat.git
synced 2024-11-30 12:24:14 +01:00
Even better file close handling
For linux, we used to send one or two EOFs via C-d to the process to signal exit, however this was inconsistent. Depending on the previous input from the attacker, sometimes one was needed, sometimes two. Sometimes, we even observed more than two being needed. Instead, we now simply loop sending one at a time and checking for the end delimeter. This will be slightly slower, but avoids hangups or accidentally closing the shell.
This commit is contained in:
parent
6cc30a6ab5
commit
3861310d71
@ -458,19 +458,21 @@ class LinuxWriter(BufferedIOBase):
|
||||
self.detach()
|
||||
return
|
||||
|
||||
# Indicate EOF
|
||||
self.popen.stdin.write(b"\x04")
|
||||
if self.since_newline != 0:
|
||||
self.popen.stdin.write(b"\x04")
|
||||
|
||||
# The number of C-d's needed to trigger an EOF in
|
||||
# the process and exit is inconsistent based on the
|
||||
# previous input. So, instead of trying to be deterministic,
|
||||
# we simply send one and check. We do this until we find
|
||||
# the ending delimeter and then exit. If the `on_close`
|
||||
# hook was setup properly, this should be fine.
|
||||
while True:
|
||||
try:
|
||||
self.popen.stdin.write(b"\x04")
|
||||
self.popen.stdin.flush()
|
||||
# Check for completion
|
||||
self.popen.wait(timeout=100)
|
||||
self.popen.wait(timeout=0.1)
|
||||
break
|
||||
except pwncat.subprocess.TimeoutExpired:
|
||||
# Nope, force terminate with C-c
|
||||
# self.popen.terminate()
|
||||
# Cleanup
|
||||
self.popen.wait()
|
||||
continue
|
||||
|
||||
# Ensure we don't touch stdio again
|
||||
self.detach()
|
||||
|
@ -5,6 +5,7 @@ import base64
|
||||
import subprocess
|
||||
|
||||
import pytest
|
||||
|
||||
from pwncat.util import random_string
|
||||
from pwncat.platform.windows import PowershellError
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user