Skip to main content

Windows Services

Introduction​

Windows services are programs that run in the background, independently of user sessions. They provide essential functionalities to the system.

Characteristics of Services​

Differences with applications​

CharacteristicApplicationService
InterfaceGenerally graphicalNo interface (or limited)
SessionLinked to a userIndependent
StartupManual by the userAutomatic at boot
ExecutionDuring the sessionContinuous in the background

Startup types​

TypeDescription
AutomaticStarts at system boot
Automatic (Delayed)Starts after boot, with delay
ManualStarts only on demand
DisabledCannot start

Service accounts​

AccountPrivilegesUsage
LocalSystemFull (admin)Critical system services
LocalServiceLimited, local onlyLow-privilege services
NetworkServiceLimited, network accessServices requiring network
User accountAccording to the accountCustom services

Management via GUI​

Services.msc​

Win+R > services.msc

Available information:

  • Service name and description
  • Status (Running, Stopped)
  • Startup type
  • Execution account

Task Manager​

Services tab for quick view.


Management via PowerShell​

List services​

# All services
Get-Service

# Running services
Get-Service | Where-Object {$_.Status -eq "Running"}

# Search by name
Get-Service -Name "*update*"

# With WMI details
Get-WmiObject Win32_Service | Select-Object Name, DisplayName, State, StartMode, PathName

Start/Stop services​

# Start
Start-Service -Name "ServiceName"

# Stop
Stop-Service -Name "ServiceName"

# Restart
Restart-Service -Name "ServiceName"

# With confirmation
Stop-Service -Name "Spooler" -Confirm

Change startup type​

# Set to automatic
Set-Service -Name "ServiceName" -StartupType Automatic

# Disable
Set-Service -Name "ServiceName" -StartupType Disabled

Create a service​

# Create a new service
New-Service -Name "MyService" `
-BinaryPathName "C:\path\to\program.exe" `
-DisplayName "My Custom Service" `
-Description "Service description" `
-StartupType Manual

# Delete (via sc.exe)
sc.exe delete "MyService"

Management via CMD​

SC Command (Service Control)​

:: List services
sc query

:: Service status
sc query "ServiceName"

:: Start
sc start "ServiceName"

:: Stop
sc stop "ServiceName"

:: Configure startup
sc config "ServiceName" start= auto
sc config "ServiceName" start= disabled

:: Create a service
sc create "MyService" binPath= "C:\path\program.exe"

:: Delete
sc delete "MyService"

NET Command​

:: Start
net start "ServiceName"

:: Stop
net stop "ServiceName"

Important System Services​

Critical Services​

ServiceShort nameRole
Windows UpdatewuauservUpdates
Windows DefenderWinDefendAntivirus
Remote Procedure CallRpcSsSystem communication
DCOM Server Process LauncherDcomLaunchDCOM activation
Windows Event LogEventLogLogging
Task SchedulerScheduleScheduled tasks
Print SpoolerSpoolerPrinting

Network Services​

ServiceShort nameRole
DHCP ClientDhcpAutomatic IP configuration
DNS ClientDnscacheName resolution
Windows FirewallmpssvcFirewall
Remote Desktop ServicesTermServiceRemote desktop
ServerLanmanServerFile sharing
WorkstationLanmanWorkstationAccess to shares

Service Security​

Risks​

  1. Vulnerable services:

    • Modifiable executables
    • Too broad permissions
    • Over-privileged accounts
  2. Attack vectors:

    • Binary replacement
    • DLL Hijacking
    • Unquoted service path

Security checks​

# Check unquoted paths
Get-WmiObject Win32_Service | Where-Object {
$_.PathName -notmatch '^"' -and
$_.PathName -match ' '
} | Select-Object Name, PathName

# Check executable permissions
Get-WmiObject Win32_Service | ForEach-Object {
$path = $_.PathName -replace '"', '' -replace ' .*', ''
if (Test-Path $path) {
Get-Acl $path | Select-Object @{N='Service';E={$_.Name}}, Path, Owner
}
}

Hardening​

  1. Principle of least privilege:

    • Use LocalService or NetworkService rather than LocalSystem
    • Create dedicated service accounts
  2. Protect binaries:

    • Restrictive permissions on executables
    • Quoted paths
  3. Disable unnecessary services:

    • Remote Registry
    • Print Spooler (if no printing)
    • Telnet (obsolete)

Service Dependencies​

Understanding dependencies​

A service may depend on other services to function.

# View service dependencies
Get-Service -Name "ServiceName" -DependentServices

# Services this service depends on
Get-Service -Name "ServiceName" -RequiredServices

Example: Print Spooler​

Print Spooler
├── Depends on: Remote Procedure Call (RPC)
└── Dependent services: (often none)

Service Logging​

Event Log​

# Service-related events
Get-WinEvent -FilterHashtable @{
LogName = 'System'
ProviderName = 'Service Control Manager'
} -MaxEvents 20 | Format-Table TimeCreated, Message -Wrap

Important Event IDs​

Event IDDescription
7000Service failed to start
7001Service depends on a service that did not start
7009Timeout at startup
7034Service terminated unexpectedly
7035Start/stop request sent
7036Service started or stopped

Exercises​

  1. List all running services on your system
  2. Identify services running under LocalSystem
  3. Find services with unquoted paths
  4. Create a test service and delete it

References​