Fixes #2267: added support for -m 22400 = AES Crypt (SHA256)
This commit is contained in:
131
tools/aescrypt2hashcat.pl
Executable file
131
tools/aescrypt2hashcat.pl
Executable file
@@ -0,0 +1,131 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#
|
||||
# Helper functions
|
||||
#
|
||||
|
||||
sub read_bytes
|
||||
{
|
||||
my $handle = shift;
|
||||
my $size = shift;
|
||||
|
||||
my $data = "";
|
||||
|
||||
read ($handle, $data, $size);
|
||||
|
||||
# this function is very strict:
|
||||
# it only returns something if all the bytes can be read
|
||||
|
||||
if (length ($data) != $size)
|
||||
{
|
||||
die "ERROR: Couldn't read data from the file. Maybe incorrect file format?\n";
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
#
|
||||
# Start
|
||||
#
|
||||
|
||||
if (scalar (@ARGV) != 1)
|
||||
{
|
||||
die "usage: $0 file.txt.aes\n";
|
||||
}
|
||||
|
||||
my $file_name = $ARGV[0];
|
||||
|
||||
my $file_handle;
|
||||
|
||||
if (! open ($file_handle, "<", $file_name))
|
||||
{
|
||||
die "ERROR: Couldn't open file '$file_name'\n";
|
||||
}
|
||||
|
||||
binmode ($file_handle);
|
||||
|
||||
|
||||
# Signature:
|
||||
|
||||
my $signature = read_bytes ($file_handle, 3);
|
||||
|
||||
if ($signature ne "AES")
|
||||
{
|
||||
die "ERROR: The file doesn't seem to be a correct aescrypt file (signature mismatch)\n";
|
||||
}
|
||||
|
||||
# Version
|
||||
|
||||
my $version = read_bytes ($file_handle, 1);
|
||||
|
||||
if ($version ne "\x02")
|
||||
{
|
||||
die "ERROR: Currently only aescrypt file version 2 is supported by this script\n";
|
||||
}
|
||||
|
||||
|
||||
read_bytes ($file_handle, 1); # reservered/skip (normally should be just \x00)
|
||||
|
||||
|
||||
# Loop over the extensions until we got extension size 0
|
||||
|
||||
my $extension_size = read_bytes ($file_handle, 2);
|
||||
|
||||
while ($extension_size ne "\x00\x00")
|
||||
{
|
||||
my $skip_size = unpack ("S>", $extension_size); # 16-bit lengths
|
||||
|
||||
read_bytes ($file_handle, $skip_size); # skip the extension
|
||||
|
||||
$extension_size = read_bytes ($file_handle, 2);
|
||||
}
|
||||
|
||||
# IV (for KDF)
|
||||
|
||||
my $iv = read_bytes ($file_handle, 16);
|
||||
|
||||
|
||||
# IV (encrypted IV for AES decryption)
|
||||
|
||||
my $iv_enc = read_bytes ($file_handle, 16);
|
||||
|
||||
|
||||
# key_enc
|
||||
|
||||
my $key_enc = read_bytes ($file_handle, 32);
|
||||
|
||||
|
||||
# HMAC
|
||||
|
||||
my $hmac = read_bytes ($file_handle, 32);
|
||||
|
||||
#
|
||||
# Hex conversion
|
||||
#
|
||||
|
||||
$iv = unpack ("H*", $iv);
|
||||
$iv_enc = unpack ("H*", $iv_enc);
|
||||
$key_enc = unpack ("H*", $key_enc);
|
||||
$hmac = unpack ("H*", $hmac);
|
||||
|
||||
#
|
||||
# Final output
|
||||
#
|
||||
|
||||
print sprintf ("\$aescrypt\$1*%s*%s*%s*%s\n", $iv, $iv_enc, $key_enc, $hmac);
|
||||
|
||||
#
|
||||
# Cleanup
|
||||
#
|
||||
|
||||
close ($file_handle);
|
||||
|
||||
exit (0);
|
||||
89
tools/test_modules/m22400.pm
Normal file
89
tools/test_modules/m22400.pm
Normal file
@@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Digest::SHA qw (sha256);
|
||||
use Digest::HMAC qw (hmac_hex);
|
||||
use Encode;
|
||||
|
||||
sub module_constraints { [[0, 256], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
|
||||
my $iv_aes = shift // random_bytes (16);
|
||||
my $key_aes = shift // random_bytes (32);
|
||||
|
||||
my $word_utf16le = encode ('UTF-16le', $word);
|
||||
|
||||
my $key = $salt . "\x00" x 16;
|
||||
|
||||
for (my $i = 0; $i < 8192; $i++)
|
||||
{
|
||||
$key = sha256 ($key . $word_utf16le);
|
||||
}
|
||||
|
||||
my $digest = hmac_hex ($iv_aes . $key_aes, $key, \&sha256, 64);
|
||||
|
||||
# hex conversion:
|
||||
|
||||
my $salt_hex = unpack ("H*", $salt);
|
||||
my $iv_hex = unpack ("H*", $iv_aes);
|
||||
my $key_hex = unpack ("H*", $key_aes);
|
||||
|
||||
my $hash = sprintf ("\$aescrypt\$1*%s*%s*%s*%s", $salt_hex, $iv_hex, $key_hex, $digest);
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my ($hash, $word) = split (':', $line);
|
||||
|
||||
return unless defined $hash;
|
||||
return unless defined $word;
|
||||
|
||||
my @data = split ('\*', $hash);
|
||||
|
||||
return unless (scalar (@data) == 5);
|
||||
|
||||
my $signature = substr ($data[0], 0, 10);
|
||||
|
||||
return unless ($signature eq "\$aescrypt\$");
|
||||
|
||||
my $version = substr ($data[0], 10);
|
||||
|
||||
return unless ($version eq "1");
|
||||
|
||||
my $salt = $data[1];
|
||||
my $iv = $data[2];
|
||||
my $key = $data[3];
|
||||
|
||||
return unless (length ($salt) == 32); # hex lengths
|
||||
return unless (length ($iv) == 32);
|
||||
return unless (length ($key) == 64);
|
||||
|
||||
# binary conversion:
|
||||
|
||||
$salt = pack ("H*", $salt);
|
||||
$iv = pack ("H*", $iv);
|
||||
$key = pack ("H*", $key);
|
||||
|
||||
my $word_packed = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word_packed, $salt, $iv, $key);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
||||
Reference in New Issue
Block a user