afd.sys use-after-free enables SYSTEM privilege escalation
A race condition in afd.sys’s Registered I/O extension can be exploited to obtain SYSTEM privileges on Windows 11 21H2.
Security & privacy Exodus Intelligence 2 Dec 2024 Disclosure Prototype evidence
Published as “Windows Sockets: From Registered I/O to SYSTEM Privileges”
Why it matters
The vulnerability enables unprivileged users to gain SYSTEM privileges on vulnerable Windows versions.
Summary
The writeup details a use-after-free bug in the afd.sys driver caused by a race between AfdRioGetAndCacheBuffer and AfdRioDereferenceBuffer. By spraying the non-paged pool with fake RIOBuffer structures via unbuffered named pipes and triggering the race, the authors achieve arbitrary read/write primitives. They then overwrite the _SEP_TOKEN_PRIVILEGES structure to elevate a process to NT AUTHORITY\SYSTEM on a Windows 11 21H2 system. The exploit is demonstrated on a single machine and described as stable.
What they found 1
- A race condition allows a malicious user to act on a freed RIOBuffer structure, creating a use-after-free.
“A race condition exists here that allows a malicious user to schedule the execution of the AfdRioGetAndCacheBuffer() and the AfdRioDereferenceBuffer() functions in different CPUs at the same time acting on the same registered buffer.”
Caveats 2
- Structure definitions are obtained by reverse engineering and may not accurately reflect structures defined in the source code.
- We tested the exploit on a Windows 11 21H2 machine
What’s new here 4
- Identifies a race condition between AfdRioGetAndCacheBuffer and AfdRioDereferenceBuffer leading to a use-after-free.
- Presents a full exploitation chain using named-pipe non-paged pool spraying to gain arbitrary read/write.
- Demonstrates privilege escalation to SYSTEM on Windows 11 21H2.
- Provides detailed reverse-engineered internal structures of the afd.sys RIO component.