Windows Services
Service Binary Hijacking
Steps
Check the services (detect which are in unusual folders)
Check our permissions in those folders
Create a malicious.exe
Remplace the .exe
Restart the service
To get a list of all installed Windows services, we can choose various methods such as the GUI snap-in services.msc, the Get-Service Cmdlet, or the Get-CimInstance Cmdlet (superseding Get-WmiObject).
List of services with binary path
Get-CimInstance -ClassName win32_service | Select Name,State,PathName | Where-Object {$_.State -like 'Running'}Enumerate the permissions
Next, let's enumerate the permissions on both service binaries. We can choose between the traditional icacls Windows utility or the PowerShell Cmdlet Get-ACL. For this example, we'll use icacls since it usable both in PowerShell and the Windows command line.
Permissions Table
F
Full access
M
Modify access
RX
Read and execute access
R
Read-only access
W
Write-only access
Permissions Abuse
Let's create a small binary on Kali, which we'll use to replace the original .exe
adduser.c
Compiling
Copy the file
Execution
or
If the service StartMode is auto:
Verify that the user have the SeShutdown privilege:
Automated Tools
PowerView
SharpUp
We can use SharpUp from the GhostPack suite of tools to check for service binaries suffering from weak ACLs.
DLL Hijacking
If there is an uncommon path for any service check the permissions after
Check the file locally
Download the .exe of the service
Create the service and start it locally
Open Process Monitor and use this filters:

If .dll is found it is vulnerable
customdll.cpp
Compiling customdll.cpp
Copy the .dll file to the desired path.
Unquoted Service Path
When a service is installed, the registry configuration specifies a path to the binary that should be executed on service start. If this binary is not encapsulated within quotes, Windows will attempt to locate the binary in different folders. Take the example binary path below.
Service Binary Path
Windows will decide the execution method of a program based on its file extension, so it's not necessary to specify it. Windows will attempt to load the following potential executables in order on service start, with a .exe being implied:
C:\ProgramC:\Program FilesC:\Program Files (x86)\SystemC:\Program Files (x86)\System Explorer\service\SystemExplorerService64
Enumerate running and stopped services
Searching for Unquoted Paths (cmd)
Check if we can start / stop the service
Check the permissions to write
Craft the malicious.exe
Use the adduser.c file created in Permissions Abuse
Copy the malicious .exe
Start the service
After the error, check if succesfull. The error stems from the fact that our cross-compiled C code does not accept the parameters that are a leftover of the original service binary path. However, Current.exe was still executed
Automated Tools
PowerView
Scheduled tasks
Search
Check the permissions
Copy the file
Last updated