1
0
mirror of https://github.com/calebstewart/pwncat.git synced 2024-11-23 17:15:38 +01:00

Added ability to detect a pty

This stops pwncat from attempting to spawn a pty when one is already
running on the shell.
This commit is contained in:
Caleb Stewart 2020-09-13 14:30:38 -04:00
parent 57809be2ee
commit e6c86e614a

View File

@ -377,33 +377,40 @@ class Victim:
self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'") self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'")
progress.update(task_id, status="spawning pty", advance=1) # This should be valid in any POSIX compliant shell
progress.update(task_id, status="checking for pty")
result = self.run("[ -t 1 ] && echo terminal")
# At this point, the system is functioning, but we don't have a raw terminal/ if b"terminal" not in result:
# pseudoterminal. Here, we attempt a couple methods of gaining a PTY. progress.update(task_id, status="spawning pty", advance=1)
method = None
method_cmd = None
if self.which("python") is not None: # At this point, the system is functioning, but we don't have a raw terminal/
method_cmd = Victim.OPEN_METHODS["python"].format( # pseudoterminal. Here, we attempt a couple methods of gaining a PTY.
self.which("python"), self.shell method = None
) method_cmd = None
method = "python"
elif self.which("script") is not None: if self.which("python") is not None:
result = self.run("script --version") method_cmd = Victim.OPEN_METHODS["python"].format(
if b"linux" in result: self.which("python"), self.shell
method_cmd = f"exec script -qc {self.shell} /dev/null" )
method = "script (util-linux)" method = "python"
elif self.which("script") is not None:
result = self.run("script --version")
if b"linux" in result:
method_cmd = f"exec script -qc {self.shell} /dev/null"
method = "script (util-linux)"
else:
method_cmd = f"exec script -q /dev/null {self.shell}"
method = "script (probably bsd)"
method = "script"
else: else:
method_cmd = f"exec script -q /dev/null {self.shell}" progress.log("[red]error[/red]: no available pty methods!")
method = "script (probably bsd)"
method = "script"
else:
progress.log("[red]error[/red]: no available pty methods!")
# Open the PTY # Open the PTY
if not isinstance(self.client, paramiko.Channel) and method is not None: if not isinstance(self.client, paramiko.Channel) and method is not None:
self.run(method_cmd, wait=False) self.run(method_cmd, wait=False)
else:
progress.update(task_id, status="pty already running", advance=1)
progress.update(task_id, status="synchronizing prompt", advance=1) progress.update(task_id, status="synchronizing prompt", advance=1)