-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: 🔨 Change the code organization to be more structured
This do not change the cli api, it's only internal changes for now
- Loading branch information
1 parent
2fed622
commit c756985
Showing
14 changed files
with
160 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters