From 0c538e9dcf3326e2167318d29db23a1670f7d704 Mon Sep 17 00:00:00 2001 From: Michael Mikovsky <77305074+Astatin3@users.noreply.github.com> Date: Mon, 24 Nov 2025 08:45:44 -0700 Subject: [PATCH] Clean up the code a little bit --- unshell-crypt/src/aes.rs | 3 + unshell-lib/src/announcement.rs | 1 + unshell-lib/src/client/client_runtime.rs | 4 - unshell-lib/src/components.rs | 1 + unshell-lib/src/logger/mod.rs | 1 + unshell-payload/Cargo.lock | 213 ----------------------- unshell-payload/Cargo.toml | 5 +- unshell-payload/build.sh | 11 +- unshell-payload/src/main.rs | 4 + 9 files changed, 21 insertions(+), 222 deletions(-) diff --git a/unshell-crypt/src/aes.rs b/unshell-crypt/src/aes.rs index e8decc9..12547c6 100644 --- a/unshell-crypt/src/aes.rs +++ b/unshell-crypt/src/aes.rs @@ -83,10 +83,12 @@ pub fn decrypt_aes_lines(input: &str, key_str: &str, iv: [u8; 16]) -> String { let mut decrypted_result = input.to_string(); let mut total_offset = 0; + // Split input by segments of base62 chars, denoted by two _'s, and attempt to decode for aes_block in Regex::new(r"_([0-9a-zA-Z]*?)_").unwrap().find_iter(&input) { let range = aes_block.range(); let aes_block = aes_block.as_str()[1..(aes_block.len() - 1)].to_string(); + // If the decryption is successful, offset the current offset position if let Ok(decrypted_block) = decrypt_aes(&aes_block, key_str, iv) { let range = (range.start + total_offset as usize)..(range.end + total_offset as usize); @@ -95,6 +97,7 @@ pub fn decrypt_aes_lines(input: &str, key_str: &str, iv: [u8; 16]) -> String { decrypted_result.replace_range(range, &decrypted_block); } else { + // If the decode is unsuccessful, leave the underscore-denoted region as is continue; } } diff --git a/unshell-lib/src/announcement.rs b/unshell-lib/src/announcement.rs index 259c5f9..3612c02 100644 --- a/unshell-lib/src/announcement.rs +++ b/unshell-lib/src/announcement.rs @@ -2,6 +2,7 @@ use bincode::{Decode, Encode}; use crate::config::RuntimeConfig; +/// Mostly temporary server message type #[derive(Debug, Encode, Decode)] pub enum Announcement { TestAnnouncement(String), diff --git a/unshell-lib/src/client/client_runtime.rs b/unshell-lib/src/client/client_runtime.rs index 07eb228..035bc2a 100644 --- a/unshell-lib/src/client/client_runtime.rs +++ b/unshell-lib/src/client/client_runtime.rs @@ -85,10 +85,7 @@ impl ClientRuntime { } impl ModuleRuntime for ClientRuntime { - // fn init(&mut self) {} - fn is_running(&self) -> bool { - // println!("Checking if running"); !self.thread_handle.is_finished() } @@ -97,6 +94,5 @@ impl ModuleRuntime for ClientRuntime { self.join_signal.store(true, Ordering::Relaxed); let _ = self.thread_handle.join(); } - // drop(self); } } diff --git a/unshell-lib/src/components.rs b/unshell-lib/src/components.rs index 6e66440..f9bb43a 100644 --- a/unshell-lib/src/components.rs +++ b/unshell-lib/src/components.rs @@ -2,6 +2,7 @@ use unshell_obfuscate::obfuscated_symbol; use crate::config::NamedComponent; +/// Publicly facing accessor function for the payload to load inside the breakout modules. #[obfuscated_symbol] pub fn get_components() -> Vec { return vec![ diff --git a/unshell-lib/src/logger/mod.rs b/unshell-lib/src/logger/mod.rs index b903931..5eeeb79 100644 --- a/unshell-lib/src/logger/mod.rs +++ b/unshell-lib/src/logger/mod.rs @@ -41,6 +41,7 @@ impl Logger for DefaultLogger { } pub fn set_logger_box(logger: Box) { + #[cfg(feature = "log")] unsafe { LOGGER = Box::leak(logger); } diff --git a/unshell-payload/Cargo.lock b/unshell-payload/Cargo.lock index 4cafaea..012dedf 100644 --- a/unshell-payload/Cargo.lock +++ b/unshell-payload/Cargo.lock @@ -31,56 +31,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anstream" -version = "0.6.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a" -dependencies = [ - "anstyle", - "anstyle-parse", - "anstyle-query", - "anstyle-wincon", - "colorchoice", - "is_terminal_polyfill", - "utf8parse", -] - -[[package]] -name = "anstyle" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78" - -[[package]] -name = "anstyle-parse" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2" -dependencies = [ - "utf8parse", -] - -[[package]] -name = "anstyle-query" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e231f6134f61b71076a3eab506c379d4f36122f2af15a9ff04415ea4c3339e2" -dependencies = [ - "windows-sys", -] - -[[package]] -name = "anstyle-wincon" -version = "3.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0633414522a32ffaac8ac6cc8f748e090c5717661fddeea04219e2344f5f2a" -dependencies = [ - "anstyle", - "once_cell_polyfill", - "windows-sys", -] - [[package]] name = "autocfg" version = "1.5.0" @@ -188,12 +138,6 @@ dependencies = [ "inout", ] -[[package]] -name = "colorchoice" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75" - [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -229,29 +173,6 @@ dependencies = [ "crypto-common", ] -[[package]] -name = "env_filter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bf3c259d255ca70051b30e2e95b5446cdb8949ac4cd22c0d7fd634d89f568e2" -dependencies = [ - "log", - "regex", -] - -[[package]] -name = "env_logger" -version = "0.11.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13c863f0904021b108aa8b2f55046443e6b1ebde8fd4a15c399893aae4fa069f" -dependencies = [ - "anstream", - "anstyle", - "env_filter", - "jiff", - "log", -] - [[package]] name = "find-msvc-tools" version = "0.1.4" @@ -335,42 +256,12 @@ dependencies = [ "generic-array", ] -[[package]] -name = "is_terminal_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" - [[package]] name = "itoa" version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" -[[package]] -name = "jiff" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be1f93b8b1eb69c77f24bbb0afdf66f54b632ee39af40ca21c4365a1d7347e49" -dependencies = [ - "jiff-static", - "log", - "portable-atomic", - "portable-atomic-util", - "serde", -] - -[[package]] -name = "jiff-static" -version = "0.2.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03343451ff899767262ec32146f6d559dd759fdadf42ff0e227c7c48f72594b4" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - [[package]] name = "js-sys" version = "0.3.82" @@ -430,27 +321,6 @@ version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" -[[package]] -name = "once_cell_polyfill" -version = "1.70.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" - -[[package]] -name = "portable-atomic" -version = "1.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f84267b20a16ea918e43c6a88433c2d54fa145c92a811b5b047ccbe153674483" - -[[package]] -name = "portable-atomic-util" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8a2f0d8d040d7848a709caf78912debcc3f33ee4b3cac47d73d1e1069e83507" -dependencies = [ - "portable-atomic", -] - [[package]] name = "proc-macro2" version = "1.0.103" @@ -639,10 +509,7 @@ dependencies = [ name = "unshell-payload" version = "0.0.0" dependencies = [ - "env_logger", "lazy_static", - "libloading", - "proc-macro2", "unshell-lib", "unshell-obfuscate", ] @@ -653,12 +520,6 @@ version = "0.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" -[[package]] -name = "utf8parse" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" - [[package]] name = "version_check" version = "0.9.5" @@ -784,80 +645,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets", -] - -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", -] - -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "wit-bindgen" version = "0.46.0" diff --git a/unshell-payload/Cargo.toml b/unshell-payload/Cargo.toml index f232ad7..81aa769 100644 --- a/unshell-payload/Cargo.toml +++ b/unshell-payload/Cargo.toml @@ -6,17 +6,16 @@ edition = "2024" [features] obfuscate = ["unshell-obfuscate/obfuscate"] +log = ["unshell-lib/log"] log_debug = ["unshell-lib/log_debug"] client = ["unshell-lib/client"] server = ["unshell-lib/server"] +# server = ["unshell-lib/server"] [dependencies] -env_logger = "0.11.8" lazy_static = "1.5.0" -libloading = "0.8.9" -proc-macro2 = "1.0.103" unshell-lib = {path = "../unshell-lib", default-features = false} unshell-obfuscate = {path = "../unshell-obfuscate"} diff --git a/unshell-payload/build.sh b/unshell-payload/build.sh index e801e7e..0792954 100755 --- a/unshell-payload/build.sh +++ b/unshell-payload/build.sh @@ -1,3 +1,10 @@ +# OBFUSCATION_KEY=abc123abc \ +# RUST_LOG=info \ +# cargo run --no-default-features $@ --release # $(ls ../*/target/release/*.so) + OBFUSCATION_KEY=abc123abc \ -RUST_LOG=info \ -cargo run --no-default-features $@ --release # $(ls ../*/target/release/*.so) +RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" \ +cargo +nightly build \ + -Z build-std=std,panic_abort \ + -Z build-std-features="optimize_for_size" \ + --profile release $@ diff --git a/unshell-payload/src/main.rs b/unshell-payload/src/main.rs index 7577683..55213cf 100644 --- a/unshell-payload/src/main.rs +++ b/unshell-payload/src/main.rs @@ -11,6 +11,7 @@ use unshell_obfuscate::{obs, symbol}; #[macro_use] extern crate unshell_lib; +// The main and initial 'configuration' for a payload lazy_static! { static ref PAYLOAD_CONFIG: PayloadConfig = PayloadConfig { id: symbol!("Test ID"), @@ -24,6 +25,7 @@ lazy_static! { } fn main() { + // Init the logger #[cfg(not(feature = "obfuscate"))] unshell_lib::logger::PrettyLogger::init(); @@ -32,12 +34,14 @@ fn main() { match || -> Result<(), ModuleError> { 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); modules.push(Module::new(&arg)?) } + // Run the manager, this is blocking. Manager::run(&PAYLOAD_CONFIG, modules); Ok(())