Guided lab: the scheduled task that looks like Windows
Plant a scheduled task with Atomic Red Team, then find it four ways and work out which one survives an attacker who names their task properly. Closes the loop on the persistence you found on the domain controller in the Northwind case.
- ATT&CK
- T1053.005
The Run key lab taught the difference between state and history. This one is the same technique class with a harder problem attached: scheduled tasks are numerous, most of them are legitimate, and a competent attacker names theirs to look like the rest.
Same requirement as before. A Windows VM you can throw away, snapshotted before you start.
Why this one is harder than a Run key
A clean Windows install ships with well over a hundred scheduled tasks. Nobody
knows what all of them do, which is exactly the cover an attacker wants. A Run
key on a workstation has maybe a dozen neighbours and an odd one stands out. A
task called SystemRestore\SR-Maintenance does not.
Set up
Same tooling as the Run key lab: Sysmon with a registry-logging config, and
Atomic Red Team. Open the entry for T1053.005, read the tests, pick one that
creates a task via schtasks.exe, and run it.
The investigation
Q1
Find the task in the event log. Which log, which event, and what does it record that a task listing does not?
Stuck? Where to look
There are two candidates. One is on by default; the other is a dedicated operational log for the scheduler itself.
Show me the method
Check Security for 4698, and Applications and Services Logs → Microsoft → Windows → TaskScheduler → Operational for 106. Look at what each contains.
Show the answer
Security 4698, "A scheduled task was created." It carries the full task XML, which means the action, the trigger, the principal it runs as, and who created it, all in one event.
TaskScheduler Operational 106 records registration too, but with less detail. Worth knowing because 4698 requires the object access audit policy to be enabled, and on many estates it simply is not, whereas the operational log is often on.
Either way the log gives you something a task listing never will: who created it and when. That is the difference between "this task exists" and "this task appeared at 09:04 on Tuesday, made by an account that had no business making it".
Q2
Find the same task on disk, without the event log. What is in the file, and why is its timestamp interesting?
Stuck? Where to look
Every registered task is also a file. Look in the System32 tree.
Show the answer
C:\Windows\System32\Tasks\ holds one XML file per task, in a folder structure
mirroring the Task Scheduler tree. The file is plain XML: trigger, action,
principal, the lot.
The timestamp matters because it is a filesystem artifact that survives log rotation. If your Security log only goes back 3 days and the task was planted 2 weeks ago, the file creation time is the only thing left telling you when. Build your timeline from artifacts with different lifetimes and you cover more ground than any single source gives you.
Q3
Now find it a third way, in the registry. Why does the scheduler keep a copy there at all?
Show me the method
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree, and
the Tasks key beside it.
Show the answer
TaskCache\Tree mirrors the folder structure; TaskCache\Tasks holds the
details keyed by GUID.
It is there for the scheduler's own speed, but for you it is a third
independent copy. Tampering usually removes one and forgets another. A task
present in the registry but missing from System32\Tasks, or the reverse, is a
much stronger signal than either copy on its own, because inconsistency between
two views is hard to fake and easy to check.
Q4
Run Autoruns and find it a fourth time. Then answer the real question: given a
task named \Microsoft\Windows\SystemRestore\SR-Maintenance running
C:\Windows\Temp\srtasks.exe, what actually gives it away?
Stuck? Where to look
The name is designed to survive a skim. Look at everything except the name.
Show me the method
Compare the executable's path against where that binary really lives, and check whether the file is signed.
Show the answer
The path, not the name. A real srtasks.exe lives in
C:\Windows\System32. This one is in C:\Windows\Temp, which is world-writable
and where no Microsoft binary is installed.
Then the signature. Autoruns shows publisher, and an unsigned binary in a Microsoft-named task is not a grey area. Turn on Options → Hide Microsoft entries and anything left in a Microsoft-looking folder is worth a hard look.
The transferable lesson: a detection matching the task name would miss this, and a detection matching the executable path would catch it. Attackers pick names to defeat human review. They have far less freedom over where they can write a file.
Q5
Write the detection. What do you alert on, and what is the tuning problem?
Show the answer
Start with Security 4698, or Sysmon Event ID 1 for schtasks.exe and Event ID
11 for file creation under System32\Tasks\.
The tuning problem is the same shape as the Run key one and worse in degree: software installers, Windows Update and management agents create tasks constantly. The rule that survives contact with production is not a longer allowlist of names, because names are the attacker's free variable.
Two conditions that hold up:
- The action's path. A task whose executable sits in
Temp,AppData,ProgramDataor a user profile is worth alerting on almost unconditionally. - The creating process's ancestry.
schtasks.exespawned bypowershell.exespawned by Word is a different event fromschtasks.exespawned by an MSI.
Notice this is the same conclusion the Run key lab reached from different evidence. When two independent investigations land on "ancestry and path beat name", that is a principle rather than a coincidence.
Clean up
Use the atomic's cleanup command, then verify with Autoruns and by checking
that the XML file is gone from System32\Tasks. Verifying in a different place
from the one you cleaned is the habit worth building.
Where this connects
You have now found the persistence from the Northwind case on a real machine, four ways. The constructed case gave you the reasoning in a tidy timeline; this gave you the artifacts in situ. Neither is sufficient alone.
Discussion
GuidelinesSign in to comment. Corrections and additions are the point — this is a working document.