smbghost(CVE-2020-0796)漏洞POC汇总及简单分析
字数 2815 2025-08-25 22:58:20
SMBGhost (CVE-2020-0796) 漏洞分析与利用指南
0x00 漏洞概述
SMBGhost (CVE-2020-0796) 是 Microsoft Server Message Block 3.1.1 (SMBv3) 协议中的一个远程代码执行漏洞。该漏洞于2020年3月10日由微软披露,并于3月12日发布补丁。
漏洞特性:
- 影响SMBv3.1.1协议处理特定请求的方式
- 可在目标SMB服务器或客户端上执行任意代码
- 服务器利用:攻击者发送特制数据包到目标SMBv3服务器
- 客户端利用:攻击者配置恶意SMBv3服务器并诱使用户连接
0x01 影响范围
受影响系统:
- Windows 10 Version 1903 (32/64/ARM64)
- Windows 10 Version 1909 (32/64/ARM64)
- Windows Server, Version 1903 (Server Core安装)
- Windows Server, Version 1909 (Server Core安装)
注意:仅影响SMB v3.1.1协议,特别是1903和1909版本。
0x02 漏洞检测方法
Python检测脚本
- 基础检测脚本:
- GitHub项目:https://github.com/ollypwn/SMBGhost
- 通过协商请求检查SMB方言3.1.1和压缩能力
- 发送特定数据包并检查响应特征
pkt = b'\x00\x00\x00\xc0\xfeSMB@\x00\x00\x00\x00\x00\x00\x00\x00\x00\x1f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00$\x00\x08\x00\x01\x00\x00\x00\x7f\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00x\x00\x00\x00\x02\x00\x00\x00\x02\x02\x10\x02"\x02$\x02\x00\x03\x02\x03\x10\x03\x11\x03\x00\x00\x00\x00\x01\x00&\x00\x00\x00\x00\x00\x01\x00 \x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x03\x00\n\x00\x00\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00'
if res[68:70] != b"\x11\x03" or res[70:72] != b"\x02\x00":
print(f"{ip} Not vulnerable.")
else:
print(f"{ip} Vulnerable")
- 增强版Python检测:
- GitHub项目:https://github.com/ioncodes/SMBGhost
- 需要安装hexdump:
pip3 install hexdump - 更详细的输出和数据结构分析
其他检测工具
-
EXE版本(奇安信):
- 下载地址:http://dl.qianxin.com/skylar6/CVE-2020-0796-Scanner.zip
- 准确性高,不会误报
-
PowerShell版本:
- GitHub项目:https://github.com/T13nn3s/CVE-2020-0796
- 检查Windows版本和补丁状态,不会误报
-
Perl版本:
- GitHub项目:https://github.com/wneessen/SMBCompScan
- 使用Socket发送数据包并分析响应
-
Nmap检测:
- 使用Nmap的smb-protocols脚本检查SMBv3.11
nmap -p445 --script smb-protocols -Pn -n $1 | grep -P '\d+\.\d+\.\d+\.\d+|^\|.\s+3.11'
0x03 漏洞利用
蓝屏POC
-
Python蓝屏POC:
- GitHub项目:https://github.com/eerykitty/CVE-2020-0796-PoC
- 使用方法:
python3 CVE-2020-0796.py <target_ip> -
替代蓝屏POC:
- GitHub项目:https://github.com/maxpl0it/Unauthenticated-CVE-2020-0796-PoC
- 使用方法:
python3 crash.py <target_ip>
本地提权利用(LPE)
2020年3月30日出现的本地提权EXP:
- GitHub项目:https://github.com/danigargu/CVE-2020-0796/
- 利用漏洞将shellcode注入winlogon.exe
- 已编译版本:https://github.com/f1tz/CVE-2020-0796-LPE-EXP
0x04 修复方案
-
安装官方补丁:
- 通过Windows Update检查更新
- 或手动下载安装KB4551762补丁:https://www.catalog.update.microsoft.com/Search.aspx?q=KB4551762
-
禁用SMB压缩:
- 注册表修改:
HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters 新建DWORD值:DisableCompression = 1 - PowerShell命令:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" DisableCompression -Type DWORD -Value 1 -Force
- 注册表修改:
-
网络层防护:
- 封堵445端口
- 使用防火墙规则限制SMB访问
0x05 技术分析
漏洞文件
- 服务端:
srv2.sys(C:\Windows\System32\drivers\srv2.sys) - 客户端:
mrxsmb.sys
漏洞成因
微软在Windows 10 v1903/Server v1903的SMB 3.1.1协议中增加了数据压缩传输支持。漏洞源于SMB客户端及服务端在解压数据(身份认证请求)时,未对COMPRESSION_TRANSFORM_HEADER结构进行充分校验,导致整数溢出。
typedef struct _COMPRESSION_TRANSFORM_HEADER {
ULONG ProtocolId;
ULONG OriginalCompressedSegmentSize;
USHORT CompressionAlgorithm;
USHORT Flags;
ULONG Length;
} COMPRESSION_TRANSFORM_HEADER, *PCOMPRESSION_TRANSFORM_HEADER;
漏洞触发流程
- SMB接收处理函数
Srv2!Srv2ReceiveHandler接收数据包 - 如果ProtocolId是0xFC, 'S', 'M', 'B',表示数据压缩,调用
Srv2DecompressMessageAsync Srv2DecompressMessageAsync调用Srv2DecompressData分配buffer并解压- 攻击者可控制
OriginalCompressedSegmentSize和OffsetOrLength参数 - 整数溢出导致分配较小buffer,后续解压操作导致缓冲区溢出
补丁分析
补丁主要增加了安全检查:
- 使用
RtlUlongAdd检查OriginalCompressedSegmentSize和OffsetOrLength的和 - 使用
RtlULongSub计算偏移量字段和压缩缓冲区大小 - 这些函数会检查整数上溢/下溢情况
0x06 结论
SMBGhost (CVE-2020-0796) 是一个严重的远程代码执行漏洞,与MS17-010和CVE-2019-0708类似,具有蠕虫级传播潜力。建议所有受影响系统立即应用补丁或采取缓解措施。
0x07 参考资料
- 微软安全公告:https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/adv200005
- CVE详情:https://portal.msrc.microsoft.com/en-US/security-guidance/advisory/CVE-2020-0796
- 360分析文章:https://blogs.360.cn/post/CVE-2020-0796.html
- SMB协议规范:https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/5606ad47-5ee0-437a-817e-70c366052962
- Synacktiv技术分析:https://www.synacktiv.com/posts/exploit/im-smbghost-daba-dee-daba-da.html
- McAfee分析:https://www.mcafee.com/blogs/other-blogs/mcafee-labs/smbghost-analysis-of-cve-2020-0796/