Unquoted Service Path

A Windows service's executable path contains spaces but is not quoted, so Windows may run a program planted earlier in that path with the service's privileges.

SeverityMedium
CVSS 3.16.7 CVSS:3.1/AV:L/AC:H/PR:L/UI:R/S:U/C:H/I:H/A:H Open in the calculator
CVSS 4.05.4 CVSS:4.0/AV:L/AC:L/AT:P/PR:L/UI:P/VC:H/VI:H/VA:H/SC:N/SI:N/SA:N Open in the calculator
CWECWE-428: Unquoted Search Path or Element
MITRE ATT&CKT1574.009 Path Interception by Unquoted Path
CategorySecurity Misconfiguration

Description

The path to a Windows service's executable, held in the service's ImagePath registry value, contains spaces but is not enclosed in quotation marks. When the service starts, Windows cannot tell where the file name ends and the arguments begin, so it tries each space-separated part of the path in turn, adding .exe. For a service installed at C:\Program Files\Vendor App\Service Host\svc.exe, Windows first looks for C:\Program.exe, then C:\Program Files\Vendor.exe, and so on, before it reaches the intended file.

The weakness can be exploited only where a standard user can write to one of the directories searched first. The system drive's root folder and C:\Program Files do not allow this by default, but software installed into a folder created elsewhere, such as directly under the system drive, often inherits permissions that let any authenticated user create files there. A local user without administrative rights can then plant a program at one of the earlier candidate paths, which Windows runs in place of the service, with the service account's privileges, the next time the service starts. Most affected services run as LocalSystem, so this normally gives full control of the host, including access to stored credentials and the ability to disable security tools. Exploitation needs local access and usually a service restart or reboot, which the attacker may have to wait for. Where no directory in the path is writable by unprivileged users, the weakness cannot be exploited until permissions change, but it remains a latent risk.

Unquoted paths are found by reviewing the service configuration, for example with sc qc or Get-CimInstance Win32_Service, and are reported by credentialed vulnerability scans and by local enumeration tools such as WinPEAS and PowerUp. Testing then establishes whether any directory in the path is writable by unprivileged users, and whether those users can restart the service or must wait for a reboot.

Remediation

Correct the service definition and the permissions around it:

  • Enclose the executable path in double quotation marks in the service's ImagePath value, under HKLM\SYSTEM\CurrentControlSet\Services in the key named after the service, leaving any arguments outside the quotation marks. The same change can be made with sc.exe config and its binPath= option.
  • Report the defect to the software vendor so that the installer quotes the path, and check again after upgrades or reinstallation, which may restore the unquoted value.
  • Remove write access for non-administrative users from every directory in the path, and install services under C:\Program Files where possible.

A corrected value looks like this:

"C:\Program Files\Vendor App\Service Host\svc.exe" -service

As an interim measure, removing write access for users from the intermediate directories prevents exploitation until the path is corrected. Confirm the fix by listing services again and checking that no service path containing a space is unquoted, and that no directory in any service path is writable by standard users.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Windows and Linux Hosts Findings

Every Windows and Linux Hosts finding