Skip to main content

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:
Windows will search for executables in this order:
  1. C:\Program.exe
  2. C:\Program Files\My.exe
  3. C:\Program Files\My App\service.exe
If an attacker can write to any of the earlier locations, they can execute arbitrary code.

Technical Details

SharpUp:
  1. Enumerates all services from registry
  2. Extracts the ImagePath value
  3. Checks if path:
    • Doesn’t start with quotes
    • Contains spaces
    • Ends with .exe
  4. For each space in the path, checks if the parent directory is writable
  5. Reports services where malicious executables can be placed

Example Output

Interpretation:
  • 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

Should return no vulnerable services.

Automated Remediation Script

Detection

Defensive Monitoring

Detection Strategies

  • 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

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)
Attack:
  1. Standard user gains access
  2. Finds unquoted path via SharpUp
  3. Places malicious Program.exe in C:\
  4. Waits for service restart or reboot
  5. Service runs malicious Program.exe as SYSTEM
Prevention:
  • Work with vendor to fix installer
  • Manually quote service path
  • Ensure C:\ is not writable by users
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
Solution:
  • Quote the path immediately
  • Move service to standard Program Files location
  • Ensure installation directory has proper permissions
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
Approach:
  1. Quote paths via automated script
  2. Test on non-production servers first
  3. Deploy via GPO or SCCM
  4. Verify no application breakage
  5. 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

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

References

Microsoft Docs

Service Security and Access Rights

MITRE ATT&CK

T1574.009 - Hijack Execution Flow: Path Interception by Unquoted Path