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
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 tasks4 by analyzing task creation events, suspicious task properties, and unusual execution5 patterns that indicate T1053.005 abuse.6domain: cybersecurity7subdomain: threat-hunting8tags:9- threat-hunting10- scheduled-tasks11- persistence12- mitre-t1053-00513- windows14- endpoint-detection15version: '1.0'16author: mahipal17license: Apache-2.018nist_csf:19- DE.CM-0120- DE.AE-0221- DE.AE-0722- ID.RA-0523mitre_attack:24- T104625- T105726- T108227- T108328- T154729metadata:30 source: https://skillmd.com/skills/mukul975/hunting-for-suspicious-scheduled-tasks31---3233# Hunting for Suspicious Scheduled Tasks3435## When to Use3637- When proactively hunting for persistence mechanisms in Windows environments38- After detecting schtasks.exe or at.exe usage in process creation logs39- When investigating malware that survives reboots and user logoffs40- During incident response to enumerate all persistence on compromised systems41- When Windows Security Event ID 4698 (Scheduled Task Created) fires for unusual tasks4243## Prerequisites4445- Windows Security Event ID 4698/4699/4702 (Task Created/Deleted/Updated)46- Sysmon Event ID 1 for schtasks.exe process creation with command lines47- Windows Task Scheduler operational log (Microsoft-Windows-TaskScheduler/Operational)48- PowerShell logging for Register-ScheduledTask cmdlet usage49- Access to Task Scheduler XML definitions on endpoints5051## Workflow52531. **Enumerate All Scheduled Tasks**: Collect complete task inventory from target systems using `schtasks /query /fo CSV /v` or `Get-ScheduledTask` PowerShell cmdlet.542. **Monitor Task Creation Events**: Track Event ID 4698 for new task creation, correlating with the creating process and user account context.553. **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.564. **Check Task Triggers**: Review trigger conditions. Tasks triggered by system startup, user logon, or short intervals (1-5 minutes) warrant investigation.575. **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.586. **Correlate with Process Execution**: Match scheduled task execution events with process creation logs to confirm what actually runs.597. **Baseline and Diff**: Compare current task inventory against known-good baselines to identify new, modified, or unexpected tasks.6061## Detection Queries6263### Splunk -- Scheduled Task Creation64```spl65index=wineventlog EventCode=469866| spath output=TaskName path=EventData.TaskName67| spath output=TaskContent path=EventData.TaskContent68| where NOT match(TaskName, "(?i)(\\\\Microsoft\\\\|\\\\Windows\\\\)")69| table _time Computer SubjectUserName TaskName TaskContent70```7172### Splunk -- Schtasks.exe Suspicious Usage73```spl74index=sysmon EventCode=1 Image="*\\schtasks.exe"75| where match(CommandLine, "(?i)/create")76| where match(CommandLine, "(?i)(powershell|cmd|wscript|cscript|mshta|rundll32|regsvr32|http|https|\\\\temp\\\\|\\\\appdata\\\\)")77| table _time Computer User CommandLine ParentImage78```7980### KQL -- Microsoft Sentinel81```kql82SecurityEvent83| where EventID == 469884| extend TaskName = tostring(EventData.TaskName)85| extend TaskContent = tostring(EventData.TaskContent)86| where TaskContent has_any ("powershell", "cmd.exe", "wscript", "http://", "https://", "\\Temp\\", "\\AppData\\")87| project TimeGenerated, Computer, Account, TaskName, TaskContent88```8990## Common Scenarios91921. **Cobalt Strike Persistence**: Creates scheduled tasks via schtasks.exe to execute PowerShell download cradles at user logon intervals.932. **Ransomware Staging**: Task created to run encryption payload at a future time, often during off-hours for maximum impact.943. **Hidden Task via SD Modification**: Attacker modifies Security Descriptor of scheduled task to hide it from normal enumeration while maintaining execution.954. **COM Handler Abuse**: Task uses COM handler rather than direct executable path, making action inspection more complex.965. **Lateral Movement via Tasks**: Remote scheduled task creation using `schtasks /create /s REMOTE_HOST` for execution on other systems.9798## Output Format99100```101Hunt ID: TH-SCHTASK-[DATE]-[SEQ]102Host: [Hostname]103Task Name: [Full task path]104Action: [Command/Script executed]105Trigger: [Startup/Logon/Timer/Event]106Created By: [User account]107Created From: [Local/Remote]108Creation Time: [Timestamp]109Run As: [Execution account]110Risk Level: [Critical/High/Medium/Low]111```