From 82d8e1ba1079f123e40b1fb04fed02d749da0dc5 Mon Sep 17 00:00:00 2001 From: Michael Mikovsky <77305074+Astatin3@users.noreply.github.com> Date: Fri, 30 Jan 2026 14:05:07 -0700 Subject: [PATCH] Work on custom binaries --- .../server/.cargo => .cargo}/config.toml | 0 Cargo.lock | 25 +++- Cargo.toml | 26 ++-- build.sh | 56 ++++++++ core-modules/client/unshell_component.toml | 11 -- core-modules/server/unshell_component.toml | 9 -- core-modules/server2/Cargo.toml | 16 +++ core-modules/server2/src/lib.rs | 5 + core-modules/unshell_component.toml | 9 -- src/config/mod.rs | 2 +- unshell-crypt/Cargo.toml | 5 +- unshell-gui/Cargo.toml | 5 +- unshell-manager/Cargo.toml | 5 +- unshell-obfuscate/Cargo.toml | 5 +- unshell-payload/Cargo.toml | 27 ++-- unshell-payload/src/main.rs | 128 ++++++++++-------- unshell-server/Cargo.toml | 5 +- unshell-server/src/config/blob.rs | 14 -- unshell-server/src/config/interface.rs | 49 ------- unshell-server/src/config/mod.rs | 91 ------------- unshell-server/src/lib.rs | 2 +- 21 files changed, 217 insertions(+), 278 deletions(-) rename {core-modules/server/.cargo => .cargo}/config.toml (100%) create mode 100755 build.sh delete mode 100644 core-modules/client/unshell_component.toml delete mode 100644 core-modules/server/unshell_component.toml create mode 100644 core-modules/server2/Cargo.toml create mode 100644 core-modules/server2/src/lib.rs delete mode 100644 core-modules/unshell_component.toml delete mode 100644 unshell-server/src/config/blob.rs delete mode 100644 unshell-server/src/config/interface.rs delete mode 100644 unshell-server/src/config/mod.rs diff --git a/core-modules/server/.cargo/config.toml b/.cargo/config.toml similarity index 100% rename from core-modules/server/.cargo/config.toml rename to .cargo/config.toml diff --git a/Cargo.lock b/Cargo.lock index e2047ee..752bd5e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3267,6 +3267,13 @@ dependencies = [ "serde", ] +[[package]] +name = "server2" +version = "0.0.0" +dependencies = [ + "unshell", +] + [[package]] name = "sha1" version = "0.10.6" @@ -3933,7 +3940,7 @@ dependencies = [ [[package]] name = "unshell-crypt" -version = "0.0.0" +version = "0.1.0" dependencies = [ "aes", "block-padding 0.4.2", @@ -3947,7 +3954,7 @@ dependencies = [ [[package]] name = "unshell-gui" -version = "0.0.0" +version = "0.1.0" dependencies = [ "chrono", "eframe", @@ -3967,7 +3974,7 @@ dependencies = [ [[package]] name = "unshell-manager" -version = "0.0.0" +version = "0.1.0" dependencies = [ "bincode", "libc", @@ -3978,7 +3985,7 @@ dependencies = [ [[package]] name = "unshell-obfuscate" -version = "0.0.0" +version = "0.1.0" dependencies = [ "proc-macro2", "quote", @@ -3989,8 +3996,16 @@ dependencies = [ ] [[package]] -name = "unshell-server" +name = "unshell-payload" version = "0.0.0" +dependencies = [ + "server2", + "unshell", +] + +[[package]] +name = "unshell-server" +version = "0.1.0" dependencies = [ "axum", "axum-extra", diff --git a/Cargo.toml b/Cargo.toml index d12bc4b..cbcb581 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["trim-paths"] +cargo-features = ["trim-paths", "panic-immediate-abort"] [package] name = "unshell" @@ -14,11 +14,14 @@ include = ["LICENSE-APACHE", "LICENSE-MIT", "**/*.rs", "Cargo.toml"] [workspace] members = [ # Binaries - "unshell-gui", "unshell-server", + "unshell-gui", + + # UnShell Binaries + "unshell-server", "unshell-payload", # Libraries "unshell-manager", "unshell-obfuscate", "unshell-crypt" -] +, "core-modules/server2"] [features] default = [] @@ -51,18 +54,21 @@ toml = "0.9.9" [profile.release] opt-level = 2 -# strip = true # Strip symbols from the binary -# opt-level = "z" # Optimize for size -# lto = true # Link tree optimization -# codegen-units = 1 -# panic = "abort" -# debug = false # Remove debug -# trim-paths="all" # Optimize all dependencies even in debug builds: [profile.dev.package."*"] opt-level = 2 +[profile.minimize] +inherits = "release" +strip = true # Strip symbols from the binary +opt-level = "z" # Optimize for size +lto = true # Link tree optimization +codegen-units = 1 +panic = "immediate-abort" +debug = false # Remove debug +trim-paths="all" + # ---------------------------------------------------------------------------------------- # Lints: diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..919f427 --- /dev/null +++ b/build.sh @@ -0,0 +1,56 @@ +# # -Cpanic=immediate-abort +# RUSTFLAGS="-Zunstable-options -Zlocation-detail=none -Zfmt-debug=none" \ +# cargo +nightly build \ +# -Z build-std=std,panic_abort \ +# -Z build-std-features= \ +# --profile minimize -p unshell-payload -- $@ + +cargo build --profile minimize -p unshell-payload + +export BINARY=./target/minimize/unshell-payload + +declare -a headers=( + ".gnu_debuglink" # - Debug information link + ".comment" #- Compiler version info + ".shstrtab" #- Section header string table (only needed by tools like readelf) + ".note.gnu.bu" ".note.gnu.build-id" # - Build ID note + ".eh_frame" ".eh_frame_hdr" # Exception handling info (can break C++ exceptions if removed) + #".gnu.version" ".gnu.version_r" # Symbol versioning (may be needed for some shared libraries) + ".gnu.hash" # Hash table for symbol lookup optimization + + + + # .shstrtab + # .interp + # .note.ABI-tag + # .dynsym + # .dynstr + # .rela.dyn + # .rodata + # .text + # .init + # .fini + # .tbss + # .fini_array + # .init_array + # .data.rel.ro + # .dynamic + # .got + # .got.plt + # .relro_padding + # .tm_clone_table + # .data + # .bss + + + +) + +# TODO: Implement FAKE section header comments and information +# Shuffle order of headers?? + +for section in "${headers[@]}" +do + strip --remove-section="$section" $BINARY + echo "Removed section header $section" +done diff --git a/core-modules/client/unshell_component.toml b/core-modules/client/unshell_component.toml deleted file mode 100644 index 37b294c..0000000 --- a/core-modules/client/unshell_component.toml +++ /dev/null @@ -1,11 +0,0 @@ -name="Client" -version="0.1" -description="Test Client module" -authors=["astatin3"] - - -[config] -header1 = { Header = "Header123" } -integer1 = { Integer = {}} - -[build_config] diff --git a/core-modules/server/unshell_component.toml b/core-modules/server/unshell_component.toml deleted file mode 100644 index 3e2ec8f..0000000 --- a/core-modules/server/unshell_component.toml +++ /dev/null @@ -1,9 +0,0 @@ -name="Server" -version="0.1" -description="Test server module for unshell" -authors=["astatin3"] - - -[config] -header1 = { Header = "Header123" } -integer1 = { Integer = {}} diff --git a/core-modules/server2/Cargo.toml b/core-modules/server2/Cargo.toml new file mode 100644 index 0000000..c48685d --- /dev/null +++ b/core-modules/server2/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "server2" +edition = "2024" + +[features] +log = ["unshell/log"] +log_debug = ["unshell/log_debug"] + +# [lib] +# crate-type = ["cdylib"] + +[dependencies] +unshell.path = "../../" + +[lints] +workspace = true diff --git a/core-modules/server2/src/lib.rs b/core-modules/server2/src/lib.rs new file mode 100644 index 0000000..12d8692 --- /dev/null +++ b/core-modules/server2/src/lib.rs @@ -0,0 +1,5 @@ +use unshell::info; + +pub fn log_test_fn() { + info!("Testttttttt"); +} diff --git a/core-modules/unshell_component.toml b/core-modules/unshell_component.toml deleted file mode 100644 index fe72aee..0000000 --- a/core-modules/unshell_component.toml +++ /dev/null @@ -1,9 +0,0 @@ -name="UnShell Core" -version="0.1" -description="Core components for UnShell" -authors=["astatin3"] - -child_components = [ - "client/unshell_component.toml", - "server/unshell_component.toml" -] diff --git a/src/config/mod.rs b/src/config/mod.rs index ac36916..9b49419 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -1,5 +1,5 @@ pub mod config_struct; -pub mod config_struct_list; +// pub mod config_struct_list; mod tree; pub use tree::{InterfaceData, InterfaceStruct, Tree, TreeMessage}; diff --git a/unshell-crypt/Cargo.toml b/unshell-crypt/Cargo.toml index ec4ccb5..5d36404 100644 --- a/unshell-crypt/Cargo.toml +++ b/unshell-crypt/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "unshell-crypt" -edition = "2024" +version.workspace = true +edition.workspace = true +authors.workspace = true +include.workspace = true [dependencies] aes = "0.8.4" diff --git a/unshell-gui/Cargo.toml b/unshell-gui/Cargo.toml index 72a023a..084e7d4 100644 --- a/unshell-gui/Cargo.toml +++ b/unshell-gui/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "unshell-gui" -edition = "2024" +version.workspace = true +edition.workspace = true +authors.workspace = true +include.workspace = true [lib] crate-type = ["cdylib"] diff --git a/unshell-manager/Cargo.toml b/unshell-manager/Cargo.toml index d6ed06c..eedba00 100644 --- a/unshell-manager/Cargo.toml +++ b/unshell-manager/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "unshell-manager" -edition = "2024" +version.workspace = true +edition.workspace = true +authors.workspace = true +include.workspace = true [features] log = ["unshell/log"] diff --git a/unshell-obfuscate/Cargo.toml b/unshell-obfuscate/Cargo.toml index 1bf7cbd..cb70025 100644 --- a/unshell-obfuscate/Cargo.toml +++ b/unshell-obfuscate/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "unshell-obfuscate" -edition = "2024" +version.workspace = true +edition.workspace = true +authors.workspace = true +include.workspace = true [features] obfuscate = [] diff --git a/unshell-payload/Cargo.toml b/unshell-payload/Cargo.toml index 49c9663..cb21ed8 100644 --- a/unshell-payload/Cargo.toml +++ b/unshell-payload/Cargo.toml @@ -1,8 +1,18 @@ +cargo-features = ["trim-paths"] + [package] name = "unshell-payload" edition = "2024" -# [features] +# [lib] +# crate-type = ["cdylib"] + +[features] +default = ["log"] +log = ["unshell/log", "server2/log"] +log_debug = ["unshell/log_debug", "server2/log_debug"] + + # obfuscate = ["unshell-obfuscate/obfuscate"] # log = ["unshell-lib/log"] # log_debug = ["unshell-lib/log_debug"] @@ -13,17 +23,6 @@ edition = "2024" [dependencies] -# lazy_static = "1.5.0" -static_init = "1.0.4" -# unshell-lib = {path = "../unshell-lib", default-features = false} -unshell-obfuscate = {path = "../unshell-obfuscate"} - -[profile.release] -# strip = true # Strip symbols from the binary -# opt-level = "z" # Optimize for size -# lto = true # Link tree optimization -# codegen-units = 1 -# panic = "abort" -# debug = false # Remove debug -# trim-paths="all" +unshell.path = "../" +server2.path = "../core-modules/server2" diff --git a/unshell-payload/src/main.rs b/unshell-payload/src/main.rs index 30f1b33..3320e66 100644 --- a/unshell-payload/src/main.rs +++ b/unshell-payload/src/main.rs @@ -1,76 +1,86 @@ -use std::{any::Any, collections::HashMap, fs::File, io::Read}; +use unshell::info; -use static_init::dynamic; -use unshell_lib::{ - ModuleError, - config::{PayloadConfig, RuntimeConfig}, - module::{Manager, Module}, -}; -use unshell_obfuscate::{obs, symbol}; - -#[macro_use] -extern crate unshell_lib; - -// The main and initial 'configuration' for a payload - -#[dynamic] -static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig { - id: symbol!("Test ID"), - components: Vec::new(), - runtime_config: vec![RuntimeConfig { - parent_component: symbol!("client").to_string(), - name: symbol!("client runtime").to_string(), - config: HashMap::from([ - (symbol!("host").to_string(), obs!("localhost:1234")), - (symbol!("retry").to_string(), obs!("1000")), - ]), - }], -}; +// use std::dyn fn main() { // Init the logger - #[cfg(not(feature = "obfuscate"))] - unshell_lib::logger::PrettyLogger::init(); + // #[cfg(not(feature = "obfuscate"))] + unshell::logger::PrettyLogger::init(); - debug!("Initialized"); - - match run() { - Ok(_) => {} - Err(e) => { - error!("ERROR! '{:?}'", e); - } - } + server2::log_test_fn(); + // info!("This is a string!"); } -fn run() -> Result<(), Box> { - let args = std::env::args(); +// use std::{any::Any, collections::HashMap, fs::File, io::Read}; - // TEMPORARY, load the module paths from command line args. - let mut modules = Vec::new(); - for arg in args.skip(1) { - // debug!("Loading module: {}", arg); +// use static_init::dynamic; +// use unshell_lib::{ +// ModuleError, +// config::{PayloadConfig, RuntimeConfig}, +// module::{Manager, Module}, +// }; +// use unshell_obfuscate::{obs, symbol}; - // 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()))?; +// #[macro_use] +// extern crate unshell_lib; - debug!("Initializing module: {}", arg); - let module = Module::new(&arg)?; +// // The main and initial 'configuration' for a payload - modules.push(module); +// #[dynamic] +// static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig { +// id: symbol!("Test ID"), +// components: Vec::new(), +// runtime_config: vec![RuntimeConfig { +// parent_component: symbol!("client").to_string(), +// name: symbol!("client runtime").to_string(), +// config: HashMap::from([ +// (symbol!("host").to_string(), obs!("localhost:1234")), +// (symbol!("retry").to_string(), obs!("1000")), +// ]), +// }], +// }; - // modules.push(Module::new(&arg)?) - } +// fn main() { - // let modules = vec +// debug!("Initialized"); - debug!("Starting manager..."); +// match run() { +// Ok(_) => {} +// Err(e) => { +// error!("ERROR! '{:?}'", e); +// } +// } +// } - // Run the manager, this is blocking. - let manager = Manager::start(&PAYLOAD_CONFIG, modules); +// fn run() -> Result<(), Box> { +// let args = std::env::args(); - Manager::join(manager); +// // TEMPORARY, load the module paths from command line args. +// let mut modules = Vec::new(); +// for arg in args.skip(1) { +// // debug!("Loading module: {}", arg); - Ok(()) -} +// // 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()))?; + +// debug!("Initializing module: {}", arg); +// let module = Module::new(&arg)?; + +// modules.push(module); + +// // modules.push(Module::new(&arg)?) +// } + +// // let modules = vec + +// debug!("Starting manager..."); + +// // Run the manager, this is blocking. +// let manager = Manager::start(&PAYLOAD_CONFIG, modules); + +// Manager::join(manager); + +// Ok(()) +// } diff --git a/unshell-server/Cargo.toml b/unshell-server/Cargo.toml index 5a9d4b4..7cea62b 100644 --- a/unshell-server/Cargo.toml +++ b/unshell-server/Cargo.toml @@ -1,6 +1,9 @@ [package] name = "unshell-server" -edition = "2024" +version.workspace = true +edition.workspace = true +authors.workspace = true +include.workspace = true [features] default = ["log_debug"] diff --git a/unshell-server/src/config/blob.rs b/unshell-server/src/config/blob.rs deleted file mode 100644 index 8ba3f78..0000000 --- a/unshell-server/src/config/blob.rs +++ /dev/null @@ -1,14 +0,0 @@ -use std::collections::HashMap; - -use unshell::config::ConfigStructField; - -// use crate::config::ConfigStructField; - -#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] -pub struct Blob { - name: String, - - parent_component: String, - // parent_runtime: String, - config: HashMap, -} diff --git a/unshell-server/src/config/interface.rs b/unshell-server/src/config/interface.rs deleted file mode 100644 index 038d642..0000000 --- a/unshell-server/src/config/interface.rs +++ /dev/null @@ -1,49 +0,0 @@ -use std::collections::HashMap; - -use serde_json::Value; - -use crate::config::ConfigStructField; - -#[derive(Clone, serde::Deserialize, serde::Serialize)] -pub enum Interface { - Sub(HashMap), - Struct { - fields: HashMap, - value: HashMap, - }, -} - -#[derive(Clone, serde::Deserialize, serde::Serialize)] -pub struct InterfaceWrapper { - pub name: String, - pub interface: Interface, -} - -impl InterfaceWrapper { - pub fn get_path(&self, elements: &Vec<&str>, depth: usize) -> Result { - if depth == elements.len() { - return Ok(self.clone()); - } - - let element = elements[depth]; - - match &self.interface { - Interface::Sub(interface_wrappers) => { - if let Some(interface) = interface_wrappers.get(element) { - interface.get_path(elements, depth) - } else { - Err("Invalid Path".into()) - } - } - - _ => Err("Invalid Path".into()), - } - } -} - -pub fn get_test_interface() -> InterfaceWrapper { - InterfaceWrapper { - name: "Root Interface".into(), - interface: Interface::Sub(HashMap::new()), - } -} diff --git a/unshell-server/src/config/mod.rs b/unshell-server/src/config/mod.rs deleted file mode 100644 index c07b80e..0000000 --- a/unshell-server/src/config/mod.rs +++ /dev/null @@ -1,91 +0,0 @@ -mod blob; - -use std::{ - collections::HashMap, - fs, - path::{Path, PathBuf}, -}; - -use unshell::{ModuleError, Result, debug, info}; - -#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)] -struct ComponentMetadata { - name: String, - description: Option, - version: Option, - authors: Option>, - - // Struct to contain build information - #[serde(default)] - build_config: BuildConfig, - - // Other components that can be pointed to by this component - #[serde(default)] - child_components: Vec, -} - -#[derive(Default, Debug, Clone, serde::Deserialize, serde::Serialize)] -struct BuildConfig { - // Cargo feature list of a component - // (Name, Description) - #[serde(default)] - features: HashMap, -} - -#[derive(Clone, Debug)] -pub struct ComponentState { - metadata: ComponentMetadata, - path: PathBuf, -} - -pub fn load_config(path: &PathBuf) -> Result> { - let path_absolute = - fs::canonicalize(path.clone()).map_err(|e| ModuleError::Error(e.to_string()))?; - debug!("Loading data from path: `{:?}`", path_absolute); - - // Read string as path - let config_str = - fs::read_to_string(path.clone()).map_err(|e| ModuleError::Error(e.to_string()))?; - - // Load config from String - let config = toml::from_str::(&config_str) - .map_err(|e| ModuleError::Error(e.to_string()))?; - - info!("Loaded component `{}`", config.name); - - let parent_path = path_absolute.parent().expect("Path must have parent"); - - if config.child_components.is_empty() { - Ok(vec![ComponentState { - metadata: config, - path: PathBuf::from(parent_path), - }]) - } else { - let mut config_vec = vec![]; - - // Load each child component - for component_path in &config.child_components { - let path = Path::join(parent_path, component_path); - let mut config = load_config(&path)?; - config_vec.append(&mut config); - } - - config_vec.insert( - 0, - ComponentState { - metadata: config, - path: PathBuf::from(parent_path), - }, - ); - - Ok(config_vec) - } -} - -// pub fn parse_toml() -> ComponentMetadata { -// let data = include_str!("../../test.toml"); - -// let config = toml::from_str(data).unwrap(); - -// config -// } diff --git a/unshell-server/src/lib.rs b/unshell-server/src/lib.rs index ee9fe40..12880e9 100644 --- a/unshell-server/src/lib.rs +++ b/unshell-server/src/lib.rs @@ -1,6 +1,6 @@ mod api; mod auth; -mod config; +// mod config; pub mod logger; mod server;