Event ID 4702
Event ID 4702: Scheduled Task Updated
A scheduled task was updated
- Log source
- Security
- How to enable it
- Object Access > Audit Other Object Access Events (Success)
- Category
- Persistence
- Priority
- Medium
- Typical volume
- High
- MITRE ATT&CK
What Event ID 4702 means
4702 is written when an existing task changes, and it contains the new definition. The old one is not included, so you need an earlier event or a copy of the task to see what was different.
Changing a task is quieter than creating one. The name is already known and approved, and the account is already SYSTEM. An attacker who replaces the command of a vendor's update task inherits all of that trust, and a rule that watches only for 4698 never fires.
Volume is the obstacle. Windows updates its own tasks constantly, mostly under \Microsoft\Windows\ and by machine accounts. Once those are removed, changes by named users and changes to the Command element are few enough to review.
Key fields to inspect
| Field | Meaning | Suspicious when |
|---|---|---|
TaskName | Path of the changed task. | A vendor or Windows task changed by a person. |
TaskContentNew | New XML definition. | A Command or Arguments that does not match the product the task belongs to. |
SubjectUserName | Who changed it. | Any account that does not end in $ and is not SYSTEM. |
SubjectLogonId | Session that changed it. | A network session. |
ClientProcessId | Process that asked for the change. | Match it to 4688 for schtasks.exe /change. |
RpcCallClientLocality | Whether the request was local or remote. | A remote client. |
Detection queries
List task changes made by people, with the command that the task now runs. Adjust names and thresholds to your environment. About these queries.
Splunk SPL
index=windows source="XmlWinEventLog:Security" EventCode=4702
| where NOT match(SubjectUserName, "\$$") AND SubjectUserName!="SYSTEM"
| eval xml=replace(replace(TaskContentNew, "<", "<"), ">", ">")
| rex field=xml "<Command>(?<command>[^<]+)"
| rex field=xml "<Arguments>(?<arguments>[^<]+)"
| table _time Computer SubjectUserName TaskName command arguments Microsoft Sentinel KQL
SecurityEvent
| where EventID == 4702
| where SubjectUserName !endswith "$" and SubjectUserName !~ "SYSTEM"
| extend Xml = replace_string(replace_string(EventData, "<", "<"), ">", ">")
| extend TaskName = extract(@'Name="TaskName">([^<]+)', 1, EventData), Command = extract(@"<Command>([^<]+)", 1, Xml), Arguments = extract(@"<Arguments>([^<]+)", 1, Xml)
| project TimeGenerated, Computer, SubjectUserName, TaskName, Command, Arguments PowerShell
Get-WinEvent -FilterHashtable @{ LogName = 'Security'; Id = 4702; StartTime = (Get-Date).AddDays(-7) } |
ForEach-Object { $d = @{ Time = $_.TimeCreated }; ([xml]$_.ToXml()).Event.EventData.Data | ForEach-Object { $d[$_.Name] = $_.'#text' }; [pscustomobject]$d } |
Where-Object { $_.SubjectUserName -notlike '*$' } |
Select-Object Time, SubjectUserName, TaskName, TaskContentNew | Format-List Attack scenarios
Hijack of a trusted task
schtasks /change /tn with a new /tr swaps the program of an existing task. After it has run, the original command may be restored, which gives two 4702 events with different content around one execution.
Adding a trigger
Instead of changing the command, the attacker adds a logon or idle trigger to a task that already runs a writable script, and then edits the script. The event shows the trigger and not the script.
Investigation checklist
- Compare the new definition with the same task on a healthy computer.
- Look for a second 4702 that restores the earlier content.
- Check signatures and write permissions of the file in Command.
- Find the process and session that made the change.
Common benign causes
- Windows maintenance, update and telemetry tasks, which change many times a day.
- Vendor updaters that move their next run time.
- Group Policy refresh that reapplies tasks.
Event ID 4702 FAQ
Why are there so many 4702 events?
Windows updates its own tasks regularly, for example after it calculates the next run. Filter machine accounts, SYSTEM and the \Microsoft\Windows\ folder to find changes made by people.
Can I see what changed in a 4702 event?
Not directly, since only the new definition is recorded. Compare it with the previous 4698 or 4702 for that task, or with the same task on a clean system.
Is 4702 logged when a task is disabled?
Disabling and enabling have their own events, 4701 and 4700. An update event can accompany them.