Clean up the code a little bit

This commit is contained in:
Michael Mikovsky
2025-11-24 08:45:44 -07:00
parent 11045522b8
commit 0c538e9dcf
9 changed files with 21 additions and 222 deletions
+3
View File
@@ -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 decrypted_result = input.to_string();
let mut total_offset = 0; 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) { for aes_block in Regex::new(r"_([0-9a-zA-Z]*?)_").unwrap().find_iter(&input) {
let range = aes_block.range(); let range = aes_block.range();
let aes_block = aes_block.as_str()[1..(aes_block.len() - 1)].to_string(); 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) { 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); 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); decrypted_result.replace_range(range, &decrypted_block);
} else { } else {
// If the decode is unsuccessful, leave the underscore-denoted region as is
continue; continue;
} }
} }
+1
View File
@@ -2,6 +2,7 @@ use bincode::{Decode, Encode};
use crate::config::RuntimeConfig; use crate::config::RuntimeConfig;
/// Mostly temporary server message type
#[derive(Debug, Encode, Decode)] #[derive(Debug, Encode, Decode)]
pub enum Announcement { pub enum Announcement {
TestAnnouncement(String), TestAnnouncement(String),
-4
View File
@@ -85,10 +85,7 @@ impl ClientRuntime {
} }
impl ModuleRuntime for ClientRuntime { impl ModuleRuntime for ClientRuntime {
// fn init(&mut self) {}
fn is_running(&self) -> bool { fn is_running(&self) -> bool {
// println!("Checking if running");
!self.thread_handle.is_finished() !self.thread_handle.is_finished()
} }
@@ -97,6 +94,5 @@ impl ModuleRuntime for ClientRuntime {
self.join_signal.store(true, Ordering::Relaxed); self.join_signal.store(true, Ordering::Relaxed);
let _ = self.thread_handle.join(); let _ = self.thread_handle.join();
} }
// drop(self);
} }
} }
+1
View File
@@ -2,6 +2,7 @@ use unshell_obfuscate::obfuscated_symbol;
use crate::config::NamedComponent; use crate::config::NamedComponent;
/// Publicly facing accessor function for the payload to load inside the breakout modules.
#[obfuscated_symbol] #[obfuscated_symbol]
pub fn get_components() -> Vec<NamedComponent> { pub fn get_components() -> Vec<NamedComponent> {
return vec![ return vec![
+1
View File
@@ -41,6 +41,7 @@ impl Logger for DefaultLogger {
} }
pub fn set_logger_box(logger: Box<dyn Logger>) { pub fn set_logger_box(logger: Box<dyn Logger>) {
#[cfg(feature = "log")]
unsafe { unsafe {
LOGGER = Box::leak(logger); LOGGER = Box::leak(logger);
} }
-213
View File
@@ -31,56 +31,6 @@ dependencies = [
"libc", "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]] [[package]]
name = "autocfg" name = "autocfg"
version = "1.5.0" version = "1.5.0"
@@ -188,12 +138,6 @@ dependencies = [
"inout", "inout",
] ]
[[package]]
name = "colorchoice"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]] [[package]]
name = "core-foundation-sys" name = "core-foundation-sys"
version = "0.8.7" version = "0.8.7"
@@ -229,29 +173,6 @@ dependencies = [
"crypto-common", "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]] [[package]]
name = "find-msvc-tools" name = "find-msvc-tools"
version = "0.1.4" version = "0.1.4"
@@ -335,42 +256,12 @@ dependencies = [
"generic-array", "generic-array",
] ]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
[[package]] [[package]]
name = "itoa" name = "itoa"
version = "1.0.15" version = "1.0.15"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" 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]] [[package]]
name = "js-sys" name = "js-sys"
version = "0.3.82" version = "0.3.82"
@@ -430,27 +321,6 @@ version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" 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]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.103" version = "1.0.103"
@@ -639,10 +509,7 @@ dependencies = [
name = "unshell-payload" name = "unshell-payload"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"env_logger",
"lazy_static", "lazy_static",
"libloading",
"proc-macro2",
"unshell-lib", "unshell-lib",
"unshell-obfuscate", "unshell-obfuscate",
] ]
@@ -653,12 +520,6 @@ version = "0.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae" checksum = "6d49784317cd0d1ee7ec5c716dd598ec5b4483ea832a2dced265471cc0f690ae"
[[package]]
name = "utf8parse"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
[[package]] [[package]]
name = "version_check" name = "version_check"
version = "0.9.5" version = "0.9.5"
@@ -784,80 +645,6 @@ dependencies = [
"windows-link", "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]] [[package]]
name = "wit-bindgen" name = "wit-bindgen"
version = "0.46.0" version = "0.46.0"
+2 -3
View File
@@ -6,17 +6,16 @@ edition = "2024"
[features] [features]
obfuscate = ["unshell-obfuscate/obfuscate"] obfuscate = ["unshell-obfuscate/obfuscate"]
log = ["unshell-lib/log"]
log_debug = ["unshell-lib/log_debug"] log_debug = ["unshell-lib/log_debug"]
client = ["unshell-lib/client"] client = ["unshell-lib/client"]
server = ["unshell-lib/server"] server = ["unshell-lib/server"]
# server = ["unshell-lib/server"]
[dependencies] [dependencies]
env_logger = "0.11.8"
lazy_static = "1.5.0" lazy_static = "1.5.0"
libloading = "0.8.9"
proc-macro2 = "1.0.103"
unshell-lib = {path = "../unshell-lib", default-features = false} unshell-lib = {path = "../unshell-lib", default-features = false}
unshell-obfuscate = {path = "../unshell-obfuscate"} unshell-obfuscate = {path = "../unshell-obfuscate"}
+9 -2
View File
@@ -1,3 +1,10 @@
# OBFUSCATION_KEY=abc123abc \
# RUST_LOG=info \
# cargo run --no-default-features $@ --release # $(ls ../*/target/release/*.so)
OBFUSCATION_KEY=abc123abc \ OBFUSCATION_KEY=abc123abc \
RUST_LOG=info \ RUSTFLAGS="-Zlocation-detail=none -Zfmt-debug=none" \
cargo run --no-default-features $@ --release # $(ls ../*/target/release/*.so) cargo +nightly build \
-Z build-std=std,panic_abort \
-Z build-std-features="optimize_for_size" \
--profile release $@
+4
View File
@@ -11,6 +11,7 @@ use unshell_obfuscate::{obs, symbol};
#[macro_use] #[macro_use]
extern crate unshell_lib; extern crate unshell_lib;
// The main and initial 'configuration' for a payload
lazy_static! { lazy_static! {
static ref PAYLOAD_CONFIG: PayloadConfig = PayloadConfig { static ref PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
id: symbol!("Test ID"), id: symbol!("Test ID"),
@@ -24,6 +25,7 @@ lazy_static! {
} }
fn main() { fn main() {
// Init the logger
#[cfg(not(feature = "obfuscate"))] #[cfg(not(feature = "obfuscate"))]
unshell_lib::logger::PrettyLogger::init(); unshell_lib::logger::PrettyLogger::init();
@@ -32,12 +34,14 @@ fn main() {
match || -> Result<(), ModuleError> { 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(); let mut modules = Vec::new();
for arg in args.skip(1) { for arg in args.skip(1) {
debug!("Loading module: {}", arg); debug!("Loading module: {}", arg);
modules.push(Module::new(&arg)?) modules.push(Module::new(&arg)?)
} }
// Run the manager, this is blocking.
Manager::run(&PAYLOAD_CONFIG, modules); Manager::run(&PAYLOAD_CONFIG, modules);
Ok(()) Ok(())