Services and Service Accounts
A Windows service is a program the Service Control Manager (SCM) starts without anyone signing in: at boot, on demand, or when a trigger fires. Services run backups, databases, agents and print queues, and they run with an identity: often LocalSystem, more powerful than any administrator, and in domains often a domain user account with a password that someone typed into a dialog years ago. That makes services a double target. Whoever can change a service's program runs code as its identity, and whoever learns a service account's password can use it everywhere the account has rights. This lesson reviews both, using a synthetic export of a server's services.
Service basics (states, start types, sc.exe, Get-Service) are in Windows Services and PowerShell on Windows; the Registry location HKLM\SYSTEM\CurrentControlSet\Services is in The Windows Registry and Event Log.
Service identities, from most to least dangerous
Identity (StartName) |
Network identity | Risk |
|---|---|---|
| a member of Domain Admins | itself, everywhere | a compromise of this one server is a compromise of the domain; never acceptable |
a domain user account with a password (CORP\svc-sql) |
itself | password often old, never rotated, reused on several servers; if it has an SPN it is Kerberoastable (Kerberoasting) |
LocalSystem |
the computer account (SQL01$) |
full control of the machine; fine for OS components, too much for most applications |
NT AUTHORITY\NetworkService / LocalService |
computer account / anonymous | low privilege, but shared by many services and holding SeImpersonatePrivilege |
virtual account NT SERVICE\<name> |
computer account | one identity per service, no password to manage: the default for local-only needs |
group managed service account CORP\gmsa-sql$ |
itself | long random password generated and rotated by AD automatically: the right choice for domain services (LAPS and gMSA) |
Misconfigurations a reviewer looks for
- Unquoted path with spaces. For
C:\Program Files\Lab Agent\agent.exewithout quotes, the SCM triesC:\Program.exe, thenC:\Program Files\Lab.exe, then the real file. If any of those earlier locations is writable by users, a planted program runs as the service. Quoting the path removes the ambiguity. - Writable program or folder. If ordinary users can modify the service's executable or its folder, they can replace it. Typical cause: software installed into
C:\ToolsorC:\Users\Public, which inherit user-writable ACLs. - Weak service ACL. The service object itself has a security descriptor; if
Authenticated Usersmay change its configuration (SERVICE_CHANGE_CONFIG), anyone can point it at another program. Sysinternals AccessChk andsc.exe sdshowshow it. - Over-privileged identity: a domain admin or a reused user account, as in the table.
Reviewing an export
The input below is shaped like Get-CimInstance Win32_Service | Select-Object Name, PathName, StartName, StartMode | ConvertTo-Json run on the lab's SQL01.corp.lab.test, plus a list of folders that the review found writable by BUILTIN\Users (in a real review that list comes from AccessChk or Get-Acl). The script applies the four checks and prints one line per finding.
$services = @'
[
{"Name":"MSSQLSERVER","PathName":"\"C:\\Program Files\\Microsoft SQL Server\\sqlservr.exe\" -sMSSQLSERVER","StartName":"CORP\\svc-sql","StartMode":"Auto"},
{"Name":"LabAgent","PathName":"C:\\Program Files\\Lab Agent\\agent.exe --service","StartName":"LocalSystem","StartMode":"Auto"},
{"Name":"ReportSync","PathName":"C:\\Tools\\reportsync.exe","StartName":"CORP\\adm-reports","StartMode":"Auto"},
{"Name":"Spooler","PathName":"C:\\Windows\\System32\\spoolsv.exe","StartName":"LocalSystem","StartMode":"Auto"},
{"Name":"WebCache","PathName":"C:\\Windows\\System32\\svchost.exe -k webcache","StartName":"NT SERVICE\\WebCache","StartMode":"Manual"},
{"Name":"BackupAgent","PathName":"\"C:\\Program Files\\Backup\\bkagent.exe\"","StartName":"CORP\\gmsa-backupquot;,"StartMode":"Auto"}
]
'@ | ConvertFrom-Json
$userWritable = @('C:\Tools', 'C:\Program Files\Lab Agent') # from the ACL review
$domainAdmins = @('CORP\adm-reports') # from the group export
function Get-Exe([string]$path) {
if ($path.StartsWith('"')) { return $path.Substring(1, $path.IndexOf('"', 1) - 1) }
if ($path -match '^(.+?\.exe)') { return $Matches[1] }
return $path
}
foreach ($s in $services | Sort-Object Name) {
$exe = Get-Exe $s.PathName
$findings = @()
if (-not $s.PathName.StartsWith('"') -and $exe.Contains(' ')) { $findings += 'unquoted path with spaces' }
$dir = $exe.Substring(0, $exe.LastIndexOf('\')) # Split-Path would use '/' on Linux
if ($userWritable -contains $dir) { $findings += "program folder writable by Users ($dir)" }
if ($domainAdmins -contains $s.StartName) { $findings += 'runs as a Domain Admin' }
elseif ($s.StartName -like 'CORP\*' -and -not $s.StartName.EndsWith('