Skip to content

Scheduled Tasks: Windows Persistence and Hidden Tasks

How Windows scheduled tasks persist in System32\Tasks and the TaskCache, how attackers hide or tamper with them, and how to find, check and remove one.

MITRE ATT&CK
T1053.005
Tactics
Execution, Persistence, Privilege escalation
Runs
On a schedule
Set up by
Users and administrators
Locations
  • C:\Windows\System32\Tasks
  • HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree
  • HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tasks
  • HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Logon
  • C:\Windows\Tasks

How it works

The Task Scheduler service (Schedule, hosted in svchost.exe and running as SYSTEM) runs registered tasks. A task has:

  • Triggers: a time or calendar schedule, system start, logon, idle, an event log query, its own registration, a session change (lock, unlock, remote connection) or a WNF state change.
  • Actions: start a program (Exec) or load a COM handler by CLSID. "Send an e-mail" and "Display a message" are deprecated since Windows 8.
  • A principal: the account (a user, a group, SYSTEM, LOCAL SERVICE or NETWORK SERVICE), the run level (LeastPrivilege or HighestAvailable) and the logon type.
  • Settings such as Hidden, Enabled, restart on failure and "run whether the user is logged on or not".

Exec actions start as children of the service's svchost.exe (taskeng.exe on Windows 7); COM handler actions load their DLL into taskhostw.exe.

When a task is registered, through schtasks, PowerShell, the Task Scheduler console or the COM API, the service writes two copies: an XML file under C:\Windows\System32\Tasks, and the TaskCache in the SOFTWARE hive. The service works from the registry copy. In the Tree key, the SD value holds the task's security descriptor; schtasks and the console use it to decide who may see the task. Remove it and the task disappears from those views, while the service keeps running it.

Tasks created through the Task Scheduler 1.0 interfaces also exist as .job files in C:\Windows\Tasks, a binary format older than the XML.

Where it lives

LocationWhat
C:\Windows\System32\Tasks\<folder>\<name>The task's XML (UTF-16), file name = task name
…\Schedule\TaskCache\Tree\<folder>\<name>Id (the task GUID), Index, SD
…\Schedule\TaskCache\Tasks\{GUID}Path, URI, Author, Description, Actions (binary), Triggers (binary, includes the account), Hash, DynamicInfo (registration and last run times)
…\Schedule\TaskCache\Boot, Logon, Plain, Maintenance\{GUID}Which trigger family the task belongs to
C:\Windows\Tasks\*.jobLegacy tasks

… is HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion. Hash is the SHA-256 of the XML file without its byte order mark, written at registration.

