2018-12-20 17:03:48 +00:00
|
|
|
#!/usr/bin/env perl
|
|
|
|
|
|
|
|
##
|
|
|
|
## Author......: See docs/credits.txt
|
|
|
|
## License.....: MIT
|
|
|
|
##
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
use Data::Types qw (is_count is_int is_whole);
|
2018-12-20 17:03:48 +00:00
|
|
|
use File::Basename;
|
|
|
|
use FindBin;
|
2019-02-16 11:08:50 +00:00
|
|
|
use List::Util 'shuffle';
|
2018-12-20 17:03:48 +00:00
|
|
|
|
|
|
|
# allows require by filename
|
|
|
|
use lib "$FindBin::Bin/test_modules";
|
|
|
|
|
2019-03-02 15:37:01 +00:00
|
|
|
my $IS_OPTIMIZED = 1;
|
2018-12-23 17:15:53 +00:00
|
|
|
|
2019-03-08 15:05:17 +00:00
|
|
|
if (exists $ENV{"IS_OPTIMIZED"} && defined $ENV{"IS_OPTIMIZED"})
|
|
|
|
{
|
|
|
|
$IS_OPTIMIZED = $ENV{"IS_OPTIMIZED"};
|
|
|
|
}
|
|
|
|
|
2018-12-20 17:03:48 +00:00
|
|
|
my $TYPES = [ 'single', 'passthrough', 'verify' ];
|
|
|
|
|
|
|
|
my $TYPE = shift @ARGV;
|
|
|
|
my $MODE = shift @ARGV;
|
|
|
|
|
|
|
|
is_in_array ($TYPE, $TYPES) or usage_exit ();
|
|
|
|
|
|
|
|
is_whole ($MODE) or die "Mode must be a number\n";
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
my $MODULE_FILE = sprintf ("m%05d.pm", $MODE);
|
2018-12-21 08:10:23 +00:00
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
eval { require $MODULE_FILE } or die "Could not load test module: $MODULE_FILE\n$@";
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
exists &{module_constraints} or die "Module function 'module_constraints' not found\n";
|
2018-12-21 08:48:51 +00:00
|
|
|
exists &{module_generate_hash} or die "Module function 'module_generate_hash' not found\n";
|
|
|
|
exists &{module_verify_hash} or die "Module function 'module_verify_hash' not found\n";
|
|
|
|
|
2018-12-28 10:53:41 +00:00
|
|
|
my $giveup_at = 1000000;
|
2019-02-27 09:23:32 +00:00
|
|
|
my $single_outputs = 8;
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
my $constraints = get_module_constraints ();
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2018-12-20 17:03:48 +00:00
|
|
|
if ($TYPE eq 'single')
|
|
|
|
{
|
|
|
|
single (@ARGV);
|
|
|
|
}
|
|
|
|
elsif ($TYPE eq 'passthrough')
|
|
|
|
{
|
|
|
|
passthrough ();
|
|
|
|
}
|
|
|
|
elsif ($TYPE eq "verify")
|
|
|
|
{
|
|
|
|
usage_exit () if scalar @ARGV != 3;
|
|
|
|
|
|
|
|
verify (@ARGV);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usage_exit ();
|
|
|
|
}
|
|
|
|
|
|
|
|
sub single
|
|
|
|
{
|
|
|
|
my $len = shift;
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
# fallback to incrementing length
|
2018-12-20 17:03:48 +00:00
|
|
|
undef $len unless is_count ($len);
|
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
my $word_min = ($IS_OPTIMIZED == 1) ? $constraints->[2]->[0] : $constraints->[0]->[0];
|
|
|
|
my $word_max = ($IS_OPTIMIZED == 1) ? $constraints->[2]->[1] : $constraints->[0]->[1];
|
|
|
|
my $salt_min = ($IS_OPTIMIZED == 1) ? $constraints->[3]->[0] : $constraints->[1]->[0];
|
|
|
|
my $salt_max = ($IS_OPTIMIZED == 1) ? $constraints->[3]->[1] : $constraints->[1]->[1];
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
my $db_word_len = init_db_word_rand ($word_min, $word_max);
|
|
|
|
my $db_salt_len = init_db_salt_rand ($salt_min, $salt_max);
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-27 23:09:25 +00:00
|
|
|
my $db_prev;
|
|
|
|
|
2019-01-03 12:41:54 +00:00
|
|
|
my $giveup = 0;
|
2018-12-27 18:54:12 +00:00
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
my $idx = 0;
|
2018-12-21 08:48:51 +00:00
|
|
|
|
2018-12-28 10:53:41 +00:00
|
|
|
while ($idx < $single_outputs)
|
2018-12-23 17:15:53 +00:00
|
|
|
{
|
2019-01-03 12:41:54 +00:00
|
|
|
last if ($giveup++ == $giveup_at);
|
2018-12-27 18:54:12 +00:00
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
my $word_len = 0;
|
|
|
|
|
|
|
|
if (defined $len)
|
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
next if $len < $word_min;
|
|
|
|
next if $len > $word_max;
|
2018-12-23 17:15:53 +00:00
|
|
|
|
|
|
|
$word_len = $len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 12:37:15 +00:00
|
|
|
$word_len = $db_word_len->[$idx];
|
2018-12-23 17:15:53 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 18:54:12 +00:00
|
|
|
my $salt_len = 0;
|
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
if ($salt_min != -1)
|
2018-12-27 18:54:12 +00:00
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
if ($salt_min == $salt_max)
|
|
|
|
{
|
|
|
|
$salt_len = $salt_min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-16 11:08:50 +00:00
|
|
|
$salt_len = $db_salt_len->[$giveup % scalar @{$db_salt_len}];
|
2018-12-29 15:23:29 +00:00
|
|
|
}
|
2018-12-27 18:54:12 +00:00
|
|
|
}
|
|
|
|
|
2018-12-27 23:09:25 +00:00
|
|
|
# mostly important for raw hashes in optimized mode
|
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
my $comb_len = $word_len + $salt_len;
|
|
|
|
|
|
|
|
if ($IS_OPTIMIZED == 1)
|
|
|
|
{
|
|
|
|
my $comb_min = $constraints->[4]->[0];
|
|
|
|
my $comb_max = $constraints->[4]->[1];
|
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
if ($comb_min != -1)
|
2018-12-23 17:15:53 +00:00
|
|
|
{
|
|
|
|
next if $comb_len < $comb_min;
|
|
|
|
next if $comb_len > $comb_max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 15:31:36 +00:00
|
|
|
my $word = random_numeric_string ($word_len) // "";
|
|
|
|
my $salt = random_numeric_string ($salt_len) // "";
|
2018-12-23 17:15:53 +00:00
|
|
|
|
2018-12-27 18:54:12 +00:00
|
|
|
# check if this combination out of word and salt was previously checked
|
2018-12-27 23:09:25 +00:00
|
|
|
next if exists $db_prev->{$word}->{$salt};
|
2018-12-27 18:54:12 +00:00
|
|
|
|
2018-12-27 23:09:25 +00:00
|
|
|
$db_prev->{$word}->{$salt} = undef;
|
|
|
|
|
|
|
|
$idx++;
|
2019-02-16 11:08:50 +00:00
|
|
|
|
|
|
|
last if ($idx >= scalar @{$db_word_len});
|
2019-01-03 12:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for my $word (sort { length $a <=> length $b } keys %{$db_prev})
|
|
|
|
{
|
|
|
|
for my $salt (sort { length $a <=> length $b } keys %{$db_prev->{$word}})
|
|
|
|
{
|
|
|
|
my $hash = module_generate_hash ($word, $salt);
|
2018-12-27 18:54:12 +00:00
|
|
|
|
2019-01-03 12:19:36 +00:00
|
|
|
# possible if the requested length is not supported by algorithm
|
|
|
|
next unless defined $hash;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2019-01-03 12:19:36 +00:00
|
|
|
my $format = "echo %-31s | ./hashcat \${OPTS} -a 0 -m %d '%s'\n";
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2019-01-03 12:19:36 +00:00
|
|
|
printf ($format, $word, $MODE, $hash);
|
|
|
|
}
|
2018-12-20 17:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub passthrough
|
|
|
|
{
|
2018-12-21 08:48:51 +00:00
|
|
|
while (my $word = <>)
|
2018-12-20 17:03:48 +00:00
|
|
|
{
|
2018-12-21 08:48:51 +00:00
|
|
|
chomp $word;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
my $word_len = length $word;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-24 13:21:45 +00:00
|
|
|
if ($IS_OPTIMIZED == 1)
|
|
|
|
{
|
|
|
|
next if ($word_len > 31);
|
|
|
|
}
|
|
|
|
|
2018-12-27 18:54:12 +00:00
|
|
|
my $giveup = 0;
|
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
my $idx = 0;
|
|
|
|
|
|
|
|
while ($idx < 1)
|
|
|
|
{
|
2019-02-16 11:08:50 +00:00
|
|
|
last if ($giveup++ == $giveup_at);
|
2018-12-27 18:54:12 +00:00
|
|
|
|
|
|
|
my $salt_len = 0;
|
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
my $salt_min = ($IS_OPTIMIZED == 1) ? $constraints->[3]->[0] : $constraints->[1]->[0];
|
|
|
|
my $salt_max = ($IS_OPTIMIZED == 1) ? $constraints->[3]->[1] : $constraints->[1]->[1];
|
|
|
|
|
|
|
|
if ($salt_min != -1)
|
2018-12-27 18:54:12 +00:00
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
if ($salt_min == $salt_max)
|
|
|
|
{
|
|
|
|
$salt_len = $salt_min;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$salt_len = random_number ($salt_min, $salt_max);
|
|
|
|
}
|
2018-12-27 18:54:12 +00:00
|
|
|
}
|
2018-12-23 17:15:53 +00:00
|
|
|
|
|
|
|
my $comb_len = $word_len + $salt_len;
|
|
|
|
|
|
|
|
if ($IS_OPTIMIZED == 1)
|
|
|
|
{
|
|
|
|
my $comb_min = $constraints->[4]->[0];
|
|
|
|
my $comb_max = $constraints->[4]->[1];
|
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
if ($comb_min != -1)
|
2018-12-23 17:15:53 +00:00
|
|
|
{
|
|
|
|
next if $comb_len < $comb_min;
|
|
|
|
next if $comb_len > $comb_max;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-27 15:31:36 +00:00
|
|
|
my $salt = random_numeric_string ($salt_len) // "";
|
2018-12-23 17:15:53 +00:00
|
|
|
|
2018-12-28 19:50:59 +00:00
|
|
|
$idx++;
|
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
my $hash = module_generate_hash ($word, $salt);
|
|
|
|
|
|
|
|
next unless defined $hash;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
print "$hash\n";
|
|
|
|
}
|
2018-12-20 17:03:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub verify
|
|
|
|
{
|
|
|
|
my $hashes_file = shift;
|
|
|
|
my $cracks_file = shift;
|
|
|
|
my $out_file = shift;
|
|
|
|
|
|
|
|
open (IN, '<', $hashes_file) or die "$hashes_file: $!\n";
|
|
|
|
|
2018-12-22 18:29:24 +00:00
|
|
|
my @hashlist;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-21 08:48:51 +00:00
|
|
|
while (my $line = <IN>)
|
2018-12-20 17:03:48 +00:00
|
|
|
{
|
2018-12-21 08:48:51 +00:00
|
|
|
$line =~ s/\n$//;
|
|
|
|
$line =~ s/\r$//;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-22 18:29:24 +00:00
|
|
|
push (@hashlist, $line);
|
2018-12-20 17:03:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:48:51 +00:00
|
|
|
close (IN);
|
2018-12-20 17:03:48 +00:00
|
|
|
|
|
|
|
open (IN, '<', $cracks_file) or die "$cracks_file: $!\n";
|
2018-12-27 14:49:18 +00:00
|
|
|
open (OUT, '>', $out_file) or die "$out_file: $!\n";
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-21 08:48:51 +00:00
|
|
|
while (my $line = <IN>)
|
2018-12-20 17:03:48 +00:00
|
|
|
{
|
2018-12-21 08:48:51 +00:00
|
|
|
$line =~ s/\n$//;
|
|
|
|
$line =~ s/\r$//;
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-27 14:49:18 +00:00
|
|
|
my ($hash, $word) = module_verify_hash ($line);
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
# possible if the hash:password pair does not match
|
2018-12-20 17:03:48 +00:00
|
|
|
next unless defined $hash;
|
|
|
|
|
2018-12-27 14:49:18 +00:00
|
|
|
# check if the crack is okay
|
|
|
|
next unless $line eq ($hash . ":" . $word);
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
# possible if the hash is in cracksfile, but not in hashfile
|
2018-12-22 18:29:24 +00:00
|
|
|
next unless is_in_array ($hash, \@hashlist);
|
2018-12-20 17:03:48 +00:00
|
|
|
|
2018-12-21 08:48:51 +00:00
|
|
|
print OUT "$line\n";
|
2018-12-20 17:03:48 +00:00
|
|
|
}
|
|
|
|
|
2018-12-21 08:48:51 +00:00
|
|
|
close (IN);
|
|
|
|
close (OUT);
|
2018-12-20 17:03:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub is_in_array
|
|
|
|
{
|
|
|
|
my $value = shift;
|
|
|
|
my $array = shift;
|
|
|
|
|
|
|
|
return unless defined $value;
|
|
|
|
return unless defined $array;
|
|
|
|
|
|
|
|
return grep { $_ eq $value } @{$array};
|
|
|
|
}
|
|
|
|
|
2018-12-29 15:23:29 +00:00
|
|
|
sub get_module_constraints
|
|
|
|
{
|
|
|
|
my $constraints = module_constraints ();
|
|
|
|
|
|
|
|
if (($constraints->[0]->[0] == -1) && ($constraints->[0]->[1] == -1))
|
|
|
|
{
|
|
|
|
# hash-mode doesn't have a pure kernel, use optimized password settings
|
|
|
|
|
|
|
|
$constraints->[0]->[0] = $constraints->[2]->[0];
|
|
|
|
$constraints->[0]->[1] = $constraints->[2]->[1];
|
|
|
|
$constraints->[1]->[0] = $constraints->[3]->[0];
|
|
|
|
$constraints->[1]->[1] = $constraints->[3]->[1];
|
|
|
|
|
2019-02-16 15:04:37 +00:00
|
|
|
$IS_OPTIMIZED = 1;
|
|
|
|
}
|
|
|
|
elsif (($constraints->[2]->[0] == -1) && ($constraints->[2]->[1] == -1))
|
2018-12-29 15:23:29 +00:00
|
|
|
{
|
|
|
|
# hash-mode doesn't have a optimized kernel, use pure password settings
|
|
|
|
|
|
|
|
$constraints->[2]->[0] = $constraints->[0]->[0];
|
|
|
|
$constraints->[2]->[1] = $constraints->[0]->[1];
|
|
|
|
$constraints->[3]->[0] = $constraints->[1]->[0];
|
|
|
|
$constraints->[3]->[1] = $constraints->[1]->[1];
|
2019-02-16 15:04:37 +00:00
|
|
|
|
|
|
|
$IS_OPTIMIZED = 0;
|
2018-12-29 15:23:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $constraints;
|
|
|
|
}
|
|
|
|
|
2018-12-28 10:53:41 +00:00
|
|
|
sub init_db_word_rand
|
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
my $len_min = shift;
|
|
|
|
my $len_max = shift;
|
|
|
|
|
|
|
|
return if ($len_min == -1);
|
|
|
|
return if ($len_max == -1);
|
2018-12-28 10:53:41 +00:00
|
|
|
|
|
|
|
if ($IS_OPTIMIZED == 1)
|
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
if ($constraints->[4]->[0] != -1)
|
2018-12-28 10:53:41 +00:00
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
my $salt_min = $constraints->[3]->[0];
|
|
|
|
my $salt_max = $constraints->[3]->[1];
|
|
|
|
|
|
|
|
if ($salt_min == $salt_max)
|
2018-12-28 10:53:41 +00:00
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
$len_max -= $salt_min;
|
2018-12-28 10:53:41 +00:00
|
|
|
}
|
|
|
|
}
|
2019-01-03 12:37:15 +00:00
|
|
|
|
2019-02-19 13:28:26 +00:00
|
|
|
# for non-fixed password length algorithms
|
2019-01-03 12:37:15 +00:00
|
|
|
|
2019-02-19 13:28:26 +00:00
|
|
|
if ($len_min != $len_max)
|
|
|
|
{
|
|
|
|
# longer than 31 does not work for -a 0 in optimized mode
|
|
|
|
|
|
|
|
$len_max = ($len_max >= 31) ? 31 : $len_max;
|
|
|
|
}
|
2019-02-20 12:45:02 +00:00
|
|
|
|
|
|
|
$len_min = ($len_min < $len_max) ? $len_min : $len_max;
|
2018-12-28 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 11:08:50 +00:00
|
|
|
my @pool;
|
|
|
|
|
2019-02-20 12:37:34 +00:00
|
|
|
for (my $len = $len_min; $len <= $len_max; $len++)
|
2019-02-16 11:08:50 +00:00
|
|
|
{
|
2019-02-20 13:18:15 +00:00
|
|
|
next if ($len == 0);
|
|
|
|
|
2019-02-16 11:08:50 +00:00
|
|
|
push @pool, $len;
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:37:34 +00:00
|
|
|
while (scalar @pool < $single_outputs)
|
|
|
|
{
|
|
|
|
@pool = shuffle (@pool);
|
|
|
|
|
|
|
|
push @pool, $pool[0];
|
|
|
|
}
|
2019-02-16 11:08:50 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
@pool = shuffle (@pool);
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
my $db_out;
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
$db_out->[0] = $len_min;
|
|
|
|
$db_out->[1] = $len_max;
|
2019-02-20 12:03:21 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
for (my $idx = 2; $idx < $single_outputs; $idx++)
|
2018-12-28 10:53:41 +00:00
|
|
|
{
|
2019-02-20 13:18:15 +00:00
|
|
|
$db_out->[$idx] = shift @pool;
|
2018-12-28 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# make sure the password length is only increasing, which is important for test.sh in -a 1 mode to work
|
|
|
|
|
2019-01-03 12:37:15 +00:00
|
|
|
@{$db_out} = sort { length $a <=> length $b } @{$db_out};
|
2018-12-28 10:53:41 +00:00
|
|
|
|
|
|
|
return $db_out;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub init_db_salt_rand
|
|
|
|
{
|
2018-12-29 15:23:29 +00:00
|
|
|
my $len_min = shift;
|
|
|
|
my $len_max = shift;
|
|
|
|
|
|
|
|
return if ($len_min == -1);
|
|
|
|
return if ($len_max == -1);
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2019-01-03 12:37:15 +00:00
|
|
|
if ($IS_OPTIMIZED == 1)
|
|
|
|
{
|
|
|
|
# longer than 51 triggers a parser bug in old hashcat, have to leave this during migration phase
|
|
|
|
# #define SALT_MAX_OLD 51
|
|
|
|
# salt_max = SALT_MAX_OLD;
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2019-01-03 12:37:15 +00:00
|
|
|
$len_max = ($len_max >= 51) ? 51 : $len_max;
|
2019-02-20 12:45:02 +00:00
|
|
|
|
|
|
|
$len_min = ($len_min < $len_max) ? $len_min : $len_max;
|
2019-01-03 12:37:15 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 11:08:50 +00:00
|
|
|
my @pool;
|
|
|
|
|
2019-02-20 12:37:34 +00:00
|
|
|
for (my $len = $len_min; $len <= $len_max; $len++)
|
2019-02-16 11:08:50 +00:00
|
|
|
{
|
2019-02-20 13:18:15 +00:00
|
|
|
next if ($len == 0);
|
|
|
|
|
2019-02-16 11:08:50 +00:00
|
|
|
push @pool, $len;
|
|
|
|
}
|
|
|
|
|
2019-02-20 12:37:34 +00:00
|
|
|
while (scalar @pool < $single_outputs)
|
|
|
|
{
|
|
|
|
@pool = shuffle (@pool);
|
|
|
|
|
|
|
|
push @pool, $pool[0];
|
|
|
|
}
|
2019-02-16 11:08:50 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
@pool = shuffle (@pool);
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
my $db_out;
|
2018-12-28 10:53:41 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
$db_out->[0] = $len_min;
|
|
|
|
$db_out->[1] = $len_max;
|
2019-02-20 12:03:21 +00:00
|
|
|
|
2019-02-20 13:18:15 +00:00
|
|
|
for (my $idx = 2; $idx < $single_outputs; $idx++)
|
2018-12-28 10:53:41 +00:00
|
|
|
{
|
2019-02-20 13:18:15 +00:00
|
|
|
$db_out->[$idx] = shift @pool;
|
2018-12-28 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
2019-01-03 12:37:15 +00:00
|
|
|
@{$db_out} = sort { length $b <=> length $a } @{$db_out};
|
2018-12-28 10:53:41 +00:00
|
|
|
|
|
|
|
return $db_out;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
# detect hashcat $HEX[...] notation and pack as binary
|
2018-12-20 17:03:48 +00:00
|
|
|
sub pack_if_HEX_notation
|
|
|
|
{
|
|
|
|
my $string = shift;
|
|
|
|
|
|
|
|
return unless defined $string;
|
|
|
|
|
|
|
|
if ($string =~ m/^\$HEX\[[0-9a-fA-F]*\]$/)
|
|
|
|
{
|
|
|
|
return pack ("H*", substr ($string, 5, -1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
# random_count (max)
|
|
|
|
# returns integer from 1 to max
|
|
|
|
sub random_count
|
|
|
|
{
|
|
|
|
my $max = shift;
|
|
|
|
|
|
|
|
return unless is_count $max;
|
|
|
|
|
|
|
|
return int ((rand ($max - 1)) + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
# random_number (min, max)
|
|
|
|
sub random_number
|
|
|
|
{
|
|
|
|
my $min = shift;
|
|
|
|
my $max = shift;
|
|
|
|
|
2018-12-23 17:15:53 +00:00
|
|
|
return if $min > $max;
|
2018-12-21 11:16:11 +00:00
|
|
|
|
2018-12-28 11:30:57 +00:00
|
|
|
return int ((rand (($max + 1) - $min)) + $min);
|
2018-12-21 11:16:11 +00:00
|
|
|
}
|
|
|
|
|
2018-12-20 17:03:48 +00:00
|
|
|
sub random_bytes
|
|
|
|
{
|
2018-12-21 11:16:11 +00:00
|
|
|
# length in bytes
|
2018-12-20 17:03:48 +00:00
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return pack ("H*", random_hex_string (2 * $count));
|
|
|
|
}
|
|
|
|
|
|
|
|
sub random_hex_string
|
|
|
|
{
|
2018-12-21 11:16:11 +00:00
|
|
|
# length in characters
|
2018-12-20 17:03:48 +00:00
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return if ! is_count ($count);
|
|
|
|
|
|
|
|
my $string;
|
|
|
|
|
2018-12-21 08:20:16 +00:00
|
|
|
$string .= sprintf ("%x", rand 16) for (1 .. $count);
|
2018-12-20 17:03:48 +00:00
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
sub random_lowercase_string
|
|
|
|
{
|
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return if ! is_count ($count);
|
|
|
|
|
|
|
|
my @chars = ('a'..'z');
|
|
|
|
|
|
|
|
my $string;
|
|
|
|
|
|
|
|
$string .= $chars[rand @chars] for (1 .. $count);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub random_uppercase_string
|
|
|
|
{
|
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return if ! is_count ($count);
|
|
|
|
|
|
|
|
my @chars = ('A'..'Z');
|
|
|
|
|
|
|
|
my $string;
|
|
|
|
|
|
|
|
$string .= $chars[rand @chars] for (1 .. $count);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub random_mixedcase_string
|
|
|
|
{
|
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return if ! is_count ($count);
|
|
|
|
|
|
|
|
my @chars = ('A'..'Z', 'a'..'z');
|
|
|
|
|
|
|
|
my $string;
|
|
|
|
|
|
|
|
$string .= $chars[rand @chars] for (1 .. $count);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2018-12-20 17:03:48 +00:00
|
|
|
sub random_numeric_string
|
|
|
|
{
|
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return if ! is_count ($count);
|
|
|
|
|
2018-12-22 18:29:24 +00:00
|
|
|
my @chars = ('0'..'9');
|
|
|
|
|
2018-12-20 17:03:48 +00:00
|
|
|
my $string;
|
|
|
|
|
2018-12-22 18:29:24 +00:00
|
|
|
$string .= $chars[rand @chars] for (1 .. $count);
|
2018-12-20 17:03:48 +00:00
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2018-12-21 11:16:11 +00:00
|
|
|
sub random_string
|
|
|
|
{
|
|
|
|
my $count = shift;
|
|
|
|
|
|
|
|
return if ! is_count ($count);
|
|
|
|
|
|
|
|
my @chars = ('A'..'Z', 'a'..'z', '0'..'9');
|
|
|
|
|
|
|
|
my $string;
|
|
|
|
|
|
|
|
$string .= $chars[rand @chars] for (1 .. $count);
|
|
|
|
|
|
|
|
return $string;
|
|
|
|
}
|
|
|
|
|
2018-12-20 17:03:48 +00:00
|
|
|
sub usage_exit
|
|
|
|
{
|
|
|
|
my $f = basename ($0);
|
|
|
|
|
|
|
|
print "\n"
|
|
|
|
. "Usage:\n"
|
|
|
|
. " $f single <mode> [length]\n"
|
|
|
|
. " $f passthrough <mode>\n"
|
|
|
|
. " $f verify <mode> <hashfile> <cracksfile> <outfile>\n"
|
|
|
|
. "\n"
|
|
|
|
. "Single:\n"
|
|
|
|
. " Generates up to 32 hashes of random numbers of incrementing length, or up to 32\n"
|
|
|
|
. " hashes of random numbers of exact [length]. Writes shell commands to stdout that\n"
|
|
|
|
. " can be processed by the test.sh script.\n"
|
|
|
|
. "\n"
|
|
|
|
. "Passthrough:\n"
|
|
|
|
. " Generates hashes for strings entered via stdin and prints them to stdout.\n"
|
|
|
|
. "\n"
|
|
|
|
. "Verify:\n"
|
|
|
|
. " Reads a list of hashes from <hashfile> and a list of hash:password pairs from\n"
|
|
|
|
. " <cracksfile>. Hashes every password and compares the hash to the corresponding\n"
|
|
|
|
. " entry in the <cracksfile>. If the hashes match and the hash is present in the\n"
|
|
|
|
. " list from <hashfile>, it will be written to the <outfile>.\n";
|
|
|
|
|
|
|
|
exit 1;
|
|
|
|
}
|