Created
June 18, 2022 06:43
-
-
Save whokilleddb/4d7d7c35bd0912828cdd0badd8e388ee to your computer and use it in GitHub Desktop.
DuckThatSha1 - A simple SHA1 cracker in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[package] | |
name = "sha1_cracker" | |
version = "0.1.0" | |
edition = "2021" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
clap = "3.2.5" | |
termion = "1.5.6" | |
sha-1 = "0.10.0" | |
hex = "0.4.3" | |
ctrlc = "3.2.1" | |
rand = "0.8.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use termion::color; | |
use clap::{Arg, App}; | |
use std::{ | |
fs, | |
error::Error | |
}; | |
use ctrlc; | |
use std::process; | |
use rand::Rng; | |
use sha1::Digest; | |
fn main() -> Result<(), Box<dyn Error>>{ | |
// Handle CTRL-C | |
ctrlc::set_handler(move || { | |
println!("\n{}🫤 Received Ctrl+C!{}",color::Fg(color::Red), color::Fg(color::Reset)); | |
process::exit(0); | |
}).expect("[-] Error setting Ctrl-C handler"); | |
// Set constants | |
const SHA1_HEX_STRING_LENGTH: usize = 40; | |
// Create APP | |
let app = App::new("DuckThatSHA1") | |
.version("0.0.1") | |
.about("Get Rusty and Duck that SHA1 hash") | |
.author("@whokilleddb") | |
.arg(Arg::new("wordlist") | |
.short('w') | |
.help("Wordlist to use") | |
.takes_value(true) | |
.required(true)) | |
.arg(Arg::new("hash") | |
.takes_value(true) | |
.required(true)) | |
.get_matches(); | |
// Get Wordlist | |
let wordlist = app.value_of("wordlist").unwrap(); | |
println!("🗒️Wordlist: {}{}{}", | |
color::Fg(color::Cyan), | |
wordlist, | |
color::Fg(color::Reset) | |
); | |
// Get SHA1 Hash | |
let hash_value: String = match app.get_one::<String>("hash"){ | |
Some(id) => id.trim().to_lowercase(), | |
None => { | |
return Err("Need Hash".into()); | |
} | |
}; | |
let sha1_hash: &str = hash_value.as_str(); | |
// Check if hash has correct length | |
if sha1_hash.len() != SHA1_HEX_STRING_LENGTH { | |
return Err("Invalid Hash Length :(".into()); | |
} | |
println!("🔒Hash: {}{}{}", | |
color::Fg(color::Green), | |
sha1_hash, | |
color::Fg(color::Reset) | |
); | |
// Read Wordlist | |
let list = fs::read_to_string(wordlist)?; | |
let mut cnt = 0; | |
for _ in list.lines() { | |
cnt = cnt + 1; | |
} | |
println!("🧮Number of words: {}{}{}", | |
color::Fg(color::Magenta), | |
cnt, | |
color::Fg(color::Reset) | |
); | |
print!("🏃Trying "); | |
let mut rng = rand::thread_rng(); | |
// Try cracking hash | |
for line in list.lines() { | |
print!("{}.", color::Fg(color::Rgb( | |
rng.gen::<u8>(), | |
rng.gen::<u8>(), | |
rng.gen::<u8>() | |
) | |
) | |
); | |
if sha1_hash == &hex::encode(sha1::Sha1::digest(line.trim().as_bytes())) { | |
println!("{}Found it!", color::Fg(color::Reset)); | |
println!("🔑 Key: {}{}{}", | |
color::Fg(color::Green), | |
line.trim(), | |
color::Fg(color::Reset) | |
); | |
return Ok(()); | |
}; | |
} | |
println!("{}", color::Fg(color::Reset)); | |
println!("💔 Failed To Crack"); | |
Ok(()) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment