Persistence
Scheduled Tasks
Scheduled tasks cheat sheet: task XML and .job files, TaskCache registry keys, DynamicInfo times, hidden tasks, TaskScheduler and 4698 events.
- Location
- C:\Windows\System32\Tasks\<TaskName>
- Proves
- A task was registered to run a command, by whom, and when it was created and last ran
- Timestamps
- DynamicInfo creation/last run as FILETIME, UTC; TaskCache key LastWrite, UTC; XML RegistrationInfo Date in ISO 8601, often no zone
- Retention
- Tasks persist until deleted; Security 4698 needs auditing, the TaskScheduler Operational log may be disabled; both roll over by size
- Access
- Administrator; task XML files copy directly, SOFTWARE hive (TaskCache) locked live: reg save, VSS or raw NTFS
- Evidence of
- PersistenceExecution
- Type
- File / file system
- Windows
- XPVista / 78 / 8.11011
- KAPE target
- ScheduledTasksRegistryHivesSystemEventLogs
- Velociraptor
- Windows.Triage.Targets:ScheduledTasksRegistryHivesSystemEventLogs
Tools
Compare all toolsWhat it is
The Task Scheduler service runs programs at a set time, at boot, at logon or when an event occurs. Attackers use it for persistence, for privilege escalation (tasks can run as SYSTEM) and for lateral movement, since schtasks /create /s <host> registers a task on a remote machine.
A task leaves traces in three places: its definition file on disk, a set of TaskCache registry keys in the SOFTWARE hive, and event logs when auditing is on. Comparing the three is how you spot tampered or hidden tasks.
Location
| Windows version | Task definitions | Registry (SOFTWARE hive) | Logs |
|---|---|---|---|
| XP / Server 2003 | C:\Windows\Tasks\*.job (binary, Task Scheduler 1.0) | none | C:\Windows\SchedLgU.txt (XP), C:\Windows\Tasks\SchedLgU.txt (2003) |
| Vista / 7 / 8 / 10 / 11 | C:\Windows\System32\Tasks\<folder>\<TaskName> (XML, no extension) | Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree and \Tasks | Microsoft-Windows-TaskScheduler/Operational, Security |
Legacy .job files can still appear in C:\Windows\Tasks on newer systems, mostly for tasks created with the deprecated at.exe (At1.job, At2.job…).
TaskCache layout:
TaskCache\Tree\<path>\<TaskName>: valuesId(task GUID),IndexandSD(security descriptor).TaskCache\Tasks\{GUID}: values such asPath,Actions,Triggers,DynamicInfo,Author,Description,Date,URI.TaskCache\Boot,Logon,Plain,Maintenance: GUID lists that sort tasks by trigger type.
What it proves
- Persistence or planned execution: a command, its arguments and the account it runs under.
- Who registered it: the XML
Author/UserId, the account in event 106 and in Security 4698. - When: creation, last run and last successful run times in
DynamicInfo, and run events in the Operational log. - It does not prove the action succeeded: confirm with event 201 (result code), Prefetch or process creation events. The XML
AuthorandDateare free text and can be forged.
Key fields
| Field | Meaning |
|---|---|
RegistrationInfo\Date, Author, URI | Registration date and author as written by the creator (not authoritative) |
Triggers | Time, boot, logon, idle or event triggers, repetition interval |
Principals\Principal (UserId, RunLevel) | Account used and HighestAvailable for elevated tasks |
Settings\Hidden | Hides the task in the console unless "Show hidden tasks" is on |
Actions\Exec (Command, Arguments, WorkingDirectory) | The program that runs |
Actions\ComHandler (ClassId) | COM object run instead of a program; resolve the CLSID |
Tree\...\SD | Security descriptor; if it is missing the task is hidden from enumeration |
Tasks\{GUID}\DynamicInfo | Binary: creation time, last run time, task state, last error code and (on recent builds) last successful run time |
Timestamps
| Timestamp | Set when | Format | Pitfalls |
|---|---|---|---|
DynamicInfo creation / last run / last success | Service registers or runs the task | FILETIME, UTC | Last-success field is absent on older versions; only the latest run is kept |
Tree and Tasks\{GUID} key LastWrite | Task registered or changed | FILETIME, UTC | Also moves on updates, so it is not a pure creation time |
XML RegistrationInfo\Date | Written by the creating tool | ISO 8601 string, often without a time zone | Can be absent or forged |
| XML file $SI times | File created or rewritten | NTFS, UTC | Updated when the task is modified |
.job last run time | Task Scheduler 1.0 runs the job | SYSTEMTIME in the file | XP-era format |
| Event 106 / 140 / 141 / 200 / 201 | Registration, update, deletion, action start and end | EVTX, UTC | Only if the channel is enabled |
| Security 4698–4702 | Task created, deleted, enabled, disabled, updated | EVTX, UTC | Requires "Audit Other Object Access Events" |
Retention and clearing
- Tasks stay until deleted. Deleting a task removes the XML and the TaskCache keys; the Operational log (141) and Security log (4699) are then the main traces, plus deleted-file evidence in the USN journal and older SOFTWARE hives in volume shadow copies.
- Security 4698 requires "Audit Other Object Access Events", and the TaskScheduler Operational channel may be disabled depending on build and configuration ("Enable All Tasks History"). Check whether the channel is enabled and holds events before reading anything into an empty result.
- Hidden tasks: the Tarrask malware deleted the
SDvalue underTaskCache\Tree. The task then disappears fromschtasks /queryand the console but keeps running. The deletion needs SYSTEM rights. The XML file and theTasks\{GUID}key remain. - Event logs roll over by size, so on busy systems the Operational log may only cover days or weeks.
Collection
- KAPE target:
ScheduledTasks(XML,.job,SchedLgU.txt, PowerShell scheduled jobs), plusRegistryHivesSystemfor TaskCache andEventLogsfor the event channels. - Velociraptor (
Windows.Triage.Targets):ScheduledTasks,RegistryHivesSystem,EventLogs. Live analysis:Windows.System.TaskScheduler(parses the XML) andWindows.EventLogs.ScheduledTasks. - Built-in: the XML files can be copied directly; the SOFTWARE hive is locked, so use
reg saveor a shadow copy.
robocopy C:\Windows\System32\Tasks E:\case\Tasks /E /COPY:DAT /DCOPY:T
reg save HKLM\SOFTWARE E:\case\SOFTWARE.hiv
wevtutil epl Microsoft-Windows-TaskScheduler/Operational E:\case\TaskScheduler.evtx
schtasks /query /fo csv /v > E:\case\schtasks.csv
Parsing tools
- Velociraptor:
Windows.System.TaskSchedulerlists commands and user context from the XML;Windows.EventLogs.ScheduledTaskscollates Operational and Security events. - RegRipper:
taskcacheandtasksplugins (SOFTWARE hive), with_tlntimeline variants. - winreg-tasks (G DATA, open source): Kaitai definitions and scripts that decode
Actions,TriggersandDynamicInfo. - TaskSchedulerView (NirSoft, free): GUI listing of tasks on a live system.
- EvtxECmd (Eric Zimmerman): maps TaskScheduler and Security task events to CSV.
- Plaso:
winjobparser for.jobfiles and thewindows_task_cacheregistry plugin.
Investigation tips
- Diff the task list from three sources: XML files,
TaskCache\TreeandTaskCache\Tasks. ATreeentry withoutSD, or a GUID with no matching XML, deserves attention. - Flag actions pointing to
powershell.exe -enc,cmd.exe /c,rundll32.exe,mshta.exe, script files, or binaries in\Users\,\ProgramData\or\Windows\Temp\. - Task names often imitate Microsoft ones (
\Microsoft\Windows\...\Update); check the author, path and binary signature rather than the name. - Security 4698 embeds the full task XML, so it can recover the definition of a task that was later deleted.
- Remote registration shows up as a network logon (logon type 3) on the target just before event 106; correlate in the event logs.
- Confirm execution with Prefetch of the action binary, and check services and WMI for parallel persistence.
Related artifacts
- Windows ServicesWindows services cheat sheet: Services key values (ImagePath, Start, Type, ServiceDll), 7045 and 4697 install events, PsExec traces and pitfalls.
- Run keys and Startup foldersRun keys and Startup folders cheat sheet: Run, RunOnce, Wow6432Node and Policies paths, StartupApproved enabled/disabled bytes, timestamps and pitfalls.
- Windows event logs (EVTX)Windows event log cheat sheet: EVTX locations, must-know event IDs for logons, processes, services and log clearing, retention, audit policy and parsing tools.
- Registry hivesRegistry hives cheat sheet: SYSTEM, SOFTWARE, SAM, SECURITY, NTUSER.DAT, UsrClass.dat, transaction logs, RegBack, LastWrite times and collection.
- Prefetch Files (.pf)Windows Prefetch cheat sheet: .pf location per version, run count, the last eight run times, referenced files, retention limits and how to parse.
- WMI repository and SCCM RecentlyUsedAppsWMI repository cheat sheet: OBJECTS.DATA, event filters, consumers and bindings, WMI-Activity 5857–5861, MOF files and SCCM CCM_RecentlyUsedApps.
- Group Policy artifactsGroup Policy cheat sheet: SYSVOL policies, Registry.pol, GPP passwords, client-side history and event logs, and how attackers abuse GPO for mass deployment.
Glossary terms
- PersistenceMechanisms that let malware or an attacker survive reboots and logoffs, such as Run keys, services, scheduled tasks or WMI subscriptions.
- Windows event IDThe number identifying an event type within a given provider; it only has meaning when paired with its provider and log channel.
- FILETIMEThe 64-bit Windows timestamp format counting 100-nanosecond intervals since 1 January 1601 UTC, used by NTFS, the registry and many artifacts.
- Lateral movementAn attacker moving from one compromised host to others in the network, using RDP, SMB, PsExec, WMI, WinRM or remote tasks and services.