This article teaches offensive and defensive techniques for scheduled task and cron job persistence across Windows and Linux systems. It demonstrates how attackers establish backdoors that survive incident response cleanup by disguising malicious tasks as legitimate system maintenance, and explains the detection methods blue teams must use to find them. The article matters because scheduled task persistence is reportedly the most common persistence technique encountered in real incident response engagements where initial cleanup failed.
- Evasive naming using legitimate Windows pathsAttackers place malicious scheduled tasks in real Windows directories like MicrosoftWindowsMaintenance rather than creating new suspicious folders. By naming a task to match existing legitimate tasks (e.g., WinSAT under Maintenance), automated detection tools that exclude Microsoft paths entirely will miss the malicious task. The article demonstrates this with a task running encoded PowerShell daily at 3AM under a legitimate Windows path that blends with System Assessment Tool tasks.
- Trigger selection affects detection evasionThe article ranks persistence triggers by detectability: ONLOGON is noisy and flagged immediately by security tools; ONSTART runs before security tools initialize and is harder to detect; DAILY at 3AM is best for evasion because it occurs during a low-activity maintenance window. Event-based triggers using specific Event IDs are described as advanced and hardest to spot because they don't appear in simple task listings.
- Event ID 4698 as the primary detection signalWhen audit logging is enabled, Windows generates Event ID 4698 whenever a scheduled task is created, recording the full task XML including the exact command being executed. The article emphasizes that evasive task naming provides no protection against this event log detection—defenders monitoring 4698 can see both the task creation and its full command regardless of whether the task path appears legitimate.
- Dual-persistence chains survive single cleanup passesThe article opens with a real scenario where defenders found and deleted an obvious decoy scheduled task, then declared the system clean. The attacker's actual persistence—a second task registered under a legitimate Windows maintenance process name running obfuscated PowerShell nightly—survived because it wasn't discovered. This demonstrates why attackers layer multiple persistence mechanisms in the same namespace.
- Autoruns signature verification exposes masked tasksEven with evasive naming under Microsoft paths, Autoruns with signature verification enabled will surface malicious tasks because it compares each task's actual executable against Microsoft's signed binary list. A task under MicrosoftWindowsMaintenance running unsigned or unexpected executables (like powershell.exe with -EncodedCommand) appears unsigned in Autoruns, creating a detection signal despite the legitimate-sounding path.
- Linux cron persists across multiple unmonitored locationsLinux cron persistence can be placed in six different locations: user crontab files, /etc/crontab, /etc/cron.d/, /etc/cron.daily/, /etc/cron.weekly/, and /etc/cron.monthly/. Incomplete cleanup missing even one location allows persistence to survive. The article provides the command find /etc/cron* -newer /etc/passwd to detect recently modified cron files by comparing against /etc/passwd as a known baseline.
- Fileless PowerShell payload execution avoids file-based detectionThe article advocates using IEX combined with DownloadString to download and execute payloads entirely in memory rather than writing .ps1 files to disk. This technique prevents file-based indicators of compromise from appearing in forensic analysis. The payload is encoded in Base64 within the scheduled task command itself, avoiding the need for separate malicious script files.
- Cleanup order and verification matter in engagement disclosureWhen removing persistence after an authorized engagement, the order of deletion and the verification steps taken affect whether traces remain. The article stresses that investigators must verify persistence removal using the same detection commands used to find it—running all enumeration commands after cleanup to confirm no artifacts remain—rather than assuming deletion was successful.
Bottom line: Scheduled task persistence succeeds primarily through evasion via legitimate naming conventions and trigger selection, but detection always surfaces malicious tasks if defenders monitor Event ID 4698, verify executable signatures in Autoruns, or check for encoded PowerShell in task commands—defenders must implement these checks specifically rather than relying on path-based exclusion lists. Attackers layer multiple persistence mechanisms in the same namespace because basic cleanup checklists mis
Part of the Ethical Hacking Mastery Course — 100 Days
🎯 What You’ll Master in Day 39
⏱️ 40 min read · 3 exercises · Day 39 of 100
✅ Before You Start
- Day 38 — Registry Persistence — run keys and COM hijacking established persistence through the Windows registry. Scheduled tasks are the second persistence tier: they survive account password changes, don’t require registry write access in all cases, and are easier to make trigger-based.
- Lab: Kali Linux + either a Windows VM or TryHackMe “Windows Persistence” room · Linux target (DVWA VM or any Metasploitable)
📋 Day 39 — Scheduled Tasks Cron Jobs Persistence
Scheduled task persistence follows directly from Day 38’s registry persistence. Together they form the core persistence toolkit covered in the Ethical Hacking course. The Kali Linux Commands reference has the full schtasks and crontab syntax for lab work.
Windows — schtasks Persistence
schtasks is the command-line interface to the Windows Task Scheduler. On an engagement, schtasks requires either administrative privileges or, in misconfigured environments, standard user access — I always check both. The key is creating a task that runs your payload reliably and blends with legitimate scheduled activity.
Windows — Naming and Trigger Evasion
The naming strategy I use for scheduled task persistence on red team engagements follows one principle: use the existing Windows task namespace. Every legitimate Windows task has a specific path — place your task in the same path with a plausible name and automated detection that works by path-exclusion will skip it entirely.
⏱️ 15 minutes · No tools required
Professional red teamers don’t use one persistence mechanism — they layer them. Design a dual-persistence chain that survives most common incident response cleanup procedures.
The IR team will find obvious persistence and “clean” the machine.
You want to survive their cleanup.
QUESTION 1 — Primary persistence (the one they find)
Design an obvious but functional schtasks entry.
What name makes it look legitimate but slightly suspicious?
What trigger makes IR teams look here first?
QUESTION 2 — Secondary persistence (the one they miss)
Design a task that mimics a real Windows task path and name.
What folder do you use? What name? What trigger?
Why would an automated tool miss it?
QUESTION 3 — Payload delivery (avoid writing files)
Your encoded PowerShell should download and execute from memory.
What PowerShell technique achieves fileless execution?
Why is DownloadString + IEX preferable to writing a .ps1?
QUESTION 4 — Blue team detection
You’re now the defender. What specific command reveals BOTH tasks?
What Autoruns output would expose your secondary task?
What event log entry does schtasks /create generate?
QUESTION 5 — Cleanup order
When cleaning up after an authorised engagement:
What order do you remove persistence and why does order matter?
📸 Write your dual-persistence design. Share in #ethical-hacking.
Linux — Cron and at Persistence
Linux cron persistence is simpler than Windows but has more locations. The cron mechanism checks multiple directories and files — missing one during cleanup means the persistence survives. I always set persistence in at least two locations when the engagement scope allows.
⏱️ 25 minutes · tryhackme.com — Windows Persistence room
TryHackMe’s Windows Persistence room lets you create and verify every persistence technique against a real Windows target without running a local VM. Work through the scheduled task sections specifically.
(Alternatively: “Windows Local Persistence” room)
Complete the scheduled task sections:
Task: Create a basic schtasks ONLOGON entry
Task: Create a SYSTEM-privileged task with encoded payload
Task: Enumerate all scheduled tasks to find the hidden one
Task: Delete your created tasks cleanly
Key questions to answer while working through the room:
1. What event ID is generated when a scheduled task is created?
2. What schtasks command lists all tasks in CSV format?
3. How does an attacker get SYSTEM via schtasks without admin?
4. What Autoruns tab shows scheduled tasks?
5. What PowerShell command queries scheduled tasks?
After completing: open Autoruns, go to Scheduled Tasks tab.
Do your created tasks appear?
Are they signed or unsigned?
Get-ScheduledTask | Where-Object {$_.TaskPath -notlike "\Microsoft\*"} | Select TaskName, TaskPath, State — filters out the Microsoft namespace and surfaces everything else for investigation.📸 Screenshot showing scheduled tasks in Autoruns. Share in #ethical-hacking.
Detection — What Blue Teams Look For
My detection recommendations for scheduled task persistence focus on the three signals that actually surface malicious tasks in a noisy environment: event log monitoring, baseline deviation, and signature validation. Any one of these catches most scheduled task persistence.
⏱️ 20 minutes · Kali Linux + your DVWA VM or any Linux lab target
Creating cron persistence in your own lab and then hunting for it as a defender is the fastest way to understand both sides of the technique. Create it. Detect it. Remove it cleanly.
Step 1: Create user-level cron persistence
On the target: crontab -e
Add line: * * * * * /bin/bash -c “echo persistence_test > /tmp/cron_fired”
Wait 60 seconds. Check: cat /tmp/cron_fired
Did the cron fire?
Step 2: Create system-level cron persistence
(Requires root) echo ‘*/2 * * * * root echo system_cron > /tmp/syscron’ >> /etc/crontab
Wait 2 minutes. Check: cat /tmp/syscron
Step 3: Create disguised cron entry
echo ‘*/5 * * * * www-data echo disguised > /tmp/disguised’ > /etc/cron.d/apt-security-update
What existing files does /etc/cron.d/ already contain?
How does your filename blend with them?
Step 4: Hunt for your own persistence (defender perspective)
crontab -l → shows user crontab
cat /etc/crontab → shows system crontab
ls -la /etc/cron.d/ → shows per-file cron jobs
find /etc/cron* -newer /etc/passwd → recently modified cron files
Step 5: Clean up everything you created
crontab -r → removes user crontab
Edit /etc/crontab to remove your line
rm /etc/cron.d/apt-security-update
Verify: all cleanup commands above return clean results
find /etc/cron* -newer /etc/passwd command is the one-liner that finds recently modified cron files — /etc/passwd is updated when user accounts change, making it a reliable “last known good” reference point. Any cron file newer than /etc/passwd is a candidate for investigation. On incident response, I run this immediately after gaining access to a compromised Linux system — it surfaces attacker-placed cron persistence that standard crontab -l commands might not show if the attacker used /etc/cron.d/ instead of the user crontab.📸 Screenshot showing your cron detection hunt output. Share in #ethical-hacking.
📋 Scheduled Task Commands — Day 39
🏆 Day 39 Complete — Scheduled Task Persistence
Windows schtasks, evasive naming, trigger selection, Linux cron across all six persistence locations, and the detection methodology that surfaces these techniques. Day 40 moves to DLL Hijacking — exploiting the Windows DLL search order to establish persistence through legitimate application load paths.
🧠 Quick Check
❓ Frequently Asked Questions
What privileges does schtasks /create require?
What is the most evasive scheduled task trigger?
Where does Linux cron store user crontabs?
What Windows event IDs detect scheduled task persistence?
Can cron persistence survive a system reimage?
How do you detect malicious cron jobs on Linux?
Day 38: Registry Persistence
Day 40: DLL Hijacking
📚 Further Reading
- Day 38 — Registry Persistence — The complementary Windows persistence mechanism. Registry run keys and COM hijacking combined with scheduled tasks gives you the dual-persistence chain used in advanced red team operations.
- Privilege Escalation Hub — Scheduled tasks are a persistence mechanism but also a privilege escalation vector when misconfigured. The hub covers writable task scripts, weak permissions on task executables, and token impersonation via task context.
- Kali Linux Commands Reference — Full syntax for schtasks, at, crontab, and the detection commands used in the blue team section of this article.
- MITRE ATT&CK — T1053 Scheduled Task/Job — The authoritative ATT&CK reference for scheduled task persistence covering all sub-techniques (T1053.002 At, T1053.003 Cron, T1053.005 Scheduled Task) with real-world threat actor usage examples.
- Autoruns for Windows — Sysinternals — The essential detection tool for all Windows persistence mechanisms including scheduled tasks. The Scheduled Tasks tab shows every task with executable signatures — unsigned tasks under Microsoft paths are the primary detection signal.

