Module 16: Windows Privilege Escalation
Enumerating Windows
Understanding Windows Privileges and Access Control Mechanisms
Built-in users and groups have a RID under 1000. These RIDs are known as well-known RIDs.
Standard users start at RID 1000.
Situational Awareness
Information to gather upon gaining access and how:
Username and hostname
whoami
Group memberships of the current user
whoami /groups
Existing users and groups
Users:
CMD:
net user
Powershell:
Get-LocalUser
Groups:
CMD:
net localgroup
Powershell:
Get-LocalGroup
Members of groups:
CMD:
net localgroup <group_name>
Powershell:
Get-LocalGroupMember <group_name>
Operating system, version and architecture
systeminfo
Network information
Network interfaces:
ipconfig /all
Routing table:
route print
Network connections:
netstat -ano
Installed applications
32-bit:
CMD:
reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" /s /v DisplayName
Powershell:
Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" | select DisplayName
64-bit:
CMD:
reg query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /v DisplayName
Powershell:
Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" | select DisplayName
Running processes
CMD:
tasklist
Powershell:
Get-Process
Hidden in Plain View
Basically look for .txt, .ini, .csv, etc. files that may have passwords stored...
Get-ChildItem -Path C:\Users\ -File -Recurse -Include *.txt,*.ini,*.pdf,*.csv -ErrorAction SilentlyContinue
Information Goldmine PowerShell
Checking the History:
Get-History
Finding the HistorySavePath:
(Get-PSReadlineOption).HistorySavePath
Creating a PowerShell remoting sessions via WinRM in a bind shell can cause unexpected behavior.
Due to this, use evil-winrm.
evil-winrm -i 192.168.50.220 -u daveadmin -p "qwertqwertqwert123\!\!"
Automated Enumeration
Using winPEAS (variations) found at:
/usr/share/peass/winpeas/
Using Ghostpack's seatbelt:
Leveraging Windows Services
Service Binary Hijacking
Querying services' Name, State, and PathName. Filter out services not Running:
Permissions in the CLI:
F
Full access
M
Modify access
RX
Read and execute access
R
Read-only access
W
Write-only access
Determining privileges on binaries associated with the services:
Assuming we found a binary with weak permissions. Let's replace it with a very basic executable. Starting with creating the .c file on Kali:
Next, we'll cross-compile the code with mingw-64 since we know the target is 64-bit.
Now we'll transfer the adduser.exe to the target and replace the original mysqld.exe with ours.
Now that the binary is replaced, we need to have the service execute it.
Checking startmode of the server:
Do we have privileges required to reboot?
Our user has permission. Disabled vs. Enabled is only in the context of the running process. In this case, it means whoami has not requested/is not currently using the SeShutdownPrivilege privilege. Thus the privileges listed are what our user does have access to.
An automated tool like PowerUp.ps1 would have found the mysql service as well, though it would have run into issues if we tried using Install-ServiceBinary due to the code of PowerUp.ps1 having issues with a path included in the way our sql example was. Thus, don't always trust automated tools to cover every exploit.
Script execution may be blocked, bypass it:
powershell -ep bypass
PowerUp.ps1 can be found here:
/usr/share/windows-resources/powersploit/Privesc/PowerUp.ps1
Using PowerUp.ps1:
DLL Hijacking
DLLs are searched in this order on current Windows versions due to safe DLL search mode:
The directory from which the application loaded.
The system directory.
The 16-bit system directory.
The Windows directory.
The current directory.
The directories that are listed in the PATH environment variable.
DLLs can have an optional entry point function named DllMain, which is executed when processes or threads attach the DLL.
We'll re-use the previous C code in our malicious DLL.
Cross-compile this code:
Unquoted Service Paths
Enumerate running/stopped services:
Get-CimInstance -ClassName win32_service | Select Name,State,PathName
Finding services with unquoted PathNames that are potentially vulnerable:
Abusing Other Windows Components
Scheduled Tasks
Querying scheduled tasks:
schtasks /query /fo LIST /v
Check for the Run as User and the PathTask.
Using Exploits
Checking for security updates that may have patched vulnerabilities in the OS version found via systeminfo
:
The SeImpersonatePrivilege can potentially be abused to perform privilege escalation. This is commonly found as a privilege for users running an Internet Information Service (IIS) web server.
Capstone Lab notes:
SeBackupPrivilege allows us to dump the reg\sam and reg\system for cracking via impacket-secretsdump -sam SAM -system SYSTEM LOCAL
Last updated