Event ID 4698
Event ID 4698: Scheduled Task Created
A scheduled task was created
- Log source
- Security
- How to enable it
- Object Access > Audit Other Object Access Events (Success)
- Category
- Persistence
- Priority
- High
- Typical volume
- Medium
- MITRE ATT&CK
-
- T1053.005 Scheduled Task/Job: Scheduled Task
What Event ID 4698 means
4698 is written when a scheduled task is registered, and it carries the complete task definition as XML. Few events are so generous: the command, its arguments, the trigger, the account and the hidden flag are all there, and remain in the log even if the task is deleted a second later.
Scheduled tasks offer three things at once to an attacker. They persist across restarts, they run as SYSTEM if created with the right account, and they can be created on a remote computer with only administrator credentials. The same mechanism therefore serves persistence, escalation and lateral movement.
TaskContent is XML inside XML, so characters arrive escaped (<Command>). Decode it before you match patterns. On current versions the event also names the client process and says whether the request came from the local machine.
Key fields to inspect
| Field | Meaning | Suspicious when |
|---|---|---|
TaskName | Path of the task in the library. | Random names in the root folder, or names that imitate Microsoft tasks outside \Microsoft\Windows\. |
TaskContent | Full XML definition. | Command or Arguments with powershell -enc, mshta, rundll32, a share, or a file in a user folder. Hidden set to true. |
SubjectUserName | Who created the task. | A user, or a service account of a web or database server. |
SubjectLogonId | Session that created it. | A type 3 logon, which means remote creation. |
ClientProcessId | Process that asked for it. | Match it to 4688 to find schtasks.exe, powershell.exe or an unknown program. |
RpcCallClientLocality | Whether the request was local or remote. | A value that shows a remote client. |
Detection queries
Find tasks whose definition runs a script host, an encoded command or a program from a writable folder. Adjust names and thresholds to your environment. About these queries.
Splunk SPL
index=windows source="XmlWinEventLog:Security" EventCode=4698
| eval xml=replace(replace(TaskContent, "<", "<"), ">", ">")
| rex field=xml "<Command>(?<command>[^<]+)"
| rex field=xml "<Arguments>(?<arguments>[^<]+)"
| regex xml="(?i)(powershell|pwsh|mshta|rundll32|regsvr32|wscript|cscript|\\\\Users\\\\|\\\\Temp\\\\|\\\\ProgramData\\\\)"
| table _time Computer SubjectUserName TaskName command arguments Microsoft Sentinel KQL
SecurityEvent
| where EventID == 4698
| extend Xml = replace_string(replace_string(EventData, "<", "<"), ">", ">")
| extend TaskName = extract(@'Name="TaskName">([^<]+)', 1, EventData)
| extend Command = extract(@"<Command>([^<]+)", 1, Xml), Arguments = extract(@"<Arguments>([^<]+)", 1, Xml)
| where strcat(Command, " ", Arguments) matches regex @"(?i)(powershell|pwsh|mshta|rundll32|regsvr32|wscript|cscript|\\Users\\|\\Temp\\|\\ProgramData\\)"
| project TimeGenerated, Computer, SubjectUserName, TaskName, Command, Arguments PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4698; StartTime = (Get-Date).AddDays(-7) } |
ForEach-Object { $d = @{ Time = $_.TimeCreated }; ([xml]$_.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d } |
Where-Object { $_.TaskName -notlike '\Microsoft\*' } |
Select-Object Time, SubjectUserName, TaskName, TaskContent | Format-List Attack scenarios
Persistence with a hidden task
A task with a logon or minute trigger starts a script from the user's profile. Hidden is true and the name imitates a browser or update service.
Remote execution with atexec or schtasks /s
A task is created on the target, run once as SYSTEM and deleted. 4698 and 4699 for the same name within seconds, in a type 3 session, are the fingerprint.
Ransomware deployment
Group Policy preferences push an immediate task to every computer. The same TaskName appears across the domain within one refresh cycle, with SYSTEM as subject.
Investigation checklist
- Decode TaskContent and record Command, Arguments, triggers and the account.
- Match SubjectLogonId to 4624 to see whether it was created remotely.
- Check for a later 4699 or 4702 with the same name.
- Collect the program that the task runs, and hash it.
- Search all hosts for the same TaskName or command.
Common benign causes
- Windows components and updaters, in their own folders.
- Software installers and endpoint management.
- Administrators' own maintenance jobs.
Event ID 4698 FAQ
How do I enable event 4698?
Enable success auditing for Object Access, Audit Other Object Access Events. The subcategory also produces 4699, 4700, 4701 and 4702 for other changes to tasks.
Can a scheduled task be created without event 4698?
Yes. Writing the registry entries of a task directly, or removing its security descriptor to hide it, can avoid or obscure the event. Compare the registry task cache with the visible library during an investigation.
What is the difference between 4698 and TaskScheduler event 106?
Event 106 in the TaskScheduler Operational log records the name and user of a registered task. 4698 adds the complete XML and the logon session, but needs an audit policy.