1
mirror of https://github.com/hashcat/hashcat synced 2024-12-23 14:13:43 +01:00

Add unit tests for multiple modules

11700, 11750, 11760, 11800, 11850, 11860, 12001, 12100, 12200, 12300, 12600 & 12700
This commit is contained in:
mhasbini 2019-02-18 20:49:57 +02:00
parent b0bffaf5eb
commit 95b8c98980
12 changed files with 728 additions and 0 deletions

View File

@ -0,0 +1,51 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
sub module_constraints { [[0, 255], [0, 255], [0, 55], [0, 55], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
# PyGOST outputs digests in little-endian order, while the kernels
# expect them in big-endian; hence the digest[::-1] mirroring.
# Using sys.stdout.write instead of print to disable \n character.
my $python_code = <<"END_CODE";
import binascii
import sys
from pygost import gost34112012256
digest = gost34112012256.new(b"$word").digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
END_CODE
my $hash = `python2 -c '$python_code'`;
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $word) = split (':', $line);
return unless defined $hash;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,54 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
sub module_constraints { [[0, 255], [0, 255], [0, 55], [0, 55], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $python_code = <<"END_CODE";
import binascii
import hmac
import sys
from pygost import gost34112012256
key = b"$word"
msg = b"$salt"
digest = hmac.new(key, msg, gost34112012256).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
END_CODE
my $digest = `python2 -c '$python_code'`;
my $hash = sprintf ("%s:%s", $digest, $salt);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $salt, $word) = split (':', $line);
return unless defined $hash;
return unless defined $salt;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,54 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
sub module_constraints { [[0, 255], [0, 55], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $python_code = <<"END_CODE";
import binascii
import hmac
import sys
from pygost import gost34112012256
key = b"$salt"
msg = b"$word"
digest = hmac.new(key, msg, gost34112012256).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
END_CODE
my $digest = `python2 -c '$python_code'`;
my $hash = sprintf ("%s:%s", $digest, $salt);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $salt, $word) = split (':', $line);
return unless defined $hash;
return unless defined $salt;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,48 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
sub module_constraints { [[0, 255], [-1, -1], [0, 55], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $python_code = <<"END_CODE";
import binascii
import sys
from pygost import gost34112012512
digest = gost34112012512.new(b"$word").digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
END_CODE
my $hash = `python2 -c '$python_code'`;
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $word) = split (':', $line);
return unless defined $hash;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,55 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
sub module_constraints { [[0, 55], [0, 55], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $python_code = <<"END_CODE";
import binascii
import hmac
import sys
from pygost import gost34112012512
key = b"$word"
msg = b"$salt"
digest = hmac.new(key, msg, gost34112012512).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
END_CODE
my $digest = `python2 -c '$python_code'`;
my $hash = sprintf ("%s:%s", $digest, $salt);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $salt, $word) = split (':', $line);
return unless defined $hash;
return unless defined $salt;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,55 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
sub module_constraints { [[0, 255], [0, 55], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $python_code = <<"END_CODE";
import binascii
import hmac
import sys
from pygost import gost34112012512
key = b"$salt"
msg = b"$word"
digest = hmac.new(key, msg, gost34112012512).digest()
sys.stdout.write(binascii.hexlify(digest[::-1]))
END_CODE
my $digest = `python2 -c '$python_code'`;
my $hash = sprintf ("%s:%s", $digest, $salt);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $salt, $word) = split (':', $line);
return unless defined $hash;
return unless defined $salt;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,65 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use MIME::Base64 qw (encode_base64 decode_base64);
use Crypt::PBKDF2;
sub module_constraints { [[0, 255], [16, 16], [0, 55], [16, 16], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $pbkdf2 = Crypt::PBKDF2->new
(
hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1'),
iterations => 10000,
output_len => 32
);
my $base64 = encode_base64 ($salt . $pbkdf2->PBKDF2 ($salt, $word), "");
my $hash = sprintf ("{PKCS5S2}%s", $base64);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($digest, $word) = split ":", $line;
return unless defined $digest;
return unless defined $word;
my $signature = substr ($digest, 0, 9);
return unless ($signature eq '{PKCS5S2}');
my $hash = substr ($digest, 9);
# base64 buf
my $base64_decoded = decode_base64 ($hash);
return if (length ($base64_decoded) != (16 + 32));
my $salt = substr ($base64_decoded, 0, 16);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,67 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use MIME::Base64 qw (encode_base64 decode_base64);
use Crypt::PBKDF2;
sub module_constraints { [[0, 255], [1, 15], [0, 55], [1, 15], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iterations = shift // 1000;
my $out_len = shift // 16;
my $pbkdf2 = Crypt::PBKDF2->new
(
hasher => Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 512),
iterations => $iterations,
output_len => $out_len
);
my $digest = encode_base64 ($pbkdf2->PBKDF2 ($salt, $word), "");
my $base64_salt = encode_base64 ($salt, "");
my $hash = sprintf ("sha512:%i:%s:%s", $iterations, $base64_salt, $digest);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($digest, $word) = split (/:([^:]+)$/, $line);
return unless defined $digest;
return unless defined $word;
my ($signature, $iterations, $salt_encoded, $hash_encoded) = split (':', $digest);
return unless ($signature eq 'sha512');
return unless defined $iterations;
return unless defined $salt_encoded;
return unless defined $hash_encoded;
my $hash = decode_base64 ($hash_encoded);
my $salt = decode_base64 ($salt_encoded);
my $out_len = length ($hash);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt, $iterations, $out_len);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,87 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Digest::SHA qw (sha512);
sub module_constraints { [[0, 255], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $default_salt = shift // 0;
my $iterations = 65536;
if ($default_salt == 1)
{
$salt = "0011223344556677";
}
my $digest = sha512 (pack ("H*", $salt) . $word);
for (my $i = 0; $i < $iterations; $i++)
{
$digest = sha512 ($digest);
}
$digest = unpack ("H*", $digest);
$digest = substr ($digest, 0, 16);
my $hash;
if ($default_salt == 0)
{
$hash = sprintf ("\$ecryptfs\$0\$1\$%s\$%s", $salt, $digest);
}
else
{
$hash = sprintf ("\$ecryptfs\$0\$%s", $digest);
}
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash_in, $word) = split (/:/, $line);
return unless defined $hash_in;
return unless defined $word;
my $signature = substr ($hash_in, 0, 12);
return unless ($signature eq '$ecryptfs$0$');
my $digest = substr ($hash_in, 12);
my $default_salt = 1;
my ($param, $hash) = split('\$', $digest);
$default_salt = 0 if ($param eq '1');
my $salt;
if ($default_salt == 0)
{
($salt, $hash) = split('\$', $hash);
}
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt, $default_salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,61 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::PBKDF2;
use Digest::SHA qw (sha512_hex);
sub module_constraints { [[0, 255], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iterations = 4096;
my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA2', 512);
my $pbkdf2 = Crypt::PBKDF2->new (
hasher => $hasher,
iterations => $iterations,
output_len => 64
);
my $salt_bin = pack ("H*", $salt);
my $key = $pbkdf2->PBKDF2 ($salt_bin. "AUTH_PBKDF2_SPEEDY_KEY", $word);
my $digest = sha512_hex ($key . $salt_bin);
my $hash = sprintf ("%s%s", uc ($digest), uc ($salt));
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($digest, $word) = split (/:/, $line);
return unless defined $digest;
return unless length ($digest) == 160;
return unless defined $word;
my $salt = substr ($digest, 128, 32);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,46 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Digest::SHA qw (sha1_hex sha256_hex);
sub module_constraints { [[0, 255], [64, 64], [0, 55], [64, 64], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $digest = sha1_hex ($word);
$digest = sha256_hex ($salt . uc $digest);
my $hash = sprintf ("%s:%s", $digest, $salt);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $salt, $word) = split (':', $line);
return unless defined $hash;
return unless defined $salt;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
1;

View File

@ -0,0 +1,85 @@
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::PBKDF2;
use Crypt::CBC;
sub module_constraints { [[0, 255], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $encrypted = shift;
my $iterations = 10;
my $salt_bin = pack ("H*", $salt);
my $hasher = Crypt::PBKDF2->hasher_from_algorithm ('HMACSHA1');
my $pbkdf2 = Crypt::PBKDF2->new (
hasher => $hasher,
iterations => $iterations,
output_len => 32
);
my $key = $pbkdf2->PBKDF2 ($salt_bin, $word);
my $cipher = Crypt::CBC->new ({
key => $key,
cipher => "Crypt::Rijndael",
iv => $salt_bin,
literal_key => 1,
header => "none",
keysize => 32
});
my $data = qq|{
"guid" : "00000000-0000-0000-0000-000000000000",
"sharedKey" : "00000000-0000-0000-0000-000000000000",
"options" : {"pbkdf2_iterations":10,"fee_policy":0,"html5_notifications":false,"logout_time":600000,"tx_display":0,"always_keep_local_backup":false}|;
unless (defined $encrypted)
{
$encrypted = unpack ("H*", $cipher->encrypt ($data));
}
my $hash = sprintf ("\$blockchain\$%s\$%s", length ($salt . $encrypted) / 2, $salt . $encrypted);
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $word) = split (':', $line);
return unless defined $hash;
return unless defined $word;
my (undef, $signature, $data_len, $data) = split '\$', $hash;
return unless ($signature eq "blockchain");
return unless (($data_len * 2) == length $data);
my $salt = substr ($data, 0, 32);
my $data_encrypted = substr ($data, 32);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt, $data_encrypted);
return ($new_hash, $word);
}
1;