mirror of
https://github.com/hashcat/hashcat.git
synced 2025-01-22 05:31:11 +00:00
Add -m 4800 unit test
This commit is contained in:
parent
c52854ebb7
commit
0d7d1219f5
83
tools/test_modules/m04800.pm
Normal file
83
tools/test_modules/m04800.pm
Normal file
@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
##
|
||||
## Author......: See docs/credits.txt
|
||||
## License.....: MIT
|
||||
##
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
use Digest::MD5 qw (md5_hex);
|
||||
|
||||
sub module_constraints { [[0, 255], [-1, -1], [0, 38], [-1, -1], [-1, -1]] } # 38 = 55 - 16 - 1
|
||||
|
||||
sub get_random_md5chap_salt
|
||||
{
|
||||
my $salt_buf = random_bytes (16);
|
||||
|
||||
my $salt = unpack ("H*", $salt_buf);
|
||||
|
||||
$salt .= ":";
|
||||
|
||||
$salt .= unpack ("H*", random_bytes (1));
|
||||
|
||||
return $salt;
|
||||
}
|
||||
|
||||
sub module_generate_hash
|
||||
{
|
||||
my $word = shift;
|
||||
my $salt = shift;
|
||||
|
||||
if (length $salt == 0)
|
||||
{
|
||||
$salt = get_random_md5chap_salt ();
|
||||
}
|
||||
|
||||
my $index = rindex ($salt, ":");
|
||||
|
||||
my $saltx = substr ($salt, 0, $index);
|
||||
my $salt_bin = pack ("H*", $saltx);
|
||||
my $chap_sign = substr ($salt, $index + 1);
|
||||
my $chap_sign_bin = pack ("H*", $chap_sign);
|
||||
|
||||
my $hash_buf = md5_hex ($chap_sign_bin . $word . $salt_bin);
|
||||
|
||||
my $hash = sprintf ("%s:%s", $hash_buf, $salt);
|
||||
|
||||
return $hash;
|
||||
}
|
||||
|
||||
sub module_verify_hash
|
||||
{
|
||||
my $line = shift;
|
||||
|
||||
my $index1 = index ($line, ":");
|
||||
|
||||
return if $index1 < 1;
|
||||
|
||||
my $index2 = index ($line, ":", $index1 + 1);
|
||||
|
||||
return if $index2 < 1;
|
||||
|
||||
my $index3 = index ($line, ":", $index2 + 1);
|
||||
|
||||
return if $index3 < 1;
|
||||
|
||||
my $salt = substr ($line, $index1 + 1, $index3 - $index1 - 1);
|
||||
|
||||
my $word = substr ($line, $index3 + 1);
|
||||
|
||||
return unless defined $salt;
|
||||
return unless defined $word;
|
||||
|
||||
$word = pack_if_HEX_notation ($word);
|
||||
|
||||
my $new_hash = module_generate_hash ($word, $salt);
|
||||
|
||||
return ($new_hash, $word);
|
||||
}
|
||||
|
||||
1;
|
||||
|
Loading…
Reference in New Issue
Block a user