Created
June 19, 2024 23:17
-
-
Save IAmJSD/e55a677247a5bb5291877212169e5acc to your computer and use it in GitHub Desktop.
Allows you to mine for a specific string inside a SSH key signature
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 ssh_key::{ | |
private::{KeypairData, RsaKeypair}, rand_core::OsRng, | |
LineEnding, PrivateKey, | |
}; | |
use std::{env, path::Path, process, thread}; | |
fn thread_worker(filter: &str) { | |
loop { | |
// Generate a SSH key pair. | |
let key_data = KeypairData::from(RsaKeypair::random(&mut OsRng, 2048).unwrap()); | |
let key = PrivateKey::new(key_data, "").unwrap(); | |
// Get the public key fingerprint. | |
let fingerprint = key.fingerprint(Default::default()).to_string()[7..].to_string(); | |
// Check if the fingerprint contains the filter. | |
if fingerprint.contains(filter) { | |
// Write the public and private key. | |
let filename_replace = fingerprint.replace(":", "").replace("/", ""); | |
let priv_filename = format!("{}.key", filename_replace); | |
key.write_openssh_file( | |
Path::new(&priv_filename), LineEnding::LF).unwrap(); | |
let pub_filename = format!("{}.pub", filename_replace); | |
key.public_key().write_openssh_file(Path::new(&pub_filename)).unwrap(); | |
// Log that we had a match. | |
println!("Match: {}", fingerprint); | |
} | |
} | |
} | |
fn main() { | |
// Get the number of CPU cores. | |
let cpus = num_cpus::get(); | |
// Get the argument passed to the program. It is a single argument with the filter. | |
let arg = Box::leak(Box::new(match env::args().nth(1) { | |
Some(arg) => arg, | |
None => { | |
println!("Usage: {} <filter>", env::args().nth(0).unwrap()); | |
process::exit(1); | |
}, | |
})); | |
// Print the number of CPU cores. | |
println!("Number of CPU cores: {}", cpus); | |
// Start the threads. | |
for _ in 0..cpus - 1 { | |
let s = arg.as_str(); | |
thread::spawn(move || { | |
thread_worker(s); | |
}); | |
} | |
thread_worker(arg.as_str()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment