How to Threat Hunt for APT33 / APT38 / Lazarus / Dragonfly's Malicious Scheduled Tasks

Unmasking Hidden Threats: A Hunter’s Guide to Malicious Scheduled Tasks

Scheduled tasks – they’re the unsung heroes of IT automation, diligently running scripts and applications at set times or in response to specific system events. But what happens when this helpful feature is turned against you? For cyber threat actors, scheduled tasks are a goldmine, offering a stealthy way to achieve persistence, escalate privileges, and execute malicious code.

Welcome to our deep dive into hunting for these sneaky adversaries. We’re peeling back the layers on how attackers misuse scheduled tasks and, more importantly, how you can spot them in your environment.

The Attacker’s Angle: Why Scheduled Tasks? (MITRE T1053)

The MITRE ATT&CK® framework, a comprehensive knowledge base of adversary tactics and techniques, flags the abuse of scheduled tasks under technique T1053: Scheduled Task/Job. This isn’t just a Windows-specific issue; attackers leverage similar mechanisms across Linux (think Cronjobs – T1053.003) and macOS (like launchd – T1053.004, though MITRE is deprecating this specific sub-technique due to evolving detection and usage patterns). Even container orchestration platforms like Kubernetes have ways to schedule jobs that can be misused.

Today, however, we’re zeroing in on the Windows environment and specifically T1053.005: Scheduled Task. Attackers love this because:

  1. Persistence: Malware can be set to run repeatedly, ensuring it survives reboots or initial removal attempts.
  2. Privilege Escalation: Tasks can often be configured to run with higher privileges (e.g., SYSTEM).
  3. Stealth: Malicious tasks can be disguised with legitimate-sounding names or buried among numerous benign tasks.
  4. Remote Execution: With the right credentials, tasks can be created and run on remote machines across a network.

Windows Task Scheduler has evolved, with versions 1.0 (pre-Windows Vista/Server 2008) and 2.0 (Vista/Server 2008 and newer) offering different capabilities, but the core threat remains.

Not Just Time-Based: Understanding Task Triggers

Many people think of scheduled tasks as simply, “run this program at 2 AM every Tuesday.” While that’s true, attackers have a much richer palette of triggers to work with. A task can be initiated based on:

  • Specific Time: The classic “at this time, on this day/week/month.” (Favored by APT33, APT38, Dragonfly, Frankenstein)
  • System Idle: Kicks off when the system is inactive. Perfect for resource-intensive malicious operations that might otherwise be noticed.
  • System Boot: Runs when the computer starts up. (Used by groups like ATOR)
  • User Logon: Activates when a specific user (or any user) logs in. (Lazarus Group, APT33, APT38 have used this)
  • Task Registration: Can be triggered when the task itself is registered.
  • Terminal Server Session Change: Responds to events like RDP connections or disconnections.

This flexibility allows attackers to tailor their malware execution to specific conditions, making detection trickier.

Crafting Malice: The schtasks.exe Command

The primary command-line utility for interacting with scheduled tasks in Windows is schtasks.exe. Attackers often use it with various flags to create their malicious entries. Here are some key flags you’ll often see in threat reports:

  • /Create: The command to create a new task.
  • /SC <schedule>: Defines the schedule type (e.g., MINUTE, HOURLY, DAILY, WEEKLY, MONTHLY, ONLOGON, ONIDLE).
  • /TN <taskname>: Specifies the name for the task. Attackers often use innocuous names like “AdobeUpdate” or “SystemHealthCheck.”
  • /TR <taskrun>: This is critical – it’s the actual command or script that will be executed.
  • /S <computer>: Allows specifying a remote computer by name or IP.
  • /U <username> & /P <password>: Provide credentials to run the task under a specific user account, potentially with elevated privileges.
  • /Z: Marks the task for deletion after its final run. Useful for one-off malicious executions.

Always consult the official Microsoft documentation for a full list of flags, but these are the ones most commonly abused.

Real-World Villains: APTs and Scheduled Tasks

