Skip to content

Instantly share code, notes, and snippets.

@wITTus
Last active May 5, 2017 11:06
Show Gist options
  • Save wITTus/5cb09bb324db99d02436c0267a26d4b3 to your computer and use it in GitHub Desktop.
Save wITTus/5cb09bb324db99d02436c0267a26d4b3 to your computer and use it in GitHub Desktop.
Concurrent search of MD5-hashed IP through the entire IPv4 space in Rust
// [dependencies]
// rust-crypto = "0.2.36"
extern crate crypto;
use std::thread;
use crypto::md5::Md5;
use crypto::digest::Digest;
use std::process;
fn main() {
let wanted = "f0fdb4c3f58e3e3f"; // <- Modify me
let n_threads = 8; // <- Modify me
let mut threads = Vec::new();
for i in 0..n_threads {
let bs = 256/n_threads;
threads.push(thread::spawn(move || {
let start = bs*i;
for ii in 0..bs {
for j in 0..256 {
println!("{}{}.{}.", "\t".repeat(i), ii+start, j);
for k in 0..256 {
for l in 0..256 {
let ip = format!("{}.{}.{}.{}", ii+start, j, k, l);
let mut md5 = Md5::new();
md5.input_str(&ip);
let result = md5.result_str();
if result.as_str().starts_with(wanted) {
println!("MATCH! Hash: {} IP: {}", result, ip);
process::exit(0);
}
}
}
}
}
}));
}
for t in threads {
match t.join() {
_ => {}
};
}
}
@daniel-e
Copy link

daniel-e commented May 2, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment