🤬
  • ■ ■ ■ ■ ■ ■
    0day-RCAs/2022/CVE-2022-21882.md
     1 +# CVE-2022-21882: Win32k Window Object Type Confusion
     2 +*RyeLv (@b2ahex)*
     3 + 
     4 +## The Basics
     5 + 
     6 +**Disclosure or Patch Date:** Jan 13, 2022
     7 + 
     8 +**Product:** Microsoft Windows
     9 + 
     10 +**Advisory:** https://msrc.microsoft.com/update-guide/vulnerability/CVE-2022-21882
     11 + 
     12 +**Affected Versions:** Before the January 2022 patch update. Windows 10,Windows 11,Windows Server 2019,Windows server 2022 (Currently only full exploits found under windows10 and windows server 2019)
     13 + 
     14 +**First Patched Version:** CVE-2022-21882,January 2022 patch update.
     15 + 
     16 +**Issue/Bug Report:** N/A
     17 + 
     18 +**Patch CL:** N/A
     19 + 
     20 +**Bug-Introducing CL:** N/A
     21 + 
     22 +**Reporter(s):** RyeLv (@b2ahex)
     23 + 
     24 +## The Code
     25 + 
     26 +**Proof-of-concept:** N/A
     27 + 
     28 +**Exploit sample:** N/A
     29 + 
     30 +**Did you have access to the exploit sample when doing the analysis?** Yes
     31 + 
     32 +## The Vulnerability
     33 + 
     34 +**Bug class:** win32k object type confusion
     35 + 
     36 +**Vulnerability details:**
     37 + 
     38 +The attacker can call the relevant GUI API at the user_mode to make the kernel call like xxxMenuWindowProc, xxxSBWndProc, xxxSwitchWndProc, xxxTooltipWndProc, etc. These kernel functions will trigger a callback xxxClientAllocWindowClassExtraBytes. Attacker can intercept this callback through hook xxxClientAllocWindowClassExtraBytes in KernelCallbackTable,and use the NtUserConsoleControl method to set the ConsoleWindow flag of the tagWND object, which will modify the window type.
     39 + 
     40 +After the final callback, the system does not check whether the window type has changed, and the wrong data is referenced due to type confusion. The difference before and after the flag modified is that before setting the flag, the system thinks that tagWND.WndExtra saves a user_mode pointer; after the flag is set, the system thinks that tagWND.WndExtra is the offset of the kernel desktop heap,and attacker can control this offset, then cause out-of-bounds R&W.
     41 + 
     42 +**Patch analysis:**
     43 + 
     44 +The patch added check code. Before the xxxClientAllocWindowClassExtraBytes method ends, the system will check the ConsoleWindow flag(0x800). If the flag is set, xxxClientAllocWindowClassExtraBytes returns false.
     45 + 
     46 +**Thoughts on how this vuln might have been found _(fuzzing, code auditing, variant analysis, etc.)_:**
     47 + 
     48 +Code auditing for user-mode callbacks related functions is feasible, and there is a lot of excellent research on this attack surface.
     49 + 
     50 +**(Historical/present/future) context of bug:**
     51 + 
     52 +https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-1732
     53 + 
     54 +## The Exploit
     55 + 
     56 +(The terms *exploit primitive*, *exploit strategy*, *exploit technique*, and *exploit flow* are [defined here](https://googleprojectzero.blogspot.com/2020/06/a-survey-of-recent-ios-kernel-exploits.html).)
     57 + 
     58 +**Exploit strategy (or strategies):**
     59 + 
     60 +Through the vulnerability to achieve out-of-bounds read and write, and modify the kernel object of another window to obtain the kernel arbitrary address read and write primitive
     61 + 
     62 +**Exploit flow:**
     63 + 
     64 +1.Trigger the vulnerability to get out-of-bounds write, modify the cbWndExtra of the window object to 0x0FFFEFFF, so use the window object WndExtra can access a large memory.
     65 + 
     66 +2.Modify the WS_CHILD flag of another window and set a specially constructed Menu(fake menu) for the other window
     67 + 
     68 +3.Get arbitrary read primitive by GetMenuBarInfo API and fake menu.
     69 + 
     70 +4.Use the SetWindowLongPtrA API to modify the ExtraBytes of another window object to get arbitrary write primitive.
     71 + 
     72 +5.Find the system eprocess with PID 4 through EPROCESS ActiveProcessLinks
     73 + 
     74 +6.Read the system token and replace the current process token
     75 + 
     76 +**Known cases of the same exploit flow:**
     77 + 
     78 +It is the same as the previous CVE-2021-1732 exploit, and is a common way of exploiting privilege escalation vulnerabilities.
     79 + 
     80 +CVE-2021-1732(https://googleprojectzero.github.io/0days-in-the-wild//0day-RCAs/2021/CVE-2021-1732.html)
     81 + 
     82 +**Part of an exploit chain?**
     83 + 
     84 +N/A
     85 + 
     86 +## The Next Steps
     87 + 
     88 +### Variant analysis
     89 + 
     90 +**Areas/approach for variant analysis (and why):**
     91 + 
     92 +Here's a quick way to check CVE-2021-1732 & CVE-2022-21882:
     93 + 
     94 +After the xxxClientAllocWindowClassExtraBytes callback is completed, determine whether the window object contains the 0x800 flag before the function return.
     95 + 
     96 +when flag has been set,it can be identified according to the calling path of xxxClientAllocWindowClassExtraBytes.
     97 + 
     98 +When the stack path is xxxCreateWindowEx -> xxxClientallocxxxxExtraBytes (CVE-2021-1732).
     99 + 
     100 +In other cases it is (CVE-2022-21882).
     101 + 
     102 + 
     103 +**Found variants:** N/A
     104 + 
     105 +### Structural improvements
     106 + 
     107 + 
     108 +**Ideas to kill the bug class:**
     109 + 
     110 +Improve the kernel 0day bounty, let more security researchers participate in the bounty program, and help the system to be more perfect.
     111 + 
     112 +**Ideas to mitigate the exploit flow:**
     113 + 
     114 +Mitigating common exploit techniques.
     115 + 
     116 +**Other potential improvements:**
     117 + 
     118 +Improve the kernel 0day bounty.
     119 + 
     120 +### 0-day detection methods
     121 + 
     122 +What are potential detection methods for similar 0-days? Meaning are there any ideas of how this exploit or similar exploits could be detected **as a 0-day**?
     123 + 
     124 +Detect strings in memory for dynamically get addresses/offset.
     125 + 
     126 +Detect the behavior of user-mode process loading kernel modules like ntoskrnl.exe.
     127 + 
     128 +Check if KernelCallbackTable is hooked.
     129 + 
     130 +## Other References
     131 + 
     132 +https://msrc.microsoft.com/update-guide/vulnerability/CVE-2022-21882
     133 + 
     134 +https://googleprojectzero.github.io/0days-in-the-wild//0day-RCAs/2021/CVE-2021-1732.html
     135 + 
     136 +https://ti.dbappsecurity.com.cn/blog/index.php/2021/02/10/windows-kernel-zero-day-exploit-is-used-by-bitter-apt-in-targeted-attack/
     137 + 
     138 +https://www.mcafee.com/blogs/enterprise/mcafee-enterprise-atr/technical-analysis-of-cve-2021-1732/
Please wait...
Page is in error, reload to recover