Skip to content

Instantly share code, notes, and snippets.

@ahsanzizan
Created March 8, 2024 07:34
Show Gist options
  • Save ahsanzizan/88bffc2864d818efa4ee125d79bc10f0 to your computer and use it in GitHub Desktop.
Save ahsanzizan/88bffc2864d818efa4ee125d79bc10f0 to your computer and use it in GitHub Desktop.
An MD5 brute-forcer using Rust
extern crate crypto;
use crypto::digest::Digest;
use crypto::md5::Md5;
fn brute_force(hash: &str, charset: &str, max_length: usize) {
for length in 1..=max_length {
let mut attempt = vec![0; length];
loop {
let guess: String = attempt
.iter()
.map(|&c| charset.chars().nth(c).unwrap())
.collect();
if md5(&guess) == hash {
println!("Found match: {}", guess);
return;
}
if !increment(&mut attempt, charset.len()) {
break;
}
}
}
}
fn md5(input: &str) -> String {
let mut hasher = Md5::new();
hasher.input_str(input);
hasher.result_str()
}
fn increment(attempt: &mut Vec<usize>, length: usize) -> bool {
for i in attempt.iter_mut().rev() {
if *i < length - 1 {
*i += 1;
return true;
}
*i = 0;
}
false
}
fn main() {
let hash = "YOUR_MD5_HASH"; // The MD5 hash
let charset = "abcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*(){}[]',./?~`\""; // Possible chars
let max_length = 20; // max length of the md5
brute_force(hash, charset, max_length);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment