Overview
The Unquoted Service Path check identifies Windows services where the executable path contains spaces but is not enclosed in quotes. This creates an ambiguity in how Windows interprets the path, potentially allowing an attacker to place a malicious executable that will be executed instead of the intended service binary.This vulnerability exists because Windows searches for executables by tokenizing paths at spaces when quotes are missing.
How It Works
When Windows tries to start a service with an unquoted path like:C:\Program.exeC:\Program Files\My.exeC:\Program Files\My App\service.exe
Technical Details
SharpUp:- Enumerates all services from registry
- Extracts the
ImagePathvalue - Checks if path:
- Doesn’t start with quotes
- Contains spaces
- Ends with .exe
- For each space in the path, checks if the parent directory is writable
- Reports services where malicious executables can be placed
Example Output
- MyApp service has unquoted path with spaces
- You can write to C:\ to create C:\Program.exe
- When MyApp service starts, Windows will execute C:\Program.exe first
- Service runs as SYSTEM, giving you SYSTEM privileges
Exploitation
Method 1: Exploit First Space
Method 2: Exploit Second Space
Method 3: Persistence via Unquoted Path
Method 4: Automatic Execution
Remediation
1
Identify Unquoted Service Paths
2
Quote Service Paths
3
Bulk Remediation
4
Secure Parent Directories
Even after quoting paths, ensure parent directories have proper permissions:
5
Verify Fix
Automated Remediation Script
Detection
Defensive Monitoring
Detection Strategies
- File System Monitoring
- Service Monitoring
- Configuration Auditing
- Monitor file creation in Program Files root
- Alert on .exe files in unusual locations (C:\Program.exe)
- Track file writes to directories containing unquoted service paths
Real-World Scenarios
Scenario 1: Third-Party Application
Scenario 1: Third-Party Application
Context: Third-party monitoring application installed with unquoted path:
C:\Program Files\Monitor Tool\service.exeVulnerable Directories:- C:\Program.exe (if writable)
- C:\Program Files\Monitor.exe (if writable)
- Standard user gains access
- Finds unquoted path via SharpUp
- Places malicious Program.exe in C:\
- Waits for service restart or reboot
- Service runs malicious Program.exe as SYSTEM
- Work with vendor to fix installer
- Manually quote service path
- Ensure C:\ is not writable by users
Scenario 2: Custom IT Service
Scenario 2: Custom IT Service
Context: IT team created custom service installed to
C:\Company Tools\Update Service\updater.exe with Automatic startup.Risk:- Can create C:\Company.exe
- Service restarts every boot
- Automatic privilege escalation
- Quote the path immediately
- Move service to standard Program Files location
- Ensure installation directory has proper permissions
Scenario 3: Legacy Application
Scenario 3: Legacy Application
Context: 10-year-old application with unquoted service path on 1,000 servers.Challenges:
- Vendor no longer supported
- Can’t easily update all servers
- Service critical for operations
- Quote paths via automated script
- Test on non-production servers first
- Deploy via GPO or SCCM
- Verify no application breakage
- Monitor for issues
Prevention Best Practices
Always Quote Paths
Developers: Always enclose service paths in quotes, even without spaces.
Install to Program Files
Install applications to standard protected locations.
Regular Audits
Periodically scan for and remediate unquoted paths.
Secure Permissions
Ensure root directories (C:) have proper write restrictions.
Development Best Practice
Related Checks
Modifiable Services
Services with weak DACL permissions
Modifiable Service Binaries
Service executables with weak file permissions
Hijackable Paths
Writable folders in system PATH
Remediation Guide
Comprehensive remediation guidance