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: Hunts for adversary persistence and execution via Windows4version: '1.0'5author: mahipal (vendored by SOCIS)6license: Apache-2.07platforms:8- linux9- macos10- windows11category: security12metadata:13 source: https://skillmd.com/skills/socisio/hunting-for-suspicious-scheduled-tasks14 socis:15 tags:16 - threat-hunting17 - scheduled-tasks18 - persistence19 - mitre-t1053-00520 - windows21 - endpoint-detection22 subdomain: threat-hunting23 upstream: mukul975/Anthropic-Cybersecurity-Skills24 nist_csf:25 - DE.CM-0126 - DE.AE-0227 - DE.AE-0728 - ID.RA-0529 mitre_attack:30 - T104631 - T105732 - T108233 - T108334 - T154735---363738# Hunting for Suspicious Scheduled Tasks3940## When to Use4142- When proactively hunting for persistence mechanisms in Windows environments43- After detecting schtasks.exe or at.exe usage in process creation logs44- When investigating malware that survives reboots and user logoffs45- During incident response to enumerate all persistence on compromised systems46- When Windows Security Event ID 4698 (Scheduled Task Created) fires for unusual tasks4748## Prerequisites4950- Windows Security Event ID 4698/4699/4702 (Task Created/Deleted/Updated)51- Sysmon Event ID 1 for schtasks.exe process creation with command lines52- Windows Task Scheduler operational log (Microsoft-Windows-TaskScheduler/Operational)53- PowerShell logging for Register-ScheduledTask cmdlet usage54- Access to Task Scheduler XML definitions on endpoints5556## Workflow57581. **Enumerate All Scheduled Tasks**: Collect complete task inventory from target systems using `schtasks /query /fo CSV /v` or `Get-ScheduledTask` PowerShell cmdlet.592. **Monitor Task Creation Events**: Track Event ID 4698 for new task creation, correlating with the creating process and user account context.603. **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.614. **Check Task Triggers**: Review trigger conditions. Tasks triggered by system startup, user logon, or short intervals (1-5 minutes) warrant investigation.625. **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.636. **Correlate with Process Execution**: Match scheduled task execution events with process creation logs to confirm what actually runs.647. **Baseline and Diff**: Compare current task inventory against known-good baselines to identify new, modified, or unexpected tasks.6566## Detection Queries6768### Splunk -- Scheduled Task Creation69```spl70index=wineventlog EventCode=469871| spath output=TaskName path=EventData.TaskName72| spath output=TaskContent path=EventData.TaskContent73| where NOT match(TaskName, "(?i)(\\\\Microsoft\\\\|\\\\Windows\\\\)")74| table _time Computer SubjectUserName TaskName TaskContent75```7677### Splunk -- Schtasks.exe Suspicious Usage78```spl79index=sysmon EventCode=1 Image="*\\schtasks.exe"80| where match(CommandLine, "(?i)/create")81| where match(CommandLine, "(?i)(powershell|cmd|wscript|cscript|mshta|rundll32|regsvr32|http|https|\\\\temp\\\\|\\\\appdata\\\\)")82| table _time Computer User CommandLine ParentImage83```8485### KQL -- Microsoft Sentinel86```kql87SecurityEvent88| where EventID == 469889| extend TaskName = tostring(EventData.TaskName)90| extend TaskContent = tostring(EventData.TaskContent)91| where TaskContent has_any ("powershell", "cmd.exe", "wscript", "http://", "https://", "\\Temp\\", "\\AppData\\")92| project TimeGenerated, Computer, Account, TaskName, TaskContent93```9495## Common Scenarios96971. **Cobalt Strike Persistence**: Creates scheduled tasks via schtasks.exe to execute PowerShell download cradles at user logon intervals.982. **Ransomware Staging**: Task created to run encryption payload at a future time, often during off-hours for maximum impact.993. **Hidden Task via SD Modification**: Attacker modifies Security Descriptor of scheduled task to hide it from normal enumeration while maintaining execution.1004. **COM Handler Abuse**: Task uses COM handler rather than direct executable path, making action inspection more complex.1015. **Lateral Movement via Tasks**: Remote scheduled task creation using `schtasks /create /s REMOTE_HOST` for execution on other systems.102103## Output Format104105```106Hunt ID: TH-SCHTASK-[DATE]-[SEQ]107Host: [Hostname]108Task Name: [Full task path]109Action: [Command/Script executed]110Trigger: [Startup/Logon/Timer/Event]111Created By: [User account]112Created From: [Local/Remote]113Creation Time: [Timestamp]114Run As: [Execution account]115Risk Level: [Critical/High/Medium/Low]116```