Skip to content

Commit

Permalink
refactor: 🔨 Change the code organization to be more structured
Browse files Browse the repository at this point in the history
This do not change the cli api, it's only internal changes for now
  • Loading branch information
AntwortEinesLebens committed Jul 7, 2024
1 parent 2fed622 commit c756985
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 111 deletions.
10 changes: 5 additions & 5 deletions src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod ads;
pub mod file;
pub mod mutex;
pub mod namepipe;
pub mod ppid;
pub mod service;
pub mod drivers;
pub mod files;
pub mod mutexes;
pub mod pipes;
pub mod processes;
91 changes: 1 addition & 90 deletions src/actions/ads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,93 +2,4 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

// Alternate Data Stream
//
// Last update 20240224

use base64::engine::{general_purpose, Engine};
use clap::Parser;
use regex_generate::{Generator, DEFAULT_MAX_REPEAT};
use std::path::Path;

#[derive(Parser)]
pub struct ADS {
#[clap(
short = 'f',
long,
required = true,
help = "Full path filename (regex)"
)]
filename: String,
#[clap(short = 'a', long, required = true, help = "ADS to use")]
ads: String,
#[clap(
short = 'd',
long,
required = false,
default_value = "V2VsY29tZSB0byB0aGUgV0FH",
help = "Data to write in base64"
)]
data: String,
}

fn create_ads(fullpath: String, adsname: String, hex_data: Vec<u8>) -> bool {
let file_base: &Path = Path::new(&fullpath);
if !file_base.exists() {
println!("Missing base file for ADS !");
return false;
}
let full_ads_name: String = format!("{}:{}", fullpath, adsname);
let file_ads: &Path = Path::new(&full_ads_name);
let ret_file: Result<(), std::io::Error> = std::fs::write(file_ads, hex_data);
match ret_file {
Ok(_) => return true,
Err(_) => return false,
}
}

impl ADS {
/* Version 20230908 */
pub fn run(&self) -> i32 {
println!("Alternate Data Stream");

if self.filename.len() > 0 {
let mut generator: Generator<rand::rngs::ThreadRng> =
match Generator::new(&self.filename, rand::thread_rng(), DEFAULT_MAX_REPEAT) {
Ok(generator) => generator,
Err(_) => {
println!("Regex expressions are malformed.");

return 1;
}
};
let mut buffer: Vec<u8> = vec![];
generator.generate(&mut buffer).unwrap();
let fullname: String = match String::from_utf8(buffer) {
Ok(string) => string,
Err(_) => {
println!("Filename contains non-utf8 characters.");

return 1;
}
};
let barrow_ads: String = self.ads.to_string();
let payload: Vec<u8> = match general_purpose::STANDARD.decode(self.data.as_str()) {
Ok(decoded) => decoded,
Err(_) => {
println!("Could not decode the data.");

return 1;
}
};
let ret_ads: bool = create_ads(fullname, barrow_ads, payload);
if ret_ads == true {
return 0;
} else {
return 1;
}
}

return 1;
}
}
pub mod create;
111 changes: 111 additions & 0 deletions src/actions/ads/create.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

// Alternate Data Stream
//
// Last update 20240224

use base64::engine::{general_purpose, Engine};
use clap::Parser;
use regex_generate::{Generator, DEFAULT_MAX_REPEAT};
use std::path::Path;

#[derive(Parser)]
pub struct Create {
#[clap(
short = 'f',
long,
required = true,
help = "Full path filename (regex)"
)]
filename: String,
#[clap(short = 'a', long, required = true, help = "ADS to use")]
ads: String,
#[clap(
short = 'd',
long,
required = false,
default_value = "V2VsY29tZSB0byB0aGUgV0FH",
help = "Data to write in base64"
)]
data: String,
}

fn create_ads(fullpath: String, adsname: String, hex_data: Vec<u8>) -> bool {
let file_base: &Path = Path::new(&fullpath);
if !file_base.exists() {
println!("Missing base file for ADS, try to create it");
let folder: &Path = file_base.parent().unwrap();

let ret_folder: Result<(), std::io::Error> = std::fs::create_dir_all(folder);
match ret_folder {
Ok(_) => println!("The folder is valid"),
Err(_) => return false,
}
let ret_file: Result<(), std::io::Error> = std::fs::write(
file_base,
vec![
87, 105, 110, 100, 111, 119, 115, 32, 65, 114, 116, 101, 102, 97, 99, 116, 32, 71,
101, 110, 101, 114, 97, 116, 111, 114,
],
);
match ret_file {
Ok(_) => println!("The base file is created"),
Err(_) => return false,
}
}
let full_ads_name: String = format!("{}:{}", fullpath, adsname);
let file_ads: &Path = Path::new(&full_ads_name);
let ret_file: Result<(), std::io::Error> = std::fs::write(file_ads, hex_data);
match ret_file {
Ok(_) => return true,
Err(_) => return false,
}
}

