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,StateExploitable Conditions
Look for these vulnerabilities in scheduled tasks:
Writable Target Binary - If the task runs a binary that your user can modify
Missing Binary - If the task attempts to run a non-existent binary in a location you can write to
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:
Identify the vulnerable task:
Check the file permissions:
Replace the file with our payload:
Set up a listener on the attacker machine:
Wait for the task to run or trigger it manually if you have permissions:
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:
Ensure task binaries have appropriate permissions (limit to SYSTEM and Administrators)
Use absolute paths with quotes for task commands
Store task binaries in protected directories
Regularly audit scheduled tasks
Disable the AlwaysInstallElevated policy
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