mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-08 22:38:01 -06:00
Work on runtime system
This commit is contained in:
Generated
-1
@@ -468,7 +468,6 @@ name = "unshell-breakout-module"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"unshell-lib",
|
"unshell-lib",
|
||||||
"unshell-obfuscate",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|||||||
@@ -10,15 +10,13 @@ crate-type = ["cdylib"]
|
|||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["client", "server"]
|
default = ["client", "server"]
|
||||||
client = []
|
client = ["unshell-lib/client"]
|
||||||
server = []
|
server = ["unshell-lib/server"]
|
||||||
obfuscate = ["unshell-obfuscate/obfuscate"]
|
obfuscate = ["unshell-lib/obfuscate"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
# unshell-modules = {path = "../unshell-modules"}
|
|
||||||
unshell-lib = {path = "../unshell-lib"}
|
unshell-lib = {path = "../unshell-lib"}
|
||||||
unshell-obfuscate = {path = "../unshell-obfuscate"}
|
|
||||||
|
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
|
|||||||
@@ -1,34 +1,5 @@
|
|||||||
#![no_main]
|
#![no_main]
|
||||||
|
|
||||||
use std::collections::HashMap;
|
pub use unshell_lib::get_components;
|
||||||
use unshell_lib::Component;
|
|
||||||
use unshell_obfuscate::obfuscated_symbol;
|
|
||||||
|
|
||||||
#[obfuscated_symbol]
|
// Behold! The world's most sophisticated shared library!
|
||||||
fn test124() {
|
|
||||||
println!("test");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[obfuscated_symbol]
|
|
||||||
pub fn get_components() -> HashMap<&'static str, Box<dyn Component>> {
|
|
||||||
let mut components: HashMap<&'static str, Box<dyn Component>> = HashMap::new();
|
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
|
||||||
components.insert(
|
|
||||||
unshell_lib::client::MODULE_NAME,
|
|
||||||
Box::new(unshell_lib::client::ClientComponent::new()),
|
|
||||||
);
|
|
||||||
|
|
||||||
components
|
|
||||||
|
|
||||||
// vec![
|
|
||||||
// Feature::Client,
|
|
||||||
// #[cfg(feature = "server")]
|
|
||||||
// Feature::Server,
|
|
||||||
// ]
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "client")]
|
|
||||||
pub use unshell_lib::client::*;
|
|
||||||
#[cfg(feature = "server")]
|
|
||||||
pub use unshell_lib::server::*;
|
|
||||||
|
|||||||
Generated
+28
-7
@@ -256,6 +256,12 @@ dependencies = [
|
|||||||
"generic-array",
|
"generic-array",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "itoa"
|
||||||
|
version = "1.0.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "js-sys"
|
name = "js-sys"
|
||||||
version = "0.3.82"
|
version = "0.3.82"
|
||||||
@@ -368,6 +374,12 @@ version = "1.0.22"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ryu"
|
||||||
|
version = "1.0.20"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.228"
|
version = "1.0.228"
|
||||||
@@ -375,6 +387,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_core",
|
"serde_core",
|
||||||
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -397,6 +410,19 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_json"
|
||||||
|
version = "1.0.145"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "402a6f66d8c709116cf22f558eab210f5a50187f702eb4d7e5ef38d9a7f1c79c"
|
||||||
|
dependencies = [
|
||||||
|
"itoa",
|
||||||
|
"memchr",
|
||||||
|
"ryu",
|
||||||
|
"serde",
|
||||||
|
"serde_core",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "sha2"
|
name = "sha2"
|
||||||
version = "0.10.9"
|
version = "0.10.9"
|
||||||
@@ -464,16 +490,11 @@ dependencies = [
|
|||||||
name = "unshell-lib"
|
name = "unshell-lib"
|
||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"aes",
|
|
||||||
"bincode",
|
"bincode",
|
||||||
"block-padding 0.4.1",
|
|
||||||
"cbc",
|
|
||||||
"chrono",
|
"chrono",
|
||||||
"getrandom",
|
|
||||||
"hex",
|
|
||||||
"hex-literal",
|
|
||||||
"libloading",
|
"libloading",
|
||||||
"sha2",
|
"serde",
|
||||||
|
"serde_json",
|
||||||
"unshell-obfuscate",
|
"unshell-obfuscate",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ client = []
|
|||||||
server = []
|
server = []
|
||||||
|
|
||||||
log_debug = []
|
log_debug = []
|
||||||
|
obfuscate = ["unshell-obfuscate/obfuscate"]
|
||||||
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -2,31 +2,40 @@ use std::{
|
|||||||
io::Read,
|
io::Read,
|
||||||
net::TcpStream,
|
net::TcpStream,
|
||||||
sync::{
|
sync::{
|
||||||
Arc, Mutex,
|
Arc,
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
},
|
},
|
||||||
thread::{self, JoinHandle},
|
thread::{self, JoinHandle},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::*;
|
use crate::{config::RuntimeConfig, *};
|
||||||
// use unshell_modules::{Manager, ModuleRuntime};
|
// use unshell_modules::{Manager, ModuleRuntime};
|
||||||
|
|
||||||
use crate::{Announcement, ModuleRuntime, module::Manager};
|
use crate::{Announcement, ModuleRuntime};
|
||||||
|
|
||||||
pub struct RuntimeTest {
|
pub struct ClientRuntime {
|
||||||
thread_handle: JoinHandle<()>,
|
thread_handle: JoinHandle<()>,
|
||||||
join_signal: Arc<AtomicBool>,
|
join_signal: Arc<AtomicBool>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RuntimeTest {
|
impl ClientRuntime {
|
||||||
pub fn new(_manager: Arc<Mutex<Manager>>) -> RuntimeTest {
|
pub fn new(config: &'static RuntimeConfig) -> Result<ClientRuntime, ModuleError> {
|
||||||
let join_signal = Arc::new(AtomicBool::new(false));
|
let join_signal = Arc::new(AtomicBool::new(false));
|
||||||
let join_clone = join_signal.clone();
|
let join_clone = join_signal.clone();
|
||||||
|
|
||||||
Self {
|
let host = match config.config.get("host") {
|
||||||
|
Some(host) => host,
|
||||||
|
None => {
|
||||||
|
return Err(ModuleError::Error(
|
||||||
|
"Could not find HOST in Client Runtime".into(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Ok(Self {
|
||||||
thread_handle: thread::spawn(move || {
|
thread_handle: thread::spawn(move || {
|
||||||
debug!("Connecting to server...");
|
debug!("Connecting to server...");
|
||||||
let mut stream = match TcpStream::connect("localhost:1234") {
|
let mut stream = match TcpStream::connect(host) {
|
||||||
Ok(stream) => stream,
|
Ok(stream) => stream,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("Failed to connect to server: {}", e);
|
error!("Failed to connect to server: {}", e);
|
||||||
@@ -64,11 +73,11 @@ impl RuntimeTest {
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
join_signal,
|
join_signal,
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ModuleRuntime for RuntimeTest {
|
impl ModuleRuntime for ClientRuntime {
|
||||||
// fn init(&mut self) {}
|
// fn init(&mut self) {}
|
||||||
|
|
||||||
fn is_running(&self) -> bool {
|
fn is_running(&self) -> bool {
|
||||||
|
|||||||
@@ -6,12 +6,15 @@ pub const MODULE_NAME: &'static str = "client";
|
|||||||
|
|
||||||
// use unshell_modules::{Manager, ModuleRuntime, module_interface};
|
// use unshell_modules::{Manager, ModuleRuntime, module_interface};
|
||||||
|
|
||||||
|
use std::any::TypeId;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
Component,
|
ModuleError,
|
||||||
module::Interface,
|
ModuleRuntime,
|
||||||
|
client::client_runtime::ClientRuntime,
|
||||||
|
config::{InterfaceWrapper, NamedComponent, RuntimeConfig},
|
||||||
module_interface,
|
module_interface,
|
||||||
warn,
|
warn, // module_interface,
|
||||||
// module_interface,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub extern "C" fn test1() {
|
pub extern "C" fn test1() {
|
||||||
@@ -32,39 +35,35 @@ module_interface! {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// #[unsafe(no_mangle)]
|
pub struct ClientInterfaceWrapper;
|
||||||
// pub fn interface() -> Interface {
|
|
||||||
// Interface::from_raw(test1, test2, test3)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// #[unsafe(no_mangle)]
|
impl InterfaceWrapper for ClientInterfaceWrapper {
|
||||||
// pub fn init(manager: Arc<Mutex<Manager>>) -> Box<dyn ModuleRuntime> {
|
fn get_interface<T: 'static>(&self) -> Option<T>
|
||||||
// info!("Initializing client module");
|
where
|
||||||
// }
|
Self: Sized,
|
||||||
|
{
|
||||||
|
if TypeId::of::<T>() == TypeId::of::<ClientInterface>() {
|
||||||
|
let my_struct = ClientInterface::from_raw(test1, test2, test3);
|
||||||
|
|
||||||
#[derive(Clone)]
|
unsafe { Some(std::mem::transmute_copy(&my_struct)) }
|
||||||
pub struct ClientComponent;
|
} else {
|
||||||
|
None
|
||||||
impl ClientComponent {
|
}
|
||||||
pub fn new() -> Self {
|
|
||||||
ClientComponent
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Component for ClientComponent {
|
fn get_interface() -> Option<&'static (dyn InterfaceWrapper + Sync)> {
|
||||||
fn name(&self) -> &'static str {
|
Some(&ClientInterfaceWrapper)
|
||||||
MODULE_NAME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>> {
|
fn start_runtime(config: &'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime>, ModuleError> {
|
||||||
// Some(Box::new(RuntimeTest::new(manager)))
|
Ok(Box::new(ClientRuntime::new(config)?))
|
||||||
// }
|
|
||||||
|
|
||||||
fn clone_box(&self) -> Box<dyn Component> {
|
|
||||||
Box::new(self.clone())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_interface(&self) -> Box<dyn Interface> {
|
pub const fn get_named_component() -> NamedComponent {
|
||||||
Box::new(ClientInterface::from_raw(test1, test2, test3))
|
NamedComponent {
|
||||||
|
name: MODULE_NAME,
|
||||||
|
get_interface: &get_interface,
|
||||||
|
start_runtime: &start_runtime,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
use unshell_obfuscate::obfuscated_symbol;
|
use unshell_obfuscate::obfuscated_symbol;
|
||||||
|
|
||||||
use crate::{Component, config::NamedComponent};
|
use crate::config::NamedComponent;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[obfuscated_symbol]
|
#[obfuscated_symbol]
|
||||||
pub fn get_components() -> Vec<NamedComponent> {
|
pub fn get_components() -> Vec<NamedComponent> {
|
||||||
// let mut components: HashMap<&'static str, Box<dyn Component>> = HashMap::new();
|
// let mut components: HashMap<&'static str, Box<dyn Component>> = HashMap::new();
|
||||||
|
|
||||||
|
// let a = crate::client::get_interface;
|
||||||
|
|
||||||
return vec![
|
return vec![
|
||||||
NamedComponent {name:,crate::client::MODULE_NAME, get_interface: crate::client::get_interface, start_runtime: todo!() },
|
#[cfg(feature = "client")]
|
||||||
|
crate::client::get_named_component(),
|
||||||
];
|
];
|
||||||
|
|
||||||
// components
|
// components
|
||||||
|
|||||||
@@ -23,23 +23,33 @@ pub struct PayloadConfig {
|
|||||||
pub struct RuntimeConfig {
|
pub struct RuntimeConfig {
|
||||||
pub parent_component: &'static str,
|
pub parent_component: &'static str,
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
pub config: HashMap<String, String>,
|
pub config: HashMap<&'static str, String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct NamedComponent {
|
pub struct NamedComponent {
|
||||||
pub name: &'static str,
|
pub name: &'static str,
|
||||||
|
|
||||||
// + Sync + Sync + Sync + Sync + Sync + Sync + Sync + Sync
|
// + Sync + Sync + Sync + Sync + Sync + Sync + Sync + Sync
|
||||||
pub get_interface: &'static (dyn Fn() -> Option<&'static (dyn InterfaceWrapper + Sync)> + Sync),
|
pub get_interface: &'static (dyn Fn() -> Option<&'static (dyn InterfaceWrapper + Sync)> + Sync),
|
||||||
pub start_runtime: &'static (
|
pub start_runtime: &'static (
|
||||||
dyn Fn(&'static RuntimeConfig) -> Result<&'static dyn ModuleRuntime, ModuleError>
|
dyn Fn(&'static RuntimeConfig) -> Result<Box<dyn ModuleRuntime>, ModuleError>
|
||||||
+ Sync
|
+ Sync
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Trait that wraps the get_interface<T>() function inside of components
|
/// Trait that wraps the get_interface<T>() function inside of components
|
||||||
pub trait InterfaceWrapper: Send + Sync {
|
pub trait InterfaceWrapper: Send + Sync {
|
||||||
fn get_interface<T>() -> Option<T>
|
fn get_interface<T: 'static>(&self) -> Option<T>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// impl<T: 'static> InterfaceWrapper for T {
|
||||||
|
// default fn get_interface<T>() -> Option<T>
|
||||||
|
// where
|
||||||
|
// Self: Sized,
|
||||||
|
// {
|
||||||
|
// None
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|||||||
+13
-13
@@ -12,12 +12,12 @@ pub use components::get_components;
|
|||||||
mod announcement;
|
mod announcement;
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
fmt,
|
||||||
sync::{Arc, Mutex},
|
// sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use announcement::Announcement;
|
pub use announcement::Announcement;
|
||||||
|
|
||||||
use crate::module::{Interface, Manager};
|
// use crate::module::{Interface, Manager};
|
||||||
|
|
||||||
///Generic error type for module-related operations.
|
///Generic error type for module-related operations.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -58,16 +58,16 @@ pub trait ModuleRuntime: Send + Sync {
|
|||||||
fn kill(self: Box<Self>);
|
fn kill(self: Box<Self>);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Component {
|
// pub trait Component {
|
||||||
fn name(&self) -> &'static str;
|
// fn name(&self) -> &'static str;
|
||||||
// fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
|
// // fn start_runtime(&self, manager: Arc<Mutex<Manager>>) -> Option<Box<dyn ModuleRuntime>>;
|
||||||
|
|
||||||
fn get_interface(&self) -> Box<dyn Interface>;
|
// fn get_interface(&self) -> Box<dyn Interface>;
|
||||||
fn clone_box(&self) -> Box<dyn Component>;
|
// fn clone_box(&self) -> Box<dyn Component>;
|
||||||
}
|
// }
|
||||||
|
|
||||||
impl Clone for Box<dyn Component> {
|
// impl Clone for Box<dyn Component> {
|
||||||
fn clone(&self) -> Box<dyn Component> {
|
// fn clone(&self) -> Box<dyn Component> {
|
||||||
self.clone_box()
|
// self.clone_box()
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|||||||
@@ -5,37 +5,35 @@ use std::{
|
|||||||
time::Duration,
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use unshell_obfuscate::symbol;
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{NamedComponent, PayloadConfig, RuntimeConfig},
|
config::{NamedComponent, PayloadConfig, RuntimeConfig},
|
||||||
*,
|
*,
|
||||||
};
|
};
|
||||||
use module::Module;
|
use module::Module;
|
||||||
|
use unshell_obfuscate::symbol;
|
||||||
|
|
||||||
// #[derive(Debug)]
|
// #[derive(Debug)]
|
||||||
pub struct Manager<'a> {
|
pub struct Manager {
|
||||||
id: &'static str,
|
id: &'static str,
|
||||||
|
|
||||||
modules: Vec<Module>,
|
pub modules: Vec<Module>,
|
||||||
|
|
||||||
active_runtimes: Vec<&'a dyn ModuleRuntime>,
|
active_runtimes: Vec<Box<dyn ModuleRuntime>>,
|
||||||
// runtime_config: Vec<RuntimeConfig>,
|
// runtime_config: Vec<RuntimeConfig>,
|
||||||
components: HashMap<String, &'a NamedComponent>,
|
components: HashMap<String, NamedComponent>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
|
// static mut MANAGER_RUNTIME: Option<Arc<Mutex<Manager>>> = None;
|
||||||
|
|
||||||
impl<'a> Manager<'a> {
|
impl Manager {
|
||||||
fn new(id: &'static str, config: &'a Vec<NamedComponent>, modules: Vec<Module>) -> Self {
|
fn new(id: &'static str, config: Vec<NamedComponent>, modules: Vec<Module>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
|
|
||||||
// config,
|
|
||||||
modules,
|
modules,
|
||||||
|
components: config
|
||||||
components: config.iter().map(|c| (c.name.to_string(), c)).collect(),
|
.into_iter()
|
||||||
|
.map(|c| (c.name.to_string(), c))
|
||||||
|
.collect(),
|
||||||
active_runtimes: Vec::new(),
|
active_runtimes: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,54 +42,49 @@ impl<'a> Manager<'a> {
|
|||||||
#[allow(static_mut_refs)]
|
#[allow(static_mut_refs)]
|
||||||
pub fn run(config: &'static PayloadConfig, modules: Vec<Module>) {
|
pub fn run(config: &'static PayloadConfig, modules: Vec<Module>) {
|
||||||
// Construct self
|
// Construct self
|
||||||
let this = Self::new(&config.id, &config.components, modules);
|
let mut this = Self::new(&config.id, config.components.clone(), modules);
|
||||||
|
|
||||||
// Load each of the pre-prepared modules
|
// Load each of the pre-prepared modules
|
||||||
// this.load_components();
|
this.load_components();
|
||||||
|
|
||||||
let this = Arc::new(Mutex::new(this));
|
let this = Arc::new(Mutex::new(this));
|
||||||
|
|
||||||
Self::start_runtimes(this.clone(), &config.runtime_config);
|
Self::start_runtimes(this.clone(), &config.runtime_config);
|
||||||
|
|
||||||
// let components = this.components.clone();
|
// drop(config);
|
||||||
|
|
||||||
// let mut runtimes: Vec<Box<dyn ModuleRuntime>> = Vec::new();
|
|
||||||
|
|
||||||
// for (_name, component) in components {
|
|
||||||
// let module_runtime = component.start_runtime(this.clone());
|
|
||||||
// if let Some(module_runtime) = module_runtime {
|
|
||||||
// runtimes.push(module_runtime);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
Self::join(this);
|
Self::join(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fn load_components(&mut self) {
|
fn load_components(&mut self) {
|
||||||
// for i in 0..self.modules.len() {
|
for module in &self.modules {
|
||||||
// debug!("Importing module {}", i);
|
// Load get_components function from shared object library
|
||||||
// // let this_lock = .unwrap();
|
let component_func = match module
|
||||||
// let component_func = if let Ok(component_func) = self.modules[i]
|
.get_symbol::<fn() -> Vec<NamedComponent>>(symbol!(b"get_components"))
|
||||||
// .get_symbol::<fn() -> HashMap<&'static str, Box<dyn Component>>>(
|
{
|
||||||
// symbol!("get_components").as_bytes(),
|
Ok(func) => func,
|
||||||
// ) {
|
Err(_) => {
|
||||||
// component_func
|
warn!("get_components function not found");
|
||||||
// } else {
|
continue;
|
||||||
// warn!("get_components function not found");
|
}
|
||||||
// continue;
|
};
|
||||||
// };
|
|
||||||
|
|
||||||
// let components = component_func();
|
let components = component_func();
|
||||||
|
let component_name = "TODO";
|
||||||
|
|
||||||
// let len = components.len();
|
debug!("{} - Retrieved payload metadata", component_name);
|
||||||
// debug!("[{}] Loaded {} components", i, len);
|
|
||||||
|
|
||||||
// self.components.extend(components);
|
// Add each component into self
|
||||||
// }
|
for c in components {
|
||||||
// }
|
debug!("{} - Found component '{}'", "TODO", c.name);
|
||||||
|
self.components.insert(c.name.to_owned(), c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Start each runtime
|
/// Start each runtime
|
||||||
fn start_runtimes(this: Arc<Mutex<Self>>, runtimes: &'static Vec<RuntimeConfig>) {
|
fn start_runtimes(this: Arc<Mutex<Self>>, runtimes: &'static Vec<RuntimeConfig>) {
|
||||||
|
debug!("Starting runtimes...");
|
||||||
for runtime in runtimes {
|
for runtime in runtimes {
|
||||||
let mut this_lock = this.lock().unwrap();
|
let mut this_lock = this.lock().unwrap();
|
||||||
|
|
||||||
@@ -106,6 +99,8 @@ impl<'a> Manager<'a> {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
debug!("Starting runtime: {}", runtime.name);
|
||||||
|
|
||||||
let runtime = match (*component.start_runtime)(runtime) {
|
let runtime = match (*component.start_runtime)(runtime) {
|
||||||
Ok(runtime) => runtime,
|
Ok(runtime) => runtime,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -7,10 +7,6 @@ mod module;
|
|||||||
pub use manager::Manager;
|
pub use manager::Manager;
|
||||||
pub use module::Module;
|
pub use module::Module;
|
||||||
|
|
||||||
pub trait Interface {
|
|
||||||
fn as_any(self: Box<Self>) -> Box<dyn std::any::Any>;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// "Module Interface" helper macro that creates a struct with function pointers
|
/// "Module Interface" helper macro that creates a struct with function pointers
|
||||||
/// Useful for defining and requiring modules' functions accross FFI boundry.
|
/// Useful for defining and requiring modules' functions accross FFI boundry.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
@@ -58,10 +54,10 @@ macro_rules! module_interface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl crate::module::Interface for $interface_name {
|
// impl crate::module::Interface for $interface_name {
|
||||||
fn as_any(self: Box<Self>) -> Box<dyn std::any::Any> {
|
// fn as_any(self: Box<Self>) -> Box<dyn std::any::Any> {
|
||||||
self
|
// self
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ use crate::{ModuleError, logger::SetupLogger, logger::logger};
|
|||||||
use crate::*;
|
use crate::*;
|
||||||
|
|
||||||
pub struct Module {
|
pub struct Module {
|
||||||
// name: String,
|
|
||||||
lib: Library,
|
lib: Library,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,6 +28,9 @@ impl Module {
|
|||||||
|
|
||||||
Ok(symbol)
|
Ok(symbol)
|
||||||
}
|
}
|
||||||
|
// pub fn get_id(&self) -> &str {
|
||||||
|
// self.id
|
||||||
|
// }
|
||||||
// pub fn get_interface<T>(&self) -> Result<T, ModuleError> {
|
// pub fn get_interface<T>(&self) -> Result<T, ModuleError> {
|
||||||
// if let Ok(interface_function) = self.get_symbol::<fn() -> T>(b"interface") {
|
// if let Ok(interface_function) = self.get_symbol::<fn() -> T>(b"interface") {
|
||||||
// Ok(interface_function())
|
// Ok(interface_function())
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ pub struct ListenerRuntime {
|
|||||||
|
|
||||||
impl ListenerRuntime {
|
impl ListenerRuntime {
|
||||||
pub fn new() -> ListenerRuntime {
|
pub fn new() -> ListenerRuntime {
|
||||||
info!("Starting listener runtime on 127.0.0.1:1234",);
|
// info!("Starting listener runtime on {}",);
|
||||||
let listener = TcpListener::bind("127.0.0.1:1234").unwrap();
|
let listener = TcpListener::bind("127.0.0.1:1234").unwrap();
|
||||||
let streams = Arc::new(Mutex::new(Vec::new()));
|
let streams = Arc::new(Mutex::new(Vec::new()));
|
||||||
|
|
||||||
@@ -51,11 +51,6 @@ impl ListenerRuntime {
|
|||||||
println!("Announcement {:?} sent", announcement);
|
println!("Announcement {:?} sent", announcement);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
||||||
// self.stream
|
|
||||||
// .write_all(&u32::to_be_bytes(bytes.len() as u32))?;
|
|
||||||
// self.stream.write_all(&bytes)?;
|
|
||||||
// self.stream.flush()?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ use syn::{ItemFn, parse_macro_input};
|
|||||||
mod format_helper;
|
mod format_helper;
|
||||||
use format_helper::*;
|
use format_helper::*;
|
||||||
|
|
||||||
|
use syn::LitStr;
|
||||||
|
|
||||||
// Put all encrypt-related dependencies in a module, so they are easier to use with the feature flag
|
// Put all encrypt-related dependencies in a module, so they are easier to use with the feature flag
|
||||||
#[cfg(feature = "obfuscate")]
|
#[cfg(feature = "obfuscate")]
|
||||||
mod obs_deps {
|
mod obs_deps {
|
||||||
pub use syn::LitStr;
|
|
||||||
pub use unshell_crypt::BACKUP_ENV_KEY;
|
pub use unshell_crypt::BACKUP_ENV_KEY;
|
||||||
pub use unshell_crypt::ENV_KEY_NAME;
|
pub use unshell_crypt::ENV_KEY_NAME;
|
||||||
pub use unshell_crypt::STATIC_IV;
|
pub use unshell_crypt::STATIC_IV;
|
||||||
@@ -24,7 +25,12 @@ use obs_deps::*;
|
|||||||
#[proc_macro]
|
#[proc_macro]
|
||||||
#[cfg(not(feature = "obfuscate"))]
|
#[cfg(not(feature = "obfuscate"))]
|
||||||
pub fn obs(input: TokenStream) -> TokenStream {
|
pub fn obs(input: TokenStream) -> TokenStream {
|
||||||
input
|
let input = parse_macro_input!(input as LitStr);
|
||||||
|
|
||||||
|
(quote::quote! {
|
||||||
|
String::from(#input)
|
||||||
|
})
|
||||||
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[proc_macro_attribute]
|
#[proc_macro_attribute]
|
||||||
@@ -48,7 +54,6 @@ pub fn symbol(input: TokenStream) -> TokenStream {
|
|||||||
pub fn obfuscated_symbol(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
pub fn obfuscated_symbol(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||||
// Parse the input function
|
// Parse the input function
|
||||||
|
|
||||||
use unshell_crypt::aes::encrypt_aes;
|
|
||||||
let func = parse_macro_input!(item as ItemFn);
|
let func = parse_macro_input!(item as ItemFn);
|
||||||
|
|
||||||
// Get the original function name
|
// Get the original function name
|
||||||
|
|||||||
Generated
+7
@@ -381,6 +381,12 @@ dependencies = [
|
|||||||
"wasm-bindgen",
|
"wasm-bindgen",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "lazy_static"
|
||||||
|
version = "1.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "libc"
|
name = "libc"
|
||||||
version = "0.2.177"
|
version = "0.2.177"
|
||||||
@@ -634,6 +640,7 @@ name = "unshell-payload"
|
|||||||
version = "0.0.0"
|
version = "0.0.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"env_logger",
|
"env_logger",
|
||||||
|
"lazy_static",
|
||||||
"libloading",
|
"libloading",
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"unshell-lib",
|
"unshell-lib",
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ log_debug = ["unshell-lib/log_debug"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
env_logger = "0.11.8"
|
env_logger = "0.11.8"
|
||||||
|
lazy_static = "1.5.0"
|
||||||
libloading = "0.8.9"
|
libloading = "0.8.9"
|
||||||
proc-macro2 = "1.0.103"
|
proc-macro2 = "1.0.103"
|
||||||
|
|
||||||
|
|||||||
+19
-19
@@ -1,30 +1,30 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
use unshell_lib::{
|
use unshell_lib::{
|
||||||
ModuleError,
|
ModuleError,
|
||||||
config::{PayloadConfig, RuntimeConfig},
|
config::{PayloadConfig, RuntimeConfig},
|
||||||
module::{Manager, Module},
|
module::{Manager, Module},
|
||||||
};
|
};
|
||||||
use unshell_obfuscate::symbol;
|
use unshell_obfuscate::{obs, symbol};
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate unshell_lib;
|
extern crate unshell_lib;
|
||||||
|
|
||||||
static PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
|
lazy_static! {
|
||||||
|
static ref PAYLOAD_CONFIG: PayloadConfig = PayloadConfig {
|
||||||
id: symbol!("Test ID"),
|
id: symbol!("Test ID"),
|
||||||
components: unshell_lib::get_components(),
|
components: unshell_lib::get_components(),
|
||||||
runtime_config: vec![
|
runtime_config: vec![RuntimeConfig {
|
||||||
RuntimeConfig {
|
parent_component: symbol!("client"),
|
||||||
"client"
|
name: symbol!("client runtime"),
|
||||||
}
|
config: HashMap::from([(symbol!("host"), obs!("localhost:1234"))]),
|
||||||
],
|
}],
|
||||||
};
|
};
|
||||||
|
}
|
||||||
// static RUNTIME_CONFIG: PayloadConfig = PayloadConfig {
|
|
||||||
// id: symbol!("Test ID"),
|
|
||||||
// components: Vec::new(),
|
|
||||||
// };
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
#[cfg(not(feature = "obfuscate"))]
|
// #[cfg(not(feature = "obfuscate"))]
|
||||||
unshell_lib::logger::PrettyLogger::init();
|
unshell_lib::logger::PrettyLogger::init();
|
||||||
|
|
||||||
debug!("Initialized");
|
debug!("Initialized");
|
||||||
@@ -32,13 +32,13 @@ fn main() {
|
|||||||
match || -> Result<(), ModuleError> {
|
match || -> Result<(), ModuleError> {
|
||||||
let args = std::env::args();
|
let args = std::env::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)?)
|
||||||
// }
|
}
|
||||||
|
|
||||||
Manager::run(&PAYLOAD_CONFIG, Vec::new());
|
Manager::run(&PAYLOAD_CONFIG, modules);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}() {
|
}() {
|
||||||
|
|||||||
Reference in New Issue
Block a user