1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-24 00:51:05 +00:00
hashcat/tools/test_modules/m09800.pm

111 lines
2.1 KiB
Perl
Raw Normal View History

2019-02-18 13:24:45 +00:00
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::RC4;
use Digest::SHA qw (sha1);
use Encode;
sub module_constraints { [[-1, -1], [-1, -1], [0, 15], [32, 32], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $param = shift;
my $param2 = shift;
my $salt_bin = pack ("H*", $salt);
my $tmp = sha1 ($salt_bin. encode ("UTF-16LE", $word));
my $version;
if (defined $param2)
{
$version = $param2;
}
else
{
$version = (unpack ("L", $tmp) & 1) ? 3 : 4;
}
my $rc4_key = sha1 ($tmp . "\x00\x00\x00\x00");
if ($version == 3)
{
$rc4_key = substr ($rc4_key, 0, 5) . "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00";
}
my $m = Crypt::RC4->new (substr ($rc4_key, 0, 16));
my $encdata;
if (defined $param)
{
$encdata = $m->RC4 (pack ("H*", $param));
}
else
{
$encdata = "A" x 16; ## can be anything
}
my $data1_buf = $encdata;
my $data2_buf = sha1 (substr ($data1_buf, 0, 16));
$m = Crypt::RC4->new (substr ($rc4_key, 0, 16));
my $encrypted1 = $m->RC4 ($data1_buf);
my $encrypted2 = $m->RC4 ($data2_buf);
my $hash = sprintf ("\$oldoffice\$%d*%s*%s*%s", $version, $salt, unpack ("H*", $encrypted1), unpack ("H*", $encrypted2));
return $hash;
}
sub module_verify_hash
{
my $line = shift;
# Office Old $3 $4
my ($hash_in, $word) = split ":", $line;
2019-02-19 11:50:57 +00:00
return unless defined $hash_in;
return unless defined $word;
2019-02-18 13:24:45 +00:00
my @data = split /\*/, $hash_in;
2019-02-19 11:50:57 +00:00
return unless scalar @data == 4;
2019-02-18 13:24:45 +00:00
my $signature = shift @data;
2019-02-19 11:50:57 +00:00
return unless (($signature eq '$oldoffice$3') || ($signature eq '$oldoffice$4'));
2019-02-18 13:24:45 +00:00
2019-02-19 11:50:57 +00:00
return unless (length $data[0] == 32);
return unless (length $data[1] == 32);
return unless (length $data[2] == 40);
2019-02-18 13:24:45 +00:00
my $salt = shift @data;
my $param = shift @data;
my $param2 = substr ($signature, 11, 1);
return unless defined $salt;
return unless defined $word;
return unless defined $param;
return unless defined $param2;
$word = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word, $salt, $param, $param2);
return ($new_hash, $word);
}
1;