diff --git a/README.md b/README.md index 6f23d97..c5c67ab 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,23 @@ The compiled binary will be available at `target/release/phantomtask.exe` ## Usage +### Help + +```powershell +Usage: phantomtask.exe [OPTIONS] + +Options: + -l, --list List active sessions on the local machine + -n, --name The name of the task to create + -f, --program The program to execute + -a, --arguments The arguments to pass to the program + -u, --username The username to run the task as + -p, --password The password for the specified username + -s, --sessionid The session ID to run the task in + -h, --help Print help + -V, --version Print version +``` + ### List Active Sessions Display all active Windows Terminal Services sessions with their details: diff --git a/src/main.rs b/src/main.rs index f8f2464..661efae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,13 @@ -mod utils; -mod tasks; mod sessions; +mod tasks; +mod utils; use sessions::list_active_sessions; use tasks::create_task; -use windows::Win32::System::RemoteDesktop::WTSGetActiveConsoleSessionId; -use windows::Win32::System::Com::CoUninitialize; use clap::{Arg, Command}; +use windows::Win32::System::Com::CoUninitialize; +use windows::Win32::System::RemoteDesktop::WTSGetActiveConsoleSessionId; fn main() -> windows_core::Result<()> { let args = Command::new("PhantomTask") @@ -90,12 +90,7 @@ fn main() -> windows_core::Result<()> { println!(); match create_task( - task_name, - task_path, - arguments, - user_name, - password, - session_id, + task_name, task_path, arguments, user_name, password, session_id, ) { Ok(_) => { println!("\n[+] Task successfully created and executed!"); @@ -105,7 +100,7 @@ fn main() -> windows_core::Result<()> { } } } - + unsafe { CoUninitialize(); println!("[i] COM library uninitialized"); diff --git a/src/sessions.rs b/src/sessions.rs index 0877472..63887a2 100644 --- a/src/sessions.rs +++ b/src/sessions.rs @@ -4,9 +4,8 @@ use std::ptr::null_mut; use windows::Win32::System::RemoteDesktop::{ WTSActive, WTSConnectQuery, WTSConnected, WTSDisconnected, WTSDomainName, WTSDown, - WTSEnumerateSessionsW, WTSFreeMemory, WTSIdle, WTSInit, - WTSListen, WTSQuerySessionInformationW, WTSReset, WTSShadow, WTSUserName, - WTS_CURRENT_SERVER_HANDLE, WTS_SESSION_INFOW, + WTSEnumerateSessionsW, WTSFreeMemory, WTSIdle, WTSInit, WTSListen, WTSQuerySessionInformationW, + WTSReset, WTSShadow, WTSUserName, WTS_CURRENT_SERVER_HANDLE, WTS_SESSION_INFOW, }; use windows_core::BSTR; @@ -144,4 +143,4 @@ pub fn get_user_from_session(session_id: u32) -> Result, windows::c Err(_) => return Ok(Some(BSTR::from("[!] WTSQuerySessionInformationW Error"))), }; } -} \ No newline at end of file +} diff --git a/src/tasks.rs b/src/tasks.rs index 809d597..087c551 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -7,11 +7,10 @@ use windows::Win32::System::Com::{ COINIT_MULTITHREADED, EOAC_NONE, RPC_C_AUTHN_LEVEL_PKT_PRIVACY, RPC_C_IMP_LEVEL_IMPERSONATE, }; use windows::Win32::System::TaskScheduler::{ - IExecAction, IPrincipal, IRegisteredTask, IRegistrationInfo, - ITaskDefinition, ITaskFolder, ITaskService, ITimeTrigger, TaskScheduler, - TASK_ACTION_EXEC, TASK_CREATE_OR_UPDATE, TASK_INSTANCES_IGNORE_NEW, - TASK_LOGON_INTERACTIVE_TOKEN, TASK_LOGON_PASSWORD, TASK_RUNLEVEL_HIGHEST, TASK_RUN_NO_FLAGS, - TASK_RUN_USE_SESSION_ID, TASK_TRIGGER_TIME, + IExecAction, IPrincipal, IRegisteredTask, IRegistrationInfo, ITaskDefinition, ITaskFolder, + ITaskService, ITimeTrigger, TaskScheduler, TASK_ACTION_EXEC, TASK_CREATE_OR_UPDATE, + TASK_INSTANCES_IGNORE_NEW, TASK_LOGON_INTERACTIVE_TOKEN, TASK_LOGON_PASSWORD, + TASK_RUNLEVEL_HIGHEST, TASK_RUN_NO_FLAGS, TASK_RUN_USE_SESSION_ID, TASK_TRIGGER_TIME, }; use windows::Win32::System::Variant::VARIANT; use windows_core::BSTR; @@ -195,8 +194,6 @@ pub fn create_task( Ok(()) } - - fn register_with_session_id( task_folder: &ITaskFolder, task_name: &str, @@ -228,4 +225,3 @@ fn register_with_session_id( ) } } - diff --git a/src/utils.rs b/src/utils.rs index 0f68521..4a5425f 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -8,4 +8,4 @@ pub fn from_wide_string(wide: *const u16) -> String { let slice = std::slice::from_raw_parts(wide, len); String::from_utf16_lossy(slice) } -} \ No newline at end of file +}