JonyFilc/PrintSpoofer-ReflectiveDLL
GitHub: JonyFilc/PrintSpoofer-ReflectiveDLL
将 Windows Print Spooler 本地提权漏洞(CVE-2019-1040/1019)封装为 Reflective DLL,支持在 Cobalt Strike 等渗透框架中通过内存注入方式从普通用户权限提升至 SYSTEM 权限。
Stars: 0 | Forks: 2
# PrintSpoofer 详情
[](LICENSE)
[](https://www.microsoft.com/windows)
[](https://isocpp.org/)
PrintSpoofer 是一个通过利用 Windows Print Spooler 服务中的漏洞(CVE-2019-1040 / CVE-2019-1019)来执行本地权限提升的工具。本项目以 **Reflective DLL** 格式实现了 PrintSpoofer exploit,使其适用于 **Cobalt Strike** 等渗透测试框架。
## 目录
* [概述](#overview)
* [工作原理](#how-it-works)
* [技术细节](#technical-details)
* [环境要求](#requirements)
* [构建](#build)
* [使用方法](#usage)
* [项目结构](#project-structure)
* [安全免责声明](#security-disclaimer)
* [参考资料](#references)
## 概述
PrintSpoofer 利用 Windows Print Spooler 服务中的漏洞,允许低权限用户获取 **SYSTEM** 级权限。该 exploit 滥用了 Print Spooler 服务处理 named pipe 的方式。
### 特性
* **Reflective DLL 格式** — 可以完全在内存中加载,无需触碰磁盘
* 适用于 **SE_IMPERSONATE_NAME** 权限
* 使用 **RPC** 协议与 Print Spooler 服务通信
* 使用 **Named Pipe** 机制执行 token 模拟
## 工作原理
PrintSpoofer 通过执行以下步骤运行:
### 1. 权限检查
该 exploit 首先检查当前 token 是否具有 `SE_IMPERSONATE_NAME` 权限。这是模拟其他用户 token 所必需的。
### 2. 创建 Named Pipe
使用随机 UUID 创建一个 named pipe。pipe 路径为:
```
\\.\pipe\\pipe\spoolss
```
### 3. 等待 Pipe 连接
在创建的 named pipe 上等待异步连接。创建一个事件,并准备 pipe 以接受传入连接。
### 4. 触发 Print Spooler 连接
在单独的线程中,向 Print Spooler 服务发出 RPC 调用。
通过调用 `RpcRemoteFindFirstPrinterChangeNotificationEx`,该服务尝试连接到我们创建的 pipe。
### 5. Token 模拟
当 Print Spooler 服务(以 SYSTEM 身份运行)连接到 named pipe 时,该 exploit 使用 `ImpersonateNamedPipeClient` 模拟该服务的 token。
这将导致获取 SYSTEM 权限。
### 6. 执行特权操作
拥有 SYSTEM token 后,现在可以执行高权限操作。
## 技术细节
### Print Spooler 漏洞
Windows Print Spooler 服务通过 named pipe 处理打印机通知。
由于该服务未正确验证 pipe 连接,攻击者可以强制其连接到恶意 pipe,然后模拟 SYSTEM token。
### RPC 通信
本项目使用 **MS-RPRN**(Print System Remote Protocol)与 Print Spooler 服务通信。
该协议通过 IDL (Interface Definition Language) 文件定义,并支持 RPC 调用。
### Reflective DLL 注入
Reflective DLL 的行为与标准 DLL 不同:
* 它可以直接加载到内存中,无需触碰磁盘
* 不需要 `LoadLibrary` API
* 手动解析并加载 PE (Portable Executable) 格式
## 环境要求
### 构建环境
* **Visual Studio 2022** (C++ Desktop Development workload)
* **Windows 10/11**
### 运行环境
* **Windows 10/11**
* **Print Spooler** 服务正在运行
* **SE_IMPERSONATE_NAME** 权限(默认情况下大多数标准用户具有此权限)
* **Cobalt Strike** 或类似框架(可选)
## 构建
### 使用 Visual Studio 构建
1. 在 Visual Studio 中打开 **PrintSpoofer.sln** 文件。
2. 选择您的 **Solution Platform** 和 **Configuration**:
* Platform: `x64` 或 `Win32`(取决于目标架构)
* Configuration: `Release` (生产环境) 或 `Debug` (开发环境)
3. 通过 `Build Solution` (Ctrl+Shift+B) 构建解决方案。
4. 编译后的 DLL 位于:
PrintSpoofer\x64\Release\PrintSpoofer.dll (针对 x64)
PrintSpoofer\Win32\Release\PrintSpoofer.dll (针对 x86)
### 构建选项
项目使用以下预处理器定义:
* `REFLECTIVE_DLL_EXPORTS`:启用 Reflective DLL 导出
* `REFLECTIVEDLLINJECTION_CUSTOM_DLLMAIN`:使用自定义 DllMain
* `REFLECTIVEDLLINJECTION_VIA_LOADREMOTELIBRARYR`:启用 LoadRemoteLibraryR(在 Release 模式下)
## 使用方法
### 配合 Cobalt Strike 使用
PrintSpoofer 可以与 Cobalt Strike 的 `elevate` 命令一起使用:
```
elevate PrintSpoofer LISTENER_NAME
```
其中:
* `PrintSpoofer`:提权模块名称
* `LISTENER_NAME`:将接收提权后 shell 的监听器
### 手动使用
可以使用 Reflective DLL 注入技术手动加载该 DLL。
### 预期输出
成功的 exploit 执行将显示:
```
[+] Found privilege: SeImpersonatePrivilege
[+] Named pipe listening...
[+] ImpersonateNamedPipeClient OK
[+] Exploit successfully, enjoy your shell
```
### 文件描述
#### dllmain.cpp
* DLL 入口点 (`DllMain`)
* 控制 exploit 逻辑
* 处理 reflective DLL 特定功能
#### PrintSpoofer.cpp
* **CheckAndEnablePrivilege**:检查并启用 token 权限
* **GenerateRandomPipeName**:使用随机 UUID 生成 pipe 名称
* **CreateSpoolNamedPipe**:创建 named pipe 并配置安全性
* **ConnectSpoolNamedPipe**:准备 pipe 以进行异步连接
* **TriggerNamedPipeConnection**:创建线程以触发 Print Spooler 连接
* **TriggerNamedPipeConnectionThread**:执行 RPC 调用
* **GetSystem**:执行 token 模拟
#### ms-rprn.idl
* Microsoft MS-RPRN 协议的 IDL 定义
* 由 MIDL 编译器处理以生成 RPC stub
#### ReflectiveLoader.cpp
* 为 Reflective DLL 注入实现 PE 解析和内存加载
## 免责声明
本工具仅用于**教育目的**和**授权渗透测试**。
## 参考资料
* [https://www.itm4n.fr/printspoofer-abusing-impersonate-privileges/](https://www.itm4n.fr/printspoofer-abusing-impersonate-privileges/)
* [https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation](https://book.hacktricks.xyz/windows-hardening/windows-local-privilege-escalation)
## 许可证
本项目基于 MIT 许可证授权。有关更多信息,请参阅 [LICENSE 文件](LICENSE)。
标签:C++17, Cobalt Strike, CVE-2019-1019, CVE-2019-1040, HTTP头分析, Named Pipe, PE 加载器, PrintSpoofer, Prisma Cloud, Reflective DLL, RPC, SYSTEM权限, Web报告查看器, Windows Print Spooler, 内存加载, 协议分析, 安全测试, 客户端加密, 客户端加密, 提权漏洞, 攻击性安全, 攻击诱捕, 本地提权, 权限提升, 端点可见性, 系统权限