# T1053.005 - Scheduled Task/Job: Scheduled Task

## Description from ATT&CK

> Adversaries may abuse the Windows Task Scheduler to perform task scheduling for initial or recurring execution of malicious code. There are multiple ways to access the Task Scheduler in Windows. The [schtasks](https://attack.mitre.org/software/S0111) utility can be run directly on the command line, or the Task Scheduler can be opened through the GUI within the Administrator Tools section of the Control Panel.(Citation: Stack Overflow) In some cases, adversaries have used a .NET wrapper for the Windows Task Scheduler, and alternatively, adversaries have used the Windows netapi32 library and [Windows Management Instrumentation](https://attack.mitre.org/techniques/T1047) (WMI) to create a scheduled task. Adversaries may also utilize the Powershell Cmdlet `Invoke-CimMethod`, which leverages WMI class `PS_ScheduledTask` to create a scheduled task via an XML path.(Citation: Red Canary - Atomic Red Team)
> 
> An adversary may use Windows Task Scheduler to execute programs at system startup or on a scheduled basis for persistence. The Windows Task Scheduler can also be abused to conduct remote Execution as part of Lateral Movement and/or to run a process under the context of a specified account (such as SYSTEM). Similar to [System Binary Proxy Execution](https://attack.mitre.org/techniques/T1218), adversaries have also abused the Windows Task Scheduler to potentially mask one-time execution under signed/trusted system processes.(Citation: ProofPoint Serpent)
> 
> Adversaries may also create "hidden" scheduled tasks (i.e. [Hide Artifacts](https://attack.mitre.org/techniques/T1564)) that may not be visible to defender tools and manual queries used to enumerate tasks. Specifically, an adversary may hide a task from `schtasks /query` and the Task Scheduler by deleting the associated Security Descriptor (SD) registry value (where deletion of this value must be completed using SYSTEM permissions).(Citation: SigmaHQ)(Citation: Tarrask scheduled task) Adversaries may also employ alternate methods to hide tasks, such as altering the metadata (e.g., `Index` value) within associated registry keys.(Citation: Defending Against Scheduled Task Attacks in Windows Environments)

[Source](https://attack.mitre.org/techniques/T1053/005)

## Atomic Tests

- [Atomic Test #1: Scheduled Task Startup Script](#atomic-test-1-scheduled-task-startup-script)
- [Atomic Test #2: Scheduled task Local](#atomic-test-2-scheduled-task-local)
- [Atomic Test #3: Scheduled task Remote](#atomic-test-3-scheduled-task-remote)
- [Atomic Test #4: Powershell Cmdlet Scheduled Task](#atomic-test-4-powershell-cmdlet-scheduled-task)
- [Atomic Test #5: Task Scheduler via VBA](#atomic-test-5-task-scheduler-via-vba)
- [Atomic Test #6: WMI Invoke-CimMethod Scheduled Task](#atomic-test-6-wmi-invoke-cimmethod-scheduled-task)
- [Atomic Test #7: Scheduled Task Executing Base64 Encoded Commands From Registry](#atomic-test-7-scheduled-task-executing-base64-encoded-commands-from-registry)
- [Atomic Test #8: Import XML Schedule Task with Hidden Attribute](#atomic-test-8-import-xml-schedule-task-with-hidden-attribute)
- [Atomic Test #9: PowerShell Modify A Scheduled Task](#atomic-test-9-powershell-modify-a-scheduled-task)
- [Atomic Test #10: Scheduled Task ("Ghost Task") via Registry Key Manipulation](#atomic-test-10-scheduled-task-ghost-task-via-registry-key-manipulation)
- [Atomic Test #11: Scheduled Task Persistence via CompMgmt.msc](#atomic-test-11-scheduled-task-persistence-via-compmgmtmsc)
- [Atomic Test #12: Scheduled Task Persistence via Eventviewer.msc](#atomic-test-12-scheduled-task-persistence-via-eventviewermsc)

### Atomic Test #1: Scheduled Task Startup Script

Run an exe on user logon or system startup.  Upon execution, success messages will be displayed for the two scheduled tasks. To view
the tasks, open the Task Scheduler and look in the Active Tasks pane.

**Supported Platforms:** Windows

**auto_generated_guid:** `fec27f65-db86-4c2d-b66c-61945aee87c2`

#### Attack Commands: Run with `command_prompt`! Elevation Required (e.g. root or admin)

```cmd
schtasks /create /tn "T1053_005_OnLogon" /sc onlogon /tr "cmd.exe /c calc.exe"
schtasks /create /tn "T1053_005_OnStartup" /sc onstart /ru system /tr "cmd.exe /c calc.exe"
```

#### Cleanup Commands

```cmd
schtasks /delete /tn "T1053_005_OnLogon" /f >nul 2>&1
schtasks /delete /tn "T1053_005_OnStartup" /f >nul 2>&1
```
### Atomic Test #2: Scheduled task Local

Upon successful execution, cmd.exe will create a scheduled task to spawn cmd.exe at 20:10.

**Supported Platforms:** Windows

**auto_generated_guid:** `42f53695-ad4a-4546-abb6-7d837f644a71`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| task_command | What you want to execute | string | C:&#92;windows&#92;system32&#92;cmd.exe|
| time | What time 24 Hour | string | 20:10|

#### Attack Commands: Run with `command_prompt`!

```cmd
SCHTASKS /Create /SC ONCE /TN spawn /TR #{task_command} /ST #{time}
```

#### Cleanup Commands

```cmd
SCHTASKS /Delete /TN spawn /F >nul 2>&1
```
### Atomic Test #3: Scheduled task Remote

Create a task on a remote system.
Upon successful execution, cmd.exe will create a scheduled task to spawn cmd.exe at 20:10 on a remote endpoint.

**Supported Platforms:** Windows

**auto_generated_guid:** `2e5eac3e-327b-4a88-a0c0-c4057039a8dd`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| task_command | What you want to execute | string | C:&#92;windows&#92;system32&#92;cmd.exe|
| time | What time 24 Hour | string | 20:10|
| target | Target | string | localhost|
| user_name | Username to authenticate with, format: DOMAIN&#92;User | string | DOMAIN&#92;user|
| password | Password to authenticate with | string | At0micStrong|

#### Attack Commands: Run with `command_prompt`! Elevation Required (e.g. root or admin)

```cmd
SCHTASKS /Create /S #{target} /RU #{user_name} /RP #{password} /TN "Atomic task" /TR "#{task_command}" /SC daily /ST #{time}
```

#### Cleanup Commands

```cmd
SCHTASKS /Delete /S #{target} /U #{user_name} /P #{password} /TN "Atomic task" /F >nul 2>&1
```
### Atomic Test #4: Powershell Cmdlet Scheduled Task

Create an atomic scheduled task that leverages native powershell cmdlets.

Upon successful execution, powershell.exe will create a scheduled task to spawn cmd.exe at 20:10.

**Supported Platforms:** Windows

**auto_generated_guid:** `af9fd58f-c4ac-4bf2-a9ba-224b71ff25fd`

#### Attack Commands: Run with `powershell`!

```powershell
$Action = New-ScheduledTaskAction -Execute "calc.exe"
$Trigger = New-ScheduledTaskTrigger -AtLogon
$User = New-ScheduledTaskPrincipal -GroupId "BUILTIN\Administrators" -RunLevel Highest
$Set = New-ScheduledTaskSettingsSet
$object = New-ScheduledTask -Action $Action -Principal $User -Trigger $Trigger -Settings $Set
Register-ScheduledTask AtomicTask -InputObject $ob