forked from hashcat/hashcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm18400.pm
110 lines (86 loc) · 2.61 KB
/
m18400.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::Mode::CBC;
use Crypt::PBKDF2;
use Digest::SHA qw (sha256 sha256_hex);
sub module_constraints { [[0, 256], [32, 32], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iter = shift // 100000;
my $iv = shift // random_hex_string (2*16);
my $plain = shift // random_hex_string (2*1024);
my $b_iv = pack ('H*', $iv);
my $b_salt = pack ('H*', $salt);
my $b_plain = pack ('H*', $plain);
my $kdf = Crypt::PBKDF2->new
(
hash_class => 'HMACSHA1',
iterations => $iter,
output_len => 32
);
my $pass_hash = sha256 ($word);
my $key = $kdf->PBKDF2 ($b_salt, $pass_hash);
my $cbc = Crypt::Mode::CBC->new ('AES', 0);
my $b_cipher = $cbc->encrypt ($b_plain, $key, $b_iv);
my $cipher = unpack ('H*', $b_cipher);
my $checksum = sha256_hex ($b_plain);
my $hash = '$odf$'."*1*1*$iter*32*$checksum*16*$iv*16*$salt*0*$cipher";
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $word) = split (':', $line);
return unless defined $hash;
return unless defined $word;
my $word_packed = pack_if_HEX_notation ($word);
# tokenize
my @data = split ('\*', $hash);
return unless scalar @data == 12;
my $signature = shift @data;
my $cipher_type = shift @data;
my $cs_type = shift @data;
my $iter = shift @data;
my $cs_len = shift @data;
my $cs = shift @data;
my $iv_len = shift @data;
my $iv = shift @data;
my $salt_len = shift @data;
my $salt = shift @data;
my $unused = shift @data;
my $cipher = shift @data;
# validate
return unless $signature eq '$odf$';
return unless $cipher_type eq '1';
return unless $cs_type eq '1';
return unless $cs_len eq '32';
return unless $iv_len eq '16';
return unless $salt_len eq '16';
return unless $unused eq '0';
return unless defined $cipher;
# decrypt
my $b_iv = pack ('H*', $iv);
my $b_salt = pack ('H*', $salt);
my $b_cipher = pack ('H*', $cipher);
my $kdf = Crypt::PBKDF2->new
(
hash_class => 'HMACSHA1',
iterations => $iter,
output_len => 32
);
my $pass_hash = sha256 ($word);
my $key = $kdf->PBKDF2 ($b_salt, $pass_hash);
my $cbc = Crypt::Mode::CBC->new ('AES', 0);
my $b_plain = $cbc->decrypt ($b_cipher, $key, $b_iv);
my $plain = unpack ('H*', $b_plain);
my $new_hash = module_generate_hash ($word_packed, $salt, $iter, $iv, $plain);
return ($new_hash, $word);
}
1;