Skip to content

Commit

Permalink
Merge pull request #20 from frack113/refactor/cli-organization
Browse files Browse the repository at this point in the history
Refactor/cli organization
  • Loading branch information
AntwortEinesLebens authored Jul 8, 2024
2 parents 67cc569 + 00bdc91 commit 199500a
Show file tree
Hide file tree
Showing 16 changed files with 283 additions and 91 deletions.
49 changes: 49 additions & 0 deletions src/actions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::actions::{
ads::ADS, drivers::Drivers, files::Files, mutexes::Mutexes, pipes::Pipes, processes::Processes,
};
use clap::{Args, Subcommand};

pub mod ads;
pub mod drivers;
pub mod files;
pub mod mutexes;
pub mod pipes;
pub mod processes;

#[derive(Debug, Args)]
pub struct Actions {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
ADS(ADS),
Drivers(Drivers),
Files(Files),
Mutexes(Mutexes),
Pipes(Pipes),
Processes(Processes),
}

pub trait Runnable {
fn run(&self) -> i32;
}

impl Runnable for Actions {
fn run(&self) -> i32 {
return match &self.command {
Commands::ADS(ads) => ads as &dyn Runnable,
Commands::Drivers(drivers) => drivers,
Commands::Files(files) => files,
Commands::Mutexes(mutexes) => mutexes,
Commands::Pipes(pipes) => pipes,
Commands::Processes(processes) => processes,
}
.run();
}
}
28 changes: 28 additions & 0 deletions src/actions/ads.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::actions::{ads::create::Create, Runnable};
use clap::{Args, Subcommand};

pub mod create;

#[derive(Debug, Args)]
pub struct ADS {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
Create(Create),
}

impl Runnable for ADS {
fn run(&self) -> i32 {
return match &self.command {
Commands::Create(create) => create as &dyn Runnable,
}
.run();
}
}
30 changes: 24 additions & 6 deletions src/malware/ads.rs → src/actions/ads/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
//
// Last update 20240224

use crate::actions::Runnable;
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 {
#[derive(Debug, Parser)]
pub struct Create {
#[clap(
short = 'f',
long,
Expand All @@ -35,8 +36,25 @@ pub struct ADS {
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;
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);
Expand All @@ -47,9 +65,9 @@ fn create_ads(fullpath: String, adsname: String, hex_data: Vec<u8>) -> bool {
}
}

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

if self.filename.len() > 0 {
Expand Down
28 changes: 28 additions & 0 deletions src/actions/drivers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::actions::{drivers::create::Create, Runnable};
use clap::{Args, Subcommand};

pub mod create;

#[derive(Debug, Args)]
pub struct Drivers {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
Create(Create),
}

impl Runnable for Drivers {
fn run(&self) -> i32 {
return match &self.command {
Commands::Create(create) => create as &dyn Runnable,
}
.run();
}
}
10 changes: 5 additions & 5 deletions src/malware/service.rs → src/actions/drivers/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//
// Last update 20240224

use crate::windows::users::is_administrator;
use crate::{actions::Runnable, windows::users::is_administrator};
use clap::Parser;
use std::{thread, time};
use windows::{
Expand All @@ -18,8 +18,8 @@ use windows::{
},
};

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

impl BYOVD {
impl Runnable for Create {
/* Version 20230908 */
pub fn run(&self) -> i32 {
fn run(&self) -> i32 {
println!("Bring Your Own Vulnerable Driver");

if !match is_administrator() {
Expand Down
28 changes: 28 additions & 0 deletions src/actions/files.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::actions::{files::create::Create, Runnable};
use clap::{Args, Subcommand};

pub mod create;

#[derive(Debug, Args)]
pub struct Files {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
Create(Create),
}

impl Runnable for Files {
fn run(&self) -> i32 {
return match &self.command {
Commands::Create(create) => create as &dyn Runnable,
}
.run();
}
}
10 changes: 5 additions & 5 deletions src/malware/file.rs → src/actions/files/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ You can use `SET | more` or `Get-ChildItem Env:` to get the list
*/

use crate::windows::users::is_administrator;
use crate::{actions::Runnable, windows::users::is_administrator};
use base64::engine::{general_purpose, Engine};
use clap::Parser;
use regex_generate::{Generator, DEFAULT_MAX_REPEAT};
use std::{io::Result as IOResult, path::Path, thread, time, time::Duration};

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

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

use crate::actions::{mutexes::create::Create, Runnable};
use clap::{Args, Subcommand};

pub mod create;

#[derive(Debug, Args)]
pub struct Mutexes {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
Create(Create),
}

impl Runnable for Mutexes {
fn run(&self) -> i32 {
return match &self.command {
Commands::Create(create) => create as &dyn Runnable,
}
.run();
}
}
9 changes: 5 additions & 4 deletions src/malware/mutex.rs → src/actions/mutexes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//
// Last update 20240224

use crate::actions::Runnable;
use clap::Parser;
use regex_generate::{Generator, DEFAULT_MAX_REPEAT};
use std::{thread, time};
Expand All @@ -17,8 +18,8 @@ use windows::{
},
};

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

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

let mut generator: Generator<rand::rngs::ThreadRng> =
Expand Down
28 changes: 28 additions & 0 deletions src/actions/pipes.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// SPDX-FileCopyrightText: 2023 The WAG development team
//
// SPDX-License-Identifier: GPL-3.0-or-later

use crate::actions::{pipes::create::Create, Runnable};
use clap::{Args, Subcommand};

pub mod create;

#[derive(Debug, Args)]
pub struct Pipes {
#[clap(subcommand)]
pub command: Commands,
}

#[derive(Debug, Subcommand)]
pub enum Commands {
Create(Create),
}

impl Runnable for Pipes {
fn run(&self) -> i32 {
return match &self.command {
Commands::Create(create) => create as &dyn Runnable,
}
.run();
}
}
14 changes: 7 additions & 7 deletions src/malware/namepipe.rs → src/actions/pipes/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
//
// Last update 20240224

use crate::actions::Runnable;
use clap::Parser;
use regex_generate::{Generator, DEFAULT_MAX_REPEAT};
use std::{thread, time};
use windows::{
core::{Result as WindowsResult, PCSTR},
Win32::{
Expand All @@ -16,11 +19,8 @@ use windows::{
},
};

use clap::Parser;
use std::{thread, time};

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

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

let mut generator: Generator<rand::rngs::ThreadRng> =
Expand Down
Loading

0 comments on commit 199500a

Please sign in to comment.