Windows persistence audit and detection
Brief
Persistence on Windows lives in a short list of places: scheduled tasks, services, Run keys, WMI subscriptions, local administrators and the keys that sign domain tickets. Each is listed with one administrative command, proven on an in-scope host with a marker carrying the test's name, removed in the same hour and matched to the event a defender should already be collecting.
Exam prep CRTP
On this page
- Check first
- How do I audit scheduled tasks for persistence?
- How do I audit services for persistence?
- How do I audit Run keys and startup folders?
- How do I audit WMI event subscriptions?
- How do I audit local administrators and new accounts?
- How do I audit krbtgt and replication rights in the domain?
- The defender sees
- Done when
- Not covered
- Tools
- Reviewed
- Situation
- Local administrator on a host named in the scope letter, or a domain account with read access to the directory for the domain checks. Nothing on this page runs as a service or a task; every demonstration creates a named object, lists it, and removes it before the step ends, and the domain step is read only.
- Goal
- A persistence audit table: for each location, what was found, the one marker created and removed, and the event that recorded both.
- Outputs
- Representative examples on placeholder hosts, trimmed to the lines that matter. Not captured from a public fixture yet.
Check first
- The scope letter names the host and allows one named marker per location, never started, never left to run.
- The marker name,
ATARUS-TEST-2026-10-27here, agreed in writing so the client can search every log for it. - An elevated shell, and the ActiveDirectory module for the domain step.
- An operator log with UTC times, to pair our actions with the client's events.
- The host's build document, which says what belongs there.
Steps
How do I audit scheduled tasks for persistence?
Get-ScheduledTask | Where-Object { $_.State -ne 'Disabled' -and $_.TaskPath -notlike '\Microsoft\*' } |
ForEach-Object { '{0}{1} {2} {3}' -f $_.TaskPath, $_.TaskName, $_.Principal.UserId, $_.Actions[0].Execute }
Expected output
\BackupSync SYSTEM C:\Program Files\VendorBackup\sync.exe
\Updater SYSTEM C:\Users\Public\upd.exe # <- a SYSTEM task that runs a binary from a folder any user can write
A task outside the \Microsoft\ tree running as SYSTEM from a user writable path, or missing from the build document, is the finding. The demonstration registers a task that would run a harmless echo at a time we never reach, reads it back and deletes it.
schtasks /Create /TN "ATARUS-TEST-2026-10-27" /TR "cmd.exe /c echo authorized test marker" /SC ONCE /ST 23:59 /F
schtasks /Query /TN "ATARUS-TEST-2026-10-27" /FO LIST /V
schtasks /Delete /TN "ATARUS-TEST-2026-10-27" /F
Expected output
SUCCESS: The scheduled task "ATARUS-TEST-2026-10-27" has successfully been created.
TaskName: \ATARUS-TEST-2026-10-27
Status: Ready
Task To Run: cmd.exe /c echo authorized test marker
SUCCESS: The scheduled task "ATARUS-TEST-2026-10-27" was successfully deleted. # <- created and removed inside one minute
Negative result. Every task outside \Microsoft\ matches the build document and runs from a protected folder. Record the count and still run the demonstration.
Fix. Enable Audit Other Object Access Events so task creation and deletion reach the Security log, and alert on new tasks in the library root.
How do I audit services for persistence?
Get-CimInstance Win32_Service | Where-Object { $_.StartMode -eq 'Auto' } |
Select-Object Name, StartName, PathName | Sort-Object Name | Format-Table -AutoSize
Expected output
Name StartName PathName
---- --------- --------
Spooler LocalSystem C:\Windows\System32\spoolsv.exe
VendorAgent LocalSystem "C:\Program Files\Vendor\agent.exe"
WinHelper LocalSystem C:\ProgramData\winhelper.exe # <- an automatic service outside Program Files and Windows
An automatic service with a binary outside Program Files and Windows, or a name that mimics a Windows component, goes in the table. The demonstration creates a manual start service and deletes it without starting it, so nothing runs.
sc.exe create ATARUS-TEST-2026-10-27 binPath= "C:\Windows\System32\cmd.exe /c echo authorized test marker" start= demand
sc.exe qc ATARUS-TEST-2026-10-27
sc.exe delete ATARUS-TEST-2026-10-27
Expected output
[SC] CreateService SUCCESS
BINARY_PATH_NAME : C:\Windows\System32\cmd.exe /c echo authorized test marker
START_TYPE : 3 DEMAND_START
[SC] DeleteService SUCCESS # <- never started, so no process ran
Negative result. Every automatic service matches the build document and a signed binary in a protected folder.
Fix. Enable Audit Security System Extension so service installation reaches the Security log, and alert on any service path outside the two protected folders.
How do I audit Run keys and startup folders?
reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Run
reg query HKCU\Software\Microsoft\Windows\CurrentVersion\Run
Expected output
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run
SecurityHealth REG_EXPAND_SZ %windir%\system32\SecurityHealthSystray.exe
OneSync REG_SZ C:\Users\Public\Libraries\onesync.exe # <- no installer owns this value
Repeat for the RunOnce keys and both Startup folders. A value pointing into a user writable folder is the finding. The demonstration adds a value under the current user, which needs no elevation, then deletes it.
reg add HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v ATARUS-TEST-2026-10-27 /t REG_SZ /d "cmd.exe /c echo authorized test marker" /f
reg delete HKCU\Software\Microsoft\Windows\CurrentVersion\Run /v ATARUS-TEST-2026-10-27 /f
Expected output
The operation completed successfully.
The operation completed successfully. # <- added and removed with no sign in between, so it never ran
Negative result. Only values owned by installed software in protected paths.
Fix. Collect Sysmon registry events for the Run and RunOnce keys, or put a Set Value audit entry on them, and alert on any value whose target is outside Program Files and Windows.
How do I audit WMI event subscriptions?
Get-CimInstance -Namespace root/subscription -ClassName __EventFilter | Select-Object Name, Query
Get-CimInstance -Namespace root/subscription -ClassName __EventConsumer | Select-Object Name, CommandLineTemplate
Get-CimInstance -Namespace root/subscription -ClassName __FilterToConsumerBinding | Select-Object Filter, Consumer
Expected output
Name Query
---- -----
SCM Event Log Filter select * from MSFT_SCMEventLogEvent
UpdaterFilter SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System' # <- fires every minute, and nothing on the host explains it
A permanent subscription is a filter, a consumer and a binding, stored in the repository and surviving a reboot. The SCM Event Log pair ships with Windows; any other filter bound to a command line or script consumer goes in the table. There is no demonstration: a binding runs its consumer on a timer, which is code executing beyond a marker.
Negative result. Only the SCM Event Log filter, consumer and binding.
Fix. Remove any binding the owner cannot explain with Remove-CimInstance, consumer and filter included, and collect Sysmon WMI events or the WMI Activity operational log so a new binding raises an alert.
How do I audit local administrators and new accounts?
Get-LocalGroupMember -Group Administrators
Get-LocalUser | Where-Object Enabled | Select-Object Name, LastLogon, PasswordLastSet
Expected output
ObjectClass Name PrincipalSource
----------- ---- ---------------
User FS01\Administrator Local
Group CORP\Domain Admins ActiveDirectory
User FS01\svc_backup2 Local # <- a local administrator the build document does not name
A local administrator nobody can account for is the oldest persistence there is. The demonstration creates a user with a password typed at a prompt, adds it to the group, and removes both without signing in as it.
New-LocalUser -Name 'ATARUS-TEST-2026-10-27' -Password (Read-Host -AsSecureString 'Test password') -Description 'Authorized security test. Remove 2026-10-27.'
Add-LocalGroupMember -Group Administrators -Member 'ATARUS-TEST-2026-10-27'
Remove-LocalGroupMember -Group Administrators -Member 'ATARUS-TEST-2026-10-27'
Remove-LocalUser -Name 'ATARUS-TEST-2026-10-27'
Expected output
Name Enabled Description
---- ------- -----------
ATARUS-TEST-2026-10-27 True Authorized security test. Remove 2026-10-27. # <- a burst of Security events inside two minutes
Negative result. Administrators holds only the built-in account and the domain groups the build document names.
Fix. Rotate the built-in administrator password with a managed solution, keep the group to the built-in account and named domain groups, and alert on membership changes on every host.
How do I audit krbtgt and replication rights in the domain?
Get-ADUser krbtgt -Properties PasswordLastSet | Select-Object Name, PasswordLastSet
(Get-Acl 'AD:\DC=corp,DC=example,DC=com').Access |
Where-Object { $_.ObjectType -in '1131f6aa-9c07-11d1-f79f-00c04fc2dcd2', '1131f6ad-9c07-11d1-f79f-00c04fc2dcd2' } |
Select-Object IdentityReference, ObjectType
Expected output
Name PasswordLastSet
---- ---------------
krbtgt 3/14/2019 9:12:41 AM # <- the key that signs every ticket in the domain has not changed in seven years
IdentityReference ObjectType
----------------- ----------
BUILTIN\Administrators 1131f6aa-9c07-11d1-f79f-00c04fc2dcd2
BUILTIN\Administrators 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2
CORP\svc_sync 1131f6ad-9c07-11d1-f79f-00c04fc2dcd2 # <- a service account that can replicate every secret
Domain persistence in the broad sense is credential material outliving a password reset: the krbtgt key, usable to mint tickets by anyone who once held it until it changes twice, and the replication rights that let an account read it. The GUIDs are Replicating Directory Changes and Replicating Directory Changes All. There is no demonstration: we never forge a ticket or replicate a secret on a client domain; the key's age and its readers are the finding.
Negative result. A PasswordLastSet inside the client's rotation period, and replication rights held only by Administrators, Domain Controllers and Enterprise Domain Controllers.
Fix. Reset the krbtgt password twice, at least ten hours apart as Microsoft's forest recovery guidance requires, repeat on a schedule, remove replication rights from every account that is not a domain controller, and alert on replication by anything else.
The defender sees
Our task shows as 4698 and its deletion as 4699 in the Security log under Audit Other Object Access Events, and as task registered and deleted in the Task Scheduler operational log. The service shows as 7045 in the System log everywhere, and as 4697 in the Security log where Audit Security System Extension is on. The Run key value shows as a Sysmon registry value set event, and as 4657 only where the key carries a Set Value audit entry. The WMI listing leaves nothing; a real subscription left Sysmon 19, 20 and 21, or 5861 in the WMI Activity log, when it was created. The account shows as 4720, 4732, 4733 and 4726 within two minutes, with 4722 and 4724 beside the creation, all carrying the marker name. The domain step is a read with no event on a default domain; replication by an account that is not a domain controller shows as 4662 with one of the two GUIDs where the domain object has an audit entry. Every command is also a Sysmon event 1 carrying the marker. A client who finds none of these has an auditing gap to report beside the locations.
Done when
Every location has been listed and recorded, every marker named ATARUS-TEST with the date has been removed and its removal logged, and the client has been asked to find each creation and deletion event.
Not covered
Reaching local administrator in the first place, forging any ticket or reading any credential, and the full Autoruns catalogue of start locations; the outputs shown are representative examples on placeholder hosts, not captured runs.