andrei-majer/bitlocker-hardening

GitHub: andrei-majer/bitlocker-hardening

通过自动将 BitLocker 从仅 TPM 模式切换为 TPM+PIN 模式,缓解 CVE-2026-45585 物理绕过漏洞的 PowerShell 脚本。

Stars: 3 | Forks: 0

# 🔐 yellowkey 缓解措施 ### 针对 CVE-2026-45585 (YellowKey) 的 BitLocker TPM+PIN 加固 **针对 WinRE BitLocker 绕过漏洞的自动化缓解方案 —— 目前尚无完整补丁** [![CVE](https://img.shields.io/badge/CVE-2026--45585-red.svg)](https://nvd.nist.gov/vuln/detail/CVE-2026-45585) [![Platform](https://img.shields.io/badge/Platform-Windows%2011%20%2F%20Server%202025-0078D4.svg)](https://www.microsoft.com/en-us/windows) [![PowerShell](https://img.shields.io/badge/PowerShell-5.1%2B-5391FE.svg)](https://learn.microsoft.com/en-us/powershell/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
## 🔍 漏洞详情 **YellowKey** 是一个已公开披露的 BitLocker 绕过漏洞,它能让拥有物理访问权限的攻击者在受 BitLocker 保护的 Windows 11 磁盘上获得不受限制的 shell 访问权限 —— 无需恢复密钥,无需 PIN 码,也无需任何凭据。 Windows 恢复环境 (`WinRE`) 内的一个组件 (`autofstx.exe`) 会执行一项事务性 NTFS 重放例程,该例程会删除 `winpeshl.ini`。其副作用是启动了一个具有对已解密卷完全访问权限的 shell。攻击者可以通过将特定文件夹复制到 USB 驱动器(或直接复制到 EFI 分区)、重启进入 WinRE 并按住 CTRL 键来触发此漏洞。 | | 详情 | |---|---| | **CVE** | [CVE-2026-45585](https://nvd.nist.gov/vuln/detail/CVE-2026-45585) | | **CVSS Score** | 6.8 (中危) | | **CVSS Vector** | `CVSS:3.1/AV:P/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H` | | **CWE** | CWE-77 (命令注入) | | **攻击向量** | 需要物理访问权限 | | **披露日期** | 2026年5月19日 | | **补丁** | 暂无 —— Microsoft 仅发布了手动缓解措施 | | **MSRC 公告** | [msrc.microsoft.com/update-guide/vulnerability/CVE-2026-45585](https://msrc.microsoft.com/update-guide/vulnerability/CVE-2026-45585) | | **PoC** | 已公开 ([Nightmare-Eclipse/YellowKey](https://github.com/Nightmare-Eclipse/YellowKey)) | | **受影响版本** | Windows 11 (24H2, 25H2, 26H1), Windows Server 2022/2025 | | **不受影响版本** | Windows 10 | ## 💡 缓解措施 从 **仅 TPM** 切换到 **TPM+PIN** 可以完全阻止该攻击。由于在启动时需要输入 PIN 码,无论 WinRE shell 是如何被触发的,攻击者都无法解密驱动器 —— 如果没有正确的 PIN 码,TPM 将不会释放卷主密钥。 该脚本会处理阻止 `manage-bde` 默认添加 PIN 保护器的组策略前置条件,然后在一次运行中安全地将驱动器从仅 TPM 模式过渡到 TPM+PIN 模式。 ## ⚡ 脚本功能 ``` Run Add-BitLockerTPMPin.ps1 (admin) │ ▼ [Version Check] ──→ exits gracefully on Windows 10 (not affected) │ ▼ [BitLocker Status Check] ──→ confirms encryption is active on C: │ ▼ [Group Policy Fix] ──→ sets UseAdvancedStartup + UseTPMPIN + UseEnhancedPin │ (required — manage-bde rejects TPM+PIN without these) ▼ [gpupdate /force] ──→ applies policy immediately without reboot │ ▼ [manage-bde -protectors -add C: -TPMAndPIN] ──→ prompts for PIN interactively │ ▼ [List Protectors] ──→ shows all current protectors for verification │ ▼ [Remove TPM-only Protector] ──→ optional, prompted with confirmation ``` ## 🚀 快速开始 ### 前置条件 - Windows 11 (24H2 或更高版本) 或 Windows Server 2022/2025 - C: 盘已启用 BitLocker - 管理员权限 - 在运行前可访问恢复密钥(将其存储在您的 Microsoft 帐户中或将其打印出来) ### 运行 ``` # 在具有管理员权限的 PowerShell 提示符中,将以下内容作为两个独立的命令运行: Set-ExecutionPolicy Bypass -Scope Process -Force ``` ``` # 所有受 BitLocker 保护的驱动器(自动检测): .\Add-BitLockerTPMPin.ps1 # 或者针对特定驱动器: .\Add-BitLockerTPMPin.ps1 -Drive C .\Add-BitLockerTPMPin.ps1 -Drive D ``` 系统将以交互方式提示您为每个驱动器设置 PIN 码。支持字母数字 PIN 码(脚本会通过注册表启用增强型 PIN 码)。 ## 📖 用法 ### 交互式流程 ``` BitLocker-protected drives found: C:\ FullyEncrypted Protection: On D:\ FullyEncrypted Protection: On Group Policy keys set. Refreshing policy... ============================== Drive: C:\ ============================== Adding TPM+PIN protector. You will be prompted for a PIN. PIN must be 6+ characters. Alphanumeric is supported. Type the PIN to use to protect the volume: Confirm the PIN by typing it again: Key Protectors Added: TPM And PIN: ID: {XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX} Current protectors on C:\: ... TPM-only protector found: {YYYYYYYY-YYYY-YYYY-YYYY-YYYYYYYYYYYY} Remove TPM-only protector on C:\? This leaves only TPM+PIN. (y/N): y TPM-only protector removed. ============================== Drive: D:\ ============================== D:\ has no TPM protector — TPM+PIN applies to the OS drive only. Skipping. Done. Verify with: manage-bde -status ``` ### 运行后验证 ``` manage-bde -status C: # 应该显示:Key Protectors: TPM And PIN # Protection Status:Protection On ``` ## 🛡️ 安全说明 **运行前请务必准备好您的恢复密钥。** 脚本只有在确认 TPM+PIN 保护器成功添加后,才会移除仅 TPM 保护器。但如果机器在运行过程中重启,或者 `manage-bde -add` 步骤部分失败,您将需要使用恢复密钥来解锁驱动器。 **立即获取您的恢复密钥:** ``` # 将恢复密钥打印到控制台(请将其保存在安全的地方) manage-bde -protectors -get C: -Type RecoveryPassword ``` 或者登录您的 Microsoft 帐户在 [account.microsoft.com/devices/recoverykey](https://account.microsoft.com/devices/recoverykey) 找到它。 **PIN 码的选择很重要。** 较短的纯数字 PIN 码在面对有针对性的物理攻击时只能提供微弱的保护。请至少使用 8 个字符。脚本已启用对字母数字 PIN 码的支持。 ## ⚙️ 组策略键值的作用 该脚本在 `HKLM:\SOFTWARE\Policies\Microsoft\FVE` 下设置了四个注册表值: | 键 | 值 | 用途 | |---|---|---| | `UseAdvancedStartup` | `1` | 启用“启动时需要附加身份验证”策略 —— 如果没有此设置,所有 `UseTPM*` 键都会被忽略 | | `UseTPMPIN` | `2` | `0` = 阻止, `1` = 要求, `2` = 允许 TPM+PIN | | `UseTPM` | `2` | 允许在 PIN 的同时使用仅 TPM(防止策略冲突) | | `UseEnhancedPin` | `1` | 允许在 PIN 码中使用字母数字字符 | 这些正是 Windows 组策略 (gpedit.msc) 会写入的键。通过注册表设置它们等同于通过 MMC 管理单元配置策略。 ## 🔧 手动步骤(不使用脚本) 如果您倾向于逐步单独执行: ``` # 1. 设置 Group Policy 注册表键 $p = "HKLM:\SOFTWARE\Policies\Microsoft\FVE" if (-not (Test-Path $p)) { New-Item -Path $p -Force } Set-ItemProperty -Path $p -Name "UseAdvancedStartup" -Value 1 -Type DWord -Force Set-ItemProperty -Path $p -Name "UseTPMPIN" -Value 2 -Type DWord -Force Set-ItemProperty -Path $p -Name "UseTPM" -Value 2 -Type DWord -Force Set-ItemProperty -Path $p -Name "UseEnhancedPin" -Value 1 -Type DWord -Force gpupdate /force # 2. 添加 TPM+PIN protector manage-bde -protectors -add C: -TPMAndPIN # 3. 查找仅 TPM 的 protector ID manage-bde -protectors -get C: # 4. 移除它(将 GUID 替换为步骤 3 中的 ID) manage-bde -protectors -delete C: -id {YOUR-TPM-ONLY-GUID} # 5. 验证 manage-bde -status C: ``` ## 🗂️ 仓库结构 ``` yellowkey-mitigation/ ├── Add-BitLockerTPMPin.ps1 # Main mitigation script └── README.md ``` ## 🤖 AI 声明 此脚本由作者与 **Claude (Anthropic)** 共同开发。所有逻辑均由作者在 Windows 11 上进行了审查和测试。 ## 📄 许可证 [MIT](https://opensource.org/licenses/MIT) — 可自由使用、修改和分发。
© 2026 Andrei Majer [![GitHub](https://img.shields.io/badge/GitHub-andrei--majer-181717?logo=github)](https://github.com/andrei-majer) [![LinkedIn](https://img.shields.io/badge/LinkedIn-Andrei%20Majer-0A66C2?logo=linkedin)](https://www.linkedin.com/in/andrei-majer/)
标签:AI合规, BitLocker, IPv6, Libemu, PowerShell, 安全防护, 数据加密, 漏洞缓解