A Windows command-line utility for creating and executing scheduled tasks with session-specific control. PhantomTask leverages the Windows Task Scheduler API to create tasks that run in specific user sessions with elevated privileges.
- Session Management: Create tasks targeting specific Windows Terminal Services sessions
 - Session Enumeration: List all active sessions on the local machine with detailed information
 - Flexible Authentication: Support for both interactive token and password-based authentication
 - Elevated Privileges: Tasks can be configured to run with highest privileges
 - Immediate Execution: Automatically triggers tasks after creation with configurable session targeting
 - Hidden Tasks: Tasks are created as hidden by default
 
- Windows operating system
 - Rust toolchain (2024 edition)
 - Administrator privileges (recommended for full functionality)
 
Clone the repository and build using Cargo:
git clone <repository-url>
cd phantomtask
cargo build --releaseThe compiled binary will be available at target/release/phantomtask.exe
Usage: phantomtask.exe [OPTIONS]
Options:
  -l, --list                   List active sessions on the local machine
  -n, --name <taskname>        The name of the task to create
  -f, --program <program>      The program to execute
  -a, --arguments <arguments>  The arguments to pass to the program
  -u, --username <username>    The username to run the task as
  -p, --password <password>    The password for the specified username
  -s, --sessionid <sessionid>  The session ID to run the task in
  -h, --help                   Print help
  -V, --version                Print versionDisplay all active Windows Terminal Services sessions with their details:
phantomtask.exe --list
# or
phantomtask.exe -lOutput example:
===== Active Sessions =====
SessionID  User                 State           Station              Domain              
=====================================================================================
0          <None>               Active          Services             <Local>            
1          Administrator        Active          Console              WORKSTATION        
If you want to execute a task as SYSTEM (session 0), change the username in get_user_from_session()! It is localisation dependent (Système, System, ...), and there is no automatic resolution on this account.
Create a scheduled task that runs in a specific session:
phantomtask.exe --name "MyTask" --program "C:\path\to\program.exe" --sessionid 1-n, --name <TASKNAME>: Name of the task to create-f, --program <PROGRAM>: The program to execute-s, --sessionid <SESSIONID>: Session ID where the task should run
-a, --arguments <ARGUMENTS>: Arguments to pass to the program-u, --username <USERNAME>: Username to run the task as-p, --password <PASSWORD>: Password for the specified username
phantomtask.exe -n "NotepadTask" -f "notepad.exe" -s 1phantomtask.exe -n "CmdTask" -f "cmd.exe" -a "/c dir" -s 1phantomtask.exe -n "UserTask" -f "C:\Tools\app.exe" -u "DOMAIN\User" -p "Password123" -s 1- COM Initialization: Initializes the Component Object Model (COM) library with multithreaded apartment
 - Task Scheduler Connection: Connects to the Windows Task Scheduler service
 - Task Definition: Creates a new task definition with:
- Time trigger (scheduled to run 1 minute after creation)
 - Execution action with specified program and arguments
 - Principal configuration (user and logon type)
 - Security settings (run with highest privileges)
 
 - Session Resolution: Resolves the username associated with the target session ID
 - Task Registration: Registers the task in the root folder of Task Scheduler
 - Immediate Execution: Triggers the task immediately using the resolved session context
 
phantomtask/
├── Cargo.toml          # Project dependencies and configuration
├── src/
│   ├── main.rs         # Entry point and CLI argument parsing
│   ├── tasks.rs        # Task creation and registration logic
│   ├── sessions.rs     # Session enumeration and user resolution
│   └── utils.rs        # Utility functions (wide string conversion)
└── README.md
- windows: Windows API bindings for Rust (v0.62.2)
- Task Scheduler COM interfaces
 - Remote Desktop Services API
 - COM and OLE support
 
 - windows-core: Core Windows types (v0.62.2)
 - clap: Command-line argument parser (v4.5.51)
 
- Windows-only (uses Windows-specific APIs)
 - Requires administrator rights for most operations
 - Session ID 0 defaults to "Système" user (in french, localization-dependent)
 
The application provides detailed console output for:
- COM initialization status
 - Task creation progress
 - Session user resolution
 - Task execution confirmation
 - Error messages with context
 
This is an obvious disclaimer because I don't want to be held responsible if someone uses this tool against anyone who hasn't asked for anything.
Usage of anything presented in this repo to attack targets without prior mutual consent is illegal. It's the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program. Only use for educational purposes.