Scheduled Tasks
Task XML format, trigger types, storage in TaskCache registry, Event IDs 4698/4702, remote task creation via ATSVC, and hunting malicious tasks.
During a forensic investigation, the analyst queries scheduled tasks on a compromised workstation. One task stands out: Name="MicrosoftEdgeUpdateCore2", Action: powershell.exe -w hidden -enc JABjACAA..., Trigger: At logon for Any user, RunAs: SYSTEM. The name mimics Edge's legitimate update task. It was registered 11 days ago. The real MicrosoftEdgeUpdateCore runs from the Edge installation directory — not PowerShell. Detection engineer's note: Event 4698 would have fired at registration. Was anyone watching?
Task Storage Architecture
Scheduled tasks are stored in two places:
Scheduled Task Storage
══════════════════════════════════════════════════════════════════
1. XML Files on disk:
C:\Windows\System32\Tasks\ (system tasks)
C:\Windows\SysWOW64\Tasks\ (32-bit tasks)
C:\Users\\AppData\...\Tasks\ (user tasks, older)
2. TaskCache registry hive:
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\
├── Tasks\{GUID} ← binary blob with path + hash
├── Tree\ ← folder hierarchy mirroring \Tasks\ files
│ └── Microsoft\Windows\...
└── Plain\ ← flat index
Both must be consistent — if an attacker deletes only the XML file
but leaves the registry entry (or vice versa), the inconsistency
is itself suspicious.
Task XML Structure
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2">
<RegistrationInfo>
<Date>2026-09-08T02:37:00</Date>
<Author>SYSTEM</Author>
<Description>Keeps Microsoft Edge up to date</Description> <!-- attacker lie -->
</RegistrationInfo>
<Triggers>
<LogonTrigger>
<Enabled>true</Enabled>
<UserId>*</UserId> <!-- Any user -->
</LogonTrigger>
</Triggers>
<Principals>
<Principal id="Author">
<UserId>S-1-5-18</UserId> <!-- SYSTEM -->
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<Hidden>true</Hidden> <!-- hidden from Task Scheduler UI -->
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit> <!-- no time limit -->
</Settings>
<Actions>
<Exec>
<Command>powershell.exe</Command>
<Arguments>-w hidden -enc JABjACAA...</Arguments>
</Exec>
</Actions>
</Task>
Trigger Types
| Trigger | XML element | Attacker use case |
|---|---|---|
| Time-based | TimeTrigger, CalendarTrigger | Regular callback (every 5 min = beaconing) |
| Logon | LogonTrigger | Executes on user logon — survives reboots, no service needed |
| Boot | BootTrigger | Executes at system boot before user logon |
| Idle | IdleTrigger | Executes when system is idle — stealth for noisy operations |
| Event | EventTrigger | Triggers on specific Windows Event ID — event-driven backdoor |
| Registration | RegistrationTrigger | Fires once immediately on task creation — useful for immediate execution |
Security Events for Task Activity
| Event ID | Channel | Description |
|---|---|---|
| 4698 | Security | Scheduled task was created — SubjectUserName, TaskName, TaskContent (full XML) |
| 4702 | Security | Scheduled task was updated — same fields as 4698 |
| 4699 | Security | Scheduled task was deleted |
| 4700 | Security | Scheduled task was enabled |
| 4701 | Security | Scheduled task was disabled |
| 106 | Microsoft-Windows-TaskScheduler/Operational | Task registered |
| 200 | Microsoft-Windows-TaskScheduler/Operational | Task action started — TaskName, InstanceId, EnginePID |
| 201 | Microsoft-Windows-TaskScheduler/Operational | Task action completed — ResultCode |
Event 4698 includes the full XML definition of the created task in the TaskContent field. This means the complete task — trigger, action, command line, run-as account — is logged at creation time. Even if the attacker later deletes the task, the 4698 event in the Security log preserves the full payload. Enable "Audit Other Object Access Events" in audit policy to generate 4698/4699/4700/4701/4702.
Remote Task Creation via ATSVC
Tasks can be created remotely using the AT service protocol (ATSVC / Task Scheduler RPC interface). This is a lateral movement technique:
- Requires: valid credentials with admin rights on target
- Network protocol: ATSVC RPC over port 445 (SMB named pipe \PIPE\atsvc)
- Detection on source: Sysmon Event 3 to port 445; Event 5140 (network share accessed: IPC$)
- Detection on target: Event 4698 with SubjectUserName being a remote user; Event 4624 type 3 from source IP
Hunting Malicious Tasks
# List all tasks with their actions and triggers
Get-ScheduledTask | ForEach-Object {
$task = $_
$info = $task | Get-ScheduledTaskInfo
$actions = $task.Actions | ForEach-Object { "$($_.Execute) $($_.Arguments)" }
[PSCustomObject]@{
Name = $task.TaskName
Path = $task.TaskPath
State = $task.State
RunAs = $task.Principal.UserId
Hidden = $task.Settings.Hidden
Actions = ($actions -join "; ")
LastRun = $info.LastRunTime
NextRun = $info.NextRunTime
}
} | Where-Object {
# Flag suspicious patterns
$_.Actions -match 'powershell|cmd\.exe|wscript|cscript|mshta|rundll32' -and
($_.Actions -match '-enc|-e |hidden|bypass|NoProfile' -or
$_.RunAs -match 'S-1-5-18|SYSTEM')
} | Format-List
Sigma Rules
title: Suspicious Scheduled Task Created with Encoded Command
status: stable
logsource:
product: windows
service: security
detection:
selection:
EventID: 4698
TaskContent|contains:
- '-enc '
- '-EncodedCommand'
- 'FromBase64String'
- 'DownloadString'
- 'IEX'
- 'Invoke-Expression'
condition: selection
level: high
tags:
- attack.persistence
- attack.t1053.005
Q & A
Q: An attacker creates a task then immediately deletes it (RegistrationTrigger fires first). What evidence remains?
Events 4698 (creation) and 4699 (deletion) both appear in the Security log, along with TaskScheduler Operational Events 106 (registered) and 141 (deleted). Most importantly, Event 4698 contains the full task XML — including the action (command line) — logged at creation time. Even with the task deleted, the XML payload is preserved in the Security event log for as long as the log is retained. The task's execution also generates Event 4688 (process creation) for the launched process. So a "create + execute + delete" task leaves: 4698 (full XML), 4688 (execution), 4699 (deletion). The attacker can't erase Security event log entries without Administrator rights and clearing the entire log (which generates Event 1102).