Skip to content

Lesson 3 of 14 · 16m

The Task Scheduler Is Cron With a Rifle Scope

Tasks are XML under System32\Tasks keyed in TaskCache, triggers go far beyond time, S4U and 'highest privileges' change the token, and ASEPs are where persistence hides.

Cron can't fire when event 1102 appears

The Task Scheduler is not a cron port. Tasks are XML files under C:\Windows\System32\Tasks, indexed by the registry cache at HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache. The trigger set includes things cron can't express: at logon, at boot, on a specific event ID, on workstation unlock, on idle — with conditions like "only on AC power" or "only if this network is reachable." schtasks /query /xml ONE /tn "\Microsoft\Windows\UpdateOrchestrator\Reboot" dumps the raw document: triggers, actions, and the <Principals> block that decides whose token the task runs under.

Creating one by hand shows the shape:

schtasks /create /tn "BackupCheck" /tr "powershell -File C:\ops\check.ps1" /sc daily /st 02:00 /ru SYSTEM /rl HIGHEST

/rl HIGHEST is the "highest privileges" flag; /ru SYSTEM is the principal. In the XML the same choices appear as <LogonType>S4U</LogonType> and <RunLevel>HighestAvailable</RunLevel> — the file is the truth, the GUI is a renderer.

schtasks.exe is the legacy CLI; the ScheduledTasks module (Get-ScheduledTask, New-ScheduledTask, Register-ScheduledTask) is the modern one and returns objects you can filter properly:

Get-ScheduledTask | Where-Object {$_.Actions.Execute -notlike 'C:\Windows\*'}

The wrong mental model: "a scheduled task is a timed job." It's a principal-plus-trigger-plus-action registration, and the principal is where it goes sideways. The two checkboxes that matter:

  • "Run whether user is logged on or not" — with "Do not store password," this is an S4U logon. The scheduler mints a token without the password, so the task cannot use saved credentials — a script that mounts a share with stored creds fails silently here.
  • "Run with highest privileges" — requests the account's full token. For an admin account this is the difference between a Medium-integrity process and a High-integrity one; leave it unchecked and your "admin" task gets denied on writes that look routine.

Task folders organize the namespace — Microsoft\Windows\... is where inbox tasks live, and anything registered outside that tree stands out by construction. Operational events live in Microsoft-Windows-TaskScheduler/Operational (106 = registered, 200 = action started, 201 = completed, 322 = "the user or admin requested on-demand run"). In the Security channel, 4698 fires on task creation and 4702 on update. Those two IDs are how persistence-by-task gets caught; alert on them.

The autostart zoo

A task is one of dozens of Auto-Start Extensibility Points — the places Windows checks for "run this" at boot or logon. The ones you actually inspect:

  • Run and RunOnce under HKLM and HKCU\Software\Microsoft\Windows\CurrentVersion
  • shell:startup, which resolves to %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup
  • Winlogon's Shell and Userinit values
  • Image File Execution Options Debugger values — attach a "debugger" to notepad.exe and your code launches every time notepad does
  • WMI permanent event subscriptions (__EventFilter + __EventConsumer + binding — fileless persistence, T1546.003)
  • COM object hijacks — register a different CLSID target and inherit whatever loads it
  • Services, and the tasks themselves

The TaskCache registry side matters for forensics: TaskCache\Tree maps task paths to GUIDs, TaskCache\Tasks holds the per-task blob — including the security descriptor that controls who can even see the task, which is why some malicious tasks don't show in the console. When output and reality disagree, look at the cache.

Nobody enumerates this by hand. Sysinternals Autoruns does — autorunsc.exe -a * -c -h -s emits the complete set as CSV, and diffing it against a gold image is a real baseline, not a thought exercise. The GUI's VirusTotal lookup (autoruns.exe -vt) is built in.

There's a real-world reason this matters: scheduled-task persistence is T1053.005, and the operators know your output is long. Emotet and Qakbot named their tasks things like Microsoft\Windows\Maintenance\WinSAT precisely because Get-ScheduledTask output is a wall nobody reads. Filter it, diff it, and treat any new SYSTEM-principal task running something outside C:\Windows as an incident until proven boring.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.