diff --git a/Cargo.toml b/Cargo.toml index 04a6f33..c9d468e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "abrute" -version = "0.1.9" +version = "0.1.10" authors = ["Daniel P. Clark <6ftdan@gmail.com>"] description = "AESCrypt Brute force attempter." documentation = "http://danielpclark.github.io/abrute/index.html" @@ -13,7 +13,7 @@ categories = ["cryptography"] [dependencies] array_tool = "^1.0" -clap = {version="~3.1.18",features=["cargo"]} +clap = {version="~4.3.0",features=["cargo"]} digits = "~1.1.0" lazy_static = "1.4.0" libc = "0.2.125" @@ -21,5 +21,5 @@ num_cpus = "~1.7" rayon = "~0.8.2" serde = "1.0.24" serde_json = "1.0.8" -tiny_http = "~0.5" +tiny_http = "~0.8" tempdir = "~0.3" diff --git a/src/core.rs b/src/core.rs index f01ef10..116d30e 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2018 Daniel P. Clark & other abrute Developers +// Copyright 2017-2023 Daniel P. Clark & other abrute Developers // // Licensed under the Apache License, Version 2.0, or the MIT license (work_load: WorkLoad) -> Result<(), Error> { if output.status.success() { let mut code_mutex = code.lock().unwrap(); - code_mutex.push(value.clone().to_string()); + code_mutex.push(value.to_string()); SUCCESS.store(true, Ordering::SeqCst); println!("Success!\nPassword is: {}", value); } diff --git a/src/main.rs b/src/main.rs index 43cb9d9..fceb0ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2018 Daniel P. Clark & other abrute Developers +// Copyright 2017-2023 Daniel P. Clark & other abrute Developers // // Licensed under the Apache License, Version 2.0, or the MIT license Result<(), Error> { let matches = Command::new("abrute - AES Brute Force File Decryptor") - .version(&format!("v{}", crate_version!())[..]) + .version(crate_version!()) .author(crate_authors!("\n")) .override_usage("abrute [OPTIONS] -- ") - .arg(Arg::new("RANGE").required(true).index(1)) - .arg(Arg::new("CHARACTERS").required(true).index(2)) + .arg( + Arg::new("RANGE") + .required(true) + .index(1) + ) + .arg( + Arg::new("CHARACTERS") + .required(true) + .index(2) + ) .arg( Arg::new("adjacent") .short('a') .long("adjacent") - .takes_value(true), + .action(ArgAction::Set) + ) + .arg( + Arg::new("start") + .short('s') + .long("start") + .action(ArgAction::Set) + ) + .arg( + Arg::new("zip") + .short('z') + .long("zip") + .action(ArgAction::SetTrue) + ) + .arg( + Arg::new("chunk") + .short('c') + .long("chunk") + .value_name("CHUNK") + .value_parser(clap::builder::NonEmptyStringValueParser::new()) + .default_value("32") + .required(false) + ) + .arg( + Arg::new("cluster") + .long("cluster") + .action(ArgAction::Set) ) - .arg(Arg::new("start").short('s').long("start").takes_value(true)) - .arg(Arg::new("zip").short('z').long("zip").takes_value(false)) - .arg(Arg::new("chunk").short('c').long("chunk").takes_value(true)) - .arg(Arg::new("cluster").long("cluster").takes_value(true)) .arg( Arg::new("reporter") .short('r') .long("reporter") - .takes_value(true), + .action(ArgAction::Set) + ) + .arg( + Arg::new("TARGET") + .required(true) + .last(true) + .index(3) ) - .arg(Arg::new("TARGET").required(true).last(true)) .help_template( "\ ------------------------------------------------------------- @@ -101,46 +136,46 @@ fn run_app() -> Result<(), Error> { -v, --version Prints version information. ------------------------------------------------------------- -USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017-2018", +USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017-2023", ) .get_matches(); - if matches.is_present("zip") { + if matches.get_flag("zip") { validate_unzip_executable()?; } else { validate_aescrpyt_executable()?; } - let (min, max) = derive_min_max(matches.value_of("RANGE").unwrap())?; + let (min, max) = derive_min_max(matches.get_one::("RANGE").unwrap())?; validate_start_string(&matches, max)?; - let mapping = derive_character_base(matches.value_of("CHARACTERS").unwrap()); + let mapping = derive_character_base(matches.get_one::("CHARACTERS").unwrap()); let resume_key_chars = mapping_to_characters(&mapping); - let mut sequencer = Digits::new(mapping, matches.value_of("start").unwrap_or("").to_string()); + let mut sequencer = Digits::new(mapping, if let Some(seq) = matches.get_one::("start") { seq.to_owned() } else { "".to_string() }); sequencer.zero_fill(min as usize); - let target = matches.value_of("TARGET").unwrap_or(""); - let adjacent = matches.value_of("adjacent"); + let target = if let Some(tar) = matches.get_one::("TARGET") { tar } else { "" }; + let adjacent = matches.get_one::("adjacent"); validate_and_prep_sequencer_adjacent(&mut sequencer, adjacent)?; validate_file_exists(&target)?; - let chunk = matches.value_of("chunk"); - if matches.is_present("chunk") { + let chunk = matches.get_one::("chunk").map(|x| x.as_str()); + if let Some(_) = matches.get_one::("chunk") { validate_chunk_input(&chunk.unwrap()[..])?; } let mut cluster_step: Option = None; - if matches.is_present("cluster") { - let (offset, step) = derive_cluster(matches.value_of("cluster").unwrap())?; + if let Some(_) = matches.get_one::("cluster") { + let (offset, step) = derive_cluster(matches.get_one::("cluster").unwrap())?; cluster_step = Some(step); let additive = sequencer.gen(offset as u64).pred_till_zero(); sequencer.mut_add(additive); } let reporter = - verify_reporter_name(matches.value_of("reporter").unwrap_or("ticker").to_string()); + verify_reporter_name(if let Some(rep) = matches.get_one::("reporter") { rep } else { "ticker" }.to_string()); // JSON URI println!("JSON endpoint available on Port 3838"); @@ -151,7 +186,7 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017-2018", use resume::{ResumeFile, ResumeKey}; let cli_key = ResumeKey::new( resume_key_chars.clone(), - adjacent.map(str::to_string), + adjacent.map(|x| x.to_string()), sequencer, target.to_string(), ); @@ -167,15 +202,11 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017-2018", cores: num_cpus::get() as u8, chunk: chunk.clone().unwrap_or("").parse::().unwrap_or(32), cluster: { - if matches.is_present("cluster") { - Some( - derive_cluster(matches.value_of("cluster").unwrap()) - .ok() - .unwrap(), - ) - } else { - None - } + matches.get_one::("cluster").map(|val| + derive_cluster(val) + .ok() + .unwrap() + ) }, character_set: resume_key_chars.clone(), start_time: SystemTime::now(), @@ -192,8 +223,8 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017-2018", max, sequencer, target.to_string(), - adjacent.map(str::to_string), - chunk.map(str::to_string), + adjacent.map(|x| x.to_string()), + chunk.map(|x| x.to_string()), cluster_step, reporter_handler, reporter, @@ -202,7 +233,7 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017-2018", let mtchs = matches.clone(); let crypt_runner = thread::spawn(move || { - if mtchs.is_present("zip") { + if mtchs.get_flag("zip") { unzip_core_loop(work_load) } else { aescrypt_core_loop(work_load) diff --git a/src/validators.rs b/src/validators.rs index fecfb4d..ae17e92 100644 --- a/src/validators.rs +++ b/src/validators.rs @@ -1,4 +1,4 @@ -// Copyright 2017-2018 Daniel P. Clark & other abrute Developers +// Copyright 2017-2023 Daniel P. Clark & other abrute Developers // // Licensed under the Apache License, Version 2.0, or the MIT license Result<(), Error> { +pub fn validate_adjacent_input(v: &String) -> Result<(), Error> { if v.parse::().is_ok() { return Ok(()); } @@ -26,12 +26,12 @@ pub fn validate_chunk_input(v: &str) -> Result<(), Error> { } pub fn validate_start_string(matches: &clap::ArgMatches, max: usize) -> Result<(), Error> { - if let Some(s) = matches.value_of("start") { + if let Some(s) = matches.get_one::("start") { if s.len() > max { return Err(Error::InvalidStringLength); } - let chrctrs: Vec = matches.value_of("CHARACTERS").unwrap().chars().collect(); + let chrctrs: Vec = matches.get_one::("CHARACTERS").unwrap().chars().collect(); let mut itr = s.chars(); loop { match itr.next() { @@ -50,12 +50,12 @@ pub fn validate_start_string(matches: &clap::ArgMatches, max: usize) -> Result<( pub fn validate_and_prep_sequencer_adjacent<'a>( sequencer: &mut Digits, - adjacent: Option<&str>, + adjacent: Option<&String>, ) -> Result<(), Error> { let seq_base = sequencer.base(); if let &Some(num) = &adjacent { - validate_adjacent_input(num.to_string())?; + validate_adjacent_input(num)?; if seq_base > 3 { sequencer.prep_non_adjacent(num.parse::().unwrap()); }