forked from hashcat/hashcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm03200.pm
74 lines (48 loc) · 1.44 KB
/
m03200.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
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Crypt::Eksblowfish::Bcrypt qw (bcrypt en_base64);
use MIME::Base64 qw (decode_base64);
sub module_constraints { [[0, 72], [16, 16], [-1, -1], [-1, -1], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iter = shift;
my $cost = "05";
if (length ($iter))
{
$cost = $iter;
}
my $hash = bcrypt ($word, sprintf ('$2a$%s$%s$', $cost, en_base64 ($salt)));
return $hash;
}
sub module_verify_hash
{
my $line = shift;
my $index1 = index ($line, ":", 33);
return if $index1 < 1;
my $hash = substr ($line, 0, $index1);
my $word = substr ($line, $index1 + 1);
my $index2 = index ($hash, "\$", 4);
my $iter = substr ($hash, 4, $index2 - 4);
my $plain_base64 = substr ($hash, $index2 + 1, 22);
# base64 mapping
my $base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
my $itoa64_2 = "./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
my $encoded = "";
for (my $i = 0; $i < length ($plain_base64); $i++)
{
my $char = substr ($plain_base64, $i, 1);
$encoded .= substr ($base64, index ($itoa64_2, $char), 1);
}
my $salt = decode_base64 ($encoded);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt, $iter);
return ($new_hash, $word);
}
1;