Windows local privilege-escalation
- 1. Automatic tools
- 2. Scheduled tasks
- 3. Services
- 4. AlwaysInstallElevated
- 5. Users
- 6. Credentials looting
- 7. NT hash extraction
- 8. Bypassing UAC
- 9. Insecure Features
- Bypassing CLM
- Applocker
1. Automatic tools
- WinPEAS
- PrivescCheck
- WES-NG - run
systeminfo
and check for misconfiguration offline usingwes.py
script. - Metasploit:
multi/recon/local_exploit_suggester
(when the shell is already established). - PowerUp.ps1 -
Invoke-AllChecks
.
2. Scheduled tasks
If an attacker is able to modify the Task To Run
file, he can run a code with Run As User
privileges.
3. Services
3.1. Executable permissions
The executable associated with a service might have insecure permissions. The attacker modifing or replacing the executable can gain the privileges of the service's account.
3.2. Unquoted paths
If the service's executable points to an unquoted path with spaces, SCM tries to execute firt binary which is the first part of the unqoted path. This SCM feature is basically disgusting but it works like that. It allows an attacker to put malicious service binary in the "wrong" path and run it before a legit one will be executed.
Example:
NOTE: To drop an executable in the root
C:\
directory you need to actually fhave admin privileges so the unquotedC:\Program Files (x86)\...
is basically useless.
3.3. Modifiable Service
The service ACL might allow to reconfigure service settings. This allows an attacker to point a malicious executable to the service and even change the account which the executable is run with.
NOTE: By changing service binary path to a cmd command, it is possible to execute shell command after service restart.
To check a service ACL the Accesschk tool might be necessary.
3.4. Modifiable Service File
Sometimes it might be possible to modify binary which is run as a service.
4. AlwaysInstallElevated
.msi
files are used to install applications on the system. They usually run with the privileges of the current user but sometimes it might be configured to run installation files with higher privileges from any user account. Malicious .msi
files can be generated using msfvenom
tool.
5. Users
Every user has some privileges and some of them might be used to perform privilege escalation:
Check current privileges: whoami /priv
5.1. SeBackup and SeRestore
The SeBackup
and SeRestore
allow a user to read and write to any file in the system, ignoring any DACL. They are used to perform full backup of the system without requiring full admin privileges. Using these privileges an attacker is able to export SAM database and extract users hashes offline. More in: post-exploitation
.
5.2. SeTakeOwnership
The SeTakeOwnership
privilege allows a user to take ownership of any object on the system. An attacker can search for a service running as SYSTEM and take ownership of the service's executable.
5.3. SeImpersonate and SeAssignPrimaryToken
These privileges allow a process to act on behalf of another user. It usually consists of being able to spawn a process under the security context of another user.
TBD...
5.4. Unpatched software
6. Credentials looting
6.1. Files
3.1.1. IIS configuration
Configuration files of the IIS web server might store some credentials.
3.1.2. Unattended Windows installations
If the OS is installed remotely (unattended installation) there is a chance that the installation config file is still somwhere in the file system. It might include credentials.
6.2. Shell history
6.3. Credential Manager
Credential Manager is a feature that stores logon-sensitive information for websites, applications, and networks. It's some kind of an OS-level vault for saved passwords. It contains:
- web credentials
- Windows credentials (e.g. NTLM and Kerberos)
List all vaults. There are two vaults by default (Web Credentials
and Windows Credentials
).
The following command lists all saved credentials for different users:
Saved credentials are used by default for a certain user. We can run a command as a different user and use these saved credentials (loaded from cache):
NOTE: Even if the credentials are not shown, you can use the
runas /savecred /user:<user> cmd.exe
command in order to use them from a memory.
6.4. SSH software
PuTTY is probably the most common SSH client for Windows in use. It often stores session parameters (e.g. proxy configuration) in the Windows registry.
6.5. Credentials keylogging
If we already have SYSTEM privileges in the OS we can set a keylogger on sessions of another user to steal their credentials.
Use meterpreter
session:
7. NT hash extraction
7.1. From local SAM
SAM (Security Account Manager) is a database with all the local user accounts and passwords. It acts as a database. Passwords, which are stored in the SAM, are hashed. SAM data is used by LSASS to verify user credentials.
Mimikatz
Mimikatz is one of the tools that are able to dump SAM file hashes.
Metasploit, when the session is already established, has built-in ability to dump SAM hashes.
CrackMapExec tool is able to remotely dump SAM hashes (via SMB using credentials).
SAM dumping and offline hashes extraction
If an attacker has privileges to access any file in the system, then he can export SAM and SYSTEM keys from the Windows registry and perform the extraction of hashes offline. Windows registry stores a copy of some of the SAM database contents to be used by services.
Now, transfer files to the attacker machine.
It can be done using metasploit
framework as well:
7.2. From LSASS memory
LSASS (Local Security Authority Subsystem Service) is a process running on every Windows OS. It verifies users logging, handles password changes, creates access tokens, writes to the Windows Security Log. In a domain environment LSASS communicates with a Domain Controller. It manages NTLM, Kerberos, NetLogon authentication. It's not possible to use Windows without lsass.exe
running. An attacker is able to dump the LSASS process memory and retrieve NT hashes.
Tips:
- Memory dump must be performed after logging in successfully. Correct data must be provided to LSASS process before extraction.
- Memory dump should be performed from SYSTEM or local Administrator account.
- Not secured LSASS memory dump can be performed using built-in Windows tools (e.g. dump.exe). Then credentials can be extracted offline.
LSASS process might have additional security layer called LSA protection. It can be omitted with tools like Mimikatz.
NOTE: Usually it's worth to run Mimikatz using Powershell without touching a disk.
Invoke-Mimikatz.ps1
script run in a shell usingIEX
is a great option to do this.
If there is no LSA, the LSASS memory can be dumped using Sysinternals Suite
(it's commonly detected):
8. Bypassing UAC
UACMe - tool to check different UAC bypass techniques.
8.1. Auto-elevation
Some executables can auto-elevate to high IL by default, without any user interaction. This applies to most of the Control Panel's functionality and some other built-in executables. To auto-elevate the executable must be signed by the Windows Publisher and must be contained in a trusted directory like %SystemRoot%/System32
or %ProgramFiles%/
. Sometimes it must declare autoElevate
property in the exec manifest file.
8.2. Scheduled tasks & environment vars
TBD
9. Insecure Features
There is various software that is insecure by design. Legit features of the software allow an attacker to escale privileges, e.g. by executing command as an administrator.
9.1. CI/CD software
Most of CI/CD software allows to execute some kind of scripts. Most often they work with escaled privileges (local Administrator or even SYSTEM). After successful login to such a software an attacker is able to execute a malicious code as an administator. Credentials usually are not hard to guess or bruteforce. Jenkins doesn't even have anti-brute-force mechanisms.
NOTE: Sometimes direct script execution is not allowed for you but at the same time you are allowed to add an extra deployment step which executes Windows commands. The result will be the same - command execution.
Bypassing CLM
Powershell Constrained Language Mode bypass techniques
Applocker
TBD