Skip to content

Lesson 12 of 14 · 15m

Persistence Is an Inventory Problem

Run keys, services, tasks, WMI subscriptions, cron, and authorized_keys — diff the re-execution paths, don't signature them.

Persistence is any mechanism that re-executes attacker code across a reboot or a credential reset. The way to hunt it is inventory-and-diff, not signatures — because the mechanisms are all legitimate OS features, and the only thing separating persistence from administration is whether you put it there.

The Windows map

Run keys — HKLM and HKCU\...\CurrentVersion\Run, RunOnce, Policies\Explorer\Run — surface in Sysmon 12/13 registry events (T1547.001). Everyone watches them; everyone also knows they're the shallow end.

Services — T1543.003 — show up as Security 4697 or System 7045. The fields carry the verdict: Service File Name pointing outside Program Files, into C:\Users\Public, %TEMP%, or C:\ProgramData with a random-ish name, running as SYSTEM with Start Type auto.

Scheduled tasks — T1053.005 — log as Security 4698/4702 and TaskScheduler/Operational 106. The tell is the action: tasks invoking powershell.exe, wscript.exe, or a binary under user-writable paths — especially with a SYSTEM principal — are the ones to explain. Attackers love tasks because schtasks /create needs no service install and the Task Scheduler GUI is where admins never look.

WMI permanent event subscriptions — T1546.003 — are the fileless option: an __EventFilter (the trigger), a CommandLineEventConsumer or ActiveScriptEventConsumer (the payload), and a __FilterToConsumerBinding welding them together, all living in the WMI repository rather than on disk. Sysmon events 19, 20, 21 log each piece. Matt Graeber's Black Hat 2015 talk built a persistent, fileless backdoor out of exactly this, and state actors have used it since. Audit it directly with Get-WmiObject -Namespace root\subscription -Class __EventConsumer — on a clean fleet that query returns nothing or your own management tooling, which makes the tail very short to hunt.

Image File Execution Options — the Debugger value under HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<name> (T1546.012) — hijacks a named binary at launch; it is the same mechanism behind the sticky-keys/sethc.exe and utilman.exe swap.

DLL search-order and phantom DLLs (T1574): drop a DLL a signed binary will load from a user-writable install dir — Teams-era appx installs made this a plague — and persistence rides inside a trusted process.

Office and accounts: STARTUP/XLSTART folders and add-ins (T1137), and the purest persistence of all — a new local or domain account (T1136; Security 4720/4732) and new keys in authorized_keys files. A forged account plus a scheduled task is persistence with zero binaries.

The Linux map

systemd units and timers in /etc/systemd/system/ and ~/.config/systemd/user/ — systemctl list-unit-files --state=enabled and list-timers --all are the audit. Cron: /etc/crontab, /etc/cron.d/, the cron.daily|hourly|weekly dirs, /var/spool/cron/ user tables, and @reboot. /etc/ld.so.preload and LD_PRELOAD — the userland-rootkit classic. /etc/profile.d/, shell rc files, /etc/rc.local. /etc/modules-load.d/ and DKMS for kernel-level. And authorized_keys — diff every file against your config-management inventory, watching for new keys and command=/from= options that smuggle behavior into a key.

Bits and pieces that escape both lists: BITS jobs (bitsadmin /list /allusers /verbose — a downloader that survives reboots), Netsh helper DLLs, Office Startup equivalents in every suite, screensaver paths, and the Winlogon Shell/Userinit values. The lesson generalizes: persistence is any re-execution path the OS honors, which is why the inventory is the honest enumeration — it lists the mechanisms the OS itself will run.

Why inventory beats signatures

The wrong model is "persistence means malware in a startup folder." The right one: webshells are persistence-as-file — the .aspx droppers from ProxyLogon and Cl0p's human2.aspx on MOVEit servers survived reboots and password resets trivially, because persistence that survives a credential change is the adversary's whole point. autorunsc.exe -a * -c -nobanner dumps every Windows autostart entry to CSV; baseline it on the golden image, diff per host, and every delta is a named question. On Linux, systemctl plus a cron plus an authorized_keys inventory does the same. The mechanism list is finite. Diff it and it has nowhere to hide.

The operating rule that makes this survivable: persistence entries have provenance. Every entry in today's diff either traces to a change you made — a package installed, a patch applied, an admin onboarded — or it doesn't. rpm -V, debsums, or Get-AuthenticodeSignature over the changed entries settles most deltas in seconds; what's left unexplained is your actual workload. Hunting persistence is bookkeeping, and the books close fast when you keep them.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.