Skip to content
Caleb SmithCyberSecurityWithSmitti
Browse PowerShell example contentPowerShell example

Service executable-path review

Preserve raw service paths and flag unquoted-space candidates for further investigation.

How to use it

.\Get-SocServicePathReview.ps1 -MaxServices 2000

Platform and permissions

Windows CIM and service-query rights.

What changes / what is read

Reads service metadata and tests candidate path existence; no service is changed.

Scope and interpretation

Text parsing is conservative. Spaces alone do not establish exploitability. File-system rights, command-line resolution and service-control permissions need separate assessment.

Practice task

Compare quoted and unquoted lab paths and explain the evidence needed before claiming a vulnerability.

Reference

Microsoft documentation. Review the documentation for your installed version and use only an authorised learning or investigation environment.

This is personal educational material. Review the complete code and your signing policy before use. PowerShell code is displayed and downloaded as text; WordPress does not run it. Collection caps limit rows/files, not every provider’s wall-clock execution time.

PowerShell · PowerShell 5.1+ syntax target; Windows collectors require the stated Windows modules. Full Windows acceptance testing remains required.Download .ps1
#requires -Version 5.1
[CmdletBinding()]
param([ValidateRange(10,5000)][int]$MaxServices=2000)
if($env:OS -ne 'Windows_NT'){throw 'Windows service metadata is required.'}
$services=@(Get-CimInstance Win32_Service -OperationTimeoutSec 15 -ErrorAction Stop | Select-Object -First ($MaxServices+1))
$rows=@(foreach($svc in ($services | Select-Object -First $MaxServices)){
    $raw=[string]$svc.PathName;$candidate=$null;$quoted=$false
    if($raw -match '^\s*"([^"]+)"'){$candidate=$Matches[1];$quoted=$true}
    elseif($raw -match '^\s*(.+?\.exe)(?:\s|$)'){$candidate=$Matches[1]}
    $expanded=if($candidate){[Environment]::ExpandEnvironmentVariables($candidate)}else{$null}
    $unquotedSpace=([bool]$candidate -and !$quoted -and $candidate.Contains(' '))
    [pscustomobject]@{Name=$svc.Name;State=$svc.State;StartMode=$svc.StartMode;RunAs=$svc.StartName;RawPath=$raw;ExecutableCandidate=$expanded;PathParsingResolved=[bool]$candidate;UnquotedSpaceReview=$unquotedSpace;CandidateExists=if($expanded){Test-Path -LiteralPath $expanded -PathType Leaf}else{$null}}
})
[pscustomobject]@{CollectedUtc=[datetime]::UtcNow;ReachedServiceCap=($services.Count -gt $MaxServices);Services=$rows;Note='Conservative text parsing is not Windows command-line resolution. Unquoted spaces alone do not prove exploitability; directory permissions, executable search behaviour and service rights need separate checks. No service is modified.'}

Example code is displayed as text. Review it and test in your own lab before use.