impl Create {
/* Version 20230908 */
pub fn run(&self) -> i32 {
println!("Alternate Data Stream");

if self.filename.len() > 0 {
let mut generator: Generator<rand::rngs::ThreadRng> =
match Generator::new(&self.filename, rand::thread_rng(), DEFAULT_MAX_REPEAT) {
Ok(generator) => generator,
Err(_) => {
println!("Regex expressions are malformed.");

return 1;
}
};
let mut buffer: Vec<u8> = vec![];
generator.generate(&mut buffer).unwrap();
let fullname: String = match String::from_utf8(buffer) {
Ok(string) => string,
Err(_) => {
println!("Filename contains non-utf8 characters.");

return 1;
}
};
let barrow_ads: String = self.ads.to_string();
let payload: Vec<u8> = match general_purpose::STANDARD.decode(self.data.as_str()) {
Ok(decoded) => decoded,
Err(_) => {
println!("Could not decode the data.");

return 1;
}
};
let ret_ads: bool = create_ads(fullname, barrow_ads, payload);
if ret_ads == true {
return 0;
} else {
return 1;
}
}

return 1;
}
}
5 changes: 5 additions & 0 deletions src/actions/drivers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod create;
4 changes: 2 additions & 2 deletions src/actions/service.rs → src/actions/drivers/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use windows::{
};

#[derive(Parser)]
pub struct BYOVD {
pub struct Create {
#[clap(
short = 'n',
long,
Expand Down Expand Up @@ -112,7 +112,7 @@ fn create_driver_service(name: &String, details: &String, path: &String) -> bool
}
}

impl BYOVD {
impl Create {
/* Version 20230908 */
pub fn run(&self) -> i32 {
println!("Bring Your Own Vulnerable Driver");
Expand Down
5 changes: 5 additions & 0 deletions src/actions/files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod create;
4 changes: 2 additions & 2 deletions src/actions/file.rs → src/actions/files/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use regex_generate::{Generator, DEFAULT_MAX_REPEAT};
use std::{io::Result as IOResult, path::Path, thread, time, time::Duration};

#[derive(Parser)]
pub struct FileCreate {
pub struct Create {
#[clap(
short = 'f',
long,
Expand Down Expand Up @@ -83,7 +83,7 @@ fn create_file(fullpath: String, hex_data: Vec<u8>) -> bool {
return false;
}

impl FileCreate {
impl Create {
pub fn run(&self) -> i32 {
if self.admin
&& !match is_administrator() {
Expand Down
5 changes: 5 additions & 0 deletions src/actions/mutexes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod create;
4 changes: 2 additions & 2 deletions src/actions/mutex.rs → src/actions/mutexes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use windows::{
};

#[derive(Parser)]
pub struct Mutex {
pub struct Create {
#[clap(
short = 'n',
long,
Expand All @@ -37,7 +37,7 @@ fn create_mutex(name: &String, wait: u64) {
let _res_server_pipe: WindowsResult<()> = unsafe { CloseHandle(mutex_handle.unwrap()) };
}

impl Mutex {
impl Create {
pub fn run(&self) -> i32 {
println!("Create Mutex");

Expand Down
5 changes: 5 additions & 0 deletions src/actions/pipes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod create;
4 changes: 2 additions & 2 deletions src/actions/namepipe.rs → src/actions/pipes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use clap::Parser;
use std::{thread, time};

#[derive(Parser)]
pub struct NamePipe {
pub struct Create {
#[clap(
short = 'n',
long,
Expand Down Expand Up @@ -50,7 +50,7 @@ fn create_name_pipe(name: &String, wait: u64) {
let _res_server_pipe: WindowsResult<()> = unsafe { CloseHandle(server_pipe.unwrap()) };
}

impl NamePipe {
impl Create {
pub fn run(&self) -> i32 {
println!("Create NamePipe");

Expand Down
5 changes: 5 additions & 0 deletions src/actions/processes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

pub mod spoofing;
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use windows::{
use std::{thread, time::Duration};

#[derive(Parser)]
pub struct PPID {
pub struct Spoofing {
#[clap(
short = 'e',
long,
Expand Down Expand Up @@ -129,7 +129,7 @@ fn create_ppid(name: &String) -> bool {
}
}

impl PPID {
impl Spoofing {
/* Version 20240209 */
pub fn run(&self) -> i32 {
println!("PPID spoofing");
Expand Down
14 changes: 8 additions & 6 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::actions::{
ads::ADS, file::FileCreate, mutex::Mutex, namepipe::NamePipe, ppid::PPID, service::BYOVD,
ads::create::Create as ADSCreate, drivers::create::Create as DriversCreate,
files::create::Create as FileCreate, mutexes::create::Create as MutexCreate,
pipes::create::Create as PipesCreate, processes::spoofing::Spoofing as ProcessesSpoofing,
};
use clap::Parser;

Expand Down Expand Up @@ -36,13 +38,13 @@ enum Commands {
#[clap(arg_required_else_help = true)]
FileCreate(FileCreate),
#[clap(arg_required_else_help = true)]
ADS(ADS),
ADS(ADSCreate),
#[clap(arg_required_else_help = true)]
NamePipe(NamePipe),
NamePipe(PipesCreate),
#[clap(arg_required_else_help = true)]
Mutex(Mutex),
Mutex(MutexCreate),
#[clap(arg_required_else_help = true)]
BYOVD(BYOVD),
BYOVD(DriversCreate),
#[clap(arg_required_else_help = true)]
PPID(PPID),
PPID(ProcessesSpoofing),
}

0 comments on commit c756985

Please sign in to comment.