Skip to content
WETNav

Investigation · Persistence

What persistence did the attacker create?

Hunt the main persistence footholds on a host: services, scheduled tasks, Run keys, WMI subscriptions and BITS jobs, with the events that survive log clearing.

When you would ask thisYou have confirmed compromise and need to find every mechanism that will re-establish access after a reboot or an eviction attempt.

Steps

  1. 1

    Services

    Service installs are a top foothold. System event 7045 (Service Control Manager) records a new service with ServiceName, ImagePath, ServiceType, StartType and AccountName, and is logged by default even where the Security equivalent 4697 is not enabled. Events 7034, 7036 and 7040 record crashes, state changes and start-type changes, which catch a service flipped to auto-start. Flag ImagePath values pointing to user-writable paths, cmd.exe or powershell.exe, and services set to run as LocalSystem.

    List installed services with image path (live host)
    Get-WinEvent -LogName System `
      -FilterXPath "*[System[Provider[@Name='Service Control Manager'] and EventID=7045]]" |
      ForEach-Object { $x = [xml]$_.ToXml(); [pscustomobject]@{
        Time    = $_.TimeCreated
        Service = ($x.Event.EventData.Data | Where-Object Name -eq 'ServiceName').'#text'
        Image   = ($x.Event.EventData.Data | Where-Object Name -eq 'ImagePath').'#text'
        Account = ($x.Event.EventData.Data | Where-Object Name -eq 'AccountName').'#text' } }
  2. 2

    Scheduled tasks

    The Task Scheduler Operational log shows registration (106, with the task name and the user that created it), updates (140), deletion (141) and execution (200 action started, 201 action completed, naming the program that ran). On the Security log, 4698 is task creation, 4702 update, 4699 deletion and 4700/4701 enable/disable. Compare the registered action against the on-disk task XML, because a tampered task can run a different binary than its logged action suggests.

  3. 3

    Registry autostart keys

    Run and RunOnce keys are the classic autostart. If Sysmon is deployed with registry coverage, event 13 (registry value set) records TargetObject and Details, so filter TargetObject for ...\CurrentVersion\Run, ...\RunOnce and the per-user equivalents. On the Security log, 4657 records a registry value change but only on keys that carry a SACL, which is rare by default. Also watch sethc.exe and utilman.exe Image File Execution Options Debugger values, the accessibility-feature backdoor.

  4. 4

    WMI event subscriptions

    A permanent WMI subscription survives reboots and leaves nothing in a Run key or Startup folder. WMI-Activity event 5861 records the binding of an event filter to a consumer, the actual persistence. If Sysmon is configured for it, events 19 (filter), 20 (consumer) and 21 (filter-to-consumer binding) give the same picture with the consumer's CommandLine or script. Look for CommandLineEventConsumer or ActiveScriptEventConsumer bound to a filter that fires at startup or on a timer.

  5. 5

    New local accounts and BITS jobs

    Account creation is persistence too: Security 4720 marks a new account and 4722 its enabling; check whether it was then placed in a privileged group. BITS is a quieter channel: BITS-Client event 3 records job creation and 59/60 the transfer start and completion, each naming the remote URL and the local file. Attackers use long-running BITS jobs to re-download payloads, so a job owned by a service account pointing at an external URL is worth running down.

Where it goes wrong

  • Task Scheduler history (the Operational log) is disabled by default on many Windows versions, so 106/200 may simply not exist; fall back to the on-disk task XML.
  • 7045 is written once at install time, so on a busy host with a 20 MB System log it may already have rolled; the service's registry key under SYSTEM\CurrentControlSet\Services persists regardless.
  • Security 4697 needs the 'Audit Security System Extension' subcategory enabled and is often off, which is why System 7045 is the more reliable service-install source.
  • Sysmon registry (13) and WMI (19/20/21) events only appear if the deployed configuration includes those rules; a thin config will miss Run-key and subscription persistence entirely.
  • A scheduled task's logged action can differ from what it actually launches if the task XML was edited after registration, so verify the XML on disk.
  • WMI subscription persistence (5861) leaves no autostart file, so Autoruns alone will not surface it.

Beyond event logs

Scheduled task definitions

C:\Windows\System32\Tasks\ (and HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree)

The XML files hold the real command, arguments, trigger and the author. Compare file creation time and author against the Task Scheduler events; a task missing from the log but present on disk suggests history was off or cleared.

Autostart locations and Autoruns

HKLM/HKCU ...\CurrentVersion\Run, RunOnce, and the per-user Startup folder; audit with Sysinternals Autoruns

Autoruns enumerates Run keys, services, tasks, Winlogon and more in one pass and can show unsigned or newly added entries, which is faster than reading events for each mechanism.

WMI repository

C:\Windows\System32\wbem\Repository\OBJECTS.DATA

The repository stores permanent event filters, consumers and bindings. Parse it (for example with offline WMI tooling) to recover subscriptions even when WMI-Activity logging was not enabled.

Services registry hive

HKLM\SYSTEM\CurrentControlSet\Services\<name>

Holds ImagePath, Start and ObjectName for every service, present even after the 7045 install event has rolled out of the log.

References