top of page
aldern00b

Upgrading a Reverse Shell with Python

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.

6 views0 comments

Recent Posts

See All

Comments


bottom of page