Join our Newsletter — 33% off our NHI Course
Home› Guides› How to Hunt for Persistence on Windows: Autoruns…
Guide SOC & Detection Engineering

How to Hunt for Persistence on Windows: Autoruns Stacking, Event Baselines and Triage

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 19 November 2026 15 min read
On this page

Hunting for persistence on Windows means asking one question across the whole estate: what is set to run again after a reboot or logon that we did not put there? This guide turns that question into a repeatable hunt. It covers the hypotheses worth testing, the data you need, how to stack Autoruns output across many hosts, which Windows and Sysmon events show new autostart entries being written, illustrative queries, and how to triage what you find without breaking production systems.

It is written for threat hunters, detection engineers and incident responders who already collect endpoint telemetry and want a hunt they can run every month. For the wider catalogue of persistence techniques across operating systems, read the Persistence Techniques Guide. For hunting method in general, start with the Threat Hunting Guide. This page stays on the practical Windows hunt.

Key takeaways

  • Persistence is one of the most huntable behaviours on Windows because the number of places that start code automatically is finite and well documented.
  • Two complementary data sets do the work: point-in-time snapshots of autostart locations (Autoruns) and the event stream that records new entries being written (Security log events 4698 and 4697, Sysmon events 11, 12, 13, 19, 20 and 21, or your EDR registry table).
  • Stacking, counting how many hosts share the same entry, turns thousands of autostart entries into a short list of rare ones. Rare is not malicious, but malicious is usually rare.
  • A baseline built from a known good image is what makes the next hunt faster. Every hunt should leave behind a better baseline and at least one new detection.
  • Persistence frequently runs as a privileged service account or the SYSTEM account. Treat the identity a task or service runs as as part of the finding, not an afterthought.
  • All queries on this page are illustrative. Test them against your own data and field mappings before relying on them.

The hunt question and hypotheses

A good hunt starts with a testable hypothesis rather than a vague wish to find bad things. For Windows persistence, these hypotheses cover most real intrusions and map to MITRE ATT&CK techniques:

Write each hypothesis into your backlog with a scope (which hosts), a time window and the data sources it needs. The Threat Hunt Hypothesis Backlog Template gives a format. Run one or two hypotheses per hunt rather than all six at once, so that each one gets proper triage.

Data sources you need before you start

Persistence hunting needs both state and change. State tells you what is configured to run now. Change tells you when and by whom it was added. Neither is enough on its own: a snapshot misses entries that were added and removed between snapshots, and an event stream misses anything configured before logging began.

Data sourceWhat it gives youHypotheses
Autoruns (autorunsc) snapshotsPoint-in-time list of autostart entries with hashes and signature statusH1 to H5
Security log 4698, "A scheduled task was created"Task name, the task XML and the account that created itH2
Security log 4697, "A service was installed in the system"Service name, file path, type, start type and service accountH3
Sysmon events 12, 13 and 14Registry key and value create, delete, set and renameH1, H5
Sysmon event 11File creation, including in Startup foldersH1
Sysmon events 19, 20 and 21WMI event filter, consumer and binding registrationH4
Sysmon event 1Process creation with full command line, used to see what the persistence actually launchedAll
Microsoft Defender XDR DeviceRegistryEventsRegistry changes with the initiating process, its command line and accountH1, H3, H5

Microsoft documents that event 4698 is generated every time a new scheduled task is created and is enabled by the Audit Other Object Access Events subcategory. Event 4697 belongs to the Audit Security System Extension subcategory. If those subcategories are not enabled, the events will not exist, so check audit policy first. The Windows Event Log Guide and the Windows Event Forwarding Guide cover collection, and the Sysmon Guide covers configuration. Note that Sysmon only records what its configuration asks for, so confirm that registry autostart paths and WMI events are included.

Collecting Autoruns snapshots at scale

Microsoft Sysinternals Autoruns lists programs configured to run at boot or logon, including Run and RunOnce keys, Startup folders, Explorer add-ons, AppInit DLLs, image hijacks, boot execute images, Winlogon notifications, auto-start services, Winsock providers and codecs. Its command line version, autorunsc, is what you run across an estate.

The documented switches that matter for hunting are:

  • -a * to collect all categories. Individual letters select categories, for example t for scheduled tasks, s for autostart services and drivers, m for WMI entries, w for Winlogon entries and l for logon startups, which is the default.
  • -c for CSV output (or -ct for tab delimited), so the results can be loaded into a SIEM or a notebook.
  • -h to include file hashes, which is what makes stacking by hash possible.
  • -s to verify digital signatures.
  • -t to show timestamps in normalised UTC.
  • * as the user argument to include autostart entries from all user profiles, not just the account running the tool.
  • -z to scan an offline Windows system, which is useful for mounted forensic images.

