Hunting for Suspicious Scheduled Tasks
When to Use
- When proactively hunting for persistence mechanisms in Windows environments
- After detecting schtasks.exe or at.exe usage in process creation logs
- When investigating malware that survives reboots and user logoffs
- During incident response to enumerate all persistence on compromised systems
- When Windows Security Event ID 4698 (Scheduled Task Created) fires for unusual tasks
Detection Gaps & Validation
- Audit gap, not "no activity": Security EID 4698/4702 only log when "Object Access > Other Object Access Events" auditing is enabled (default OFF) — absence of 4698 does NOT mean no tasks. Corroborate with Microsoft-Windows-TaskScheduler/Operational (EID 106/140/200) and the registry
HKLM\...\Schedule\TaskCache\Tree.
- Action-type evasion: tasks whose action is a
ComHandler CLSID, and tasks created by writing directly to TaskCache, bypass schtasks.exe EID 1 command-line hunting.
- SD-deletion hiding: removing the task's SD makes it vanish from
schtasks /query and the GUI while it still executes — diff TaskCache\Tree GUIDs against \Tasks to surface orphans.
- Renamed binary: match EID 1
OriginalFileName + CommandLine, since a renamed schtasks.exe defeats Image-name rules.
- Validate: run Atomic T1053.005 schtasks and
Register-ScheduledTask; confirm 4698 + a new TaskCache registry entry both appear.
- FP tuning: baseline
\Microsoft\Windows\ built-ins and vendor updater tasks by author/signer.
Prerequisites
- Windows Security Event ID 4698/4699/4702 (Task Created/Deleted/Updated)
- Sysmon Event ID 1 for schtasks.exe process creation with command lines
- Windows Task Scheduler operational log (Microsoft-Windows-TaskScheduler/Operational)
- PowerShell logging for Register-ScheduledTask cmdlet usage
- Access to Task Scheduler XML definitions on endpoints
Workflow
- Enumerate All Scheduled Tasks: Collect complete task inventory from target systems using
schtasks /query /fo CSV /v or Get-ScheduledTask PowerShell cmdlet.
- Monitor Task Creation Events: Track Event ID 4698 for new task creation, correlating with the creating process and user account context.
- Analyze Task Actions: Examine what each task executes. Flag tasks running scripts (PowerShell, cmd, wscript), binaries from user-writable paths (TEMP, AppData, Downloads), or encoded/obfuscated commands.
- Check Task Triggers: Review trigger conditions. Tasks triggered by system startup, user logon, or short intervals (1-5 minutes) warrant investigation.
- Identify Hidden or Disguised Tasks: Hunt for tasks with names mimicking legitimate Windows tasks, tasks with Security Descriptor modifications hiding them from standard enumeration, or tasks stored in non-standard registry locations.
- Correlate with Process Execution: Match scheduled task execution events with process creation logs to confirm what actually runs.
- Baseline and Diff: Compare current task inventory against known-good baselines to identify new, modified, or unexpected tasks.
Detection Queries
Splunk -- Scheduled Task Creation
index=wineventlog EventCode=4698
| spath output=TaskName path=EventData.TaskName
| spath output=TaskContent path=EventData.TaskContent
| where NOT match(TaskName, "(?i)(\\\\Microsoft\\\\|\\\\Windows\\\\)")
| table _time Computer SubjectUserName TaskName TaskContent
Splunk -- Schtasks.exe Suspicious Usage
index=sysmon EventCode=1 Image="*\\schtasks.exe"
| where match(CommandLine, "(?i)/create")
| where match(CommandLine, "(?i)(powershell|cmd|wscript|cscript|mshta|rundll32|regsvr32|http|https|\\\\temp\\\\|\\\\appdata\\\\)")
| table _time Computer User CommandLine ParentImage
KQL -- Microsoft Sentinel
SecurityEvent
| where EventID == 4698
| extend TaskName = tostring(EventData.TaskName)
| extend TaskContent = tostring(EventData.TaskContent)
| where TaskContent has_any ("powershell", "cmd.exe", "wscript", "http://", "https://", "\\Temp\\", "\\AppData\\")
| project TimeGenerated, Computer, Account, TaskName, TaskContent
Common Scenarios
- Cobalt Strike Persistence: Creates scheduled tasks via schtasks.exe to execute PowerShell download cradles at user logon intervals.
- Ransomware Staging: Task created to run encryption payload at a future time, often during off-hours for maximum impact.
- Hidden Task via SD Modification: Attacker modifies Security Descriptor of scheduled task to hide it from normal enumeration while maintaining execution.
- COM Handler Abuse: Task uses COM handler rather than direct executable path, making action inspection more complex.
- Lateral Movement via Tasks: Remote scheduled task creation using
schtasks /create /s REMOTE_HOST for execution on other systems.
Output Format
Hunt ID: TH-SCHTASK-[DATE]-[SEQ]
Host: [Hostname]
Task Name: [Full task path]
Action: [Command/Script executed]
Trigger: [Startup/Logon/Timer/Event]
Created By: [User account]
Created From: [Local/Remote]
Creation Time: [Timestamp]
Run As: [Execution account]
Risk Level: [Critical/High/Medium/Low]
1---2name: hunting-for-suspicious-scheduled-tasks3description: Hunt for adversary persistence and execution via Windows scheduled tasks by analyzing task creation events, suspicious task properties, and unusual execution patterns that indicate T1053.005 abuse.4license: Apache-2.05---67# Hunting for Suspicious Scheduled Tasks89## When to Use1011- When proactively hunting for persistence mechanisms in Windows environments12- After detecting schtasks.exe or at.exe usage in process creation logs13- When investigating malware that survives reboots and user logoffs14- During incident response to enumerate all persistence on compromised systems15- When Windows Security Event ID 4698 (Scheduled Task Created) fires for unusual tasks1617## Detection Gaps & Validation1819- **Audit gap, not "no activity":** Security EID 4698/4702 only log when "Object Access > Other Object Access Events" auditing is enabled (default OFF) — absence of 4698 does NOT mean no tasks. Corroborate with Microsoft-Windows-TaskScheduler/Operational (EID 106/140/200) and the registry `HKLM\...\Schedule\TaskCache\Tree`.20- **Action-type evasion:** tasks whose action is a `ComHandler` CLSID, and tasks created by writing directly to `TaskCache`, bypass schtasks.exe EID 1 command-line hunting.21- **SD-deletion hiding:** removing the task's SD makes it vanish from `schtasks /query` and the GUI while it still executes — diff `TaskCache\Tree` GUIDs against `\Tasks` to surface orphans.22- **Renamed binary:** match EID 1 `OriginalFileName` + CommandLine, since a renamed schtasks.exe defeats Image-name rules.23- **Validate:** run Atomic T1053.005 schtasks and `Register-ScheduledTask`; confirm 4698 + a new TaskCache registry entry both appear.24- **FP tuning:** baseline `\Microsoft\Windows\` built-ins and vendor updater tasks by author/signer.2526## Prerequisites2728- Windows Security Event ID 4698/4699/4702 (Task Created/Deleted/Updated)29- Sysmon Event ID 1 for schtasks.exe process creation with command lines30- Windows Task Scheduler operational log (Microsoft-Windows-TaskScheduler/Operational)31- PowerShell logging for Register-ScheduledTask cmdlet usage32- Access to Task Scheduler XML definitions on endpoints3334## Workflow35361. **Enumerate All Scheduled Tasks**: Collect complete task inventory from target systems using `schtasks /query /fo CSV /v` or `Get-ScheduledTask` PowerShell cmdlet.372. **Monitor Task Creation Events**: Track Event ID 4698 for new task creation, correlating with the creating process and user account context.383. **Analyze Task Actions**: Examine what each task executes. Flag tasks running scripts (PowerShell, cmd, wscript), binaries from user-writable paths (TEMP, AppData, Downloads), or encoded/obfuscated commands.394. **Check Task Triggers**: Review trigger conditions. Tasks triggered by system startup, user logon, or short intervals (1-5 minutes) warrant investigation.405. **Identify Hidden or Disguised Tasks**: Hunt for tasks with names mimicking legitimate Windows tasks, tasks with Security Descriptor modifications hiding them from standard enumeration, or tasks stored in non-standard registry locations.416. **Correlate with Process Execution**: Match scheduled task execution events with process creation logs to confirm what actually runs.427. **Baseline and Diff**: Compare current task inventory against known-good baselines to identify new, modified, or unexpected tasks.4344## Detection Queries4546### Splunk -- Scheduled Task Creation47```spl48index=wineventlog EventCode=469849| spath output=TaskName path=EventData.TaskName50| spath output=TaskContent path=EventData.TaskContent51| where NOT match(TaskName, "(?i)(\\\\Microsoft\\\\|\\\\Windows\\\\)")52| table _time Computer SubjectUserName TaskName TaskContent53```5455### Splunk -- Schtasks.exe Suspicious Usage56```spl57index=sysmon EventCode=1 Image="*\\schtasks.exe"58| where match(CommandLine, "(?i)/create")59| where match(CommandLine, "(?i)(powershell|cmd|wscript|cscript|mshta|rundll32|regsvr32|http|https|\\\\temp\\\\|\\\\appdata\\\\)")60| table _time Computer User CommandLine ParentImage61```6263### KQL -- Microsoft Sentinel64```kql65SecurityEvent66| where EventID == 469867| extend TaskName = tostring(EventData.TaskName)68| extend TaskContent = tostring(EventData.TaskContent)69| where TaskContent has_any ("powershell", "cmd.exe", "wscript", "http://", "https://", "\\Temp\\", "\\AppData\\")70| project TimeGenerated, Computer, Account, TaskName, TaskContent71```7273## Common Scenarios74751. **Cobalt Strike Persistence**: Creates scheduled tasks via schtasks.exe to execute PowerShell download cradles at user logon intervals.762. **Ransomware Staging**: Task created to run encryption payload at a future time, often during off-hours for maximum impact.773. **Hidden Task via SD Modification**: Attacker modifies Security Descriptor of scheduled task to hide it from normal enumeration while maintaining execution.784. **COM Handler Abuse**: Task uses COM handler rather than direct executable path, making action inspection more complex.795. **Lateral Movement via Tasks**: Remote scheduled task creation using `schtasks /create /s REMOTE_HOST` for execution on other systems.8081## Output Format8283```84Hunt ID: TH-SCHTASK-[DATE]-[SEQ]85Host: [Hostname]86Task Name: [Full task path]87Action: [Command/Script executed]88Trigger: [Startup/Logon/Timer/Event]89Created By: [User account]90Created From: [Local/Remote]91Creation Time: [Timestamp]92Run As: [Execution account]93Risk Level: [Critical/High/Medium/Low]94```