mirror of
https://github.com/nelsbrock/fingerprunk.git
synced 2026-10-13 21:29:34 +02:00
Compare commits
13
Commits
0.3.0
..
bf246ea88d
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bf246ea88d
|
||
|
|
19ddf681e1
|
||
|
|
b1cab3c4fe
|
||
|
|
c22d4bdb27
|
||
|
|
3439e51865
|
||
|
|
a07aaca068
|
||
|
|
20c0a919c5
|
||
|
|
3ea0de1cdb
|
||
|
|
9f992caef9
|
||
|
|
c8bedabe1f
|
||
|
|
e8b83d41cb
|
||
|
|
6af66fd292
|
||
|
|
bc07cba585
|
No files matched your search
Generated
+244
-546
File diff suppressed because it is too large.
Load diff
+3
-4
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fingerprunk"
|
name = "fingerprunk"
|
||||||
version = "0.3.0"
|
version = "0.4.1"
|
||||||
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"
|
||||||
@@ -13,8 +13,7 @@ categories = ["command-line-utilities"]
|
|||||||
anyhow = "1.0.102"
|
anyhow = "1.0.102"
|
||||||
clap = { version = "4.6.1", features = ["derive"] }
|
clap = { version = "4.6.1", features = ["derive"] }
|
||||||
ctrlc = "3.5.2"
|
ctrlc = "3.5.2"
|
||||||
fancy-regex = "0.18.0"
|
fancy-regex = "0.19.2"
|
||||||
num-integer = "0.1.46"
|
num-integer = "0.1.46"
|
||||||
num_cpus = "1.17.0"
|
|
||||||
rpassword = "7.5.2"
|
rpassword = "7.5.2"
|
||||||
sequoia-openpgp = "2.2.0"
|
sequoia-openpgp = "2.3.0"
|
||||||
+12
-16
@@ -3,7 +3,7 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Write},
|
fmt::{self, Write},
|
||||||
io,
|
io,
|
||||||
num::NonZeroU64,
|
num::NonZero,
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, AtomicU64, Ordering},
|
atomic::{AtomicBool, AtomicU64, Ordering},
|
||||||
mpsc,
|
mpsc,
|
||||||
@@ -38,9 +38,10 @@ enum Message {
|
|||||||
pub struct Config {
|
pub struct Config {
|
||||||
pub regex: Regex,
|
pub regex: Regex,
|
||||||
pub status_enabled: bool,
|
pub status_enabled: bool,
|
||||||
pub stop_after: Option<NonZeroU64>,
|
pub count: Option<NonZero<u64>>,
|
||||||
pub password: Option<Password>,
|
pub password: Option<Password>,
|
||||||
pub userids: Vec<UserID>,
|
pub userids: Vec<UserID>,
|
||||||
|
pub workers: NonZero<usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -83,24 +84,20 @@ impl Fingerprunk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
thread::scope(|scope| {
|
thread::scope(|scope| {
|
||||||
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, || self.status_displayer_thread())?,
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
for num in 0..num_cpus::get() {
|
for num in 0..self.config.workers.get() {
|
||||||
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(sender))?;
|
.spawn_scoped(scope, || self.worker_thread(&sender))?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut stdout = io::stdout().lock();
|
let mut stdout = io::stdout().lock();
|
||||||
@@ -109,12 +106,12 @@ impl Fingerprunk {
|
|||||||
for message in receiver {
|
for message in receiver {
|
||||||
match message {
|
match message {
|
||||||
Message::Key(key) => {
|
Message::Key(key) => {
|
||||||
let cert = self.key_to_cert(&key)?;
|
let cert = self.key_to_cert(key)?;
|
||||||
self.serialize_cert(cert, &mut stdout)?;
|
self.serialize_cert(&cert, &mut stdout)?;
|
||||||
|
|
||||||
// Increase "found" counter and stop if enough matches have been found
|
// Increase "found" counter and stop if enough matches have been found
|
||||||
let prev = self.counter_found.fetch_add(1, Ordering::Relaxed);
|
let prev = self.counter_found.fetch_add(1, Ordering::Relaxed);
|
||||||
if self.config.stop_after.is_some_and(|s| prev + 1 == s.get()) {
|
if self.config.count.is_some_and(|s| prev + 1 == s.get()) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +131,7 @@ impl Fingerprunk {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn worker_thread(&self, sender: mpsc::SyncSender<Message>) {
|
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) {
|
||||||
@@ -160,7 +157,7 @@ impl Fingerprunk {
|
|||||||
.expect("should check regex without error")
|
.expect("should check regex without error")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn key_to_cert(&self, key: &SecretKey) -> anyhow::Result<Cert> {
|
fn key_to_cert(&self, mut key: SecretKey) -> anyhow::Result<Cert> {
|
||||||
let creation_time = SystemTime::now();
|
let creation_time = SystemTime::now();
|
||||||
|
|
||||||
let mut signer = key
|
let mut signer = key
|
||||||
@@ -174,7 +171,6 @@ impl Fingerprunk {
|
|||||||
|
|
||||||
// Create certificate
|
// Create certificate
|
||||||
let mut cert = Cert::try_from(Packet::SecretKey({
|
let mut cert = Cert::try_from(Packet::SecretKey({
|
||||||
let mut key = key.clone();
|
|
||||||
if let Some(ref password) = self.config.password {
|
if let Some(ref password) = self.config.password {
|
||||||
let (k, mut secret) = key.take_secret();
|
let (k, mut secret) = key.take_secret();
|
||||||
secret.encrypt_in_place(&k, password)?;
|
secret.encrypt_in_place(&k, password)?;
|
||||||
@@ -204,7 +200,7 @@ impl Fingerprunk {
|
|||||||
Ok(cert)
|
Ok(cert)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn serialize_cert(&self, cert: Cert, to: impl io::Write) -> anyhow::Result<()> {
|
fn serialize_cert(&self, cert: &Cert, to: impl io::Write) -> anyhow::Result<()> {
|
||||||
let mut comments = cert.armor_headers();
|
let mut comments = cert.armor_headers();
|
||||||
comments.push(format!(
|
comments.push(format!(
|
||||||
"Generated with Fingerprunk. Regex: {}",
|
"Generated with Fingerprunk. Regex: {}",
|
||||||
|
|||||||
+30
-15
@@ -1,9 +1,9 @@
|
|||||||
use std::{
|
use std::{
|
||||||
io::{self, IsTerminal},
|
io::{self, IsTerminal},
|
||||||
num::NonZeroU64,
|
num::NonZero,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::{Context as AnyhowContext, anyhow};
|
use anyhow::{Context, anyhow};
|
||||||
use clap::{ArgAction, Parser, ValueEnum};
|
use clap::{ArgAction, Parser, ValueEnum};
|
||||||
use fancy_regex::Regex;
|
use fancy_regex::Regex;
|
||||||
use fingerprunk::Fingerprunk;
|
use fingerprunk::Fingerprunk;
|
||||||
@@ -14,8 +14,8 @@ use sequoia_openpgp::packet::UserID;
|
|||||||
struct Args {
|
struct Args {
|
||||||
/// Filter key fingerprints by using a regular expression.
|
/// Filter key fingerprints by using a regular expression.
|
||||||
///
|
///
|
||||||
/// This regex is matched against the hexadecimal representation of the fingerprint, without
|
/// This regex is matched against the upper-case hexadecimal representation of the fingerprint,
|
||||||
/// spaces or other additional symbols.
|
/// without spaces or other additional symbols.
|
||||||
///
|
///
|
||||||
/// This is implemented using the fancy-regex library: <https://crates.io/crates/fancy-regex>.
|
/// This is implemented using the fancy-regex library: <https://crates.io/crates/fancy-regex>.
|
||||||
/// You can test and debug your regex here: <https://fancy-regex.github.io/fancy-regex/>.
|
/// You can test and debug your regex here: <https://fancy-regex.github.io/fancy-regex/>.
|
||||||
@@ -27,12 +27,12 @@ struct Args {
|
|||||||
/// By default, status information is only shown if stderr is bound to a terminal and stdout is
|
/// By default, status information is only shown if stderr is bound to a terminal and stdout is
|
||||||
/// *not* bound to a terminal. The latter in particular prevents found keys (which are printed
|
/// *not* bound to a terminal. The latter in particular prevents found keys (which are printed
|
||||||
/// to stdin) from being "overwritten" by status information printed to stderr.
|
/// to stdin) from being "overwritten" by status information printed to stderr.
|
||||||
#[arg(long, value_enum, default_value_t)]
|
#[arg(long, value_enum, value_name = "WHEN", default_value_t)]
|
||||||
status: StatusEnabled,
|
status: StatusEnabled,
|
||||||
|
|
||||||
/// Stop once the specified number of matching keys has been found.
|
/// Stop once the specified number of matching keys has been found.
|
||||||
#[arg(long)]
|
#[arg(short = 'n', long, value_name = "NUM")]
|
||||||
stop_after: Option<NonZeroU64>,
|
count: Option<NonZero<u64>>,
|
||||||
|
|
||||||
/// Prompt for a password and use it to encrypt matching keys.
|
/// Prompt for a password and use it to encrypt matching keys.
|
||||||
///
|
///
|
||||||
@@ -50,6 +50,13 @@ struct Args {
|
|||||||
/// Disables the warning about importing keys without user IDs into GnuPG.
|
/// Disables the warning about importing keys without user IDs into GnuPG.
|
||||||
#[arg(long, conflicts_with = "userid", action = ArgAction::SetTrue)]
|
#[arg(long, conflicts_with = "userid", action = ArgAction::SetTrue)]
|
||||||
no_userid: bool,
|
no_userid: bool,
|
||||||
|
|
||||||
|
/// Use the specified amount of worker threads.
|
||||||
|
///
|
||||||
|
/// If not specified, the amount of worker threads will be set to the amount of the machine's
|
||||||
|
/// available parallelism.
|
||||||
|
#[arg(long, value_name = "NUM")]
|
||||||
|
workers: Option<NonZero<usize>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(ValueEnum, Clone, Copy, Debug, Default)]
|
#[derive(ValueEnum, Clone, Copy, Debug, Default)]
|
||||||
@@ -73,24 +80,33 @@ impl StatusEnabled {
|
|||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
|
let workers = match args.workers {
|
||||||
|
Some(workers) => workers,
|
||||||
|
None => std::thread::available_parallelism().context(
|
||||||
|
"unable to determine available parallelism, \
|
||||||
|
use `--workers <NUM>` to specify amount of worker threads",
|
||||||
|
)?,
|
||||||
|
};
|
||||||
|
|
||||||
if !args.no_userid && args.userid.is_empty() {
|
if !args.no_userid && args.userid.is_empty() {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"WARNING: No user ID was provided.\n\
|
"WARNING: No user ID was provided.\n\
|
||||||
You may experience problems importing generated keys into GnuPG.\n\
|
You may experience problems importing generated keys into GnuPG.\n\
|
||||||
Use the --userid option to add a user ID.\n"
|
Use `--userid <USERID>` to add a user ID.\n"
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let password = if args.password {
|
let password = if args.password {
|
||||||
let password = rpassword::prompt_password(
|
let password = rpassword::prompt_password(
|
||||||
"Enter password for encrypting found keys (leave empty for no encryption): ",
|
"Enter password for encrypting found keys (leave empty for no encryption): ",
|
||||||
)
|
)
|
||||||
.with_context(|| "Failed to prompt password")?;
|
.context("Failed to prompt password")?;
|
||||||
|
|
||||||
if password.is_empty() {
|
if password.is_empty() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let password_retype = rpassword::prompt_password("Retype password: ")
|
let password_retype = rpassword::prompt_password("Retype password: ")
|
||||||
.with_context(|| "Failed to prompt password retype")?;
|
.context("Failed to prompt password retype")?;
|
||||||
if password_retype == password {
|
if password_retype == password {
|
||||||
Some(password.into())
|
Some(password.into())
|
||||||
} else {
|
} else {
|
||||||
@@ -104,12 +120,11 @@ fn main() -> anyhow::Result<()> {
|
|||||||
let config = fingerprunk::Config {
|
let config = fingerprunk::Config {
|
||||||
regex: args.regex,
|
regex: args.regex,
|
||||||
status_enabled: args.status.evaluate(),
|
status_enabled: args.status.evaluate(),
|
||||||
stop_after: args.stop_after,
|
count: args.count,
|
||||||
password,
|
password,
|
||||||
userids: args.userid,
|
userids: args.userid,
|
||||||
|
workers,
|
||||||
};
|
};
|
||||||
|
|
||||||
Fingerprunk::new_from_config(config).run()?;
|
Fingerprunk::new_from_config(config).run()
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user