Leveraging Windows Services

Service Binary Hijacking

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

174B
Open

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

  1. The directory from which the application loaded.

  2. The system directory.

  3. The 16-bit system directory.

  4. The Windows directory.

  5. The current directory.

  6. The directories that are listed in the PATH environment variable.

Initial checks

Best way to analysis the service is to copy it in own system and then run it.

To determine the Path we need to copy it to own system and run it.

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.

Insufficient Permission.

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.

Missing DLL is here

Now we can perform binary hijacking steps.

Look at the permission of the binary file.
Got the shell

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

Automated tools add user as:

username: john

password: Password123!

Last updated