A stock Windows 10 or 11 system has well over a hundred tasks under \Microsoft\Windows\, plus vendor tasks at the root (browser and OneDrive updaters, drivers' helpers). Tasks are machine-wide; there is no per-user store.

Any user can register a task that runs as themselves. A task that runs as SYSTEM or as another account, or with HighestAvailable for an administrator, needs administrator rights. Deleting a Tree key's SD value needs SYSTEM.

How attackers use it

Tasks are among the most common ways back in, because one line creates them, locally or remotely:

schtasks /create /tn "\Microsoft\Windows\Maintenance\SvcCheck" /tr "C:\ProgramData\svc\svc.exe" /sc onstart /ru SYSTEM
schtasks /create /s HOST /tn Updater /tr "powershell -w hidden -enc …" /sc minute /mo 30 /ru SYSTEM
Register-ScheduledTask -TaskName Updater -Action (New-ScheduledTaskAction -Execute 'rundll32.exe' -Argument 'C:\Users\Public\u.dll,Start') -Trigger (New-ScheduledTaskTrigger -AtLogOn)

Remote tools use the same service over RPC, Impacket's atexec among them. Typical actions are powershell -enc, rundll32 or regsvr32 on a DLL in a writable folder, mshta on a URL, or a script host. Disguise relies on names and folders: a task under \Microsoft\Windows\ named like a maintenance job, an author set to "Microsoft Corporation", Hidden set to true.

Two documented cases go further:

  • Tarrask, described by Microsoft in 2022 and attributed to HAFNIUM, deleted the SD value of its tasks' Tree keys as SYSTEM. The tasks kept running but no longer showed in schtasks /query or the console.
  • In the SolarWinds intrusions, Microsoft described the operators updating an existing legitimate task to run their tool, then restoring the original action.

COM handler actions are another quiet route: the task names a CLSID, and a COM hijack of that class changes what runs without touching the task.

How to check a host

On a live machine:

schtasks /query /fo LIST /v > tasks.txt
schtasks /query /tn "\Microsoft\Windows\Maintenance\SvcCheck" /xml
Get-ScheduledTask | Where-Object TaskPath -notlike '\Microsoft\*' | Select-Object TaskPath, TaskName, State, Author
Get-ScheduledTask -TaskName Updater | Select-Object -ExpandProperty Actions
Get-ScheduledTaskInfo -TaskName Updater
autorunsc.exe -accepteula -a t -h -s -c > tasks.csv

To find tasks hidden by a missing SD, read the registry instead of asking the service:

Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree' -Recurse | Where-Object { $_.GetValue('Id') -and -not $_.GetValue('SD') }

Offline: the SOFTWARE hive's TaskCache and the System32\Tasks folder, side by side. Every registered task should have both; DynamicInfo gives its registration and last run times. Compare the TaskCache actions with the XML: they should be the same.

Events: Security log 4698 (task created), 4699 (deleted), 4700 and 4701 (enabled, disabled) and 4702 (updated), with "Audit Other Object Access Events" on; Microsoft-Windows-TaskScheduler/Operational 106 (registered), 140 (updated), 141 (deleted), 200 and 201 (action started and completed) when task history is enabled.

Suspicious: programs in ProgramData, Users\Public or temporary folders; interpreters with inline or encoded code; SYSTEM tasks from outside Microsoft; tasks under \Microsoft\ with no matching task on a clean machine of the same build; random names; a Tree key without SD; a file and a registration that disagree.

What Windows Persistence flags

The tool joins three sources: the XML files under System32\Tasks at any depth, the TaskCache from the SOFTWARE hive (Tree, Tasks and the category keys), and .job files. It matches them by path and by the GUID in Tree\…\Id. Each task shows its run-as account (from the XML principal or from the TaskCache Triggers value), run level, author, actions, triggers, hidden setting, registration and last run times from DynamicInfo, and whether it was found as a file, in the TaskCache, or both.

From the correlation, following Scheduled Tasks Parser:

  • Task hidden from schtasks (no security descriptor): a Tree key with an Id and no SD.
  • Registered task without its XML file and Task file never registered: only when both sides were collected and at least half of the registered tasks have their file, so a partial collection does not flag everything.
  • Task registered without a Tree key.
  • Task file changed after registration: the 32-byte Hash no longer matches the SHA-256 of the file. Older 4-byte hashes are not compared.
  • Task file and registry run different actions, with the registered actions in the details.
  • Task URI differs from its path (URI).

On the task itself: the command-line rules on every action, in system context when the task runs as SYSTEM, LOCAL SERVICE, NETWORK SERVICE or with highest privileges (for example Encoded PowerShell command, Windows program used to run outside code, Runs from a temporary or public folder); Non-Microsoft task with SYSTEM or highest privileges; Hidden task setting outside Microsoft's tasks; Deprecated task action; Machine-made name on the task name; Legacy .job task for .job files. Across mechanisms: Written date (the file, or for a registry-only task its registration, in the 7 days before the newest time seen for that host), Inside a Defender exclusion (exclusion), program also runs from mechanisms.

A task counts as Microsoft's when its author starts with "Microsoft", is a $(@%SystemRoot%\…) resource string, or is empty under \Microsoft\, and its first program runs from Windows' folders or Program Files (or it starts no program, as with a COM handler). A forged "Microsoft Corporation" author on a task that runs from ProgramData therefore still gets the SYSTEM and hidden flags. Microsoft's tasks whose program sits in Windows' folders, or that use a COM handler, are hidden by "Hide Windows entries" unless flagged. A task with no trigger counts as enabled when its settings say so, since it can still be run on demand.

Limits: the author is still the task's own claim, so a forged Microsoft author on a task that runs a Windows program (rundll32 on a DLL in System32, for example) passes as Microsoft's. COM handler CLSIDs are shown, not resolved. For a task found only in the registry, the trigger comes from its TaskCache category.

Cleaning up

  1. Preserve: schtasks /query /tn "\Name" /xml > task.xml, copy the file from System32\Tasks, and reg export "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache" taskcache.reg.
  2. Delete: schtasks /delete /tn "\Name" /f or Unregister-ScheduledTask -TaskPath '\' -TaskName Name -Confirm:$false.
  3. A task with no SD is invisible to both. As SYSTEM, delete its Tree key, its Tasks\{GUID} key, its entry under Boot, Logon, Plain or Maintenance, and the XML file, then reboot so the service reloads its store.
  4. A modified Microsoft task should be restored, not deleted: re-register it from a clean machine of the same build with schtasks /create /tn "\Path" /xml clean.xml /f.
  5. Remove the payload, and look for it in services, WMI subscriptions and Run keys. A task set to run whether the user is logged on or not stores that account's password on the machine, unless told not to: change it.

See also

On Windows Forensics

The artifacts behind this technique, in the Windows Forensics reference: