Leveraging Windows Services
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.
Initial Checks:
# Check for Installed windows Service.
# PowerShell Command
# Check for abnormal installation path
Get-CimInstance -ClassName win32_service | Select Name,State,PathName | Where-Object {$_.State -like 'Running'}
# Skipping default system32 folder.
Get-CimInstance -ClassName win32_service | Select Name,State,PathName | Where-Object {$_.State -like 'Running' -and $_.PathName -notmatch "WINDOWS\\system32"}
# checking all processes running or stoped both. Skipping default system32 folder. also
# Useful in Unquoted service path attact.
Get-CimInstance -ClassName win32_service | Select Name,State,PathName, StartMode | Where-Object {$_.PathName -notmatch "WINDOWS\\system32"}
# Check the permission of current user to that path.
icacls <PATH OF THE FOLDER>
# Check the restart permission of the binary
Get-CimInstance -ClassName win32_service | Select Name, StartMode | Where-Object {$_.Name -like '<NameOfTheService>'}
# If not then check the restart permission.
# Check for restart permission
whoami /priv # See the SeShutDownPrivilege. It must be enabled.
While checking the working of binary, if needed you can make a task.
Code for making User and creating executable file
Compiling the code
Now you can access the created account using below commands:
Directly Getting shell
Using automated tools
DLL Hijacking
Best source:
This has every thing mentioned here.
Common Technique used during DLL Hijacking
DLL Replacement
DLL Search Order Hijacking
Phantom DLL Hijacking
DLL Redirection
WinSxS DLL Replacement
Relative Path DLL Hijacking
DLL search order
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.
Initial checks
Creating User using DLL Hijacking
Now you can access the created account using the below commands:
Example attempt of DLL Hijacking
Others attempted, but failed in a specific scenario due to lacking permissions.
Before running .exe We need to check from were binary file is searching for the dll file named BetaLibrary.dll So, Let's copy file to WINPREP and start procmon as admin.



Example of DLL Hijacking and then getting shell.
Transfer the file.
we will transfer this file to our testing window and then will check for dll files.
start xfreerdp from this folder.
Start the powershell as administrator and run procmon on C:\Tools directory.

Before running this binary we have to create the service, for this binary. Because this is a service file and not a regular binary file.
Now you can see if there is any dll file that is missing.

Now we can perform binary hijacking steps.


Getting shell using DLL Hijacking
Example from Module exercise:
Unquoted Service Paths
Initial Check
Adding user by using exe file
Make exe file (Click here) and send it to the victim machine (Click here).
Using Getting Reverse shell using .exe file
Unoquoted service automated tool
Last updated