Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add badtouch oneshot #57

Merged
merged 6 commits into from
Jul 5, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add oneshot command
  • Loading branch information
kpcyrd committed Jul 3, 2018
commit c73e0a8e8f4ccdb300bcd0fa9ceea8f4599b3fb3
14 changes: 14 additions & 0 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ pub enum SubCommand {
name="creds",
about="Credential confirmation attack")]
Creds(Creds),
#[structopt(author = "",
name="oneshot",
about="Test a single username-password combination")]
Oneshot(Oneshot),
#[structopt(author = "",
name="fsck",
about="Verify and fix encoding of a list")]
Expand All @@ -51,6 +55,16 @@ pub struct Creds {
pub scripts: Vec<String>,
}

#[derive(StructOpt, Debug)]
pub struct Oneshot {
#[structopt(help="Script to run")]
pub script: String,
#[structopt(help="Username to test")]
pub user: String,
#[structopt(help="Password to test")]
pub password: String,
}

#[derive(StructOpt, Debug)]
pub struct Fsck {
#[structopt(short = "q", long = "quiet",
Expand Down
18 changes: 18 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ extern crate error_chain;
#[macro_use] extern crate log;

use badtouch::args;
use badtouch::ctx::Script;
use badtouch::fsck;
use badtouch::utils;
use badtouch::config::Config;
Expand Down Expand Up @@ -105,6 +106,22 @@ fn setup_credential_confirmation(pool: &mut Scheduler, args: args::Creds, config
Ok(attempts)
}

fn run_oneshot(oneshot: args::Oneshot, config: Arc<Config>) -> Result<()> {
let script = Script::load(&oneshot.script, config)?;
let user = oneshot.user;
let password = oneshot.password;

let valid = script.run_once(&user, &password)?;

if valid {
// TODO: this is duplicate code, see further down below
println!("{} {}({}) => {:?}:{:?}", "[+]".bold(), "valid".green(),
script.descr().yellow(), user, password);
}

Ok(())
}

fn set_nofile(config: &Config) -> Result<()> {
let (soft_limit, hard_limit) = getrlimit(Resource::RLIMIT_NOFILE)?;
info!("soft_limit={:?}, hard_limit={:?}", soft_limit, hard_limit);
Expand Down Expand Up @@ -138,6 +155,7 @@ fn run() -> Result<()> {
let attempts = match args.subcommand {
args::SubCommand::Dict(dict) => setup_dictionary_attack(&mut pool, dict, &config)?,
args::SubCommand::Creds(creds) => setup_credential_confirmation(&mut pool, creds, &config)?,
args::SubCommand::Oneshot(oneshot) => return run_oneshot(oneshot, config),
args::SubCommand::Fsck(fsck) => return fsck::run_fsck(&fsck),
};

Expand Down