Stabilizing Netcat Shell

Binamra Pandey
2 min readAug 22, 2022

The Basic Netcat shell has some limitations like we cannot use “Up arrow/Down arrow” to scroll through previous commands, cannot use the “clear” command nor can we use keyboard shortcuts.
So we need to stabilize these shells using various techniques. One of the techniques which require “python” is shown below.

First, you need to type the following python command

python -c ‘import pty;pty.spawn(“/bin/bash”)’

But sometimes if you get an error, you need to use “python3” instead of “python”

Now we need to export xterm. This helps to run command like “clear”. We can do that by the following command

export TERM=xterm

Now the final step is to be able to use keyboard shortcuts in the Nectcat terminal. We can do this by giving access of shortcuts. Follow these steps to give access of shortcuts.

Background the Netcat shell using CTRL+Z
Back in your own terminal type “stty raw -echo; fg

Now you have a fully stable Netcat shell.

Note: After you exit your Netcat shell, you need to fix your terminal cause any input in your own terminal will not be visible(as a result of having a disabled terminal echo). You can fix this by the following command.

Type “reset” in your own terminal when you exit Netcat

So to Summarize

1. python -c ‘import pty;pty.spawn(“/bin/bash”)’ [Use python3 if you encounter any errors]
2. export TERM=xterm
3. Background the Netcat shell using CTRL+Z
4. Back in your own terminal type stty raw -echo; fg
5. type reset when you exit from Netcat shell

Thank You!!!
Follow me on Twitter:- @BinamraPandey

--

--