-
Notifications
You must be signed in to change notification settings - Fork 3
/
vanitygpg.pl
124 lines (91 loc) · 3.15 KB
/
vanitygpg.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#! /usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use threads;
use threads::shared;
use Time::HiRes qw(usleep nanosleep gettimeofday);
use Data::Dumper;
use POSIX;
my ($thread_count, $stop, @threads, $started_at, @needles);
$stop = 0;
$thread_count=48;
$started_at = gettimeofday();
my ($key_len, $key_name, $key_pass, $key_email, @status, $keycount, $matchstring) :shared;
$key_len=2048;
$key_name='user';
$key_pass='pass';
$key_email='[email protected]';
$keycount=0;
#add your desired key matches in this array, they will all be applied to each key, when a matching key for ANY is found, hashing will stop.
@needles = ( '.*?(.)(?:(.*?\1.*?){6,})',
'^B17CE0',
'^6666'
);
#assemble regex into single match
$matchstring = '(?:'.join('|', @needles).')';
print "Matching against regex string: $matchstring\n";
until ($stop) {
# thread
my $num = 0;
for (my $tc=1; $tc<=$thread_count; $tc++){
my $t = threads->new(\&keyThread, $tc);
push (@threads, $t);
print "Spawned $tc threads\n";
}
my $loopy = 0;
until ($stop){
for (my $tr=1; $tr<=$thread_count; $tr++){
#print "Thread $tr status: @status[$tr]\n";
if (@status[$tr] eq 'found'){
print "------ FOUND A KEY!!!!!!! ------\n\n\n";
exit();
}
}
$loopy++;
if ($loopy%10==0){
print "Found $keycount keys so far, running for " . sprintf("%.1f",(gettimeofday()-$started_at))."s (Rate:" . sprintf("%.1f",$keycount/(gettimeofday()-$started_at)) ."/s)\n";
}
for ("1".."1000"){
#dat entropy
rand(10000000);
}
usleep(500000);
}
}
sub keyThread{
my $number = shift;
my $tid = threads->tid();
print "Thread $tid started, using key_scratch $number for this key ID\n";
my $KEYRING_OPTS = "--no-default-keyring --secret-keyring ./foo$number.sec --keyring ./foo$number.pub" ;
until ($stop){
@status[$number]='running';
# Generate a key
my $quiet = `bash keybatchgen.sh $number $key_len $key_name $key_pass $key_email 2>&1`;
$keycount++;
# Get the key short ID
my $short_id = `gpg $KEYRING_OPTS --list-secret-keys | grep 'sec ' | cut -d ' ' -f 4`;
my $long_id = `gpg $KEYRING_OPTS --keyid-format LONG --list-secret-keys | grep 'sec ' | cut -d ' ' -f 4`;
# Cut the key_length part
my $cut = $key_len . 'R\/';
$short_id =~ s/$cut//;
$long_id =~ s/$cut//;
chomp $short_id;
chomp $long_id;
my @matches;
# Print it
print "Found S:$short_id, L:$long_id\n";
# Only export if it match a pattern
if (@matches = ($long_id =~ m/$matchstring/o)){
@status[$number]='found';
print Dumper(@matches);
print "Export $short_id\n";
# Create the filename
my $base_name = '0x' . $long_id;
# export it
`gpg $KEYRING_OPTS --output $base_name.pub.gpg --armor --export $short_id`;
`gpg $KEYRING_OPTS --output $base_name.sec.gpg --armor --export-secret-key $short_id`;
threads->exit();
}
}
}