top of page

Upgrading a Reverse Shell with Python

aldern00b

The first technique we'll be discussing is applicable only to Linux boxes, as they will nearly always have Python installed by default. This is a three stage process:


The first thing to do is use


python -c 'import pty;pty.spawn("/bin/bash")'

which uses Python to spawn a better featured bash shell; note that some targets may need the version of Python specified. If this is the case, replace python with python2 or python3 as required.


Step two is:


export TERM=xterm

this will give us access to term commands such as clear.


Finally (and most importantly) we will background the shell using Ctrl + Z on our keyboard, which will bring us back to our own terminal, pushing our remote terminal into the background.


Back in our own terminal we use


stty raw -echo; fg

This does two things: first, it turns off our own terminal echo (which gives us access to tab autocompletes, the arrow keys, and Ctrl + C to kill processes). It then foregrounds the reverse shell we had, completing the process.


Note that if the shell dies, any input in your own terminal will not be visible (as a result of having disabled terminal echo). To fix this, type reset and press enter.

Recent Posts

See All

Privilege Escalation with SUID

There's two things you'll need. Once you're connected to the box you'll need to know all the SUID capable binaries' available. To do...

Comments


AlderN00b

I.T. Admin    |    Hacking    |    Learning

©2022 by AlderN00b. Proudly created with Wix.com

bottom of page