8 - Unquoted Service Path
Topics
Introduction to the Windows Shells
Windows Permissions
Reverse Shells in Windows
SeImpersonatePrivilege Exploitation
On Cross Compilation
Windows Services
Weak Service Permissions
Unquoted Service Path
DLL Hijacking
Always Install Elevated
Files with Sensitive Data
Windows Hashes
Stored Credentials and the Windows Vault
Scheduled Task
Critical Registry Paths
Useful Tools
AMSI Bypass
Unquoted Service Path Vulnerability
The unquoted service path vulnerability arises when a Windows service binary's path contains spaces but lacks proper quotation marks. This leads the operating system to search for the service binary using a specific sequence of rules, potentially allowing an attacker to exploit the path traversal behavior.
When starting a service, Windows interprets its binary path as specified in the service configuration. If the path contains spaces and is unquoted, the system checks multiple potential executable paths in order, which can lead to unintended execution.
Example Service Configuration
If the above path is unquoted, Windows will attempt to execute the following binaries in this order:
C:\Users\Quickemu\Downloads\Example.exe
C:\Users\Quickemu\Downloads\Example Directory\Another.exe
C:\Users\Quickemu\Downloads\Example Directory\Another Directory\simpleService.exe
Attack Scenario
An attacker with write access to any of the intermediary directories can plant a malicious binary, such as Example.exe
. When the service starts, Windows will execute the malicious binary instead of the intended service binary.
Exploiting Unquoted Service Paths
Exploit Steps
Identify the Vulnerable Service View the service configuration:
Create a Malicious Binary Generate a reverse shell binary:
Place the Malicious Binary in a Targeted Path
Restart the Service
When the service restarts, Windows will execute Example.exe
instead of simpleService.exe
, effectively hijacking the service.
Additional Examples
Example 1
For the binary path:
The following binaries will be checked in order:
C:\Program.exe
C:\Program Files.exe
C:\Program Files (x86)\Company\Company.exe
C:\Program Files (x86)\Company\Company App\App.exe
Example 2
For the binary path:
The following binaries will be checked in order:
C:\Program\Cool.exe
C:\Program\Cool Company\Cool.exe
C:\Program\Cool Company\Cool Binary.exe
Enumeration of Unquoted Service Paths
Using winPEAS
winPEAS
can identify unquoted service paths.
Example Output
Look for the following indicators in the output:
Fixing the Vulnerability
Fix Using RegEdit
Open the Registry Editor (
regedit.exe
).Navigate to:
Locate the
ImagePath
key and add quotes around the binary path:
Fix Using sc.exe
Use the sc.exe
command to update the service path with quotes:
Other Resources
Disclaimer
❗ Never use tools and techniques on real IP addresses, hosts or networks without proper authorization!❗
Last updated