An illustrative collection command is autorunsc -a * -c -h -s -t *, redirected to a file named for the host and date. Do not add -m (hide Microsoft entries) on the collection run. Hiding signed Microsoft entries is helpful for a quick look, but attackers abuse Microsoft binaries such as script hosts and rundll32 as the launched command, so you want the full set in your data and can filter later. The VirusTotal switches (-v and -vt) send hashes to a third party; decide as a matter of policy whether that is acceptable before using them, and never use the upload option on files that may contain your own data.

Run collection from your software deployment or EDR live response tooling, write results to a central share or storage bucket with restricted write access, and keep every snapshot. History is what lets you answer "when did this first appear?".

Stacking: finding the rare entries

Stacking, also called frequency analysis or least frequency of occurrence, counts how many hosts share each entry and sorts from rarest to most common. On a managed estate built from a small number of images, the same few hundred autostart entries appear on nearly every host. A payload added by an intruder usually appears on one host or a handful.

Stack on more than one key, because each catches different things:

  • By hash: an image path that is common but with a rare hash suggests a replaced or trojanised binary.
  • By launch string (image path plus arguments): catches a common binary such as a script host launched with a rare argument.
  • By entry name and location: catches a rare task name or Run value even if the launched binary is common.
  • By signer: unsigned or unexpectedly signed entries on servers deserve attention first.

Illustrative pseudocode for a notebook or SIEM. Check the column headings in your own autorunsc CSV output and map them to the descriptive names used here:

load all host CSVs; add column host; group by (entry location, entry name, image path, launch string, hash); count distinct host; sort ascending; keep rows where host count <= 3

The Jupyter Notebooks for Threat Hunting guide covers running this kind of analysis in a notebook. Stack within like-for-like groups (domain controllers with domain controllers, developer laptops with developer laptops). Mixing server roles with workstations floods the rare end of the stack with legitimate role-specific software.

Building and using a baseline

A baseline is the set of autostart entries you have reviewed and accepted as legitimate. Build the first one from a freshly deployed reference host for each image, then add entries as triage confirms them. Store the baseline as data (entry location, entry name, launch string, hash, signer, reason accepted, who accepted it and when), not as a spreadsheet nobody owns.

On every subsequent hunt, subtract the baseline from the new snapshots. What remains is new since the last review. Over a few cycles, the residue shrinks to genuine change: new software, updates and anything malicious. That residue is also your best source of candidate detections, because anything you keep finding by hand should become a rule.

Two cautions. First, a baseline taken from an already compromised host bakes the compromise in, so build from clean reference images. Second, baselines decay. Software updates change hashes every month, so allow matching on signer plus path for trusted vendors, but never on path alone.

Event-based hunting: catching persistence as it is written

Snapshots show state; events show the moment of change and, critically, which process and account made the change. The following queries are illustrative. Field names come from Microsoft documentation for the events and table named, but you must map them to your SIEM schema.

Scheduled tasks (event 4698)

Microsoft documents that event 4698 includes the subject account (SubjectUserName and SubjectDomainName), the TaskName in the form of a path under the Task Scheduler Library, and TaskContent, which holds the full task XML. Microsoft's own monitoring advice is to watch tasks created in the root of the library, where manually created or malicious tasks often appear, and to alert when TaskContent contains a LogonType of Password, because the account password is then stored in Credential Manager.

Illustrative logic: EventID == 4698 | where TaskContent contains "<Command>" | extract the command | flag commands in user-writable paths (AppData, Temp, ProgramData, Public), script hosts, encoded PowerShell, or TaskName with no folder path. Stack the extracted command across hosts as you would with Autoruns.

Services (event 4697)

Event 4697 records ServiceName, ServiceFileName, ServiceType, ServiceStartType and ServiceAccount. Microsoft's monitoring recommendations for this event are a ready-made hunt list:

  • ServiceFileName outside the Windows directory or Program Files folders.
  • ServiceType of 0x1, 0x2 or 0x8, which are rare high-privilege types that start early in boot.
  • ServiceStartType of 0 or 1, used by drivers.
  • ServiceStartType of 4, because installing a new service in the disabled state is uncommon.
  • ServiceAccount other than localSystem, localService or networkService, which means a named account is running the service.

Microsoft also notes that changes made to the service file path after installation are not logged by 4697, so pair it with registry monitoring of service configuration keys to catch an existing service being repointed.

Registry autostarts (Sysmon 12 and 13, or DeviceRegistryEvents)

Sysmon event 13 records registry value modifications and event 12 records key and value creation and deletion; Microsoft describes both as useful for monitoring autostart locations. In Microsoft Defender XDR, the DeviceRegistryEvents table carries RegistryKey, RegistryValueName, RegistryValueData, ActionType, InitiatingProcessFileName, InitiatingProcessCommandLine and InitiatingProcessAccountName.

Illustrative KQL:

DeviceRegistryEvents | where Timestamp > ago(30d) | where RegistryKey has @"\CurrentVersion\Run" | summarize Hosts = dcount(DeviceId), Example = any(RegistryValueData) by RegistryValueName, InitiatingProcessFileName | where Hosts <= 3 | order by Hosts asc

