Scheduled Task Persistence
Malware registers a Windows scheduled task that re-launches its payload on a trigger — logon, a fixed interval, or system idle — providing durable, often privileged, persistence.
The Windows Task Scheduler runs programs on triggers — at logon, at boot, on a timer, when the machine goes idle, or in response to an event-log entry. Malware abuses it to re-launch its payload reliably and, when running as SYSTEM, with high privilege. Scheduled tasks survive reboots, are easy to register, and blend in among the hundreds of legitimate tasks Windows ships with.
Tasks can be created with the built-in schtasks.exe utility, via PowerShell's ScheduledTasks module, or directly through the ITaskService COM interface. Each task is stored both as an XML file on disk and as registry entries describing the trigger and action.
How it works
A command-line registration that runs a payload every hour:
schtasks /create /tn "OneDrive Reporting Task" /tr "C:\Users\Public\report.exe"
/sc minute /mo 60 /ru SYSTEM /fThe resulting task is materialised in two places that an analyst should examine:
XML: C:\Windows\System32\Tasks\OneDrive Reporting Task
Registry: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\<taskname>
HKLM\...\Schedule\TaskCache\Tasks\{GUID} (Actions, Triggers as binary blobs)The XML <Actions> element holds the executable path and arguments; <Triggers> defines when it runs. Attackers favour innocuous task names placed under existing folders (e.g., \Microsoft\Windows\) to hide among Microsoft's own tasks, and sometimes register a task whose action is a LOLBin (mshta, rundll32, powershell -enc ...).
Detection & analysis
Static analysis:
- Examine the on-disk task XML under
C:\Windows\System32\Tasks\. The<Command>and<Arguments>reveal the payload; theAuthorand registration date in the file metadata help scope the intrusion. - Parse the
TaskCacheregistry subtree offline with RegRipper or Registry Explorer; theTasks\{GUID}Actionsvalue is a binary blob containing the executable path. TheTreekey's last-write time dates creation. - In a malware sample, look for
schtasks.exeinvocations, the stringsTasks/TaskCache, or imports/COM use oftaskschd.dllandITaskService.
Dynamic analysis:
- Run the sample and watch for a child
schtasks.exeor asvchost.exeTask Scheduler call. Sysmon Event ID 1 (Process Create) captures theschtasks /createcommand line. - The Microsoft-Windows-TaskScheduler/Operational log records Event ID 106 (task registered) and 140 (task updated); Security log Event ID 4698 logs task creation when audit policy is enabled. Sysmon Event IDs 12/13 capture the
TaskCacheregistry writes.
Detection rule hint:
Alert on task registration where the action points to a user-writable or temp directory, invokes a script interpreter or LOLBin, or where the task is created by a non-installer process. Correlate Event ID 4698/106 with the writing process and flag tasks whose names impersonate Microsoft tasks but whose binaries are unsigned.