Service misconfigurations and unquoted paths

Unquoted Service Paths

Understanding the Attack

Think of it like this: You ask someone to "Run C:\Program Files\Vulnerable Application\service.exe" but you don't put quotes around it. The person hears this as separate words and tries to find what you mean:

  1. First they think: "Maybe you mean run a program called 'Program'"

  2. Then they think: "Maybe you mean run 'Program Files\Vulnerable'"

  3. Finally they understand: "Oh, you mean the full path"

This is exactly what Windows does with unquoted service paths.

How Windows Searches for Files

When Windows tries to start a service with this unquoted path:

C:\Program Files\Vulnerable Application\service.exe

Windows reads this left to right and treats each space as a potential "end of filename". Here's what actually happens:

Attempt 1: Windows takes everything before the first space

  • Tries to run: C:\Program.exe

  • Reasoning: "Maybe 'Program' is the executable name and everything after the space is parameters"

  • If C:\Program.exe exists β†’ Windows runs it and stops!

  • If not found β†’ continues to attempt 2

Attempt 2: Windows takes everything before the second space

  • Tries to run: C:\Program Files\Vulnerable.exe

  • Reasoning: "Maybe 'Vulnerable' is the executable name"

  • If C:\Program Files\Vulnerable.exe exists β†’ Windows runs it and stops!

  • If not found β†’ continues to attempt 3

Attempt 3: Windows takes everything before the third space

  • Tries to run: C:\Program Files\Vulnerable Application\service.exe

  • This is the legitimate service executable

A Real Example

Let's say you have a backup service configured like this:

An attacker who can write files to C:\Program Files\ could:

  1. Create a malicious file named Backup.exe

  2. Place it in C:\Program Files\Backup.exe

  3. When the service starts, Windows finds C:\Program Files\Backup.exe first

  4. Windows runs the attacker's file instead of the real backup software

  5. The malicious code now runs with SYSTEM privileges

The key insight: Windows executes the FIRST matching file it finds, not the intended one.

Why This Is Dangerous

The problem is clear: if an attacker can place a malicious file called Program.exe in C:\ or Some.exe in C:\Program Files\, their file will run instead of the real service. Since services often run with high privileges (like SYSTEM), the attacker's code inherits those same privileges.

Real-World Example

Consider this vulnerable service:

An attacker could place malicious files at:

  • C:\Program.exe (runs as SYSTEM)

  • C:\Program Files\Backup.exe (runs as SYSTEM)

When the service starts, Windows would execute the attacker's file with SYSTEM privileges instead of the real backup software.

Enumeration

Finding Vulnerable Services

Basic command to find unquoted paths:

This command:

  • Gets all services with their paths and start modes

  • Filters for auto-starting services (more valuable targets)

  • Excludes Windows system services (harder to exploit)

  • Excludes already quoted paths (not vulnerable)

PowerShell method for cleaner output:

Check specific service details:

Get service info from registry:

Verifying Exploitability

Just finding an unquoted path isn't enough. You need write access to the intermediate directories.

Test write permissions:

Use AccessChk for detailed analysis:

Exploitation Techniques

Creating the Malicious Executable

Simple user creation payload:

Compile the payload:

Alternative using MSFVenom:

Deployment and Execution

Place the malicious file:

Trigger service restart:

Or restart in one command:

If you can't restart the service manually, you can wait for a system reboot since auto-start services will trigger automatically.

Advanced Payloads

Reverse shell for interactive access:

Stealthy payload that maintains service functionality:


Service Misconfigurations

Types of Misconfigurations

Service misconfigurations occur when Windows services are set up with weak permissions. Unlike unquoted paths which exploit Windows' file search behavior, these vulnerabilities exist because administrators set incorrect permissions.

1. Writable Service Binaries

The service executable file itself can be modified by regular users.

2. Weak Registry Permissions

The registry keys that control service configuration can be modified.

3. Weak Service Control Permissions

Users can start, stop, or reconfigure services they shouldn't be able to control.

Enumeration

Finding Modifiable Services

Check service control permissions:

Find writable service binaries:

Check registry permissions:

Automated enumeration with PowerUp:

Attack Methods

Binary Replacement Attack

If you can write to the service executable, simply replace it with your malicious version.

Registry Modification Attack

If the service registry key is writable, change the ImagePath to point to your executable.

Service Configuration Attack

If you have service control permissions, reconfigure the service temporarily.

DLL Hijacking Attack

Some services load DLL files from their directory. If a DLL is missing and you can write to that directory, you can provide a malicious DLL.

Find missing DLLs using Process Monitor:

  1. Start Process Monitor

  2. Filter by the service process name

  3. Look for "NAME NOT FOUND" or "PATH NOT FOUND" entries for DLL files

Create and deploy malicious DLL:

Advanced Techniques

Token Impersonation

If you can control a service running as SYSTEM, use token impersonation tools to elevate your privileges.

Service Dependency Manipulation

Create a malicious service and make the target service depend on it.

Last updated

Was this helpful?