1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Copyright 2017 Daniel P. Clark & other abrute Developers
// 
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
// http://opensource.org/licenses/MIT>, at your option. This file may not be
// copied, modified, or distributed except according to those terms.
//
extern crate digits;
extern crate rayon;
use digits::Digits;
use std::io::{self, Write}; 
mod result;
use result::Error;
use std::error::Error as StdError;
mod process_input;
use process_input::*;
mod validators;
use validators::*;
mod core;
use core::*;
#[macro_use]
extern crate clap;
use clap::{Arg, App};

fn run_app() -> Result<(), Error> {
  let matches = App::new("abrute - AES Brute Force File Decryptor").
    version(&format!("v{}", crate_version!())[..]).
    version_short("v").
    author(crate_authors!("\n")).
    usage("abrute <RANGE> <CHARACTERS> [OPTIONS] -- <TARGET>").
    arg(Arg::with_name("RANGE").
          required(true).
          index(1)
    ).
    arg(Arg::with_name("CHARACTERS").
          required(true).
          index(2)
    ).
    arg(Arg::with_name("adjacent").
          short("a").
          long("adjacent").
          takes_value(true)
    ).
    arg(Arg::with_name("start").
          short("s").
          long("start").
          takes_value(true)
    ).
    arg(Arg::with_name("zip").
          short("z").
          long("zip").
          takes_value(false)
    ).
    arg(Arg::with_name("TARGET").
          required(true).
          last(true)
    ).
    template("\
-------------------------------------------------------------
       {bin} {version}
-------------------------------------------------------------
           By: {author}


  USAGE:\tabrute <RANGE> <CHARACTERS> [OPTIONS] -- <TARGET>

   <RANGE>         Single digit or a range 4:6 for password length.
   <CHARACTERS>    Characters to use in password attempt. Don't use quotes
                   unless they may be in the password. Backslash may escape
                   characters such as space.
   -a, --adjacent  Set a limit for allowed adjacent characters. Zero will
                   not allow any characters of the same kind to neighbor
                   in the attempts.
   -s, --start     Starting character sequence to begin with.
   -z, --zip       Use `unzip` decryption instead of `aescrypt`.
   <TARGET>        Target file to decrypt.  The target must be preceeded
                   by a double dash: -- target.aes
   -h, --help      Prints help information.
   -v, --version   Prints version information.

-------------------------------------------------------------
USE OF THIS BINARY FALLS UNDER THE MIT LICENSE       (c) 2017").
    get_matches();

  if matches.is_present("zip") {
    validate_unzip_executable()?;
  } else {
    validate_aescrpyt_executable()?;
  }
    
  let (min, max) = derive_min_max(matches.value_of("RANGE").unwrap())?;
  
  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());
  sequencer.zero_fill(min as usize);

  let target = matches.value_of("TARGET").unwrap_or("");
  let adjacent = matches.value_of("adjacent");

  validate_and_prep_sequencer_adjacent(&mut sequencer, adjacent)?;
  validate_file_exists(&target)?;

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

fn main() {
  ::std::process::exit(
    match run_app() {
      Ok(_) => 0,
      Err(err) => {
        writeln!(
          io::stderr(),
          "Error: {}\n{}\n\nUse `abrute -h` for a help menu.",
          err,
          err.description()
        ).unwrap();
        1
      }
    }
  );
}