Persistence
Windows Services
Windows services cheat sheet: Services key values (ImagePath, Start, Type, ServiceDll), 7045 and 4697 install events, PsExec traces and pitfalls.
- Location
- SYSTEM\ControlSet00x\Services\<ServiceName>
- Proves
- A service or driver was installed to run a binary, its account and start mode
- Timestamps
- Service key LastWrite as FILETIME, UTC; System 7045/7036 and Security 4697 TimeCreated in EVTX, UTC
- Retention
- Key persists until the service is deleted; System log rolls over by size; 4697 only if audited; PsExec-style services self-delete
- Access
- Administrator; SYSTEM hive locked live: reg save, VSS or raw NTFS with .LOG files; export EVTX with wevtutil
- Evidence of
- PersistenceExecution
- Type
- Registry
- Windows
- XPVista / 78 / 8.11011
- KAPE target
- RegistryHivesSystemEventLogs
- Velociraptor
- Windows.Triage.Targets:RegistryHivesSystemEventLogs
Tools
Compare all toolsWhat it is
Every Windows service and kernel driver is registered by the Service Control Manager (SCM) as a subkey of Services in the SYSTEM hive. The subkey holds the binary to run, the start mode and the account. Creating a service needs administrative rights, and auto-start services run as SYSTEM by default. That makes services a classic place for persistence, and remote service creation (PsExec, Impacket, sc \\host create) a classic lateral movement technique.
Services leave two kinds of evidence: the registry configuration, which shows what is installed now, and event log records of installation and state changes.
Location
| Source | Location | Windows versions |
|---|---|---|
| Service configuration | SYSTEM hive: ControlSet00x\Services\<ServiceName> (live: HKLM\SYSTEM\CurrentControlSet\Services) | All |
| svchost-hosted DLL | ...\Services\<ServiceName>\Parameters\ServiceDll (sometimes directly under the service key) | All |
| svchost groups | SOFTWARE hive: Microsoft\Windows NT\CurrentVersion\Svchost | All |
| Install event | System.evtx, Service Control Manager event 7045 | Vista and later |
| Install event (audit) | Security.evtx, event 4697 | Windows 10 / Server 2016 and later, with "Audit Security System Extension" |
| State changes | System.evtx, events 7034, 7036, 7040 | Vista and later |
Offline hives have no CurrentControlSet: read Select\Current to know which ControlSet00x was active (control set). The hive's .LOG1/.LOG2 transaction logs can hold recent changes that were not yet written to the hive.
What it proves
- A service or driver was configured to run a specific binary or command line, as a given account, with a given start mode.
- Installation time and account: 7045 records the name, image path, type, start type and account; 4697 also records the SID and logon ID of the account that installed it.
- Execution: 7036 shows the service entered the running state; 7034 shows it terminated unexpectedly.
- It does not prove who installed a service unless 4697 is available, and the registry alone does not prove the service ever started.
Key fields
| Value | Meaning |
|---|---|
ImagePath | Binary or full command line; drivers use \SystemRoot\... or System32\drivers\... |
Start | 0 boot, 1 system, 2 automatic, 3 manual (demand), 4 disabled |
DelayedAutostart | 1 = automatic (delayed start) |
Type | 0x1 kernel driver, 0x2 file system driver, 0x10 own process, 0x20 shared process (svchost) |
ObjectName | Account the service runs as (LocalSystem, NT AUTHORITY\LocalService, a user) |
DisplayName, Description | Free text; often copied from real services by attackers |
Parameters\ServiceDll | DLL loaded by svchost.exe for shared-process services |
FailureCommand | Command run by the SCM when the service fails (recovery action) |
Timestamps
| Timestamp | Set when | Format | Pitfalls |
|---|---|---|---|
| Service key LastWrite | Any value of the key changes | FILETIME, UTC | Reflects the latest change (start type, path), not necessarily creation |
| 7045 TimeCreated | SCM registers a new service | EVTX, UTC | Records the configuration at creation only |
| 4697 TimeCreated | New service installed, if audited | EVTX, UTC | Later changes to path or account are not logged |
| 7036 / 7034 / 7040 | State or start-type change | EVTX, UTC | 7036 is very noisy; filter by service name |
Retention and clearing
- The registry entry stays until the service is deleted (
sc delete). A deleted service leaves its 7045 record in the System log and, sometimes, older copies of the key in shadow-copy SYSTEM hives or unallocated hive space. - The System log rolls over by size; on busy servers 7045 records for older installs may be gone. Clearing the System log creates event 104; clearing the Security log creates 1102.
- 4697 is not generated unless the "Audit Security System Extension" subcategory is enabled.
- Tools like PsExec delete their service after use, so the registry may be clean while 7045, 7036 and the dropped binary's Prefetch remain.
Collection
- KAPE target:
RegistryHivesSystem(SYSTEM and SOFTWARE with transaction logs) andEventLogs. No dedicated services target exists. - Velociraptor (
Windows.Triage.Targets):RegistryHivesSystem,EventLogs. Live:Windows.System.Services;Windows.EventLogs.ServiceCreationComspecfinds 7045 records withCOMSPEC/cmd.exein the image path;Windows.Events.ServiceCreationmonitors 7045 in real time. - Built-in:
reg save HKLM\SYSTEM E:\case\SYSTEM.hiv
wevtutil epl System E:\case\System.evtx
Get-WinEvent -FilterHashtable @{LogName='System'; Id=7045} | Format-List TimeCreated, Message
Get-CimInstance Win32_Service | Select-Object Name, StartMode, StartName, PathName
Parsing tools
- Registry Explorer / RECmd (Eric Zimmerman): browse
Services; community batch files export service configuration to CSV. - RegRipper:
services,svcandsvcdllplugins (SYSTEM hive),svc_tlnfor timelines. - EvtxECmd (Eric Zimmerman): maps 7045, 7036, 7034, 7040 and 4697 to CSV.
- Velociraptor:
Windows.System.Services, with optional hashes and Authenticode checks. - Autoruns (Sysinternals, free): Services and Drivers tabs, including against an offline Windows directory.
- Plaso:
windows_servicesregistry plugin.
Investigation tips
- Hunt 7045 for image paths in
\Users\,\ProgramData\,\Windows\Temp\orADMIN$, forcmd.exe /cor%COMSPEC%command lines (typical of smbexec-style tools) and for random short service names. PSEXESVCin 7045 or in a service key points to Sysinternals PsExec; check for thePSEXESVC.EXEPrefetch file and a network logon just before.- For
svchostservices, the real payload isServiceDll, notImagePath: verify the DLL path and signature. - A service with
Type0x1 andStart0 or 1 is a driver loading at boot; unexpected ones may be rootkits or vulnerable drivers. - Compare 7045 with the current registry: a service present in the log but absent from the hive was removed after use.
- Tie the binary to Amcache (SHA-1) and look for parallel persistence in scheduled tasks and Run keys.
Related artifacts
- Scheduled TasksScheduled tasks cheat sheet: task XML and .job files, TaskCache registry keys, DynamicInfo times, hidden tasks, TaskScheduler and 4698 events.
- Run keys and Startup foldersRun keys and Startup folders cheat sheet: Run, RunOnce, Wow6432Node and Policies paths, StartupApproved enabled/disabled bytes, timestamps and pitfalls.
- Windows event logs (EVTX)Windows event log cheat sheet: EVTX locations, must-know event IDs for logons, processes, services and log clearing, retention, audit policy and parsing tools.
- Prefetch Files (.pf)Windows Prefetch cheat sheet: .pf location per version, run count, the last eight run times, referenced files, retention limits and how to parse.
- Amcache.hveAmcache.hve cheat sheet: file and program inventory keys, SHA-1 hashes, PE metadata, timestamps and why an entry alone does not prove execution.
- Registry hivesRegistry hives cheat sheet: SYSTEM, SOFTWARE, SAM, SECURITY, NTUSER.DAT, UsrClass.dat, transaction logs, RegBack, LastWrite times and collection.
- Remote access tools (RMM)RMM and remote access tool cheat sheet: AnyDesk, TeamViewer, ScreenConnect and more, their log files, connection IDs, IPs and timestamps, and how to hunt abuse.
- Group Policy artifactsGroup Policy cheat sheet: SYSVOL policies, Registry.pol, GPP passwords, client-side history and event logs, and how attackers abuse GPO for mass deployment.
- Installed Programs (Uninstall Keys, MSI, AppX)Installed programs cheat sheet: Uninstall keys, MsiInstaller events 1033/11707, cached MSIs, AppX packages, winget logs and Amcache to date software installs.
- Kernel Drivers (.sys, Driver Services, BYOVD)Kernel drivers cheat sheet: driver services (Type 1/2), event 7045, DriverStore, setupapi.dev.log, Amcache and CodeIntegrity logs to hunt BYOVD and rootkits.
Glossary terms
- PersistenceMechanisms that let malware or an attacker survive reboots and logoffs, such as Run keys, services, scheduled tasks or WMI subscriptions.
- Lateral movementAn attacker moving from one compromised host to others in the network, using RDP, SMB, PsExec, WMI, WinRM or remote tasks and services.
- ControlSet and CurrentControlSetThe numbered configuration sets in the SYSTEM hive; CurrentControlSet is a runtime link that does not exist in an offline hive file.
- Registry key LastWrite timeThe single FILETIME stored in every registry key that records when the key or one of its values was last changed, in UTC.
- Windows event IDThe number identifying an event type within a given provider; it only has meaning when paired with its provider and log channel.