Original text by By Valentina Palmiotti co-authored by Ruben Boonen
‘Patch Tuesday, Exploit Wednesday’ is an old hacker adage that refers to the weaponization of vulnerabilities the day after monthly security patches become publicly available. As security improves and exploit mitigations become more sophisticated, the amount of research and development required to craft a weaponized exploit has increased. This is especially relevant for memory corruption vulnerabilities.

However, with the addition of new features (and memory-unsafe C code) in the Windows 11 kernel, ripe new attack surfaces can be introduced. By honing in on this newly introduced code, we demonstrate that vulnerabilities that can be trivially weaponized still occur frequently. In this blog post, we analyze and exploit a vulnerability in the Windows Ancillary Function Driver for Winsock,
Patch Diff and Root Cause Analysis
Based on the details of CVE-2023-21768 published by the Microsoft Security Response Center (MSRC), the vulnerability exists within the Ancillary Function Driver (AFD), whose binary filename is
- AFD.sys / Windows 11 22H2 / 10.0.22621.608 (December 2022)
- AFD.sys / Windows 11 22H2 / 10.0.22621.1105 (January 2023)
Ghidra was used to create binary exports for both of these files so they could be compared in BinDiff. An overview of the matched functions is shown below.

Only one function appeared to have been changed,
Pre-patch,

Post-patch,

This change shown above is the only update to the identified function. Some quick analysis showed that a check is being performed based on
This check is missing in the pre-patch version of the driver. Since the function has a specific switch statement for
From this update, we can infer that an attacker can reach this code path with a controlled value at
The function prototype itself contains both the

Reverse Engineering
We now know the location of the vulnerability, but not how to trigger the execution of the vulnerable code path. We’ll do some reverse engineering before beginning to work on a Proof-of-Concept (PoC).
First, the vulnerable function was cross-referenced to understand where and how it was used.

A single call to the vulnerable function is made in
We repeat the process, looking for cross-references to

This table contains the dispatch routines for the AFD driver. Dispatch routines are used to handle requests from Win32 applications by calling
However, the pointer above is not within the

It’s worth noting that it’s the last input/output control (IOCTL) code in the table, indicating that
At this point, we had a couple of options. We could reverse engineer the corresponding Winsock API in a user space to better understand how the underlying kernel function was called, or reverse engineer the kernel code and call into it directly. We didn’t actually know which Winsock function corresponded to
We came across some code published by x86matthew that performs socket operations by calling into the AFD driver directly, forgoing the Winsock library. This is interesting from a stealth perspective, but for our purposes, it is a nice template to create a handle to a TCP socket to make IOCTL requests to the AFD driver. From there, we were able to reach the target function, as evidenced by reaching a breakpoint set in WinDbg while kernel debugging.

Now, refer back to the function prototype for
At this point, we don’t know how to populate the data in
Let’s go through each of the checks.
The first check we encounter is at the beginning of

This check tells us that the size of the
The next check validates values in various fields in our structure:

At the time we didn’t know what any of the fields correspond to, so we pass in a
The next check we encounter is after a call to

The call must return success in order to proceed to the correct code execution path, which means that we must pass in a valid handle to an
Afterward, we reach a loop whose counter was one of the values from our struct:

This loop checked a field from our structure to verify it contained a valid user mode pointer and copied data to it. The pointer is incremented after each iteration of the loop. We filled in the pointers with valid addresses and set the counter to 1. From here, we were able to finally reach the vulnerable function

Once inside

Finally, the last check to pass before reaching the target code is a call to
This function will block until either:
- A completion record becomes available for the
parameterIoCompletionObject
- The timeout expires, which is passed in as a parameter of the function
We control the timeout value via our structure, but simply setting a timeout of 0 is not sufficient for the function to return success. In order for this function to return with no errors, there must be at least one completion record available. After some research, we found the undocumented function

Triggering Arbitrary Write-Where
Now that we can reach the vulnerable code, we can fill the appropriate field in our structure with an arbitrary address to write to. The value that we write to the address comes from an integer whose pointer is passed into the call to


