Scheduled Tasks

Scheduled tasks in Windows can create privilege escalation opportunities when misconfigured. This document covers methods to identify and exploit vulnerable scheduled tasks.

Identifying Scheduled Tasks

List all scheduled tasks with various commands:

# Basic listing of all scheduled tasks
schtasks

# List tasks with more details in a readable format
schtasks /query /fo LIST

# Query a specific task with verbose output
schtasks /query /tn <TASKNAME> /fo list /v

# Using PowerShell to get all scheduled tasks
Get-ScheduledTask | Where-Object {$_.State -ne "Disabled"} | Format-Table TaskName,TaskPath,State

Exploitable Conditions

Look for these vulnerabilities in scheduled tasks:

  1. Writable Target Binary - If the task runs a binary that your user can modify

  2. Missing Binary - If the task attempts to run a non-existent binary in a location you can write to

  3. Weak Permissions on Task Definition - If you can modify the task itself

Checking File Permissions

When you identify a potential target task, check file permissions on the binary it runs:

Permissions flags to look for:

  • (F) - Full control

  • (M) - Modify

  • (W) - Write

  • (I) - Permission inherited from parent container

Exploiting Writable Target Binaries

If you find a scheduled task runs a binary that you can modify:

Practical Example

This example shows how to exploit a vulnerable scheduled task:

  1. Identify the vulnerable task:

  1. Check the file permissions:

  1. Replace the file with our payload:

  1. Set up a listener on the attacker machine:

  1. Wait for the task to run or trigger it manually if you have permissions:

  1. Receive the reverse shell with taskusr1 privileges:

AlwaysInstallElevated Privilege Escalation

The Windows Installer service can be configured to run with elevated privileges for all users. This can be exploited to install a malicious MSI package with SYSTEM privileges.

Checking Registry Settings

Both registry keys need to be set to 1 for this attack to work:

Creating Malicious MSI

If both keys are set to 1, create a malicious MSI package on your attack machine:

Exploiting

Transfer the MSI to the target and execute it:

Finding Files in Windows

To find files in Windows when searching for potential privilege escalation vectors:

Protection and Mitigation

To protect systems from scheduled task vulnerabilities:

  1. Ensure task binaries have appropriate permissions (limit to SYSTEM and Administrators)

  2. Use absolute paths with quotes for task commands

  3. Store task binaries in protected directories

  4. Regularly audit scheduled tasks

  5. Disable the AlwaysInstallElevated policy

  6. Monitor for unexpected modifications to scheduled tasks

Other Scheduled Task Exploitation Techniques

  • Check for credentials in task arguments/parameters

  • Look for scripts that access other writable files

  • Inspect task actions for potential DLL hijacking

  • Monitor file modifications to detect privilege escalation attempts

Last updated