Upgrading Simple Shells to Fully Interactive TTYs
Imagine you’re a hacking pro, right? You pull off this cool move, catching a reverse shell with netcat. The netcat messages start showing off, and the “id” command spills secrets like a chatterbox.
But, oh boy, here comes the buzzkill! You’re typing away, a command misbehaves, you freak out, hit “Ctrl-C,” and suddenly, the whole connection goes poof.
Now, these not-so-smart shells have more issues than a cat trying to sneak past a bunch of dogs:
Commands like “su” and “ssh” act like drama queens, demanding a fancy terminal.
STDERR stays hidden, like it’s playing hide and seek.
Using text editors like Vim becomes a slapstick comedy — imagine trying to teach a robot to tango.
Tab completion? It takes a vacation, and it’s not sending a postcard.
Going back in command history with the up arrow? Nope, too old-school.
Job control? It’s like a part-time job — doesn’t work full hours.
And the comedy show goes on…
To keep it simple, catching those shells is okay, but I really prefer working with a fully interactive TTY. It just makes things smoother.
First you need to upgrade your shell using one of those commands :
$ python -c "import pty; pty.spawn('/bin/bash')"
or
$ ruby -e "exec '/bin/bash'"
or
$ perl -e "exec '/bin/bash';"
for me i will use python
Next , Press CTRL + Z
to background process and get back to your host machine
Then , Use stty command to set terminal line settings and foreground back the target terminal:
$ stty raw -echo; fg
Finally, Set the terminal environment to something more appealing (e.g. xterm, xterm-256, etc):
$ export TERM=xterm-256-color
You should now have a stabilized bash shell that can tab complete, clear the screen, and use CTRL + C
!
Here’s another trick in the bag to secure a stable terminal window, you can turn to the socat command-line tool. The only catch is that the target machine might not have this tool ready to roll out of the box. So, you’ll have to take a few extra steps to get it installed.
For more details, check out the reference on
Upgrading Simple Shells to Fully Interactive TTYs
Thanks for reading < 3
Subscribe to my newsletter
Read articles from Abdullah Elmasry directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by