mirror of
https://github.com/hashcat/hashcat.git
synced 2024-11-22 08:08:10 +00:00
Prepare unit-test for -m 31200
This commit is contained in:
parent
ea6173b307
commit
866aaf02ce
110
tools/test_modules/m31200.pm
Normal file
110
tools/test_modules/m31200.pm
Normal file
@ -0,0 +1,110 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Crypt::PBKDF2;
|
||||
use Digest::SHA qw (sha1);
|
||||
use Crypt::CBC;
|
||||
|
||||
sub module_constraints { [[0, 256], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
my $iter = shift // 10000;
|
||||
my $ct = shift;
|
||||
|
||||
my $pbkdf2 = Crypt::PBKDF2->new
|
||||
(
|
||||
hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1'),
|
||||
iterations => $iter,
|
||||
output_len => 48
|
||||
);
|
||||
|
||||
my $salt_bin = pack ("H*", $salt);
|
||||
|
||||
my $pbkdf2key = $pbkdf2->PBKDF2 ($salt_bin, $word);
|
||||
|
||||
my $key = substr ($pbkdf2key, 0, 32);
|
||||
my $iv = substr ($pbkdf2key, 32, 16);
|
||||
|
||||
my $pt;
|
||||
|
||||
if (defined $ct)
|
||||
{
|
||||
my $aes_cbc = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
iv => $iv,
|
||||
key => $key,
|
||||
keysize => 32,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "none"
|
||||
});
|
||||
|
||||
my $ct_bin = pack ("H*", $ct);
|
||||
|
||||
$pt = $aes_cbc->decrypt ($ct_bin);
|
||||
|
||||
if (substr ($pt, 4, 12) ne "\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c\x0c")
|
||||
{
|
||||
$pt = "\xff" x 16;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$pt = "\xff" x 16;
|
||||
}
|
||||
|
||||
my $aes_cbc = Crypt::CBC->new ({
|
||||
cipher => "Crypt::Rijndael",
|
||||
iv => $iv,
|
||||
key => $key,
|
||||
keysize => 32,
|
||||
literal_key => 1,
|
||||
header => "none",
|
||||
padding => "none"
|
||||
});
|
||||
|
||||
my $ct_bin = $aes_cbc->encrypt ($pt);
|
||||
|
||||
my $hash = sprintf ('$vbk$*%s*%d*%s', pack ("H*", $salt_bin), $iter, pack ("H*", $ct_bin));
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $idx = index ($line, ':');
|
||||
|
||||
return unless $idx >= 0;
|
||||
|
||||
my $hash = substr ($line, 0, $idx);
|
||||
my $word = substr ($line, $idx + 1);
|
||||
|
||||
return unless substr ($hash, 0, 5) eq '$vbk$';
|
||||
|
||||
my ($signature, $salt, $iter, $ct) = split '\*', $hash;
|
||||
|
||||
return unless defined $signature;
|
||||
return unless defined $salt;
|
||||
return unless defined $iter;
|
||||
return unless defined $ct;
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $iter, $ct);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in New Issue
Block a user