Upgrading shell
Netcat is a great tool, but it also has its shortcoming -
Hitting “Ctrl-C”, for instance, drops the entire shell instead of canceling the current command as on a regular terminal shell;
You cannot run interactive commands like su to log into other local accounts or SSH to connect to other hosts;
Text editors like Vim and Nano cannot be used properly to edit files (only non-interactively);
Features like job control, tab complete and command history with the up-arrow are also missing.
To overcome some of these problems we need to switch to an interactive TTY (i.e. terminal) shell.
Different PTY modules
Python pty module
Perl
Using socat
On Kali (listen):
On Victim (launch):
If not download in Victim:
Other ways
Related Shell Escape Sequences
Vi / Vim
awk
find
Netcat Magic
1.First spawn a PTY shell with python or with bash ,
2. Background the process with Ctrl-z
3. Examine the current terminal and STTY info so we can force the connected shell to match it:
The information needed is the size of the current TTY (“Example: rows 38; columns 116”)
4. With the shell still backgrounded, now set the current STTY to type raw and tell it to echo the input characters with the following command:
With a raw stty, input/output will look weird and you won’t see the next commands, but as you type they are being processed.
5. Next foreground the shell with fg
. It will re-open the reverse shell but formatting will be off. Finally, reinitialize the terminal with enter button
6. After the reset
the shell should look normal again. The last step is to set the shell, terminal type and stty size to match our current Kali window (from the info gathered above)
The end result is a fully interactive TTY with all the features we’d expect (tab-complete, history, job control, etc) all over a netcat connection :)
Obtaining a full interactive shell with zsh
Current kali terminal come with zsh shell so it's important to learn this method as above will not work with zsh shell
1.Get tty shell with above commands and then background the process with ctrl+z
2. Get the number of rows and columns with
3. To ignore hotkeys in the local shell and return to your reverse shell, enter
4. Configure your rows and columns
5. Export term
6. All you need to do now, is reload your shell:
Last updated