In our proof of concept, this write value is always equal to
LPE with IORING
With the ability to write a fixed value (0x1) at an arbitrary kernel address, we proceeded to turn this into a full arbitrary kernel Read/Write. Because this vulnerability affects the latest versions of Windows 11(22H2), we chose to leverage a Windows I/O ring object corruption to create our primitive. Yarden Shafir has written a number of excellent posts on Windows I/O rings and also developed and disclosed the primitive that we leveraged in our exploit chain. As far as we are aware this is the first instance where this primitive has been used in a public exploit.
When an I/O Ring is initialized by a user two separate structures are created, one in user space and one in kernel space. These structures are shown below.
The kernel object maps to

Note that the kernel object has two fields,
On the user space side, when calling
typedef struct _HIORING { HANDLE handle; NT_IORING_INFO Info; ULONG IoRingKernelAcceptedVersion; PVOID RegBufferArray; ULONG BufferArraySize; PVOID Unknown; ULONG FileHandlesCount; ULONG SubQueueHead; ULONG SubQueueTail; };
If a vulnerability, such as the one covered in this blog post, allows you to update the
As we saw above, we are able to use the vulnerability to write
In the first trigger we set the

And in the second trigger we set

All that remains is to queue I/O operations by writing pointers to forged

One such

To perform an arbitrary write, an I/O operation is tasked to read data from a file handle and write that data to a Kernel address.

Conversely, to perform an arbitrary read, an I/O operation is tasked to read data at a kernel address and write that data to a file handle.

Demo
With the primitive set up all that remains is using some standard kernel post-exploitation techniques to leak the token of an elevated process like System (PID 4) and overwrite the token of a different process.
Exploitation In the Wild
After the public release of our exploit code, Xiaoliang Liu (@flame36987044) from 360 Icesword Lab disclosed publicly for the first time, that they discovered a sample exploiting this vulnerability in the wild (ITW) earlier this year. The technique utilized by the ITW sample differed from ours. The attacker triggers the vulnerability using the corresponding Winsock API function,
The official statement from 360 Icesword Lab is as follows:
“360 IceSword Lab focuses on APT detection and defense. Based on our 0day vulnerability radar system, we discovered an exploit sample of CVE-2023-21768 in the wild in January this year, which differs from the exploits announced by @chompie1337 and @FuzzySec in that it is exploited through system mechanisms and vulnerability features. The exploit is related to
Conclusion and Final Reflections
You may notice that in some parts of the reverse engineering our analysis is superficial. It’s sometimes helpful to only observe some relevant state changes and treat portions of the program as a black box, to avoid getting led down an irrelevant rabbit hole. This allowed us to turn around an exploit quickly, even though maximizing the completion speed was not our goal.
Additionally, we conducted a patch diffing review of all the reported vulnerabilities in
The lack of support for Supervisor Mode Access Protection (SMAP) in the Windows kernel leaves us with plentiful options to construct new data-only exploit primitives. These primitives aren’t feasible in other operating systems that support SMAP. For example, consider CVE-2021-41073, a vulnerability in Linux’s implementation of I/O Ring pre-registered buffers, (the same feature we abuse in Windows for a R/W primitive). This vulnerability can allow overwriting a kernel pointer for a registered buffer, but it cannot be used to construct an arbitrary R/W primitive because if the pointer is replaced with a user pointer, and the kernel tries to read or write there, the system will crash.
Despite best efforts by Microsoft to kill beloved exploit primitives, there are bound to be new primitives to be discovered that take their place. We were able to exploit the latest version of Windows 11 22H2 without encountering any mitigations or constraints from Virtualization Based Security features such as HVCI.
References
- MSRC (CVE-2023-21768
- I/O Rings – When One I/O Operation is Not Enough (@yarden_shafir)
- IoRing vs. io_uring: a comparison of Windows and Linux implementations (@yarden_shafir)
- One Year to I/O Ring: What Changed? (@yarden_shafir)
- One I/O Ring to Rule Them All: A Full Read/Write Exploit Primitive on Windows 11 (@yarden_shafir)
- Arbitrary Kernel RW using IORING’s (@FuzzySec)
- NTSockets – Downloading a file via HTTP using the NtCreateFile and NtDeviceIoControlFile syscalls (@x86matthew)
- Reverse Engineering AFD.sys (@bool101)
- Microsoft Windows Ancillary Function Driver for WinSock privilege escalation CVE-2023-21768 Vulnerability Report