Summery

A Windows Service is a long-running background executable or application managed by the Service Control Manager and is similar to the concept of daemons on Unix systems.

They can be controlled using:

  • Services app (GUI)
  • PowerShell
  • sc.exe (CLI)

Each service runs as a user account that determines its permissions:

  • LocalSystem - Very powerful, almost full system access
  • Network Service - Limited account, can access network resources
  • Local Service - Very limited local permissions
  • Custom user - A specific local/domain account chosen by the creator
    The account decides what the service is allowed to do.

Commands

For Windows services, these are the main commands worth remembering:

ActionPowerShellCMD
List servicesGet-Servicesc.exe query
All servicesGet-CimInstance Win32_Servicesc.exe query type= service state= all
Running onlyGet-Service | ? Status -eq Runningsc.exe query state= active
Status(Get-Service mysql).Statussc.exe query mysql
StartStart-Service mysqlsc.exe start mysql
StopStop-Service mysqlsc.exe stop mysql
RestartRestart-Service mysqlsc.exe stop mysql + sc.exe start mysql
DisableSet-Service mysql -StartupType Disabledsc.exe config mysql start= disabled
EnableSet-Service mysql -StartupType Automaticsc.exe config mysql start= auto
Service detailsGet-Service mysql | Format-List *sc.exe qc mysql
Startup type(Get-Service mysql).StartTypesc.exe qc mysql
Dependencies(Get-Service mysql).ServicesDependedOnsc.exe qc mysql
Dependents(Get-Service mysql).DependentServicessc.exe qc mysql
Service executableGet-CimInstance Win32_Service -Filter "Name='mysql'" | select PathNamesc.exe qc mysql
Note:
sc.exe is the naming used in PowerShell to run that CMD command. Inside CMD, you can refer to it as sc. This issue exists, because in PowerShell sc means Set-Content.

Resources

Some well-known attack paths conneced to services are: