3 Commits
Author SHA1 Message Date
nelsbrock 241fecd8a7 release version 0.2.0 2025-10-25 19:32:59 +02:00
nelsbrock 273c1059a2 fix README.md 2025-10-25 19:28:58 +02:00
nelsbrock 1f659c33a7 stop gracefully on ctrl-c 2025-10-25 18:54:40 +02:00
5 changed files with 108 additions and 69 deletions
Generated
+50 -14
View File
@@ -231,9 +231,9 @@ dependencies = [
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.2.41" version = "1.2.43"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac9fe6cdbb24b6ade63616c0a0688e45bb56732262c158df3c0c4bea4ca47cb7" checksum = "739eb0f94557554b3ca9a86d2d37bebd49c5e6d0c1d2bda35ba5bdac830befc2"
dependencies = [ dependencies = [
"find-msvc-tools", "find-msvc-tools",
"shlex", "shlex",
@@ -254,6 +254,12 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cfg_aliases"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]] [[package]]
name = "chrono" name = "chrono"
version = "0.4.42" version = "0.4.42"
@@ -364,6 +370,17 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "ctrlc"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "881c5d0a13b2f1498e2306e82cbada78390e152d4b1378fb28a84f4dcd0dc4f3"
dependencies = [
"dispatch",
"nix",
"windows-sys 0.61.2",
]
[[package]] [[package]]
name = "digest" name = "digest"
version = "0.10.7" version = "0.10.7"
@@ -396,6 +413,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "dispatch"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
[[package]] [[package]]
name = "displaydoc" name = "displaydoc"
version = "0.2.5" version = "0.2.5"
@@ -469,10 +492,11 @@ checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127"
[[package]] [[package]]
name = "fingerprunk" name = "fingerprunk"
version = "0.1.0" version = "0.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"clap", "clap",
"ctrlc",
"fancy-regex", "fancy-regex",
"num-integer", "num-integer",
"num_cpus", "num_cpus",
@@ -488,9 +512,9 @@ checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.1.4" version = "1.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc5a4e564e38c699f2880d3fda590bedc2e69f3f84cd48b457bd892ce61d0aa9" checksum = "bfe33edd8e85a12a67454e37f8c75e730830d83e313556ab9ebf9ee7fbeb3bfb"
dependencies = [ dependencies = [
"crc32fast", "crc32fast",
"miniz_oxide", "miniz_oxide",
@@ -508,9 +532,9 @@ dependencies = [
[[package]] [[package]]
name = "generic-array" name = "generic-array"
version = "1.3.4" version = "1.3.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "985a5578ebdb02351d484a77fb27e7cb79272f1ba9bc24692d8243c3cfe40660" checksum = "eaf57c49a95fd1fe24b90b3033bee6dc7e8f1288d51494cb44e627c295e38542"
dependencies = [ dependencies = [
"rustversion", "rustversion",
"typenum", "typenum",
@@ -884,6 +908,18 @@ version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086"
[[package]]
name = "nix"
version = "0.30.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74523f3a35e05aba87a1d978330aef40f67b0304ac79c1c00b294c9830543db6"
dependencies = [
"bitflags",
"cfg-if",
"cfg_aliases",
"libc",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.3" version = "7.1.3"
@@ -1010,9 +1046,9 @@ checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.101" version = "1.0.103"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" checksum = "5ee95bc4ef87b8d5ba32e8b7714ccc834865276eab0aed5c9958d00ec45f49e8"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@@ -1212,7 +1248,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f606421e4a6012877e893c399822a4ed4b089164c5969424e1b9d1e66e6964b" checksum = "1f606421e4a6012877e893c399822a4ed4b089164c5969424e1b9d1e66e6964b"
dependencies = [ dependencies = [
"digest", "digest",
"generic-array 1.3.4", "generic-array 1.3.5",
] ]
[[package]] [[package]]
@@ -1271,9 +1307,9 @@ checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
[[package]] [[package]]
name = "syn" name = "syn"
version = "2.0.107" version = "2.0.108"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a26dbd934e5451d21ef060c018dae56fc073894c5a7896f882928a76e6d081b" checksum = "da58917d35242480a05c2897064da0a80589a2a0476c9a3f2fdc83b53502e917"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1382,9 +1418,9 @@ checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
[[package]] [[package]]
name = "unicode-ident" name = "unicode-ident"
version = "1.0.19" version = "1.0.20"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f63a545481291138910575129486daeaf8ac54aee4387fe7906919f7830c7d9d" checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06"
[[package]] [[package]]
name = "unicode-xid" name = "unicode-xid"
+2 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "fingerprunk" name = "fingerprunk"
version = "0.1.0" version = "0.2.0"
authors = ["Niklas Elsbrock <mail@nelsbrock.de>"] authors = ["Niklas Elsbrock <mail@nelsbrock.de>"]
edition = "2024" edition = "2024"
description = "CLI tool for brute-forcing OpenPGP keys with cool fingerprints" description = "CLI tool for brute-forcing OpenPGP keys with cool fingerprints"
@@ -12,6 +12,7 @@ categories = ["command-line-utilities"]
[dependencies] [dependencies]
anyhow = "1.0.100" anyhow = "1.0.100"
clap = { version = "4.5.50", features = ["derive"] } clap = { version = "4.5.50", features = ["derive"] }
ctrlc = "3.5.0"
fancy-regex = "0.16.2" fancy-regex = "0.16.2"
num-integer = "0.1.46" num-integer = "0.1.46"
num_cpus = "1.17.0" num_cpus = "1.17.0"
+8 -8
View File
@@ -51,7 +51,7 @@ Also see <https://en.wikipedia.org/wiki/Hexspeak> for some further examples of "
### How long does it take? ### How long does it take?
On my machine with an AMD Ryzen 7 5800X processor, Fingerprunk is able to generate and check about On my machine with an AMD Ryzen 7 5800X processor, Fingerprunk is able to generate and check about
41000 keys per second. This means that for finding a fingerprint with a string of *n* specific 43500 keys per second. This means that for finding a fingerprint with a string of *n* specific
hexadecimal digits at a specific place, I could expect the following runtimes until finding the hexadecimal digits at a specific place, I could expect the following runtimes until finding the
first key: first key:
@@ -60,15 +60,15 @@ first key:
| 1 | 16 = 16¹ | < 0.1 secs | | 1 | 16 = 16¹ | < 0.1 secs |
| 2 | 256 = 16² | < 0.1 secs | | 2 | 256 = 16² | < 0.1 secs |
| 3 | 4096 = 16³ | 0.1 secs | | 3 | 4096 = 16³ | 0.1 secs |
| 4 | 65536 = 16⁴ | 1.6 secs | | 4 | 65536 = 16⁴ | 1.5 secs |
| 5 | 1048576 = 16⁵ | 26 secs | | 5 | 1048576 = 16⁵ | 24 secs |
| 6 | 16777216 = 16⁶ | 7 mins | | 6 | 16777216 = 16⁶ | 6 mins |
| 7 | 268435456 = 16⁷ | 2 hours | | 7 | 268435456 = 16⁷ | 2 hours |
| 8 | 4294967296 = 16⁸ | 1 days | | 8 | 4294967296 = 16⁸ | 1 days |
| 9 | 68719476736 = 16⁹ | 19 days | | 9 | 68719476736 = 16⁹ | 18 days |
| 10 | 1099511627776 = 16¹⁰ | 310 days | | 10 | 1099511627776 = 16¹⁰ | 293 days |
| 11 | 17592186044416 = 16¹¹ | 14 years | | 11 | 17592186044416 = 16¹¹ | 13 years |
| 12 | 281474976710656 = 16¹² | 218 years | | 12 | 281474976710656 = 16¹² | 205 years |
As you can see, anything above 10 fixed digits is pretty much unfeasible, at least with a normal As you can see, anything above 10 fixed digits is pretty much unfeasible, at least with a normal
personal computer. personal computer.
+47 -45
View File
@@ -28,6 +28,12 @@ use sequoia_openpgp::{
type SecretKey = Key<SecretParts, PrimaryRole>; type SecretKey = Key<SecretParts, PrimaryRole>;
#[allow(clippy::large_enum_variant)]
enum Message {
Key(SecretKey),
Stop,
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Config { pub struct Config {
pub regex: Regex, pub regex: Regex,
@@ -63,54 +69,71 @@ impl Fingerprunk {
} }
} }
pub fn run(mut self) { pub fn run(mut self) -> anyhow::Result<()> {
self.started_instant = Instant::now(); self.started_instant = Instant::now();
let (tx, rx) = mpsc::channel(); let (sender, receiver) = mpsc::channel();
{
let sender = sender.clone();
ctrlc::set_handler(move || {
let _ = sender.send(Message::Stop);
})?;
}
thread::scope(|scope| { thread::scope(|scope| {
const THREAD_SPAWN_EXPECT_MSG: &str = "should be able to spawn thread";
let ref_self = &self; let ref_self = &self;
let status_displayer = if self.config.status_enabled { let status_displayer = if self.config.status_enabled {
Some( Some(
thread::Builder::new() thread::Builder::new()
.name("status_displayer".to_string()) .name("status_displayer".to_string())
.spawn_scoped(scope, move || ref_self.status_displayer_thread()) .spawn_scoped(scope, move || ref_self.status_displayer_thread())?,
.expect(THREAD_SPAWN_EXPECT_MSG),
) )
} else { } else {
None None
}; };
for num in 0..num_cpus::get() { for num in 0..num_cpus::get() {
let tx = tx.clone(); let sender = sender.clone();
thread::Builder::new() thread::Builder::new()
.name(format!("worker-{num:03}")) .name(format!("worker-{num:03}"))
.spawn_scoped(scope, move || ref_self.worker_thread(tx)) .spawn_scoped(scope, move || ref_self.worker_thread(sender))?;
.expect(THREAD_SPAWN_EXPECT_MSG);
} }
let on_stop = || { let mut stdout = io::stdout().lock();
// Ask all other threads to stop
self.stop.store(true, Ordering::Relaxed);
// Unpark the status displayer thread // Receive and process messages from the workers and the ctrl-c handler
if let Some(status_displayer) = status_displayer { for message in receiver {
status_displayer.thread().unpark(); match message {
Message::Key(key) => {
let cert = self.key_to_cert(&key)?;
self.serialize_cert(cert, &mut stdout)?;
// Increase "found" counter and stop if enough matches have been found
let prev = self.counter_found.fetch_add(1, Ordering::Relaxed);
if self.config.stop_after.is_some_and(|s| prev + 1 == s.get()) {
break;
}
}
Message::Stop => break,
} }
}; }
thread::Builder::new() // Ask all other threads to stop
.name("finalizer".to_string()) self.stop.store(true, Ordering::Relaxed);
.spawn_scoped(scope, move || ref_self.finalizer_thread(rx, on_stop))
.expect(THREAD_SPAWN_EXPECT_MSG); // Unpark the status displayer thread, if existant
}); if let Some(status_displayer) = status_displayer {
status_displayer.thread().unpark();
}
Ok(())
})
} }
fn worker_thread(&self, matches_tx: mpsc::Sender<SecretKey>) { fn worker_thread(&self, sender: mpsc::Sender<Message>) {
let mut fingerprint_hex = String::with_capacity(20 * 2); let mut fingerprint_hex = String::with_capacity(20 * 2);
while !self.stop.load(Ordering::Relaxed) { while !self.stop.load(Ordering::Relaxed) {
@@ -120,8 +143,8 @@ impl Fingerprunk {
write!(fingerprint_hex, "{:X}", key.fingerprint()) write!(fingerprint_hex, "{:X}", key.fingerprint())
.expect("should write into string without error"); .expect("should write into string without error");
if self.check_fingerprint(&fingerprint_hex) { if self.check_fingerprint(&fingerprint_hex) {
matches_tx sender
.send(Key::V4(key)) .send(Message::Key(Key::V4(key)))
.expect("should be able to send key"); .expect("should be able to send key");
} }
self.counter_tried.fetch_add(1, Ordering::Relaxed); self.counter_tried.fetch_add(1, Ordering::Relaxed);
@@ -136,27 +159,6 @@ impl Fingerprunk {
.expect("should check regex without error") .expect("should check regex without error")
} }
fn finalizer_thread(&self, matches_rx: mpsc::Receiver<SecretKey>, on_stop: impl FnOnce()) {
let mut stdout = io::stdout().lock();
for key in matches_rx {
let cert = self
.key_to_cert(&key)
.expect("should be able to create certificate");
self.serialize_cert(cert, &mut stdout)
.expect("should be able to serialize certificate");
let prev = self.counter_found.fetch_add(1, Ordering::Relaxed);
if self.config.stop_after.is_some_and(|s| prev + 1 == s.get()) {
break;
}
}
on_stop();
}
fn key_to_cert(&self, key: &SecretKey) -> anyhow::Result<Cert> { fn key_to_cert(&self, key: &SecretKey) -> anyhow::Result<Cert> {
let sig = SignatureBuilder::new(SignatureType::DirectKey) let sig = SignatureBuilder::new(SignatureType::DirectKey)
.set_hash_algo(HashAlgorithm::SHA512) .set_hash_algo(HashAlgorithm::SHA512)
+1 -1
View File
@@ -89,7 +89,7 @@ fn main() -> anyhow::Result<()> {
password, password,
}; };
Fingerprunk::new_from_config(config).run(); Fingerprunk::new_from_config(config).run()?;
Ok(()) Ok(())
} }