Scheduled tasks abuse

Task Permission Weaknesses

Understanding Windows Scheduled Tasks

Windows Scheduled Tasks are like having a personal assistant that automatically runs programs at specific times or when certain events happen. These tasks are managed by the Task Scheduler service, which runs with SYSTEM privileges - the highest level of access in Windows.

How Scheduled Tasks Work

Task Scheduler Architecture:

Task Scheduler Service (runs as SYSTEM)
β”œβ”€β”€ Task Definitions (stored in registry and XML files)
β”œβ”€β”€ Task Triggers (when to run: time, events, logon, etc.)
β”œβ”€β”€ Task Actions (what to run: programs, scripts, commands)
└── Task Security (who the task runs as: SYSTEM, Admin, User)

Task Storage Locations:

  • Registry: HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache

  • XML Files: C:\Windows\System32\Tasks\

  • Legacy: C:\Windows\Tasks\ (older .job files)

Why Scheduled Tasks Are Valuable Targets

High-Privilege Execution:

  • Many tasks run as SYSTEM (highest Windows privileges)

  • Tasks can run even when no user is logged in

  • Tasks inherit the security context they're configured with

Attack Surface:

  • Task definitions might have weak permissions

  • Task executables might be modifiable

  • Working directories might be writable

  • Task creation might be allowed for low-privileged users

Real-World Task Examples

Legitimate System Tasks:

Vulnerable Configuration Example: If the task executable C:\Program Files\UpdateApp\updater.exe is writable by regular users, an attacker could:

  1. Replace updater.exe with malicious code

  2. Wait for the scheduled task to run

  3. Their malicious code executes with SYSTEM privileges

Enumeration

Basic Task Discovery

List all scheduled tasks:

Show specific task details:

PowerShell task enumeration:

Exploitation Techniques

Task Creation Privilege Escalation

Create SYSTEM task (requires task creation privileges):

Create task with immediate execution:

PowerShell task creation:

Task Modification Attacks

Hijack existing task:


Task File and Executable Hijacking

Understanding Task File Structure

Scheduled tasks are stored as XML files in C:\Windows\System32\Tasks\. These files contain task configuration, triggers, actions, and security settings. Each task has a corresponding entry in the registry for caching and quick access.

Task XML Structure Example

Typical Task XML Content:

What Makes This Vulnerable:

  • If the XML file has weak permissions, it can be directly modified

  • If the executable path is writable, the binary can be replaced

  • If the working directory is writable, DLL hijacking is possible

Enumeration

Finding Vulnerable Task Files

Check XML file permissions:

Search for interesting task content:

PowerShell executable permission check:

Registry-Based Task Analysis

Check task registry permissions:

Exploitation Techniques

Direct XML File Modification

PowerShell XML manipulation:

Task Executable Replacement

Binary replacement attack:

PowerShell Script Hijacking

Find PowerShell-based tasks:

Script hijacking function:

DLL Hijacking in Task Context

Find potential DLL hijacking opportunities:


Task Creation and Modification

Understanding Task Privileges and Security Context

Tasks can run under different security contexts, which determines what level of access they have:

  • SYSTEM - Highest privileges, can access all system resources

  • Administrator - High privileges but with some limitations

  • Specific User Account - Limited to that user's privileges

  • Interactive User - Runs with currently logged-in user's privileges

Task Trigger Types

Common Trigger Types:

  • Time-based - Specific times, intervals, or schedules

  • Event-based - System events, log entries, or state changes

  • Logon triggers - User logon/logoff events

  • Startup triggers - System boot events

  • Idle triggers - System idle state

Enumeration

Task Trigger Analysis

Enumerate task triggers:

PowerShell trigger analysis:

Security Context Analysis

Find high-privilege tasks:

Exploitation Techniques

Stealth Task Creation

Create hidden tasks in legitimate locations:

PowerShell stealth task with encoded payload:

Task Trigger Manipulation

Modify existing task triggers:

Event-based trigger exploitation:

Living Off The Land Techniques

Using built-in Windows binaries:

Task Masquerading

Copy and modify legitimate tasks:

Quick Enumeration

PowerUp task checks:

WinPEAS task analysis:

Seatbelt task enumeration:

Last updated

Was this helpful?