Skip to content

Lesson 3 of 9 · 25m

Unquoted Service Paths and Writable Path Components

Understand how Windows resolves ambiguous service command lines, where the attacker-controlled filenames appear, and how to fix the root cause.

Unquoted service paths feel antique until you find one on a hospital workstation or a build server installed by a vendor that has not updated its installer since Windows 7. The bug is not that spaces exist. The bug is that a path containing spaces is stored without quotes, forcing Windows to guess which whitespace-delimited prefix was intended. If an attacker can create one of those guesses, the service launches the wrong executable.

Read the ImagePath literally

sc.exe qc VendorAgent
BINARY_PATH_NAME   : C:\Program Files\Contoso Suite\agent\bin\agent.exe
SERVICE_START_NAME : LocalSystem

The correct form should quote the executable and leave arguments outside the quote:

"C:\Program Files\Contoso Suite\agent\bin\agent.exe" --service

Know the candidate filenames

For the example above, the resolution attempts are conceptually:

C:\Program.exe
C:\Program Files\Contoso.exe
C:\Program Files\Contoso Suite\agent\bin\agent.exe

Writable location is the exploit condition

The vulnerable string alone is not enough. Check ACLs for each candidate directory:

icacls "C:\"
icacls "C:\Program Files"

On a normally hardened host, standard users cannot create C:\Program.exe or write under Program Files. The classic escalation appears when installers weaken ACLs, applications install to user-writable directories, or legacy compatibility changes grant broad write access.

Validate without breaking production

In a lab, the safest proof is a benign executable that writes a marker file and exits, placed at the earliest writable candidate. Observe service start behavior, remove the proof, and restore any modified ACLs. In production, you can often prove exploitability through ACL analysis alone: the unquoted ImagePath plus write permission is already a broken authorization chain.

The fix is more than adding quotes once

Correct the service configuration:

sc.exe config VendorAgent binPath= "\"C:\Program Files\Contoso Suite\agent\bin\agent.exe\" --service"

Then audit the installer or deployment mechanism that created it. If the vendor reinstaller recreates the unquoted path every patch cycle, your remediation is temporary. Also remove the write permission that made the ambiguity exploitable; both controls matter, but quotes are the direct fix for the parsing bug.

Field notes

  • Arguments after the executable belong outside the closing quote. Quoting the entire command line can break legitimate service startup.
  • A quoted path with a writable executable is still vulnerable to binary replacement. These are separate findings that often coexist.
  • Environmental variables and relative paths in ImagePath create related ambiguity; expand and inspect the final command line rather than assuming correctness.

Was this lesson helpful?

Sign in to rate