mirror of
https://github.com/nelsbrock/fingerprunk.git
synced 2026-08-15 00:16:47 +02:00
Compare commits
7
Commits
561a4d220b
...
0.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
890d8fa0be
|
||
|
|
112a6b087b
|
||
|
|
fe984f2e43
|
||
|
|
b1450070d1
|
||
|
|
241fecd8a7
|
||
|
|
273c1059a2
|
||
|
|
1f659c33a7
|
Generated
+499
-391
File diff suppressed because it is too large
Load Diff
+6
-5
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fingerprunk"
|
name = "fingerprunk"
|
||||||
version = "0.1.0"
|
version = "0.2.2"
|
||||||
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"
|
||||||
@@ -10,10 +10,11 @@ keywords = ["fingerprint", "openpgp", "bruteforce"]
|
|||||||
categories = ["command-line-utilities"]
|
categories = ["command-line-utilities"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.100"
|
anyhow = "1.0.102"
|
||||||
clap = { version = "4.5.50", features = ["derive"] }
|
clap = { version = "4.6.0", features = ["derive"] }
|
||||||
fancy-regex = "0.16.2"
|
ctrlc = "3.5.2"
|
||||||
|
fancy-regex = "0.17.0"
|
||||||
num-integer = "0.1.46"
|
num-integer = "0.1.46"
|
||||||
num_cpus = "1.17.0"
|
num_cpus = "1.17.0"
|
||||||
rpassword = "7.4.0"
|
rpassword = "7.4.0"
|
||||||
sequoia-openpgp = "2.0.0"
|
sequoia-openpgp = "2.2.0"
|
||||||
|
|||||||
@@ -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.
|
||||||
+48
-46
@@ -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::sync_channel(16);
|
||||||
|
|
||||||
|
{
|
||||||
|
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::SyncSender<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,9 +143,9 @@ 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
|
// The channel might already be closed here if we're stopping.
|
||||||
.send(Key::V4(key))
|
// That is fine, so we just ignore the error.
|
||||||
.expect("should be able to send key");
|
let _ = sender.send(Message::Key(Key::V4(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
@@ -89,7 +89,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
password,
|
password,
|
||||||
};
|
};
|
||||||
|
|
||||||
Fingerprunk::new_from_config(config).run();
|
Fingerprunk::new_from_config(config).run()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user