From 2697d8670cb139d5cc89599c760c2a0f45e92dea Mon Sep 17 00:00:00 2001 From: AntwortEinesLebens Date: Mon, 16 Sep 2024 15:05:14 +0200 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=94=A8=20Return=20Result=20di?= =?UTF-8?q?rectly=20and=20remove=20all=20exit=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because Result implements Terminaison trait, the cli will return the right exit code --- src/actions.rs | 4 ++-- src/actions/ads.rs | 2 +- src/actions/ads/create.rs | 6 +++--- src/actions/drivers.rs | 2 +- src/actions/drivers/create.rs | 6 +++--- src/actions/files.rs | 2 +- src/actions/files/create.rs | 6 +++--- src/actions/mutexes.rs | 2 +- src/actions/mutexes/create.rs | 4 ++-- src/actions/pipes.rs | 2 +- src/actions/pipes/create.rs | 4 ++-- src/actions/processes.rs | 2 +- src/actions/processes/spoofing.rs | 6 ++---- src/main.rs | 16 +++++----------- 14 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/actions.rs b/src/actions.rs index ebc5141..0e7f704 100644 --- a/src/actions.rs +++ b/src/actions.rs @@ -33,11 +33,11 @@ pub enum Commands { } pub trait Runnable { - fn run(&self) -> Result>; + fn run(&self) -> Result<(), Box>; } impl Runnable for Actions { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::AlternateDataStreams(alternate_data_streams) => { alternate_data_streams as &dyn Runnable diff --git a/src/actions/ads.rs b/src/actions/ads.rs index 004c48f..57bd700 100644 --- a/src/actions/ads.rs +++ b/src/actions/ads.rs @@ -20,7 +20,7 @@ pub enum Commands { } impl Runnable for AlternateDataStreams { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::Create(create) => create as &dyn Runnable, } diff --git a/src/actions/ads/create.rs b/src/actions/ads/create.rs index bf29a46..072ca1f 100644 --- a/src/actions/ads/create.rs +++ b/src/actions/ads/create.rs @@ -64,7 +64,7 @@ fn create_ads(fullpath: String, adsname: String, hex_data: Vec) -> bool { impl Runnable for Create { /* Version 20230908 */ - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { println!("Alternate Data Stream"); if !self.filename.is_empty() { @@ -77,9 +77,9 @@ impl Runnable for Create { let payload: Vec = general_purpose::STANDARD.decode(self.data.as_str())?; let ret_ads: bool = create_ads(fullname, barrow_ads, payload); - return Ok(!ret_ads as i32); + return Ok(()); } - Ok(1) + Ok(()) } } diff --git a/src/actions/drivers.rs b/src/actions/drivers.rs index 03344c5..0c17673 100644 --- a/src/actions/drivers.rs +++ b/src/actions/drivers.rs @@ -20,7 +20,7 @@ pub enum Commands { } impl Runnable for Drivers { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::Create(create) => create as &dyn Runnable, } diff --git a/src/actions/drivers/create.rs b/src/actions/drivers/create.rs index 566d299..80a85bb 100644 --- a/src/actions/drivers/create.rs +++ b/src/actions/drivers/create.rs @@ -114,18 +114,18 @@ fn create_driver_service(name: &str, details: &str, path: &str) -> bool { impl Runnable for Create { /* Version 20230908 */ - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { println!("Bring Your Own Vulnerable Driver"); if !is_administrator()? { println!("Need to have Administrator right to create the service"); - return Ok(1); + return Ok(()); } // Todo check path is valid or not :) let result: bool = create_driver_service(&self.internal, &self.display, &self.path); - Ok(!result as i32) + Ok(()) } } diff --git a/src/actions/files.rs b/src/actions/files.rs index 5a7073e..b908c7a 100644 --- a/src/actions/files.rs +++ b/src/actions/files.rs @@ -20,7 +20,7 @@ pub enum Commands { } impl Runnable for Files { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::Create(create) => create as &dyn Runnable, } diff --git a/src/actions/files/create.rs b/src/actions/files/create.rs index b05a584..bc1f903 100644 --- a/src/actions/files/create.rs +++ b/src/actions/files/create.rs @@ -90,10 +90,10 @@ fn create_file(fullpath: String, hex_data: Vec) -> bool { } impl Runnable for Create { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { if self.admin && !is_administrator()? { println!("Need to have Administrator right to create the file"); - return Ok(1); + return Ok(()); } let mut generator: Generator = @@ -107,6 +107,6 @@ impl Runnable for Create { let payload: Vec = general_purpose::STANDARD.decode(self.magicbyte.as_str())?; let ret: bool = create_file(fullname, payload); - Ok(!ret as i32) + Ok(()) } } diff --git a/src/actions/mutexes.rs b/src/actions/mutexes.rs index 3085d41..e51e2ba 100644 --- a/src/actions/mutexes.rs +++ b/src/actions/mutexes.rs @@ -20,7 +20,7 @@ pub enum Commands { } impl Runnable for Mutexes { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::Create(create) => create as &dyn Runnable, } diff --git a/src/actions/mutexes/create.rs b/src/actions/mutexes/create.rs index 559b947..986b1af 100644 --- a/src/actions/mutexes/create.rs +++ b/src/actions/mutexes/create.rs @@ -39,7 +39,7 @@ fn create_mutex(name: &String, wait: u64) { } impl Runnable for Create { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { println!("Create Mutex"); let mut generator: Generator = @@ -52,6 +52,6 @@ impl Runnable for Create { create_mutex(&payload, 2000); - Ok(0) + Ok(()) } } diff --git a/src/actions/pipes.rs b/src/actions/pipes.rs index 502c2f2..061b810 100644 --- a/src/actions/pipes.rs +++ b/src/actions/pipes.rs @@ -20,7 +20,7 @@ pub enum Commands { } impl Runnable for Pipes { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::Create(create) => create as &dyn Runnable, } diff --git a/src/actions/pipes/create.rs b/src/actions/pipes/create.rs index cf20cec..e42ab4c 100644 --- a/src/actions/pipes/create.rs +++ b/src/actions/pipes/create.rs @@ -51,7 +51,7 @@ fn create_name_pipe(name: &String, wait: u64) { } impl Runnable for Create { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { println!("Create NamePipe"); let mut generator: Generator = @@ -64,6 +64,6 @@ impl Runnable for Create { create_name_pipe(&payload, 2000); - Ok(0) + Ok(()) } } diff --git a/src/actions/processes.rs b/src/actions/processes.rs index 76452ac..0cbdf3d 100644 --- a/src/actions/processes.rs +++ b/src/actions/processes.rs @@ -20,7 +20,7 @@ pub enum Commands { } impl Runnable for Processes { - fn run(&self) -> Result> { + fn run(&self) -> Result<(), Box> { match &self.command { Commands::Spoofing(spoofing) => spoofing as &dyn Runnable, } diff --git a/src/actions/processes/spoofing.rs b/src/actions/processes/spoofing.rs index 1c8a3ad..d3d12f1 100644 --- a/src/actions/processes/spoofing.rs +++ b/src/actions/processes/spoofing.rs @@ -97,9 +97,7 @@ fn spoof(executable: &str, parent_pid: u32) -> Result<(), Box> { } impl Runnable for Spoofing { - fn run(&self) -> Result> { - spoof(&self.executable, get_pid(&self.parent_executable)?)?; - - Ok(0) + fn run(&self) -> Result<(), Box> { + Ok(spoof(&self.executable, get_pid(&self.parent_executable)?)?) } } diff --git a/src/main.rs b/src/main.rs index b167f6b..d18c9a0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,7 @@ mod windows; use actions::Runnable; use clap::Parser; use cli::{Arguments, Commands}; +use std::error::Error; fn banner() { let banner: &str = " @@ -23,17 +24,10 @@ fn banner() { println!("{}", banner); } -fn main() { +fn main() -> Result<(), Box> { banner(); - match Arguments::parse().command { - Commands::Actions(action) => match action.run() { - Ok(code) => std::process::exit(code), - Err(error) => { - println!("Error: {}", error); - - std::process::exit(1); - } - }, - }; + Ok(match Arguments::parse().command { + Commands::Actions(action) => action.run()?, + }) }