The KQL for Threat Hunting Guide and Splunk SPL for Threat Hunting Guide cover the query languages in depth.

Startup folder files (Sysmon 11)

Sysmon event 11 logs file creation and overwrite, which Microsoft describes as useful for monitoring autostart locations. Filter on target paths containing the Startup folder and stack by file name and creating process.

WMI subscriptions (Sysmon 19, 20 and 21)

Sysmon logs WMI event filter registration (19, with namespace, name and filter expression), consumer registration (20, with consumer name and destination) and consumer to filter binding (21). Permanent WMI subscriptions are rare on most estates, so every 20 and 21 event outside known management tooling deserves review. The Autoruns m category gives the state view of the same thing.

Triage: deciding what a rare entry is

Each rare entry needs a quick, consistent decision. Work through these questions in order:

  1. What does it launch? Resolve the full command line, including what any script or DLL argument points at.
  2. Is the target file signed, and by whom? An unsigned file in a user-writable path launched at logon on a server is high priority.
  3. Who created it? Use 4698, 4697 or the initiating process fields to find the account and process responsible. Software installers and management agents are expected creators; an interactive shell, a script host or an Office process is not.
  4. When did it first appear? Compare snapshot history. A first appearance that matches a known change window is reassuring; one at night on a weekend is not.
  5. Which identity will it run as? A task or service set to run as a privileged service account or domain account widens the blast radius, and if the task stores a password, that credential must now be treated as exposed.
  6. Does it appear elsewhere? Pivot on the hash, task name, service name and launch string across all hosts.

Record the outcome for every entry: benign and added to baseline, suspicious and escalated, or malicious and handed to incident response. Do not delete suspicious entries during the hunt. Removing persistence before scoping the intrusion alerts the attacker and destroys evidence; eviction belongs to the response process.

Where identity fits

Persistence and non-human identities are tightly linked. Scheduled tasks and services run as an account, and attackers like to borrow an existing service account because its activity already looks routine. When a hunt finds a malicious task or service, the questions extend beyond the host: which account does it run as, where else is that account used, and has its credential been stored or exposed? Microsoft specifically warns that tasks using a Password logon type store the account password in Credential Manager.

Build these checks into triage. Flag any new task or service whose ServiceAccount or task principal is a named domain account, rotate any credential stored in a malicious task, and review the account's recent logons. The Service Account Security Guide covers reducing standing privilege so that a borrowed service account is worth less to an attacker.

Turning hunt findings into detections

A hunt that finds nothing still produces value if it leaves something behind. After each cycle:

  • Convert the stacking logic into a scheduled query that alerts on new entries absent from the baseline on high-value hosts such as domain controllers and identity servers.
  • Turn Microsoft's 4697 monitoring recommendations into individual rules, starting with services installed from user-writable paths and services running as named accounts.
  • Alert on any WMI consumer registration outside your management tooling allow list.
  • Record data gaps, such as hosts missing Sysmon or audit subcategories not enabled, and fix them before the next hunt.
  • Document the hunt in a report so the next hunter starts from your baseline, not from zero.

Common failure patterns

  • Collecting with Microsoft entries hidden. Attackers launch payloads through signed Microsoft binaries. Hiding them at collection time hides the attack.
  • Stacking across mixed roles. Comparing servers with laptops floods the rare end of the stack with legitimate software and wears out analysts.
  • Snapshots only, no events. Entries added and removed between snapshots never appear, and you cannot tell who created anything.
  • Audit policy assumed, not checked. Events 4698 and 4697 need their audit subcategories enabled. Many estates find out during an incident that they were never collected.
  • Baselining by path alone. A trusted path with a replaced binary passes a path-only baseline.
  • Cleaning up during the hunt. Deleting a malicious task before scoping alerts the attacker and loses evidence.
  • Ignoring the run-as account. Treating persistence as a host problem misses the credential the attacker now holds.

Practitioner checklist

  • Confirm Audit Other Object Access Events and Audit Security System Extension are enabled and forwarded.
  • Confirm Sysmon configuration covers registry autostart keys, Startup folders and WMI events 19 to 21.
  • Collect autorunsc output with all categories, hashes, signatures and UTC timestamps for all user profiles, without hiding Microsoft entries.
  • Stack by hash, launch string, entry name and signer, within groups of hosts with the same role.
  • Build and maintain a baseline from clean reference images, recording who accepted each entry and why.
  • Query 4698, 4697, registry and WMI events for the hunt window and stack the results.
  • Triage every rare entry with the six questions above and record an outcome.
  • Check the run-as identity for every suspicious task or service and rotate exposed credentials through incident response.
  • Hand malicious findings to incident response before removing anything.
  • Leave behind at least one new detection and a list of fixed data gaps.

Standards and references

Related NHI Mgmt Group resources: Threat Hunting Guide · Persistence Techniques Guide · Sysmon Guide · Threat Hunt Hypothesis Backlog Template

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.