Let’s look at how some known Advanced Persistent Threat (APT) groups and malware campaigns have used scheduled tasks, with examples often drawn from MITRE ATT&CK documentation:

  1. Chimera & Cobalt Strike: This group used a scheduled task to execute an update.bat script as the SYSTEM user, launching Cobalt Strike. The task was set not to error if it already existed (reducing noise) and was not deleted after completion, ensuring persistence.

    DOS

     
    schtasks /create /tn "update" /tr "C:\Windows\Temp\update.bat" /sc ONCE /st 00:00 /ru "SYSTEM" /f
    
  2. APT3 & Downloaders: APT3 created a task named “MySC” designed to run test.exe from the C:\Users\Public\ folder. This task was triggered on user login and ran as SYSTEM, providing high privileges for their downloader.

    DOS

     
    schtasks /create /tn "MySC" /tr "C:\Users\Public\test.exe" /sc ONLOGON /ru "SYSTEM" /f
    
  3. MuddyWater & PowerStats Backdoor: This group leveraged scheduled tasks for persistence of their PowerShell-based backdoor. They created a task named “Microsoft Edge” (a deceptive name) that ran wscript.exe (often used to launch script files) daily at noon. If they lost access, the task would re-establish it the next day.

    DOS

     
    schtasks /create /tn "Microsoft Edge" /tr "wscript.exe C:\Users\Public\Microsoft\Edge\edge.vbs" /sc DAILY /st 12:00 /f
    

These examples highlight the versatility and effectiveness of scheduled tasks for malicious purposes.

Turning on the Lights: Enabling Essential Audit Logging

Here’s the kicker: by default, Windows doesn’t log the creation, deletion, or modification of scheduled tasks in the detail you need for effective threat hunting. You need to enable advanced audit policies.

You can do this via Group Policy (GPO) in a domain environment or locally on a standalone machine using the Local Security Policy (secpol.msc). Here’s the path for local configuration:

  1. Open Local Security Policy (secpol.msc).
  2. Navigate to: Security Settings -> Advanced Audit Policy Configuration -> System Audit Policies - Local Group Policy Object -> Object Access.
  3. Find and open Audit Other Object Access Events.
  4. Check both Success and Failure boxes.
  5. Apply and OK.

Enabling this setting is paramount. If you’re in a U.S. Department of Defense environment, this is likely already mandated by a STIG (Security Technical Implementation Guide). For everyone else, consider this a critical step.

Key Event IDs for Your Scheduled Task Hunt

Once advanced logging is enabled, the Windows Security Event Log becomes your best friend. Look for these Event IDs:

  • Event ID 4698: A scheduled task was created.
    • This is your primary alert for new tasks. The event details (often in XML format) will show you the task name, the command to be executed (<Command> and <Arguments>), the user account that created it (SubjectUserName), and trigger details. This is invaluable for spotting suspicious schtasks.exe command lines or tasks running with SYSTEM privileges.
  • Event ID 4699: A scheduled task was deleted.
    • Useful for tracking if an attacker is trying to cover their tracks by removing a task.
  • Event ID 4700: A scheduled task was enabled.
    • Indicates a previously disabled task has been reactivated.
  • Event ID 4701: A scheduled task was disabled.
    • Shows a task has been made inactive.
  • Event ID 4702: A scheduled task was updated.
    • This is crucial. If a legitimate task is suddenly modified to point to a malicious binary or script, this event will flag it. You can see what changed.

When hunting, consider hypotheses like:

  • “Are there any new tasks running as SYSTEM that aren’t part of our baseline?”
  • “Are known legitimate tasks being modified (Event ID 4702)?”
  • “Are tasks being created with suspicious command-line arguments or pointing to unusual locations (e.g., Temp folders, user profile directories)?”

Stay Vigilant: Scheduled Tasks are a Persistent Threat

Malicious scheduled tasks are a favored technique for a reason: they’re effective and can blend in. The good news is that with the right audit policies enabled, their activity becomes highly visible in your Windows Event Logs.

By understanding how attackers create and use these tasks, and by actively monitoring the relevant event IDs, you add a powerful capability to your threat hunting arsenal. Don’t let attackers hide in plain sight. Turn on that logging, know what to look for, and keep hunting!

We hope this sheds some light on the darker corners of scheduled tasks. Stay tuned for more insights to bolster your defenses!

See how Insane Cyber transforms security

Our products are designed to work with
you and keep your network protected.