Better static runtime config, work on connections.

This commit is contained in:
Michael Mikovsky
2025-11-25 14:27:06 -07:00
parent dc153774e5
commit 1efa3206ae
16 changed files with 634 additions and 122 deletions
+220 -12
View File
@@ -57,6 +57,18 @@ dependencies = [
"virtue",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "block-buffer"
version = "0.10.4"
@@ -115,6 +127,18 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chrono"
version = "0.4.42"
@@ -153,6 +177,21 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -272,12 +311,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.177"
@@ -294,6 +327,15 @@ dependencies = [
"windows-link",
]
[[package]]
name = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.28"
@@ -321,6 +363,38 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "parking_lot"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-link",
]
[[package]]
name = "ppv-lite86"
version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
dependencies = [
"zerocopy",
]
[[package]]
name = "proc-macro2"
version = "1.0.103"
@@ -345,6 +419,44 @@ version = "5.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f"
[[package]]
name = "rand"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1"
dependencies = [
"rand_chacha",
"rand_core",
]
[[package]]
name = "rand_chacha"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb"
dependencies = [
"ppv-lite86",
"rand_core",
]
[[package]]
name = "rand_core"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38"
dependencies = [
"getrandom",
]
[[package]]
name = "redox_syscall"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
"bitflags 2.10.0",
]
[[package]]
name = "regex"
version = "1.12.2"
@@ -386,6 +498,12 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.228"
@@ -413,7 +531,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.110",
]
[[package]]
@@ -446,6 +564,51 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "smallvec"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "static_init"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bae1df58c5fea7502e8e352ec26b5579f6178e1fdb311e088580c980dee25ed"
dependencies = [
"bitflags 1.3.2",
"cfg_aliases 0.2.1",
"libc",
"parking_lot",
"parking_lot_core",
"static_init_macro",
"winapi",
]
[[package]]
name = "static_init_macro"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1389c88ddd739ec6d3f8f83343764a0e944cd23cfbf126a9796a714b0b6edd6f"
dependencies = [
"cfg_aliases 0.1.1",
"memchr",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.110"
@@ -473,7 +636,7 @@ checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5"
name = "unshell-cli"
version = "0.0.0"
dependencies = [
"lazy_static",
"static_init",
"unshell-crypt",
"unshell-lib",
"unshell-obfuscate",
@@ -499,7 +662,10 @@ version = "0.0.0"
dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"libc",
"libloading",
"rand",
"serde",
"serde_json",
"unshell-obfuscate",
@@ -511,7 +677,7 @@ version = "0.0.0"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.110",
"unshell-crypt",
]
@@ -574,7 +740,7 @@ dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"syn 2.0.110",
"wasm-bindgen-shared",
]
@@ -587,6 +753,28 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.62.2"
@@ -608,7 +796,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.110",
]
[[package]]
@@ -619,7 +807,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.110",
]
[[package]]
@@ -651,3 +839,23 @@ name = "wit-bindgen"
version = "0.46.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59"
[[package]]
name = "zerocopy"
version = "0.8.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ea879c944afe8a2b25fef16bb4ba234f47c694565e97383b36f3a878219065c"
dependencies = [
"zerocopy-derive",
]
[[package]]
name = "zerocopy-derive"
version = "0.8.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf955aa904d6040f70dc8e9384444cb1030aed272ba3cb09bbc4ab9e7c1f34f5"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.110",
]
+3 -2
View File
@@ -3,7 +3,8 @@ name = "unshell-cli"
edition = "2024"
[dependencies]
unshell-lib = {path = "../unshell-lib"}
unshell-lib = {path = "../unshell-lib", features=["log_debug"]}
unshell-obfuscate = {path = "../unshell-obfuscate"}
unshell-crypt = {path = "../unshell-crypt"}
lazy_static = "1.5.0"
# lazy_static = "1.5.0"
static_init = "1.0.4"
+33 -7
View File
@@ -1,21 +1,47 @@
use lazy_static::lazy_static;
use unshell_lib::{config::PayloadConfig, module::Manager};
use unshell_obfuscate::symbol;
use std::collections::HashMap;
lazy_static! {
static ref PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
use static_init::dynamic;
use unshell_lib::{
config::{PayloadConfig, RuntimeConfig},
module::Manager,
};
use unshell_obfuscate::{obs, symbol};
#[dynamic]
static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
id: symbol!("Test ID"),
components: unshell_lib::get_components(),
runtime_config: vec![],
};
use std::alloc::{Layout, alloc};
use std::ptr;
fn leak<T>(value: T) -> &'static mut T {
unsafe {
let layout = Layout::new::<T>();
let ptr = alloc(layout) as *mut T;
ptr::write(ptr, value);
&mut *ptr
}
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
unshell_lib::logger::PrettyLogger::init();
Manager::run(&PAYLOAD_CONFIG, Vec::new());
let manager = Manager::start(&PAYLOAD_CONFIG, Vec::new());
// let mut serverruntime = unshell_lib::server::ListenerRuntime::new();
let runtime = leak(RuntimeConfig {
parent_component: symbol!("server").to_string(),
name: symbol!("server runtime").to_string(),
config: HashMap::from([(symbol!("host").to_string(), obs!("localhost:1234"))]),
});
Manager::start_runtime(manager.clone(), runtime);
// Manager::st
Manager::join(manager);
// loop {
// print!("> ");
+16
View File
@@ -153,6 +153,21 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -521,6 +536,7 @@ version = "0.0.0"
dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"libc",
"libloading",
"rand",
+1
View File
@@ -25,3 +25,4 @@ serde = {version = "1.0.228", features=["derive"]}
serde_json = "1.0.145"
libc = "0.2.177"
rand = "0.9.2"
crossbeam-channel = "0.5.15"
+2
View File
@@ -8,5 +8,7 @@ pub fn get_components() -> Vec<NamedComponent> {
return vec![
#[cfg(feature = "client")]
crate::client::get_named_component(),
#[cfg(feature = "server")]
crate::server::get_named_component(),
];
}
+1
View File
@@ -4,6 +4,7 @@ pub mod client;
pub mod config;
pub mod logger;
pub mod module;
pub mod network;
pub mod server;
mod components;
+1
View File
@@ -40,6 +40,7 @@ impl Logger for DefaultLogger {
fn log(&self, _: Record) {}
}
#[allow(unused_variables)]
pub fn set_logger_box(logger: Box<dyn Logger>) {
#[cfg(feature = "log")]
unsafe {
+34 -49
View File
@@ -39,7 +39,7 @@ impl Manager {
/// Create Manager, and run initilization for each Module
#[allow(static_mut_refs)]
pub fn run(config: &'static PayloadConfig, modules: Vec<Module>) {
pub fn start(config: &'static PayloadConfig, modules: Vec<Module>) -> Arc<Mutex<Self>> {
// Construct self
let mut this = Self::new(&config.id, config.components.clone(), modules);
@@ -51,11 +51,12 @@ impl Manager {
let this = Arc::new(Mutex::new(this));
Self::start_runtimes(this.clone(), &config.runtime_config);
debug!("Starting runtimes...");
for runtime in &config.runtime_config {
Self::start_runtime(this.clone(), runtime);
}
// drop(config);
Self::join(this);
this
}
fn load_components(&mut self) {
@@ -84,39 +85,8 @@ impl Manager {
}
}
/// Start each runtime
fn start_runtimes(this: Arc<Mutex<Self>>, runtimes: &'static Vec<RuntimeConfig>) {
debug!("Starting runtimes...");
for runtime in runtimes {
let mut this_lock = this.lock().unwrap();
let component = match this_lock.components.get(&runtime.parent_component) {
Some(component) => component,
None => {
warn!(
"Could not find component '{}' which is referenced by runtime: {}",
runtime.parent_component, runtime.name
);
continue;
}
};
debug!("Starting runtime: {}", runtime.name);
let runtime = match (*component.start_runtime)(runtime) {
Ok(runtime) => runtime,
Err(e) => {
warn!("Failed to start runtime: {:?}", e);
continue;
}
};
this_lock.active_runtimes.push(runtime);
}
}
/// Iterateratively loop through all runtimes, until all are finished executing
fn join(this: Arc<Mutex<Self>>) {
pub fn join(this: Arc<Mutex<Self>>) {
loop {
let mut this_lock = this.lock().unwrap();
@@ -140,20 +110,35 @@ impl Manager {
}
}
// pub fn get_component(&self) -> HashMap<&'static str, Box<dyn Component>> {
// self.components.clone()
// }
/// Start a runtime
pub fn start_runtime<'a>(this: Arc<Mutex<Self>>, runtime: &'static RuntimeConfig) {
let mut this_lock = this.lock().unwrap();
let component = match this_lock.components.get(&runtime.parent_component) {
Some(component) => component,
None => {
warn!(
"Could not find component '{}' which is referenced by runtime: {}",
runtime.parent_component, runtime.name
);
return;
}
};
debug!("Starting runtime: {}", runtime.name);
let runtime = match (*component.start_runtime)(runtime) {
Ok(runtime) => runtime,
Err(e) => {
warn!("Failed to start runtime: {:?}", e);
return;
}
};
this_lock.active_runtimes.push(runtime);
}
pub fn get_name(&self) -> &str {
self.id
}
// pub extern "C" fn test1234(&self, float: f32) {
// info!("Manager Test Sucsessfull! {}", float.powf(2.));
// }
// #[allow(static_mut_refs, improper_ctypes_definitions)]
// pub extern "C" fn get_manager() -> Arc<Mutex<Manager>> {
// unsafe { MANAGER_RUNTIME.clone().unwrap() }
// }
}
+68
View File
@@ -0,0 +1,68 @@
use std::sync::{
Arc,
atomic::{AtomicBool, Ordering},
};
use crate::{Announcement, ModuleError, network::Stream};
use crossbeam_channel::{Receiver, Sender};
pub struct Connection {
tx: Sender<Announcement>,
rx: Receiver<Announcement>,
is_alive: Arc<AtomicBool>,
}
impl Connection {
pub fn new() -> (Connection, Connection) {
let (tx_mgr, rx) = crossbeam_channel::unbounded();
let (tx, rx_mgr) = crossbeam_channel::unbounded();
let alive = Arc::new(AtomicBool::new(false));
(
Self {
tx: tx_mgr,
rx: rx_mgr,
is_alive: alive.clone(),
},
Self {
tx,
rx,
is_alive: alive,
},
)
}
}
impl Stream<Announcement> for Connection {
fn is_alive(&self) -> bool {
self.is_alive.load(Ordering::Relaxed)
}
fn len(&self) -> usize {
self.rx.len()
}
fn read(&mut self) -> Option<Announcement> {
match self.rx.is_empty() {
true => None,
false => self.rx.recv().ok(),
}
}
fn write(&mut self, data: Announcement) -> Result<(), crate::ModuleError> {
self.tx
.send(data)
.map_err(|_| ModuleError::Error("Failed to send".into()))?;
Ok(())
}
fn try_clone(&self) -> Result<Box<dyn Stream<Announcement> + Send + Sync>, crate::ModuleError> {
Ok(Box::new(Self {
tx: self.tx.clone(),
rx: self.rx.clone(),
is_alive: self.is_alive.clone(),
}))
}
}
+18
View File
@@ -0,0 +1,18 @@
mod connection;
pub use connection::Connection;
use crate::ModuleError;
/// This is the data transmission type
pub trait Stream<T>: Send + Sync {
// fn get_info(&self) -> String;
fn is_alive(&self) -> bool;
fn len(&self) -> usize;
fn read(&mut self) -> Option<T>;
fn write(&mut self, data: T) -> Result<(), ModuleError>;
fn try_clone(&self) -> Result<Box<dyn Stream<T> + Send + Sync>, ModuleError>;
}
+23
View File
@@ -1,3 +1,26 @@
mod server_runtime;
pub use server_runtime::ListenerRuntime;
use crate::{
ModuleError, ModuleRuntime,
config::{InterfaceWrapper, NamedComponent, RuntimeConfig},
};
pub const COMPONENT_NAME: &'static str = "server";
fn get_interface() -> Option<&'static (dyn InterfaceWrapper + Sync)> {
None
}
fn start_runtime(config: &'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime>, ModuleError> {
Ok(Box::new(ListenerRuntime::new(config)?))
}
pub const fn get_named_component() -> NamedComponent {
NamedComponent {
name: COMPONENT_NAME,
get_interface: &get_interface,
start_runtime: &start_runtime,
}
}
+19 -7
View File
@@ -5,10 +5,11 @@ use std::{
thread::{self, JoinHandle},
};
use crate::*;
use crate::{config::RuntimeConfig, *};
pub struct ListenerRuntime {
thread_handle: JoinHandle<()>,
// join_signal: Arc<AtomicBool>,
// listener: TcpListener,
streams: Arc<Mutex<Vec<TcpStream>>>,
// reader: BufReader<TcpListener>,
@@ -16,9 +17,19 @@ pub struct ListenerRuntime {
}
impl ListenerRuntime {
pub fn new() -> ListenerRuntime {
pub fn new(config: &'static RuntimeConfig) -> Result<Self, ModuleError> {
// info!("Starting listener runtime on {}",);
let listener = TcpListener::bind("127.0.0.1:1234").unwrap();
let host = match config.config.get("host") {
Some(host) => host,
None => {
return Err(ModuleError::Error(
"Could not find HOST in Server Runtime".into(),
));
}
};
let listener = TcpListener::bind(host).unwrap();
let streams = Arc::new(Mutex::new(Vec::new()));
let streams_clone = streams.clone();
@@ -27,14 +38,14 @@ impl ListenerRuntime {
let streams = streams_clone.clone();
for stream in listener.incoming() {
let stream = stream.unwrap();
println!("New connection from {}", stream.peer_addr().unwrap());
debug!("New connection from {}", stream.peer_addr().unwrap());
streams.lock().unwrap().push(stream);
}
});
Self {
Ok(Self {
thread_handle,
streams,
}
})
}
pub fn send(&mut self, announcement: &Announcement) -> Result<(), std::io::Error> {
@@ -48,7 +59,7 @@ impl ListenerRuntime {
stream.flush()?;
}
println!("Announcement {:?} sent", announcement);
debug!("Announcement {:?} sent", announcement);
Ok(())
}
@@ -81,6 +92,7 @@ impl ModuleRuntime for ListenerRuntime {
fn kill(self: Box<Self>) {
if !self.thread_handle.is_finished() {
// self.join_signal.store(true, Ordering::Relaxed);
let _ = self.thread_handle.join();
}
// drop(self);
+161 -13
View File
@@ -57,6 +57,18 @@ dependencies = [
"virtue",
]
[[package]]
name = "bitflags"
version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitflags"
version = "2.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "812e12b5285cc515a9c72a5c1d3b6d46a19dac5acfef5265968c166106e31dd3"
[[package]]
name = "block-buffer"
version = "0.10.4"
@@ -115,6 +127,18 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chrono"
version = "0.4.42"
@@ -153,6 +177,21 @@ dependencies = [
"libc",
]
[[package]]
name = "crossbeam-channel"
version = "0.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "82b8f8f868b36967f9606790d1903570de9ceaf870a7bf9fbbd3016d636a2cb2"
dependencies = [
"crossbeam-utils",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -272,12 +311,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "lazy_static"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
[[package]]
name = "libc"
version = "0.2.177"
@@ -294,6 +327,15 @@ dependencies = [
"windows-link",
]
[[package]]
name = "lock_api"
version = "0.4.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965"
dependencies = [
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.28"
@@ -321,6 +363,29 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "parking_lot"
version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a"
dependencies = [
"lock_api",
"parking_lot_core",
]
[[package]]
name = "parking_lot_core"
version = "0.9.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1"
dependencies = [
"cfg-if",
"libc",
"redox_syscall",
"smallvec",
"windows-link",
]
[[package]]
name = "ppv-lite86"
version = "0.2.21"
@@ -383,6 +448,15 @@ dependencies = [
"getrandom",
]
[[package]]
name = "redox_syscall"
version = "0.5.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d"
dependencies = [
"bitflags 2.10.0",
]
[[package]]
name = "regex"
version = "1.12.2"
@@ -424,6 +498,12 @@ version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
[[package]]
name = "scopeguard"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49"
[[package]]
name = "serde"
version = "1.0.228"
@@ -451,7 +531,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.109",
]
[[package]]
@@ -484,6 +564,51 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "smallvec"
version = "1.15.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03"
[[package]]
name = "static_init"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8bae1df58c5fea7502e8e352ec26b5579f6178e1fdb311e088580c980dee25ed"
dependencies = [
"bitflags 1.3.2",
"cfg_aliases 0.2.1",
"libc",
"parking_lot",
"parking_lot_core",
"static_init_macro",
"winapi",
]
[[package]]
name = "static_init_macro"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1389c88ddd739ec6d3f8f83343764a0e944cd23cfbf126a9796a714b0b6edd6f"
dependencies = [
"cfg_aliases 0.1.1",
"memchr",
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "syn"
version = "1.0.109"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "syn"
version = "2.0.109"
@@ -527,6 +652,7 @@ version = "0.0.0"
dependencies = [
"bincode",
"chrono",
"crossbeam-channel",
"libc",
"libloading",
"rand",
@@ -541,7 +667,7 @@ version = "0.0.0"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.109",
"unshell-crypt",
]
@@ -549,7 +675,7 @@ dependencies = [
name = "unshell-payload"
version = "0.0.0"
dependencies = [
"lazy_static",
"static_init",
"unshell-lib",
"unshell-obfuscate",
]
@@ -613,7 +739,7 @@ dependencies = [
"bumpalo",
"proc-macro2",
"quote",
"syn",
"syn 2.0.109",
"wasm-bindgen-shared",
]
@@ -626,6 +752,28 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.62.2"
@@ -647,7 +795,7 @@ checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.109",
]
[[package]]
@@ -658,7 +806,7 @@ checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.109",
]
[[package]]
@@ -708,5 +856,5 @@ checksum = "c640b22cd9817fae95be82f0d2f90b11f7605f6c319d16705c459b27ac2cbc26"
dependencies = [
"proc-macro2",
"quote",
"syn",
"syn 2.0.109",
]
+2 -1
View File
@@ -15,7 +15,8 @@ server = ["unshell-lib/server"]
[dependencies]
lazy_static = "1.5.0"
# lazy_static = "1.5.0"
static_init = "1.0.4"
unshell-lib = {path = "../unshell-lib", default-features = false}
unshell-obfuscate = {path = "../unshell-obfuscate"}
+20 -19
View File
@@ -1,11 +1,10 @@
use std::fs::File;
use std::{collections::HashMap, io::Read};
use std::collections::HashMap;
use lazy_static::lazy_static;
use static_init::dynamic;
use unshell_lib::{
ModuleError,
config::{PayloadConfig, RuntimeConfig},
module::{Manager, Module},
module::Manager,
};
use unshell_obfuscate::{obs, symbol};
@@ -13,8 +12,9 @@ use unshell_obfuscate::{obs, symbol};
extern crate unshell_lib;
// The main and initial 'configuration' for a payload
lazy_static! {
static ref PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
#[dynamic]
static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
id: symbol!("Test ID"),
components: unshell_lib::get_components(),
runtime_config: vec![RuntimeConfig {
@@ -23,7 +23,6 @@ lazy_static! {
config: HashMap::from([(symbol!("host").to_string(), obs!("localhost:1234"))]),
}],
};
}
fn main() {
// Init the logger
@@ -33,25 +32,27 @@ fn main() {
debug!("Initialized");
match || -> Result<(), ModuleError> {
let args = std::env::args();
// let args = std::env::args();
// TEMPORARY, load the module paths from command line args.
let mut modules = Vec::new();
for arg in args.skip(1) {
debug!("Loading module: {}", arg);
// let mut modules = Vec::new();
// for arg in args.skip(1) {
// debug!("Loading module: {}", arg);
let mut file = File::open(arg).map_err(|e| ModuleError::Error(e.to_string().into()))?;
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)
.map_err(|e| ModuleError::Error(e.to_string().into()))?;
// let mut file = File::open(arg).map_err(|e| ModuleError::Error(e.to_string().into()))?;
// let mut buffer = Vec::new();
// file.read_to_end(&mut buffer)
// .map_err(|e| ModuleError::Error(e.to_string().into()))?;
modules.push(Module::new_bytes(&buffer)?)
// modules.push(Module::new_bytes(&buffer)?)
// modules.push(Module::new(&arg)?)
}
// // modules.push(Module::new(&arg)?)
// }
// Run the manager, this is blocking.
Manager::run(&PAYLOAD_CONFIG, modules);
let manager = Manager::start(&PAYLOAD_CONFIG, Vec::new());
Manager::join(manager);
Ok(())
}() {