Escalation
Common ways for the attacker to gain and execute commands with elevated privileges
Utilman.exe
Utilman is a built-in Windows application used to provide Ease of Access options during the lock screen
Since Utilman is run with SYSTEM privileges, we will effectively gain SYSTEM privileges if we replace the original binary for any payload we like. As we can take ownership of any file, replacing it is trivial.
- Start by taking ownership with the following command
Being the owner of a file doesn't mean that you have privileges over it, but you can assign yourself any privileges you need.
- Give your user full permissions over utilman.exe you with the following command
- Replace utilman.exe with a copy of cmd.exe
- Lock the screen from the start menu, and click on the "Ease of Access" button
Since we replaced utilman.exe with a copy of cmd.exe, we will get a command prompt with SYSTEM privileges.
AlwaysInstallElevated
Windows installer files (.msi) are used to install applications on the system and they usually run with the privilege level of the user that starts it. However, these can be configured to run with higher privileges from any user account and could potentially allow us to generate a malicious MSI file that would run with admin privileges.
This method requires two registry values to be set. You can query these from the command line using the commands below.
Both need to be set, otherwise exploitation will not be possible.
You can generate a malicious .msi file using msfvenom
Once you have transferred the file you have created, you can run the installer with the command below
Windows Services
If the executable associated with a service has weak permissions that allow an attacker to modify or replace it, the attacker can gain the privileges of the service's account trivially.
- Query the service configuration using sc
- Proceed to check the permissions on the executable:
- Generate an exe-service payload using msfvenom and serve it through a python webserver:
We can then pull the payload from Powershell with the following command:
Once the payload is in the Windows server, we proceed to replace the service executable with our payload.
Finally, execute.
AutoElevate
Some executables can auto-elevate without any user intervention. This applies to most of the Control Panel's functionality and some executables provided with Windows. For an application to auto-elevate:
- The executable must be signed by the Windows Publisher
- The executable must be contained in a trusted directory, like %SystemRoot%/System32/ or %ProgramFiles%/
Executable files (.exe) must declare the autoElevate element inside their manifests. To check a file's manifest, we can use sigcheck, a tool provided as part of the Sysinternals suite.
azman.msc
Open the Run prompt, type "azman.msc" and press OK. This will be spawned from the mmc.exe process with elevated privileges.
To open a shell, we will abuse the application's help feature.
- In the navigation menu, select
Help > Help Topics - Right click anywhere on the help article and select
View Source
This will spawn a notepad process that we can leverage to get a shell. Go to File > Open, select All Files in the dropdown, and go to C:\Windows\System32 and search for cmd.exe.
Right-click and select Open. You will now have a command prompt opened with elevated access!
Fodhelper
Check to see if your user is part of the Administrators group and that it is running with a medium integrity token
We set the required registry values to associate the ms-settings class to a reverse shell
And another technique...
To avoid detection, we need to clean up after ourselves with the following commands:
Popular Tools
WinPEAS
WinPEAS is a script that search for possible paths to escalate privileges on Windows hosts.
PrivescCheck
This script aims to identify Local Privilege Escalation (LPE) vulnerabilities that are usually due to Windows configuration issues, or bad practices. It can also gather useful information for some exploitation and post-exploitation tasks.
WES-NG
WES-NG is a tool based on the output of Windows' systeminfo utility which provides the list of vulnerabilities the OS is vulnerable to, including any exploits for these vulnerabilities.