devianntsec/CVE-2024-30051-DWMHeapOverflow-Masters-Thesis

GitHub: devianntsec/CVE-2024-30051-DWMHeapOverflow-Masters-Thesis

针对 Windows DWM 堆溢出漏洞(CVE-2024-30051)的完整研究项目,包含改进的 PoC、实证堆喷射分析和详细技术文档,用于学习本地权限提升技术。

Stars: 0 | Forks: 0

# CVE-2024-30051 — Windows DWM 堆溢出权限提升 · 硕士论文研究 [![Platform](https://img.shields.io/badge/Platform-Windows%2011%2022H2-blue)](https://msrc.microsoft.com/update-guide/en-US/advisory/CVE-2024-30051) [![Language](https://img.shields.io/badge/Language-C%2B%2B-informational)](https://github.com/devianntsec) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![Research](https://img.shields.io/badge/Research-Master's%20Thesis-purple)](https://github.com/devianntsec) [![CVSS](https://img.shields.io/badge/CVSS-7.8%20(High)-orange)](https://nvd.nist.gov/vuln/detail/CVE-2024-30051) ## 描述 本代码库包含我关于 **CVE-2024-30051** 的 **硕士论文研究**,这是 Windows Desktop Window Manager 核心库 (`dwmcore.dll`) 中的一个高危 (CVSS 7.8) **权限提升** 漏洞。 该漏洞源于 `CCommandBuffer::Initialize` 中的 **整数除法大小计算错误**。由于此计算错误,用于 `new()` 的大小与用于 `memcpy()` 的大小不一致,从而产生 **0x8F 字节的堆溢出**。成功的漏洞利用会导致 `dwm.exe` 加载攻击者控制的 DLL,在具有 **SYSTEM 完整性级别** 的 `window manager\dwm-1` 账户下执行任意代码。 ### 我的贡献 | 方面 | 描述 | |--------|-------------| | **自动重试循环** | 自动重试最多 10 次,首次成功即退出 | | **会话日志记录** | 每个会话的完整时间戳日志保存至 `%TEMP%\cve_30051_log.txt` | | **实证堆喷射分析** | 两种配置(步长=0x20 vs 步长=0x10)下的 20 个会话 | | **后渗透 Payload** | 自定义 DLL,包含权限横幅、`whoami` 输出和自动清理 | | **学术文档** | 根本原因、漏洞利用链和统计发现 | ## 代码库结构 ``` CVE-2024-30051-Masters-Thesis/ ├── README.md # This file ├── LICENSE # MIT License ├── setup.bat # Helper script — copies s11.dll to required location │ ├── exploit/ # Visual Studio 2022 solution │ ├── C21.sln # Solution file (contains C26f + payload projects) │ │ │ ├── exploit_src/ # Main exploit source (C26f.exe) │ │ ├── c26f.vcxproj # Visual Studio project file │ │ ├── c26f.filters # Project file filters (organizes source files in IDE) │ │ └── main.cpp # Exploit entry point — heap spray + hooking + overflow │ │ │ └── payload/ # Payload DLL source (s11.dll) │ ├── payload.vcxproj # Visual Studio project file │ ├── payload.vcxproj.filters # Project file filters │ ├── dllmain.cpp # DLL entry point — spawns SYSTEM shell + cleanup │ ├── framework.h # Windows header includes │ ├── pch.h # Precompiled header definitions │ └── pch.cpp # Precompiled header source │ └── docs/ ├── analysis/ │ ├── 01-root-cause.md # Integer division │bug in CCommandBuffer::Initialize │ ├── 02-heap-spray.md # Empirical data from │20 sessions, statistical findings │ └── 03-timeline.md # Discovery, │disclosure, and patch chronology │ └── screenshots/ └── ... # Media ``` ## 快速开始 ### 前置条件 - Windows 11 22H2 (build 22621.3447,**未修补** — 无 KB5037771) - Visual Studio 2022 及 C++ Desktop 工作负载 - 机器应为虚拟机(运行于 VirtualBox/VMware),测试前请建立快照 ### 步骤 1 — 构建 Payload DLL 1. 在 Visual Studio 中打开 `C21.sln` 2. 以 **Release x64** 配置构建 `payload` 项目 ### 步骤 2 — 放置 DLL 从代码库根目录运行 `setup.bat`。它会将 `s11.dll` 复制到所需位置,并可选择启动漏洞利用程序。 ### 步骤 3 — 构建 Exploit 1. 以 **Release x64** 配置构建 `C26f` 项目 ### 步骤 4 — 运行 ``` x64\Release\C26f.exe ``` 或者使用 `setup.bat`,它会在放置 DLL 后提供直接启动的选项。 请从标准(非提升权限)CMD 运行。该漏洞利用程序将: 1. 自动重试最多 10 次 2. 成功后,`dwm.exe` 会加载 `s11.dll` 并生成一个具有 **SYSTEM 完整性级别** 的 CMD 3. 会话日志将写入 `%TEMP%\cve_30051_log.txt` 4. 完成后会弹出一个摘要 MessageBox ## Exploit 配置 在 `main.cpp` 的顶部,以下 `#define` 值控制堆喷射: ``` #define MAX_ATTEMPTS 10 // Max auto-retry attempts #define SPRAY_STEP 0x10 // Hole spacing (0x20 = 512 holes, 0x10 = 1024 holes) #define SPRAY_RANGE_START 0x3000 // Spray range start index #define SPRAY_RANGE_END 0x7000 // Spray range end index #define SLEEP_POST_SPRAY 0xC8 // ms wait after spray (200ms) #define SLEEP_POST_HOLES 0xC8 // ms wait after freeing holes (200ms) ``` ## 技术概览 ### 漏洞根本原因 在 `CCommandBuffer::Initialize` (dwmcore.dll 10.0.22621.3447) 中,`CD2DSharedBuffer::GetBufferSize` 被调用了两次。用于 `new()` 的大小在乘法之前经过了除以 `0x90` 的整数除法,而 `memcpy()` 使用的是原始大小: ``` buffer_size = GetBufferSize() → e.g. 0x23F size_new = (0x23F / 0x90) * 0x90 = 0x1B0 ← allocated size_memcpy = 0x23F ← copied overflow = 0x23F - 0x1B0 = 0x8F bytes ``` ### 漏洞利用链 ``` 1. Hook RtlCreateHeap → capture dwmcore heap handle 2. Hook RtlAllocateHeap → capture base chunk address 3. Hook NtDCompositionCreateChannel → capture MappedAddress 4. Hook NtDCompositionCommitChannel → modify size field (0x120 → 0x23F) inject additional batch commands 5. Heap spray 0x10000 CHolographicInteropTexture objects (size=0x1B0) 6. Free holes every 0x10 indices → create gaps for overflow landing 7. Write payload into overflow buffer → KCBTable+0x388 + LoadLibraryA + DLL path 8. Release all spray objects → trigger overflow → LoadLibraryA("s11.dll") 9. dwm.exe loads payload DLL → spawns CMD as SYSTEM integrity ``` ### 关键偏移量 (Build 22621.3447) | 字段 | 值 | 备注 | |-------|-------|-------| | `value4` | `0x1B0` | 分配大小 | | `value5` | `0x50` | 对象类型 | | `posicion` | `0x1B0` | 从 base+0x48+44 到写入目标的偏移 | | `offset_to_0x120` | `0x48` | 启动后始终具有确定性 | | `KCBTable+0x388` | 运行时 | 待覆盖的 vftable 指针 | ## 实证堆喷射分析 作为硕士论文研究的一部分,在两种喷射配置下进行了 20 次受控会话。每个会话均使用干净的虚拟机快照。 ### 结果 | 配置 | 孔数 | 每次尝试的理论概率 | 观察到的平均值 | 最差情况 | |--------|-------|----------------------------------|-----------------|------------| | `SPRAY_STEP=0x20` | 512 | 0.78% | **2.4 次尝试** | 9 | | `SPRAY_STEP=0x10` | 1024 | 1.56% | **2.44 次尝试** | 8 | ### 关键发现 将孔数加倍(0x20 → 0x10)在观察到的成功率上**没有产生统计上显著的改善**。理论概率(0.78% vs 1.56%)与实证率(干净启动后堆上的首次尝试成功率约 41%)差异巨大。 **结论:** 系统启动后的 DWM 堆表现出一种 **确定性的初始结构**,该结构本身就有利于漏洞利用成功。瓶颈不在于孔密度,而在于可预测的 LFH 状态,该状态将 `CHolographicInteropTexture` 对象放置在有利于溢出的位置,而与喷射粒度无关。 此发现已在 [`docs/analysis/02-heap-spray.md`](docs/analysis/02-heap-spray.md) 中详细记录。 ## 后渗透输出 成功后,将打开一个 CMD 窗口显示: ``` ===================================================== CVE-2024-30051 - Windows DWM Heap Overflow EoP CWE-122 | CVSS 7.8 | Elevation of Privilege ===================================================== Researched and reproduced by : devianntsec Original PoC by : Ricardo Narvaja (Fortra) Target : Windows 11 22H2 (22621.3447) ===================================================== [*] Current user: window manager\dwm-1 [*] Mandatory Integrity Level: Mandatory Label\System Mandatory Level Label S-1-16-16384 [*] Enabled privileges: SeImpersonatePrivilege Impersonate a client after auth Enabled ===================================================== Shell running under DWM process - SYSTEM level ===================================================== ``` 横幅部分以 **绿色** 显示(通过嵌入式 PowerShell)。`whoami` 部分使用默认终端颜色。交互式 CMD 会话保持打开状态,并带有自定义提示符。工件(`s11.dll` 和 `.bat` 脚本)将在 5 秒后通过延迟清理进程自动删除。 ## 技术文档 | 文档 | 描述 | |----------|-------------| | [根本原因分析](docs/analysis/01-root-cause.md) | CCommandBuffer::Initialize 中的整数除法错误 | | [堆喷射分析](docs/analysis/02-heap-spray.md) | 20 个会话的实证数据及统计发现 | | [CVE 时间线](docs/analysis/03-timeline.md) | 发现、披露和补丁时间顺序 | ## 学术背景 本研究是我的 **网络安全硕士论文**(UCAM — Campus Internacional de Ciberseguridad)的一部分,旨在分析跨多种环境的 N-Day 漏洞。 此 CVE 代表了论文中的 **Windows 桌面应用程序** 向量,展示了: - 基于堆的缓冲区溢出利用 - 滥用 DirectComposition API 进行内核交互 - 无需外部工具的进程内 API 挂钩 - 堆喷射可靠性的实证分析 **关键词:** `EoP` · `堆溢出` · `DirectComposition` · `DWM` · `Windows 内核` · `CVE-2024-30051` ## 作者 **Annais Molina (devianntsec)** — 网络安全硕士研究生 [![GitHub](https://img.shields.io/badge/GitHub-@devianntsec-181717?style=flat-square&logo=github)](https://github.com/devianntsec) [![LinkedIn](https://img.shields.io/badge/LinkedIn-Annais%20Molina-0077B5?style=flat-square&logo=linkedin)](https://linkedin.com/in/annais-molina-fuentes) [![Email](https://img.shields.io/badge/Email-me%40deviannt.com-D14836?style=flat-square&logo=gmail)](mailto:me@deviannt.com) ## 致谢 - [**Ricardo Narvaja (Fortra/CoreSecurity)**](https://github.com/fortra/CVE-2024-30051) — 原始 PoC 和逆向工程文章 - [**Kaspersky GReAT**](https://securelist.com/cve-2024-30051/112954/) — 原始漏洞发现及负责任披露 - [**Microsoft MSRC**](https://msrc.microsoft.com/update-guide/en-US/advisory/CVE-2024-30051) — 补丁 KB5037771 (2024 年 5 月) ## 许可证 MIT 许可证 — 详见 [LICENSE](LICENSE) ## 法律免责声明 本代码库仅 **用于教育和安全研究目的**,是学术硕士论文的一部分。所有测试均在无网络暴露的隔离虚拟机上进行。请仅在你拥有或获得明确书面授权测试的系统上使用。未经授权对系统使用是非法的,可能导致刑事起诉。
© 2026 Annais Molina · 网络安全硕士论文
UCAM Universidad Católica San Antonio de Murcia · Campus Internacional de Ciberseguridad
标签:0day挖掘, C++, CVE-2024-30051, dwmcore.dll, DWM 利用, PoC, RFI远程文件包含, Web报告查看器, Windows 11, Windows 安全, 二进制分析, 云安全运维, 内核安全, 利用开发, 协议分析, 堆喷射, 堆溢出, 安全学术研究, 安全漏洞, 恶意代码开发, 情报收集, 数据擦除, 暴力破解, 权限提升, 漏洞研究, 硕士学位论文, 端点可见性, 缓冲区溢出