1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-18 06:08:16 +00:00
hashcat/tools/test_modules/m08500.pm

90 lines
1.6 KiB
Perl
Raw Normal View History

2019-02-08 12:00:40 +00:00
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Convert::EBCDIC qw (ascii2ebcdic);
use Crypt::DES;
2019-02-17 14:49:57 +00:00
sub module_constraints { [[0, 8], [1, 8], [-1, -1], [-1, -1], [-1, -1]] }
sub racf_hash
{
my ($username, $password) = @_;
$username = substr ($username . " " x 8, 0, 8);
$password = substr ($password . " " x 8, 0, 8);
my $username_ebc = ascii2ebcdic ($username);
my $password_ebc = ascii2ebcdic ($password);
my @pw = split ("", $password_ebc);
for (my $i = 0; $i < 8; $i++)
{
$pw[$i] = unpack ("C", $pw[$i]);
$pw[$i] ^= 0x55;
$pw[$i] <<= 1;
$pw[$i] = pack ("C", $pw[$i] & 0xff);
}
my $key = join ("", @pw);
my $cipher = new Crypt::DES $key;
my $ciphertext = $cipher->encrypt ($username_ebc);
my $ct = unpack ("H16", $ciphertext);
return $ct;
}
2019-02-08 12:00:40 +00:00
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $hash_buf = racf_hash (uc $salt, $word);
2019-02-17 14:49:57 +00:00
my $hash = sprintf ('$racf$*%s*%s', uc $salt, uc $hash_buf);
2019-02-08 12:00:40 +00:00
2019-02-17 14:49:57 +00:00
return $hash;
2019-02-08 12:00:40 +00:00
}
sub module_verify_hash
{
my $line = shift;
my @line_elements = split (":", $line);
return if scalar @line_elements < 2;
my $hash_in = shift @line_elements;
my $word = join (":", @line_elements);
2019-02-17 14:49:57 +00:00
# check signature
2019-02-08 12:00:40 +00:00
my @hash_elements = split ('\*', $hash_in);
return unless ($hash_elements[0] eq '$racf$');
my $salt = $hash_elements[1];
2019-02-17 14:49:57 +00:00
return unless defined $salt;
return unless defined $word;
2019-02-08 12:00:40 +00:00
2019-02-17 14:49:57 +00:00
$word = pack_if_HEX_notation ($word);
2019-02-08 12:00:40 +00:00
2019-02-17 14:49:57 +00:00
my $new_hash = module_generate_hash ($word, $salt);
2019-02-08 12:00:40 +00:00
2019-02-17 14:49:57 +00:00
return ($new_hash, $word);
2019-02-08 12:00:40 +00:00
}
1;