Skip to content
WETNav

PersistenceHigh

Service persistence

Also known as Malicious service install, New service persistence

Installing a Windows service that auto-starts attacker code as SYSTEM. System 7045 and Security 4697 record the install.

Signals in the logs

  1. 01System7045A service was installed in the systemAny host

    A new service was installed by the Service Control Manager.

    ServiceName
    name of the installed service
    ImagePath
    the binary or command the service runs
    StartType
    auto start / demand start
    AccountName
    account the service runs as, often LocalSystem
  2. 02Security4697A service was installed in the systemAny host

    A service was installed (Security log equivalent, when enabled).

    ServiceName
    name of the installed service
    ServiceFileName
    the service image path or command
    ServiceAccount
    account the service runs as
  3. 03System7040Service start type was changedAny host

    A service start type was changed, e.g. a disabled defensive service set to disabled or a dormant service set to auto.

    param1
    service display name
    param4
    new start type

What happens

A Windows service runs automatically at boot, typically as LocalSystem, which makes a new service a durable, high-privilege persistence mechanism. An operator installs one with sc.exe create, the New-Service cmdlet, or direct writes under HKLM\SYSTEM\CurrentControlSet\Services, pointing the ImagePath at their binary or at cmd.exe/powershell.exe running a payload. The install is well audited: the Service Control Manager writes System 7045 with the service name, image path, service type, and start type; Security 4697 records the same install when the Security System Extension subcategory is enabled. Because 7045 is written to the System log by default, it frequently survives when the Security log has been cleared, making it one of the most reliable persistence and lateral-movement indicators.

Logging you need

  • System 7045 is written by default and needs no audit policy.
  • Security 4697 requires the Audit Security System Extension subcategory, which is off by default.
  • ImagePath pointing at cmd.exe, powershell.exe, rundll32.exe, or a user-writable path is the detail that separates benign from suspect.

Hunt queries

Starting points. Tune thresholds and exclusions to your environment before alerting on them.

Get-WinEvent -FilterHashtable @{LogName='System'; ProviderName='Service Control Manager'; Id=7045}

Benign look-alikes

  • Legitimate software installs that register drivers or background services.
  • Management agents, antivirus, and backup tools that install services.
  • Administrative tools such as PsExec, whose PSEXESVC service is benign when run by your own staff.

Notes

  • An ImagePath beginning %COMSPEC% /Q /c echo is the smbexec pattern; see the smbexec lateral technique.
  • A short-lived service created and deleted within seconds is typical of remote command execution tools rather than genuine persistence.

References