Skip to content

Commit

Permalink
Clusters supported now via CLI. Fixes #21
Browse files Browse the repository at this point in the history
  • Loading branch information
danielpclark committed Dec 7, 2017
1 parent baa7de3 commit 20327a7
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "abrute"
version = "0.1.5"
version = "0.1.6"
authors = ["Daniel P. Clark <[email protected]>"]
description = "AESCrypt Brute force attempter."
documentation = "http:https://danielpclark.github.io/abrute/index.html"
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ sudo cp target/release/abrute /usr/bin/
-z, --zip Use `unzip` decryption instead of `aescrypt`.
-c, --chunk Workload chunk size per core before status update.
Defaults to 32.
--cluster Takes an offset and cluster size such as 1:4 for the
first system in a cluster of 4. Helps different systems
split the workload without trying the same passwords.
<TARGET> Target file to decrypt. The target must be preceeded
by a double dash: -- target.aes
-h, --help Prints help information.
Expand Down
20 changes: 13 additions & 7 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn has_five_minutes_passed(t: Instant) -> bool {
Instant::now().duration_since(t) > Duration::new(300,0)
}

fn chunk_sequence(d: &mut Digits, adj: Option<String>, chunk: usize) -> Vec<String> {
fn chunk_sequence(d: &mut Digits, adj: Option<String>, chunk: usize, step: Option<usize>) -> Vec<String> {
let qty: usize = num_cpus::get() * chunk;
let mut counter = 0;
let mut result = vec![];
Expand All @@ -32,13 +32,17 @@ fn chunk_sequence(d: &mut Digits, adj: Option<String>, chunk: usize) -> Vec<Stri

if let Some(a) = adj.clone() {
if d.base() > 3 {
result.push(d.step_non_adjacent(a.parse::<u8>().unwrap() as usize).to_s());
for _ in 0..step.unwrap_or(1) {
d.step_non_adjacent(a.parse::<u8>().unwrap() as usize);
}
result.push(d.to_s());
counter += 1;
continue;
}
}

result.push(d.succ().to_s());
let step_size = d.gen(step.unwrap_or(1) as u64);
result.push(d.mut_add(step_size).to_s());
counter += 1;
}
result
Expand Down Expand Up @@ -81,7 +85,7 @@ fn has_reached_end<'a>(sequencer: &Digits, max: usize) -> Result<(), Error> {
}

pub fn aescrypt_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
let WorkLoad(characters, max, mut sequencer, target, adj, chunk_size) = work_load;
let WorkLoad(characters, max, mut sequencer, target, adj, chunk_size, cluster_step) = work_load;
let mut time_keeper = Instant::now();
loop {
has_reached_end(&sequencer, max)?;
Expand All @@ -90,7 +94,8 @@ pub fn aescrypt_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
let chunk = chunk_sequence(
&mut sequencer,
adj.clone(),
chunk_size.clone().map_or(32, |s| s.parse::<usize>().ok().unwrap())
chunk_size.clone().map_or(32, |s| s.parse::<usize>().ok().unwrap()),
cluster_step
);
let code: Mutex<Vec<String>> = Mutex::new(vec![]);

Expand Down Expand Up @@ -153,7 +158,7 @@ fn any_file_contents(dir: &TempDir, omit: &str) -> bool {
}

pub fn unzip_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
let WorkLoad(characters, max, mut sequencer, target, adj, chunk_size) = work_load;
let WorkLoad(characters, max, mut sequencer, target, adj, chunk_size, cluster_step) = work_load;
let mut time_keeper = Instant::now();
if let Ok(dir) = TempDir::new("abrute") {
let cwd = env::current_dir().unwrap();
Expand All @@ -169,7 +174,8 @@ pub fn unzip_core_loop<'a>(work_load: WorkLoad) -> Result<(), Error> {
let chunk = chunk_sequence(
&mut sequencer,
adj.clone(),
chunk_size.clone().map_or(32, |s| s.parse::<usize>().ok().unwrap())
chunk_size.clone().map_or(32, |s| s.parse::<usize>().ok().unwrap()),
cluster_step
);
let code: Mutex<Vec<Result<(), Error>>> = Mutex::new(vec![]);

Expand Down
21 changes: 19 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ pub struct WorkLoad(
pub Digits, // mut sequencer: Digits,
pub String, // target: String,
pub Option<String>, // adj: Option<String>
pub Option<String> // chunk: Option<String>
pub Option<String>, // chunk: Option<String>
pub Option<usize> // cluster_step: Option<(usize,usize)>
);

fn run_app() -> Result<(), Error> {
Expand Down Expand Up @@ -67,6 +68,10 @@ fn run_app() -> Result<(), Error> {
long("chunk").
takes_value(true)
).
arg(Arg::with_name("cluster").
long("cluster").
takes_value(true)
).
arg(Arg::with_name("TARGET").
required(true).
last(true)
Expand All @@ -91,6 +96,9 @@ fn run_app() -> Result<(), Error> {
-z, --zip Use `unzip` decryption instead of `aescrypt`.
-c, --chunk Workload chunk size per core before status update.
Defaults to 32.
--cluster Takes an offset and cluster size such as 1:4 for the
first system in a cluster of 4. Helps different systems
split the workload without trying the same passwords.
<TARGET> Target file to decrypt. The target must be preceeded
by a double dash: -- target.aes
-h, --help Prints help information.
Expand Down Expand Up @@ -126,6 +134,14 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
validate_chunk_input(&chunk.unwrap()[..])?;
}

let mut cluster_step: Option<usize> = None;
if matches.is_present("cluster") {
let (offset, step) = derive_cluster(matches.value_of("cluster").unwrap())?;
cluster_step = Some(step);
let additive = sequencer.gen(offset as u64).pred_till_zero();
sequencer.mut_add(additive);
}

// Begin Resume Feature
let starting = sequencer.to_s();
use ::resume::{ResumeKey,ResumeFile};
Expand All @@ -148,7 +164,8 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
sequencer,
target.to_string(),
adjacent.map(str::to_string),
chunk.map(str::to_string)
chunk.map(str::to_string),
cluster_step
);

if matches.is_present("zip") {
Expand Down
13 changes: 13 additions & 0 deletions src/process_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ pub fn derive_min_max(range: &str) -> Result<(usize, usize), Error> {
Ok((min, get_max()))
}

pub fn derive_cluster(range: &str) -> Result<(usize, usize), Error> {
let rvals = range.split(':').collect::<Vec<&str>>();
if rvals.len() != 2 { return Err(Error::InvalidRange); }
for item in &rvals { if item.parse::<usize>().is_err() { return Err(Error::InvalidRange); } }
let mut rivals = rvals.iter();
let offset = rivals.next().unwrap();
let cluster_size = rivals.next().unwrap();
let offset = offset.parse::<usize>().unwrap();
let cluster_size = cluster_size.parse::<usize>().unwrap();
if offset > cluster_size || offset == 0 { return Err(Error::InvalidRange); }
Ok((offset, cluster_size))
}

pub fn derive_character_base(characters: &str) -> BaseCustom<char> {
BaseCustom::<char>::new(characters.chars().collect())
}
Expand Down

0 comments on commit 20327a7

Please sign in to comment.