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-tasks
3description: Hunt for adversary persistence and execution via Windows scheduled tasks
4 by analyzing task creation events, suspicious task properties, and unusual execution
5 patterns that indicate T1053.005 abuse.
6domain: cybersecurity
7subdomain: threat-hunting
8tags:
9- threat-hunting
10- scheduled-tasks
11- persistence
12- mitre-t1053-005
13- windows
14- endpoint-detection
15version: '1.0'
16author: mahipal
17license: Apache-2.0
18nist_csf:
19- DE.CM-01
20- DE.AE-02
21- DE.AE-07
22- ID.RA-05
23mitre_attack:
24- T1046
25- T1057
26- T1082
27- T1083
28- T1547
29source: https://github.com/mukul975/Anthropic-Cybersecurity-Skills
30source_commit: 04450304b12645cb2b974ab96d28c0664758a88d
31metadata:
32 source: https://skillmd.com/skills/yanacuti1121/hunting-for-suspicious-scheduled-tasks
33---
34
35# Hunting for Suspicious Scheduled Tasks
36
37## When to Use
38
39- When proactively hunting for persistence mechanisms in Windows environments
40- After detecting schtasks.exe or at.exe usage in process creation logs
41- When investigating malware that survives reboots and user logoffs
42- During incident response to enumerate all persistence on compromised systems
43- When Windows Security Event ID 4698 (Scheduled Task Created) fires for unusual tasks
44
45## Prerequisites
46
47- Windows Security Event ID 4698/4699/4702 (Task Created/Deleted/Updated)
48- Sysmon Event ID 1 for schtasks.exe process creation with command lines
49- Windows Task Scheduler operational log (Microsoft-Windows-TaskScheduler/Operational)
50- PowerShell logging for Register-ScheduledTask cmdlet usage
51- Access to Task Scheduler XML definitions on endpoints
52
53## Workflow
54
551. **Enumerate All Scheduled Tasks**: Collect complete task inventory from target systems using `schtasks /query /fo CSV /v` or `Get-ScheduledTask` PowerShell cmdlet.
562. **Monitor Task Creation Events**: Track Event ID 4698 for new task creation, correlating with the creating process and user account context.
573. **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.
584. **Check Task Triggers**: Review trigger conditions. Tasks triggered by system startup, user logon, or short intervals (1-5 minutes) warrant investigation.
595. **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.
606. **Correlate with Process Execution**: Match scheduled task execution events with process creation logs to confirm what actually runs.
617. **Baseline and Diff**: Compare current task inventory against known-good baselines to identify new, modified, or unexpected tasks.
62
63## Detection Queries
64
65### Splunk -- Scheduled Task Creation
66```spl
67index=wineventlog EventCode=4698
68| spath output=TaskName path=EventData.TaskName
69| spath output=TaskContent path=EventData.TaskContent
70| where NOT match(TaskName, "(?i)(\\\\Microsoft\\\\|\\\\Windows\\\\)")
71| table _time Computer SubjectUserName TaskName TaskContent
72```
73
74### Splunk -- Schtasks.exe Suspicious Usage
75```spl
76index=sysmon EventCode=1 Image="*\\schtasks.exe"
77| where match(CommandLine, "(?i)/create")
78| where match(CommandLine, "(?i)(powershell|cmd|wscript|cscript|mshta|rundll32|regsvr32|http|https|\\\\temp\\\\|\\\\appdata\\\\)")
79| table _time Computer User CommandLine ParentImage
80```
81
82### KQL -- Microsoft Sentinel
83```kql
84SecurityEvent
85| where EventID == 4698
86| extend TaskName = tostring(EventData.TaskName)
87| extend TaskContent = tostring(EventData.TaskContent)
88| where TaskContent has_any ("powershell", "cmd.exe", "wscript", "http://", "https://", "\\Temp\\", "\\AppData\\")
89| project TimeGenerated, Computer, Account, TaskName, TaskContent
90```
91
92## Common Scenarios
93
941. **Cobalt Strike Persistence**: Creates scheduled tasks via schtasks.exe to execute PowerShell download cradles at user logon intervals.
952. **Ransomware Staging**: Task created to run encryption payload at a future time, often during off-hours for maximum impact.
963. **Hidden Task via SD Modification**: Attacker modifies Security Descriptor of scheduled task to hide it from normal enumeration while maintaining execution.
974. **COM Handler Abuse**: Task uses COM handler rather than direct executable path, making action inspection more complex.
985. **Lateral Movement via Tasks**: Remote scheduled task creation using `schtasks /create /s REMOTE_HOST` for execution on other systems.
99
100## Output Format
101
102```
103Hunt ID: TH-SCHTASK-[DATE]-[SEQ]
104Host: [Hostname]
105Task Name: [Full task path]
106Action: [Command/Script executed]
107Trigger: [Startup/Logon/Timer/Event]
108Created By: [User account]
109Created From: [Local/Remote]
110Creation Time: [Timestamp]
111Run As: [Execution account]
112Risk Level: [Critical/High/Medium/Low]
113```