Skip to content

Commit

Permalink
Merge pull request #18 from danielpclark/resume
Browse files Browse the repository at this point in the history
Auto-Resume feature
  • Loading branch information
danielpclark committed Dec 6, 2017
2 parents 8637b6b + 63c6a27 commit c950cd3
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 16 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ target/
**/*.rs.bk
Cargo.lock
**/*.swp
.abrute
.abrute.bak
**/.abrute
**/.abrute.bak
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ language: rust
os:
- linux
rust:
- stable
- beta
- nightly
before_install:
- wget https://www.aescrypt.com/download/v3/linux/aescrypt-3.13.tgz
Expand Down
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "abrute"
version = "0.1.3"
version = "0.1.4"
authors = ["Daniel P. Clark <[email protected]>"]
description = "AESCrypt Brute force attempter."
documentation = "http:https://danielpclark.github.io/abrute/index.html"
Expand All @@ -12,8 +12,9 @@ keywords = ["crypto","text","cryptography","security"]
categories = ["cryptography"]

[dependencies]
array_tool = "^1.0"
tempdir = "0.3"
clap = "^2.26"
digits = "^0.3.6"
digits = "~1.1.0"
num_cpus = "^1.0"
rayon = "0.8.2"
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ a secondary system.

## Installation

_abrute needs the nightly build of Rust for the TryFrom trait._

To use the install script you need to have the following commands available on your
system `curl wget unzip sudo cc` and possibly other build essentials for C.

Expand Down Expand Up @@ -58,7 +60,7 @@ cd ../.. && rm -rf aescrypt-3.13
Next you need to have [Rust installed](https://www.rust-lang.org/en-US/install.html).

```bash
curl https://sh.rustup.rs -sSf | sh
curl https://sh.rustup.rs -sSf | sh -s -- --channel=nightly
```

Then you can get and compile abrute.
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ else
if [ "$Rust_answer" == "y" ];
then
# User agreed, proceed with installation
curl https://sh.rustup.rs -sSf | sh
curl https://sh.rustup.rs -sSf | sh -s -- --channel=nightly
else
# User refused, abort installation
exit 1
Expand Down
31 changes: 25 additions & 6 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rayon::prelude::*;
use super::result::Error;
extern crate num_cpus;
extern crate tempdir;
use resume::{ResumeKey,ResumeFile};
use self::tempdir::TempDir;
use std::{fs,path,env};

Expand Down Expand Up @@ -60,12 +61,12 @@ fn unzip_command(value: &str, target: &str) -> Output {
unwrap()
}

fn progress_report<'a>(sequencer: &Digits<'a>) {
fn progress_report<'a>(sequencer: &Digits) {
print!("{}..", sequencer.to_s()); // Verbose
io::stdout().flush().unwrap();
}

fn has_reached_end<'a>(sequencer: &Digits<'a>, max: usize) -> Result<(), Error> {
fn has_reached_end<'a>(sequencer: &Digits, max: usize) -> Result<(), Error> {
if sequencer.length() > max {
return Err(Error::PasswordNotFound);
}
Expand All @@ -74,12 +75,12 @@ fn has_reached_end<'a>(sequencer: &Digits<'a>, max: usize) -> Result<(), Error>
}

pub fn aescrypt_core_loop<'a>(
characters: String,
max: usize,
mut sequencer: Digits<'a>,
mut sequencer: Digits,
target: &str,
adj: Option<&str>
) -> Result<(), Error> {

loop {
has_reached_end(&sequencer, max)?;
progress_report(&sequencer);
Expand Down Expand Up @@ -111,6 +112,15 @@ pub fn aescrypt_core_loop<'a>(

break;
}

ResumeFile::save(
ResumeKey::new(
characters.clone(),
adj.map(str::to_string),
sequencer.clone(),
target.to_string()
)
);
}

Ok(())
Expand All @@ -133,12 +143,12 @@ fn any_file_contents(dir: &TempDir, omit: &str) -> bool {
}

