Windows Services
SCM architecture, service types and start modes, svchost ServiceDll hosting, service creation telemetry, and malicious service persistence detection.
Incident response on a compromised server. The team finds a service named "WindowsFontDriverHost2" with description "Manages fonts for the desktop window manager." Binary path: C:\ProgramData\FontHelper\fonthost.exe. Start type: Automatic. Current state: Running. It was created 4 days ago at 2:37 AM — perfectly mimicking a legitimate Windows service name. Running it as SYSTEM. This is malware persistence via Windows Service — a classic technique because services auto-start, run as SYSTEM, and persist reboots.
SCM Architecture
Service Control Manager Architecture
══════════════════════════════════════════════════════════════════
Boot / System startup
│
▼
┌───────────────────────────────────────────────────────────┐
│ SCM (services.exe) │
│ The central service controller — runs at boot, SYSTEM │
│ │
│ Reads service database from registry: │
│ HKLM\SYSTEM\CurrentControlSet\Services\ │
│ │
│ For each AutoStart service: │
│ ├── Type 0x10 (Win32OwnProcess): spawns own exe │
│ ├── Type 0x20 (Win32ShareProcess): loads into svchost │
│ └── Type 0x01 (KernelDriver): loads driver │
└───────────────────────────────────────────────────────────┘
│
├──► spawns svchost.exe -k netsvcs -p (for Type 0x20)
│ svchost loads ServiceDll from registry
│
└──► spawns .exe (for Type 0x10)
Service Registry Structure
Every service has a key under HKLM\SYSTEM\CurrentControlSet\Services\:
| Registry Value | Description | Attacker target |
|---|---|---|
| ImagePath | Executable path (Type 0x10) or "svchost.exe -k groupname" (Type 0x20) | Change to malware binary path |
| Start | 0=Boot, 1=System, 2=Automatic, 3=Manual, 4=Disabled | Set to 2 (AutoStart) for persistence |
| Type | 0x10=OwnProcess, 0x20=ShareProcess, 0x01=KernelDriver | Usually 0x10 for malicious services |
| ObjectName | Account to run as (LocalSystem, LocalService, NetworkService, or domain account) | LocalSystem for max privileges |
| Description | Human-readable description (shown in services.msc) | Set to mimic legitimate service |
| Parameters\ServiceDll | For Type 0x20: actual DLL loaded by svchost | Replace DLL path for stealthy injection into svchost |
Svchost and ServiceDll Hosting
Many Windows services run inside shared svchost.exe processes (Type 0x20). The actual code is in a DLL specified by Parameters\ServiceDll. This is a stealthy persistence target:
HKLM\SYSTEM\CurrentControlSet\Services\wuauserv
Type = 0x20 (ShareProcess, runs in svchost)
ImagePath = %SystemRoot%\system32\svchost.exe -k netsvcs -p
Start = 2 (Automatic)
Parameters\
ServiceDll = %SystemRoot%\System32\wuaueng.dll ← attacker changes this
# Attacker replaces legitimate DLL path:
HKLM\...\Parameters\ServiceDll = C:\ProgramData\evil.dll
# Now svchost.exe loads evil.dll — malware runs inside trusted svchost.exe
Defenders often alert on services where ImagePath points to an unusual location. But ServiceDll hijacking points ImagePath at the legitimate svchost.exe — nothing unusual there. The malicious path is buried in Parameters\ServiceDll. Always check ServiceDll for svchost-hosted services, not just ImagePath.
Service Creation Telemetry
| Event ID | Channel | Description |
|---|---|---|
| 7045 | System | New service installed — ServiceName, ImagePath, StartType, AccountName |
| 7036 | System | Service entered running/stopped state |
| 7040 | System | Service start type changed (e.g., Disabled → Automatic) |
| 4697 | Security | A service was installed — mirrors 7045, requires audit policy |
| 4688 | Security | Process creation — sc.exe command line shows service creation parameters |
Sigma Rules
title: Suspicious Service Installed from Unusual Path
status: stable
logsource:
product: windows
service: system
definition: 'Event ID 7045'
detection:
selection:
EventID: 7045
filter_legit_paths:
ImagePath|startswith:
- 'C:\Windows\'
- 'C:\Program Files\'
- 'C:\Program Files (x86)\'
condition: selection and not filter_legit_paths
falsepositives:
- Software installation to non-standard paths
- Pentest tools (Metasploit creates a service)
level: high
tags:
- attack.persistence
- attack.t1543.003
title: ServiceDll Registry Value Modified
status: experimental
logsource:
product: windows
category: registry_set
definition: 'Sysmon Event ID 13'
detection:
selection:
TargetObject|contains: '\Services\'
TargetObject|endswith: '\Parameters\ServiceDll'
filter_installer:
Image|endswith: '\msiexec.exe'
condition: selection and not filter_installer
level: high
Q & A
Q: Event 7045 fires for a new service with ImagePath C:\Windows\System32\cmd.exe. Is this always malicious?
Very likely malicious. Legitimate services don't use cmd.exe as their binary — cmd.exe is an interactive shell, not a service executable. A service binary must implement the Service Control Handler protocol (RegisterServiceCtrlHandler, SetServiceStatus) — cmd.exe doesn't do this, so the service would either fail to start or start and immediately exit. The attacker may be using sc.exe to register a one-shot execution rather than persistent service: sc create evil binPath= "cmd.exe /c ...". Event 7045 with cmd.exe, powershell.exe, or wscript.exe as ImagePath should always be investigated. Even if the service fails to start, the registry key remains — malware may use the "install service" API call purely to achieve code execution once.