Hacktricks-skills windows-registry-hive-exploitation
Windows registry hive exploitation for local privilege escalation. Use this skill whenever the user mentions registry exploitation, Windows LPE, hive corruption, CVE-2023-23420, CVE-2023-23423, registry memory corruption, or any Windows privilege escalation involving registry hives. Also trigger for questions about deterministic heap grooming, paged pool overflows, or inter-hive attacks on Windows systems.
git clone https://github.com/abelrguezr/hacktricks-skills
skills/windows-hardening/windows-local-privilege-escalation/windows-registry-hive-exploitation/SKILL.MDWindows Registry Hive Exploitation
A skill for understanding and applying Windows registry hive corruption techniques for local privilege escalation (LPE) in authorized security testing contexts.
⚠️ Legal and Ethical Notice
This skill is for authorized security research and penetration testing only. Only use these techniques on systems you own or have explicit written authorization to test. Unauthorized exploitation of these vulnerabilities is illegal and unethical.
Why Hive Corruption is Special
Windows registry hives are memory-mapped
files managed by a custom allocator (.regf
HvAllocateCell, HvReallocateCell, HvFreeCell). The allocator has three critical properties:
- No randomization – Cell placement depends only on the order/size of prior registry API calls, making layouts reproducible across hosts.
- No integrity checks – Manually altered header/data fields are trusted by kernel consumers (
routines) and the Registry process.Cmp* - Shared address space – Attacker-controlled hives are often mapped into the same user-mode address range as HKLM/HKU hives, enabling inter-hive overflows.
This makes hive-based memory corruption bugs (e.g., CVE-2023-23420 / CVE-2023-23423) uniquely reliable for LPE.
Deterministic Layout Grooming
Because hive allocation is deterministic, you can groom cell placement purely via Win32 APIs:
Grooming Workflow
- Reset the target key – Delete and recreate the key so the hive bin contains only known cells.
- Allocate predictable runs of cells by creating values with carefully selected sizes:
- Key/value metadata cells are multiples of 8 bytes.
- Writing
-byte values forces a fresh0x3FD8
-byte bin (0x4000
data +0x3FD8
header/padding), ideal for interleaving bins._HBIN
- Use resize-friendly types (e.g.,
) so you can free/extend individual cells by callingREG_BINARY
with different lengths.RegSetValueEx - Record the sequence of operations (create/delete/resize). Replaying it reproduces the same layout on other systems.
Example Grooming Pattern
void MakeBin(HKEY base, const wchar_t *name, size_t bytes) { std::vector<uint8_t> buf(bytes, 0x41); RegSetKeyValueW(base, NULL, name, REG_BINARY, buf.data(), (DWORD)buf.size()); } void Groom(HKEY hive) { for (int i = 0; i < 0x20; ++i) { wchar_t value[32]; swprintf(value, L"bin_%02d", i); MakeBin(hive, value, 0x3FD8); RegDeleteKeyValueW(hive, NULL, value); // leaves holes for victim cells } }
Once a corruption primitive is available, the groom guarantees that the target cell resides next to the sprayed holes, enabling precise overwrites without heap spraying.
Finding Writable Privileged Hives
Windows only evaluates the ACL on the final component of a registry path. If any descendant under HKLM/HKU grants
KEY_SET_VALUE, KEY_CREATE_SUB_KEY, or WRITE_DAC to low-privileged users, you can reach it even when every parent key is locked down.
Enumeration Strategy
- From an elevated context, walk
and\Registry\Machine
, dumping each key's security descriptor. Store items whose DACL allows unprivileged SIDs.\Registry\User - As a normal user, attempt
withRegOpenKeyEx
against the recorded paths. Successful opens are viable targets.KEY_SET_VALUE|KEY_CREATE_SUB_KEY - Maintain a cache of open handles to stable writable locations so PoCs can directly deploy corrupted metadata.
PowerShell Enumeration Script
# Enumerate writable HKLM keys accessible to Users group $targets = Get-ChildItem Registry::HKEY_LOCAL_MACHINE -Recurse -ErrorAction SilentlyContinue | Where-Object { try { $acl = Get-Acl $_.PsPath $acl.Access | Where-Object { $_.IdentityReference -match 'S-1-5-32-545' } } catch { $false } } | Select-Object -ExpandProperty PsPath foreach ($path in $targets) { try { Get-Item -Path $path -ErrorAction Stop | Out-Null Write-Host "[+] Accessible: $path" } catch {} }
Project Zero found >1000 such writable keys in HKLM on Windows 11, including long-lived entries like
HKLM\SOFTWARE\Microsoft\DRM and several HKLM\SYSTEM branches.
Cross-User Hive Abuse
Every user hive contains
HKCU\Software\Microsoft\Input\TypingInsights, whose ACL grants KEY_ALL_ACCESS to Everyone (S-1-1-0). This enables:
- Filling another user's hive up to the 2 GiB limit, causing logon failures or forcing hive truncation.
- Dropping corrupted cells into other users'
, setting up lateral exploits.NTUSER.DAT - Modifying differencing hives for sandboxed apps that rely on per-user overlay hives.
This makes hive corruption vulnerabilities applicable to lateral movement, not just elevation within the same account.
Metadata Corruption to Paged Pool Overflow
Large registry values are stored in
_CM_BIG_DATA records:
holds the logical size. Its high bit indicates whether the payload lives inside the cell or in big-data storage._CM_KEY_VALUE.DataLength
counts 16 KiB chunks (16384 bytes minus metadata) referenced via a chunk table._CM_BIG_DATA.Count
When any component calls
CmpGetValueData:
- The kernel allocates a paged pool buffer sized strictly from
.DataLength - It copies
bytes from hive storage into that buffer.Count * 0x4000
If you corrupt the cell so
DataLength < 16344 * (Count - 1), the copy overruns the destination linearly into adjacent paged-pool objects.
Exploit Chain
- Use the deterministic groom to place the vulnerable
near controllable metadata._CM_KEY_VALUE - Flip
to a small number (e.g., 0x100) while leavingDataLength
intact._CM_BIG_DATA.Count - Pool-groom from user mode (pipes, ALPC ports, section objects) so a chosen object (like
owner orEPROCESS->Token
) occupies the next chunk after the allocation.SRVNET_BUFFER - Trigger a read (e.g.,
,RegQueryValueEx
) soNtQueryValueKey
copies all chunks and overwrites the neighbor's fields with attacker-controlled data from the hive.CmpGetValueData - Use the corrupted kernel object to pivot to arbitrary read/write or direct SYSTEM token theft.
Because the overflow length equals
(Count * 0x4000) - DataLength, you get a precise byte budget and full control over the bytes written.
Inter-Hive Linear Overflows
Hives mounted by the Registry process are mapped in 2 MiB-aligned views with no guard gaps. You can force two different hives to grow in lockstep until their
_HBIN ranges touch:
- Choose an attacker-writable hive (app hive or user hive) and a privileged target (e.g.,
).HKLM\SOFTWARE - Continuously create/delete
-byte values in both hives. Each allocation adds a0x3FD8
-byte bin, so running both writers in parallel interleaves their bins in virtual memory.0x4000 - Once the final bin of the attacker hive sits immediately before an HBIN belonging to HKLM, use the hive corruption bug to overflow out of the attacker hive, smashing HBIN headers or cells inside HKLM.
- With HKLM metadata under control you can:
- Stage a big-data inconsistency primitive directly in the privileged hive.
- Corrupt configuration data consumed by SYSTEM services before it ever leaves the kernel.
The absence of guard pages means a linear overwrite from an unprivileged hive can directly corrupt SYSTEM-owned hive structures.
Operational Tips
- Monitor hive placement with
(user-mode) and!vad
/!reg view
(kernel) to confirm adjacency before triggering the overflow.!pool - Cache writable HKLM paths discovered during enumeration so corruption primitives can be deployed quickly even after reboots.
- Combine hive grooming with standard pool feng shui (pipe pair freelists,
onNtAllocateVirtualMemory
process) to stabilize post-overflow primitives.Registry
Debugging and Analysis
WinDbg Commands
!process Registry 0 # Find Registry process !vad <pid> # View VAD tree for hive mappings !reg view # View registry hive structures !pool <address> # Analyze paged pool allocations
Key Structures
– Hive bin header (0x4000 bytes)_HBIN
– Key value metadata cell_CM_KEY_VALUE
– Large value storage record_CM_BIG_DATA
/HvAllocateCell
/HvReallocateCell
– Allocator functionsHvFreeCell
References
- Project Zero – The Windows Registry Adventure #8: Practical exploitation of hive memory corruption
- CVE-2023-23420, CVE-2023-23423 – Windows Registry memory corruption vulnerabilities