pub fn unzip_core_loop<'a>(
characters: String,
max: usize,
mut sequencer: Digits<'a>,
mut sequencer: Digits,
target: &str,
adj: Option<&str>
) -> Result<(), Error> {

if let Ok(dir) = TempDir::new("abrute") {
let cwd = env::current_dir().unwrap();
let working = path::Path::new(&dir.path().as_os_str()).join(&target);
Expand Down Expand Up @@ -182,6 +192,15 @@ pub fn unzip_core_loop<'a>(
if !code.is_empty() {
return code.pop().unwrap();
}

ResumeFile::save(
ResumeKey::new(
characters.clone(),
adj.map(str::to_string),
sequencer.clone(),
target.to_string()
)
);
}
} else {
return Err(Error::FailedTempDir);
Expand Down
25 changes: 22 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
// http:https://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.

#![feature(try_from)]
extern crate digits;
extern crate rayon;
use digits::Digits;
use std::io::{self, Write};
mod resume;
mod result;
use result::Error;
use std::error::Error as StdError;
Expand Down Expand Up @@ -93,7 +95,8 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
validate_start_string(&matches, max)?;

let mapping = derive_character_base(matches.value_of("CHARACTERS").unwrap());
let mut sequencer = Digits::new(&mapping, matches.value_of("start").unwrap_or("").to_string());
let resume_key_chars = mapping_to_characters(&mapping);
let mut sequencer = Digits::new(mapping, matches.value_of("start").unwrap_or("").to_string());
sequencer.zero_fill(min as usize);

let target = matches.value_of("TARGET").unwrap_or("");
Expand All @@ -102,10 +105,26 @@ USE OF THIS BINARY FALLS UNDER THE MIT LICENSE (c) 2017").
validate_and_prep_sequencer_adjacent(&mut sequencer, adjacent)?;
validate_file_exists(&target)?;

// Begin Resume Feature
let starting = sequencer.to_s();
use ::resume::{ResumeKey,ResumeFile};
let cli_key = ResumeKey::new(
resume_key_chars.clone(),
adjacent.map(str::to_string),
sequencer,
target.to_string(),
);
let latest = cli_key.latest(ResumeFile::load());
let sequencer = latest.start;
if starting != sequencer.to_s() {
println!("Resuming from last save point: {}", sequencer.to_s());
}
// End Resume Feature

if matches.is_present("zip") {
unzip_core_loop(max, sequencer, target, adjacent)
unzip_core_loop(resume_key_chars, max, sequencer, target, adjacent)
} else {
aescrypt_core_loop(max, sequencer, target, adjacent)
aescrypt_core_loop(resume_key_chars, max, sequencer, target, adjacent)
}
}

Expand Down
7 changes: 7 additions & 0 deletions src/process_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ pub fn derive_character_base(characters: &str) -> BaseCustom<char> {
BaseCustom::<char>::new(characters.chars().collect())
}

pub fn mapping_to_characters(m: &BaseCustom<char>) -> String {
let mut crs = String::new();
for x in 0..m.base as usize {
crs.push_str(&m.gen(x as u64)[..]);
}
crs
}
8 changes: 8 additions & 0 deletions src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub enum Error {
InvalidRange,
InvalidStringLength,
PasswordNotFound,
MalformedResumeKey,
UnzipMissing,
}

Expand All @@ -32,6 +33,7 @@ impl fmt::Display for Error {
Error::InvalidRange => f.write_str("InvalidRange" ),
Error::InvalidStringLength => f.write_str("InvalidStringLength" ),
Error::PasswordNotFound => f.write_str("PasswordNotFound" ),
Error::MalformedResumeKey => f.write_str("MalformedResumeKey" ),
Error::UnzipMissing => f.write_str("UnzipMissing" ),
}
}
Expand Down Expand Up @@ -77,6 +79,11 @@ fn password_not_found() -> &'static str {
"Password not found for given length and character set."
}

#[inline]
fn malformed_resume_key() -> &'static str {
"The input data was not formatted properly for creating ResumeKey."
}

#[inline]
fn unzip_missing() -> &'static str {
"unzip does not appear to be installed."
Expand All @@ -93,6 +100,7 @@ impl StdError for Error {
Error::InvalidRange => invalid_range(),
Error::InvalidStringLength => invalid_string_length(),
Error::PasswordNotFound => password_not_found(),
Error::MalformedResumeKey => malformed_resume_key(),
Error::UnzipMissing => unzip_missing(),
}
}
Expand Down
Loading

0 comments on commit c950cd3

Please sign in to comment.