1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Update unit test for -m 31800 to match reference description for extraction tool

This commit is contained in:
jsteube 2023-04-04 11:36:34 +00:00
parent b782d5f795
commit 1c6c650931

View File

@ -13,26 +13,20 @@ use Crypt::AuthEnc::GCM;
use MIME::Base64 qw (decode_base64 encode_base64);
use Crypt::KeyDerivation ':all';
sub module_constraints { [[0, 256], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
sub module_constraints { [[0, 256], [64, 64], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iterations = shift;
my $email = shift;
my $algorithm = shift;
my $secret_key = shift;
my $ct = shift;
my $plaintext_length = shift;
my $iv = shift;
my $cryptext = shift;
my $expected_hmac = shift;
my $hmac_d_data = shift;
my $word = shift;
my $hkdf_salt = shift;
my $hkdf_key = shift // random_hex_string (64);
my $iterations = shift // 100000;
my $iv = shift // random_hex_string (32);
my $ct = shift;
my $tag = shift;
my $email = shift // "31800\@hashcat.net";
my $salt_bin = pack ("H*", $salt);
my $hkdf_pass_salt = hkdf ($salt_bin, $email, 'SHA256', 32, "PBES2g-HS256");
my $hkdf_salt_bin = pack ("H*", $hkdf_salt);
my $kdf = Crypt::PBKDF2->new
(
@ -41,28 +35,25 @@ sub module_generate_hash
output_len => 32
);
my $password_key = $kdf->PBKDF2 ($hkdf_pass_salt, $word);
my $password_key = $kdf->PBKDF2 ($hkdf_salt_bin, $word);
my $hkdf_key = hkdf ("798JRYLJVD423DC286TVMH43EB", "ASWWYB", 'SHA256', 32, "A3");
my $hkdf_key_bin = pack ("H*", $hkdf_key);
my $muk = xor_len ($password_key, $hkdf_key, 32);
my $muk = xor_len ($password_key, $hkdf_key_bin, 32);
my $pt;
my $iv_bin;
my $iv_bin = pack ("H*", $iv);
if (defined $ct)
{
my $ct_bin = pack ("H*", $ct);
$iv_bin = substr ($ct_bin, 0 + length ("opdata01"), 16);
my $data_bin = substr ($ct_bin, 0 + length ("opdata01") + 16, -16);
my $tag_bin = substr ($ct_bin, -16);
my $tag_bin = pack ("H*", $tag);
my $aes = Crypt::AuthEnc::GCM->new ("AES", $muk, $iv_bin);
$pt = $aes->decrypt_add ($data_bin);
$pt = $aes->decrypt_add ($ct_bin);
my $result_tag = $aes->decrypt_done ($tag_bin);
@ -88,14 +79,7 @@ sub module_generate_hash
## so far so good
my $hash = sprintf
(
'$mobilekeychain$%s',
unpack ("H*", "opdata01" . $iv_bin . $ct_bin . $tag_bin)
);
my $hash = sprintf ('$mobilekeychain$%s$%s$%s$%u$%s$%s$%s', $email, unpack ("H*", $hkdf_salt_bin), unpack ("H*", $hkdf_key_bin), $iterations, unpack ("H*", $iv_bin), unpack ("H*", $ct_bin), unpack ("H*", $tag_bin));
return $hash;
}
@ -113,44 +97,20 @@ sub module_verify_hash
return unless substr ($hash, 0, 16) eq '$mobilekeychain$';
my (undef, $signature, $email, $salt_len, $salt, $algorithm, $secret_key, $iterations, $ct_len, $ct, $plaintext_length, $iv_len, $iv, $cryptext_len, $cryptext, $expected_hmac_len, $expected_hmac, $hmac_d_data_len, $hmac_d_data) = split '\$', $hash;
my (undef, $signature, $email, $hkdf_salt, $hkdf_key, $iterations, $iv, $ct, $tag) = split '\$', $hash;
return unless defined $signature;
return unless defined $email;
return unless defined $salt_len;
return unless defined $salt;
return unless defined $algorithm;
return unless defined $secret_key;
return unless defined $hkdf_salt;
return unless defined $hkdf_key;
return unless defined $iterations;
return unless defined $ct_len;
return unless defined $ct;
return unless defined $plaintext_length;
return unless defined $iv_len;
return unless defined $iv;
return unless defined $cryptext_len;
return unless defined $cryptext;
return unless defined $expected_hmac_len;
return unless defined $expected_hmac;
return unless defined $hmac_d_data_len;
return unless defined $hmac_d_data;
my $salt_bin = pack ("H*", $salt);
my $ct_bin = pack ("H*", $ct);
my $iv_bin = pack ("H*", $iv);
my $cryptext_bin = pack ("H*", $cryptext);
my $expected_hmac_bin = pack ("H*", $expected_hmac);
my $hmac_d_data_bin = pack ("H*", $hmac_d_data);
return unless length ($salt_bin) == $salt_len;
return unless length ($ct_bin) == $ct_len;
return unless length ($iv_bin) == $iv_len;
return unless length ($cryptext_bin) == $cryptext_len;
return unless length ($expected_hmac_bin) == $expected_hmac_len;
return unless length ($hmac_d_data_bin) == $hmac_d_data_len;
return unless defined $ct;
return unless defined $tag;
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt, $iterations, $email, $algorithm, $secret_key, $ct, $plaintext_length, $iv, $cryptext, $expected_hmac, $hmac_d_data);
my $new_hash = module_generate_hash ($word_packed, $hkdf_salt, $hkdf_key, $iterations, $iv, $ct, $tag, $email);
return ($new_hash, $word);
}