Dev.to Security 🔐 Cybersecurity 👁 0

Unquoted service paths: the book's filter had false positives

The scenario is fictional. PowerShell and events come from the book (untested on Windows). Only the path-matching logic was tested, in Python, on synthetic strings. What you'll learn Three service weaknesse

The scenario is fictional. PowerShell and events come from the book (untested on Windows). Only the path-matching logic was tested, in Python, on synthetic strings.

What you'll learn

  • Three service weaknesses: unquoted path, writable binary, writable registry key
  • Detection: services.exe spawning non-standard paths, and 7045
  • Why the book's filter flags svchost.exe -k ...
  • Remediation with sc.exe config

The filter bug

The book's condition (not starting with a quote and containing a space) also matches standard services that merely have arguments, such as C:\Windows\system32\svchost.exe -k NetworkService -p. On synthetic data it returned 3 hits including a false one.

Better: require whitespace before the first .exe.

vuln = (not p.startswith('"')
        and re.match(r'^[^"]*?\s[^"]*?\.exe', p, re.I)
        and not re.match(r'^\S+?\.exe', p, re.I))

Only the two truly unquoted paths were flagged.

Fix

sc.exe config "VulnSvc" binPath= "\"C:\Program Files\App\svc.exe\""

Also tighten ACLs on binaries and service keys, and alert on any 7045 from a non-standard path.

Next: turning the web03 incident into a report.

Adapted from chapters 16 and 25 of my Japanese book on server defense.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.