You catch a reverse shell but it's unstable. How do you upgrade it?
Short answer
Spawn a pseudo-terminal (commonly python -c 'import pty; pty.spawn("/bin/bash")'), background it with Ctrl-Z, run stty raw -echo on your local side, foreground it, and reset TERM and the rows/columns. That gives you a full TTY with job control, tab completion, and working editors.
A raw reverse shell from nc is a "dumb" shell: no job control, no tab completion, no arrow keys, and Ctrl-C kills the entire session instead of the running command. Tools like su, ssh, sudo, and text editors refuse to run because there is no real terminal attached. Upgrading to a proper TTY is almost mandatory before privilege escalation.
The standard upgrade
The most common sequence:
- Spawn a PTY on the target:
python3 -c 'import pty; pty.spawn("/bin/bash")'. This allocates a pseudo-terminal so programs believe they have a real terminal. - Background the shell with
Ctrl-Z. - Fix your local terminal:
stty raw -echo; fg. Raw mode passes keystrokes straight through (so Ctrl-C goes to the remote process, not your nc), and disabling echo stops doubled characters. - Restore environment:
export TERM=xtermand set the window size withstty rows <r> cols <c>so editors render correctly.
After this you get tab completion, command history, Ctrl-C that interrupts only the foreground job, and full-screen tools.
When python is missing
Fall back to script -qc /bin/bash /dev/null, or use socat for a fully interactive PTY in one step if you can get the binary onto the host. expect and certain language runtimes (perl, ruby) can also spawn a PTY.
Why it matters
Without a TTY you cannot su to another user, run sudo, or use the interactive privilege-escalation tools that win boxes. The upgrade is the bridge between "I have code execution" and "I can actually work."
What interviewers look for
They want the actual incantation — pty.spawn, Ctrl-Z, stty raw -echo, fg, and fixing TERM — plus the reason each step exists, and a fallback for when python is absent.
Likely follow-ups
- Why does Ctrl-C kill your whole shell before you upgrade it?
- What do you do if python isn't installed on the target?