Category: Digital Forensics
Tags: windows-services, forensics, event-logs, persistence, lateral-movement
Windows services are the background workforce of the operating system -- hundreds of processes running silently, doing everything from managing your network stack to updating your desktop wallpaper on a schedule nobody asked for. They start automatically, run with elevated privileges, and most administrators couldn't name half of them on a good day.
Which makes them absolutely perfect for attackers.
Services offer persistence that survives reboots, execution with SYSTEM-level privileges, and the kind of anonymity that comes from hiding in a crowd of 300 identical-looking entries. Fortunately, Windows is pathologically incapable of keeping quiet about service activity. Every service installation, modification, and failure leaves forensic evidence scattered across the registry, event logs, and file system -- if you know where to look.
How Windows Services Work
A service is a long-running executable managed by the Service Control Manager (SCM). Unlike regular applications, services run in their own session (Session 0), have no user interface, and can start before anyone logs in.
Service Types
| Type | Value | Description |
|---|---|---|
| Kernel Driver | 0x01 | Loaded by the boot loader |
| File System Driver | 0x02 | File system driver |
| Win32 Own Process | 0x10 | Runs in its own process -- most common for malware |
| Win32 Share Process | 0x20 | Shares svchost.exe with other services |
| Interactive | 0x100 | Can interact with desktop (deprecated, still abused) |
Service Start Types
| Start Type | Value | When It Starts |
|---|---|---|
| Boot | 0 | Loaded by boot loader (drivers only) |
| System | 1 | Loaded during kernel initialisation |
| Automatic | 2 | Started by SCM at boot -- the persistence favourite |
| Manual | 3 | Started on demand |
| Disabled | 4 | Cannot be started |
Attackers overwhelmingly prefer Automatic (Type 2) or Manual (Type 3) start. Automatic provides guaranteed persistence. Manual allows on-demand execution triggered by the attacker without the noise of running constantly.
Registry: The Service Census
Every installed service has a registry key under:
HKLM\SYSTEM\CurrentControlSet\Services\<ServiceName>
Key Registry Values
| Value | What It Contains | Forensic Significance |
|---|---|---|
ImagePath |
Path to executable or command line | The most important value. Malicious services point to unusual locations |
Start |
Start type (0-4) | Automatic (2) = persistence mechanism |
Type |
Service type | Own Process (0x10) is most common for malware |
ObjectName |
Account the service runs as | LocalSystem = maximum privileges |
DisplayName |
Human-readable name | Often mimics legitimate services |
Description |
Service description | Sometimes left blank by lazy attackers |
FailureActions |
What happens on crash | Can be abused to execute commands on "failure" |
DependOnService |
Service dependencies | Rarely set by malware |
Suspicious ImagePath Patterns
The ImagePath value is where most investigations start and end. Legitimate services point to C:\Windows\System32\ or C:\Program Files\. Anything else warrants scrutiny.
# Legitimate examples
%SystemRoot%\System32\svchost.exe -k netsvcs
"C:\Program Files\Windows Defender\MsMpEng.exe"
# Suspicious examples
C:\Users\Public\svchost.exe # Right name, wrong neighbourhood
C:\Windows\Temp\update.exe # Temp directory = red flag
cmd.exe /c powershell -enc BASE64BLOB # PowerShell encoded command as a service
C:\ProgramData\Microsoft\Crypto\RSA\svhost.exe # Note: svhost, not svchost
\\10.10.10.5\share\payload.exe # UNC path -- lateral movement
Registry Timestamps
Registry key last-write timestamps tell you when a service was installed or last modified. Cross-reference with Event Log analysis to build a timeline.
# Extract service registry data with RECmd
RECmd.exe -d C:\Evidence\SYSTEM --bn .\BatchExamples\Services.reb --csv C:\Output\
Event Logs: The Audit Trail
Windows logs service activity across multiple event sources. The combination of System and Security logs provides both the "what" and the "who."
Event ID 7045 -- New Service Installed
The single most important event for detecting malicious service creation. Logged in the System event log.
| Field | Description |
|---|---|
| Service Name | Internal service name |
| Service File Name | The ImagePath -- the executable or command |
| Service Type | Kernel driver, own process, share process |
| Service Start Type | Boot, System, Automatic, Manual, Disabled |
| Service Account | LocalSystem, NetworkService, or specific account |
<!-- Example: PsExec service creation -->
<Event>
<System>
<EventID>7045</EventID>
<TimeCreated SystemTime="2024-03-15T14:22:33.1234567Z"/>
</System>
<EventData>
<Data Name="ServiceName">PSEXESVC</Data>
<Data Name="ImagePath">%SystemRoot%\PSEXESVC.exe</Data>
<Data Name="ServiceType">user mode service</Data>
<Data Name="StartType">demand start</Data>
<Data Name="AccountName">LocalSystem</Data>
</EventData>
</Event>
Known Attack Tool Service Patterns
| Tool | Service Name | ImagePath Pattern | Start Type |
|---|---|---|---|
| PsExec | PSEXESVC |
%SystemRoot%\PSEXESVC.exe |
Manual |
| Metasploit | Random 7-char | Random path in %TEMP% |
Manual |
| Cobalt Strike | Varies (configurable) | PowerShell encoded command or DLL | Automatic |
| Impacket smbexec | BTOBTO (default) |
cmd.exe /Q /c commands |
Manual |
| Impacket atexec | Via scheduled task | cmd.exe with output redirect | N/A |
| CrackMapExec | Random | cmd.exe /Q /c commands |
Manual |
PsExec's PSEXESVC is so well-known that attackers routinely rename it. The service still creates Event ID 7045, but with a different name. Look for the execution pattern: service created, short-lived, then deleted.
Additional Service Events
| Event ID | Log | What It Records |
|---|---|---|
| 7045 | System | New service installed (name, path, type, account) |
| 7034 | System | Service crashed unexpectedly |
| 7035 | System | Service sent start/stop control |
| 7036 | System | Service entered running/stopped state |
| 7040 | System | Service start type changed |
| 4697 | Security | Service installed (includes installing user SID) |
| 4688 | Security | Process creation (if audit policy enabled) |
Event ID 4697 in the Security log is the better forensic source because it records who installed the service (the account SID), not just what was installed. However, it requires "Audit Security System Extension" to be enabled -- which in many environments, it isn't.
Common Service-Based Attack Patterns
Pattern 1: Lateral Movement via PsExec
PsExec copies its service binary to the target's ADMIN$ share, creates a service, runs the command, then cleans up. The cleanup often leaves traces:
- Event 5140 (Security) -- Network share
\\*\ADMIN$accessed - Event 7045 (System) --
PSEXESVCservice created - Event 7036 (System) -- Service started, then stopped
- Prefetch --
PSEXESVC.EXE-*.pfmay persist even after binary deletion - Registry -- Service key may linger if cleanup fails
- Event 7045 with the full command path
- Registry key under
HKLM\SYSTEM\CurrentControlSet\Services\backdoor - If the binary is a DLL:
svchost.exeloads it, making process-based detection harder - Compare service DLL paths against a known-good baseline
- Check for DLLs in non-standard directories loaded by
svchost.exe - Sysmon Event ID 7 (Image Loaded) records DLL loads with hashes
- Create a service that immediately exits (fails)
- Configure
FailureActionsto run their payload on first failure - The payload executes with the service account's privileges
- Windows Forensics 101: The Registry -- the registry hives where service keys live
- Windows Forensics 104: Event Logs -- the logs that record service activity
- Incident Response 103: Ransomware -- ransomware frequently installs as a service
- Offensive Security 101: Attack Lifecycle -- where service abuse fits in the kill chain
Pattern 2: Persistence via New Service
sc create backdoor binPath= "C:\ProgramData\update.exe" start= auto obj= LocalSystem
Leaves:
Pattern 3: Service DLL Hijacking
Rather than creating a new service, attackers replace or add a DLL loaded by an existing service. The service itself is legitimate -- only its payload has changed.
Detection approach:
Pattern 4: Service Failure Abuse
The FailureActions registry value can specify a command to run when a service "fails." An attacker can:
This bypasses some monitoring that only watches ImagePath.
Triage and Investigation
Quick Service Audit with PowerShell
# List services with unusual image paths
Get-WmiObject Win32_Service | Where-Object {
$_.PathName -and
$_.PathName -notmatch 'System32|SysWOW64|Program Files'
} | Select-Object Name, DisplayName, PathName, StartMode, State |
Format-Table -AutoSize
# Services running as SYSTEM from non-standard paths
Get-WmiObject Win32_Service | Where-Object {
$_.StartName -eq 'LocalSystem' -and
$_.PathName -notmatch 'System32|SysWOW64|Program Files|Windows'
} | Select-Object Name, PathName
# Recently created services (registry timestamp)
Get-ChildItem 'HKLM:\SYSTEM\CurrentControlSet\Services' |
Sort-Object LastWriteTime -Descending |
Select-Object PSChildName, LastWriteTime -First 20
Offline Analysis with Eric Zimmerman Tools
# Parse SYSTEM hive for service entries
RECmd.exe -d C:\Evidence\SYSTEM --bn BatchExamples\Services.reb --csv C:\Output\
# Timeline service creation alongside event logs
EvtxECmd.exe -d C:\Evidence\winevt\Logs\ --csv C:\Output\ --csvf events.csv
# Filter for EventID 7045, 4697 in the output
Service Stacking Across the Enterprise
On a single system, one unusual service could be anything. Across an enterprise, a service that exists on exactly one machine is either the most interesting thing in the investigation or the IT department's pet project. Either way, it deserves attention.
# Collect service lists from multiple hosts, then stack:
# - Services present on only 1-2 hosts = investigate
# - Services with random names = investigate
# - Services running from user-writable directories = investigate




