forked from hashcat/hashcat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathm06300.pm
178 lines (128 loc) · 3.1 KB
/
m06300.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/usr/bin/env perl
##
## Author......: See docs/credits.txt
## License.....: MIT
##
use strict;
use warnings;
use Digest::MD5 qw (md5);
sub module_constraints { [[0, 256], [0, 8], [0, 15], [0, 8], [-1, -1]] }
sub module_generate_hash
{
my $word = shift;
my $salt = shift;
my $iterations = 1000; # hard coded by the AIX format
my $hash_buf = md5_crypt ('', $iterations, $word, $salt);
return sprintf ("{smd5}%s", $hash_buf);
}
sub module_verify_hash
{
my $line = shift;
my ($hash, $word) = split (':', $line);
return unless defined $hash;
return unless defined $word;
my $index2 = index ($hash, "}");
my $index3 = rindex ($hash, "\$");
my $salt = substr ($hash, $index2 + 1, $index3 - $index2 - 1);
my $word_packed = pack_if_HEX_notation ($word);
my $new_hash = module_generate_hash ($word_packed, $salt);
return ($new_hash, $word);
}
sub md5_crypt
{
my $magic = shift;
my $iter = shift;
my $pass = shift;
my $salt = shift;
my $hash = ""; # hash to be returned by this function
my $final = md5 ($pass . $salt . $pass);
$salt = substr ($salt, 0, 8);
my $tmp = $pass . $magic . $salt;
my $pass_len = length ($pass);
my $i;
for ($i = $pass_len; $i > 0; $i -= 16)
{
my $len = 16;
if ($i < $len)
{
$len = $i;
}
$tmp .= substr ($final, 0, $len);
}
$i = $pass_len;
while ($i > 0)
{
if ($i & 1)
{
$tmp .= chr (0);
}
else
{
$tmp .= substr ($pass, 0, 1);
}
$i >>= 1;
}
$final = md5 ($tmp);
for ($i = 0; $i < $iter; $i++)
{
$tmp = "";
if ($i & 1)
{
$tmp .= $pass;
}
else
{
$tmp .= $final;
}
if ($i % 3)
{
$tmp .= $salt;
}
if ($i % 7)
{
$tmp .= $pass;
}
if ($i & 1)
{
$tmp .= $final;
}
else
{
$tmp .= $pass;
}
$final = md5 ($tmp);
}
# done
# now format the output sting ("hash")
my $hash_buf;
$hash = to64 ((ord (substr ($final, 0, 1)) << 16) | (ord (substr ($final, 6, 1)) << 8) | (ord (substr ($final, 12, 1))), 4);
$hash .= to64 ((ord (substr ($final, 1, 1)) << 16) | (ord (substr ($final, 7, 1)) << 8) | (ord (substr ($final, 13, 1))), 4);
$hash .= to64 ((ord (substr ($final, 2, 1)) << 16) | (ord (substr ($final, 8, 1)) << 8) | (ord (substr ($final, 14, 1))), 4);
$hash .= to64 ((ord (substr ($final, 3, 1)) << 16) | (ord (substr ($final, 9, 1)) << 8) | (ord (substr ($final, 15, 1))), 4);
$hash .= to64 ((ord (substr ($final, 4, 1)) << 16) | (ord (substr ($final, 10, 1)) << 8) | (ord (substr ($final, 5, 1))), 4);
$hash .= to64 (ord (substr ($final, 11, 1)), 2);
if ($iter == 1000) # default
{
$hash_buf = sprintf ("%s%s\$%s", $magic , $salt , $hash);
}
else
{
$hash_buf = sprintf ("%srounds=%i\$%s\$%s", $magic, $iter, $salt , $hash);
}
return $hash_buf;
}
sub to64
{
my $v = shift;
my $n = shift;
my $itoa64 = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
my $ret = "";
while (($n - 1) >= 0)
{
$n = $n - 1;
$ret .= substr ($itoa64, $v & 0x3f, 1);
$v = $v >> 6;
}
return $ret
}
1;