Chapter 68

Scheduled Tasks

Task XML format, trigger types, storage in TaskCache registry, Event IDs 4698/4702, remote task creation via ATSVC, and hunting malicious tasks.

Scenario

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

XMLExample task definition
<?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

TriggerXML elementAttacker use case
Time-basedTimeTrigger, CalendarTriggerRegular callback (every 5 min = beaconing)
LogonLogonTriggerExecutes on user logon — survives reboots, no service needed
BootBootTriggerExecutes at system boot before user logon
IdleIdleTriggerExecutes when system is idle — stealth for noisy operations
EventEventTriggerTriggers on specific Windows Event ID — event-driven backdoor
RegistrationRegistrationTriggerFires once immediately on task creation — useful for immediate execution

Security Events for Task Activity

Event IDChannelDescription
4698SecurityScheduled task was created — SubjectUserName, TaskName, TaskContent (full XML)
4702SecurityScheduled task was updated — same fields as 4698
4699SecurityScheduled task was deleted
4700SecurityScheduled task was enabled
4701SecurityScheduled task was disabled
106Microsoft-Windows-TaskScheduler/OperationalTask registered
200Microsoft-Windows-TaskScheduler/OperationalTask action started — TaskName, InstanceId, EnginePID
201Microsoft-Windows-TaskScheduler/OperationalTask action completed — ResultCode
Why Event 4698 is essential

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:

Hunting Malicious Tasks

PowerShellhunt_malicious_tasks.ps1
# 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

YAMLmalicious_scheduled_task.yml
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).