From 75ad247712497c452d55a26dae1d6017270fbfc1 Mon Sep 17 00:00:00 2001 From: pitust <41321673+pitust@users.noreply.github.com> Date: Mon, 14 Sep 2020 00:11:34 +0100 Subject: [PATCH 1/5] Added a better prompt --- pwncat/remote/victim.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/pwncat/remote/victim.py b/pwncat/remote/victim.py index 79ebf30..473100c 100644 --- a/pwncat/remote/victim.py +++ b/pwncat/remote/victim.py @@ -113,11 +113,9 @@ class Victim: # Saved remote terminal state (for transition to/from raw mode) self.saved_term_state = None # util.enter_raw_mode() # util.restore_terminal(self.saved_term_state, new_line=False) - # Prompt and prompt prefix - self.remote_prefix = "\\[\\033[01;31m\\](remote)\\[\\033[00m\\]" + # Prompt self.remote_prompt = ( - "\\[\\033[01;33m\\]\\u@\\h\\[\\033[00m\\]:\\[" - "\\033[01;36m\\]\\w\\[\\033[00m\\]\\$ " + """$(command printf "\033[01;31m(remote)\033[0m \033[01;33m$(whoami)@$(hostname)\033[0m:\033[1;36m$PWD\033[0m$ ")""" ) # Aliases for equivalent commands self.binary_aliases = { @@ -368,12 +366,6 @@ class Victim: progress.update(task_id, status="prompt") - if self.shell == "/bin/sh": - progress.log( - f"[yellow]warning[/yellow]: /bin/sh does not support colored prompts." - ) - self.remote_prefix = "(remote)" - self.remote_prompt = f"{pwncat.victim.host.ip}:$PWD\\$ " self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'") @@ -416,7 +408,7 @@ class Victim: # This stuff won't carry through to the PTY, so we need to reset it again. self.run("unset PROMPT_COMMAND") - self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'") + self.run(f"export PS1='{self.remote_prompt}'") # Make sure HISTFILE is unset in this PTY (it resets when a pty is # opened) @@ -1839,7 +1831,7 @@ class Victim: self.has_cr = True self.has_echo = True self.run("echo") - self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'") + self.run(f"export PS1='{self.remote_prompt}'") def flush_output(self, some=False): """ @@ -1909,7 +1901,7 @@ class Victim: self.run("unset HISTFILE; export HISTCONTROL=ignorespace") self.run("unset PROMPT_COMMAND") self.run("unalias -a") - self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'") + self.run(f"export PS1='{self.remote_prompt}'") self.run(f"tput rmam") def recvuntil(self, needle: bytes, interp=False, timeout=None): From 13b690867d4fef388fcae81177e199225f4f7150 Mon Sep 17 00:00:00 2001 From: pitust <41321673+pitust@users.noreply.github.com> Date: Mon, 14 Sep 2020 00:14:07 +0100 Subject: [PATCH 2/5] Fixed prompt.py --- pwncat/commands/prompt.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/pwncat/commands/prompt.py b/pwncat/commands/prompt.py index 210d955..c404048 100644 --- a/pwncat/commands/prompt.py +++ b/pwncat/commands/prompt.py @@ -20,7 +20,7 @@ class Command(CommandDefinition): Complete.NONE, group="mutex", action="store_true", - help="Set a basic prompt with no color or automatic system information", + help="Set a basic prompt with no color or automatic system information. There _should_ be no reason to use that anymore (unless your local terminal has no ANSI support)", ), "--fancy,-f": Parameter( Complete.NONE, @@ -33,13 +33,8 @@ class Command(CommandDefinition): def run(self, args): if args.fancy: - pwncat.victim.remote_prefix = "\\[\\033[01;31m\\](remote)\\[\\033[00m\\]" - pwncat.victim.remote_prompt = ( - "\\[\\033[01;33m\\]\\u@\\h\\[\\033[00m\\]:\\[" - "\\033[01;36m\\]\\w\\[\\033[00m\\]\\$ " - ) + pwncat.victim.remote_prompt = """$(command printf "\033[01;31m(remote)\033[0m \033[01;33m$(whoami)@$(hostname)\033[0m:\033[1;36m$PWD\033[0m$ ")""" else: - pwncat.victim.remote_prefix = "(remote)" - pwncat.victim.remote_prompt = f"{pwncat.victim.host.ip}:$PWD\\$ " + pwncat.victim.remote_prompt = f"(remote) {pwncat.victim.host.ip}:$PWD\\$ " pwncat.victim.reset(hard=False) From be5f33e415b61ea1a0948c99415ca51c41bd3251 Mon Sep 17 00:00:00 2001 From: pitust <41321673+pitust@users.noreply.github.com> Date: Mon, 14 Sep 2020 00:15:01 +0100 Subject: [PATCH 3/5] Update README.md to reflect prompt changes --- README.md | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/README.md b/README.md index 31cf7e2..b2494c5 100644 --- a/README.md +++ b/README.md @@ -145,32 +145,6 @@ slipped through the cracks and been observed in the wild. When this happens, `pw will do whatever it can to preserve your terminal, but you may be greeted with some peculiar output or command failures. -### Dash Support - -The Debian shell `dash` aims to be a very minimalistic shell. It's focus is not on user -interface, but on running scripts quickly and correctly. As a result, some of the features -we expect from an interactive shell simply don't work in `dash`. `pwncat` tries not to -depend on a specific shell environment, so if you start your reverse or bind shell with -`/bin/sh` or `/bin/dash`, then you may get a weird prompt. `dash` does not obey the -terminal escape sequences which `pwncat` adds, so you may get a very long terminal like this: - -```shell script -\[\033[01;31m\](remote)\[\033[00m\] \[\033[01;33m\]\u@\h\[\033[00m\]:\[\033[01;36m\]\w\[\033[00m\]$ -``` - -Currently, the only workaround is to use the `prompt` command at the local `pwncat` prompt. -The command allows you to modify the prompt which `pwncat` will automatically set whenever -resetting the remote terminal. Two options are provided: "basic" and "fancy". The "fancy" -prompt is the default which causes the above output in Dash. To switch to the basic prompt -you can use the following command at the `pwncat` prompt: - -```shell script -prompt --basic -``` - -While this is inconvenient, it does not affect the behaviour of `pwncat`. All `pwncat` -features will continue to function properly no matter what your prompt looks like. - ### BSD Support While BSD is a Unix-based kernel, in practice it's userland tools are noticeably From 599b4133b6aa454445a4b862483881d3554173db Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Sun, 13 Sep 2020 21:26:39 -0400 Subject: [PATCH 4/5] Removed reference to remote_prefix and fixed escaping in prompt --- pwncat/remote/victim.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pwncat/remote/victim.py b/pwncat/remote/victim.py index 473100c..f30650a 100644 --- a/pwncat/remote/victim.py +++ b/pwncat/remote/victim.py @@ -114,9 +114,7 @@ class Victim: self.saved_term_state = None # util.enter_raw_mode() # util.restore_terminal(self.saved_term_state, new_line=False) # Prompt - self.remote_prompt = ( - """$(command printf "\033[01;31m(remote)\033[0m \033[01;33m$(whoami)@$(hostname)\033[0m:\033[1;36m$PWD\033[0m$ ")""" - ) + self.remote_prompt = """$(command printf "\\033[01;31m(remote)\\033[0m \\033[01;33m$(whoami)@$(hostname)\\033[0m:\\033[1;36m$PWD\\033[0m$ ")""" # Aliases for equivalent commands self.binary_aliases = { "python": [ @@ -366,8 +364,7 @@ class Victim: progress.update(task_id, status="prompt") - - self.run(f"export PS1='{self.remote_prefix} {self.remote_prompt}'") + self.run(f"export PS1='{self.remote_prompt}'") # This should be valid in any POSIX compliant shell progress.update(task_id, status="checking for pty") From 98706fb40e8c8ea4a0cd176c1a26599da38a4ec8 Mon Sep 17 00:00:00 2001 From: Caleb Stewart Date: Sun, 13 Sep 2020 21:28:31 -0400 Subject: [PATCH 5/5] Added escaping for the prompt command --- pwncat/commands/prompt.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pwncat/commands/prompt.py b/pwncat/commands/prompt.py index c404048..8da6d19 100644 --- a/pwncat/commands/prompt.py +++ b/pwncat/commands/prompt.py @@ -33,7 +33,7 @@ class Command(CommandDefinition): def run(self, args): if args.fancy: - pwncat.victim.remote_prompt = """$(command printf "\033[01;31m(remote)\033[0m \033[01;33m$(whoami)@$(hostname)\033[0m:\033[1;36m$PWD\033[0m$ ")""" + pwncat.victim.remote_prompt = """$(command printf "\\033[01;31m(remote)\\033[0m \\033[01;33m$(whoami)@$(hostname)\\033[0m:\\033[1;36m$PWD\\033[0m$ ")""" else: pwncat.victim.remote_prompt = f"(remote) {pwncat.victim.host.ip}:$PWD\\$ "