This repository has been archived by the owner on Aug 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhcchrgen.pl
303 lines (268 loc) · 10.8 KB
/
hcchrgen.pl
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use Digest::MD5;
# name.........: hcchrgen.pl
# author.......: Rub3nCT
# description..: automates the process of creating hcchr charset files for hashcat with
# different encodings for each language.
#
# requirements.:
# - iconv GNU binary, needed to convert between different encodings.
# - 'UTF8' folder must contain UTF-8 encoded files with the most common characters.
# - 'UTF8/Special' folder can contain files that also include special characters.
#
# results......:
# - 'Charsets/Standard' folder charset files will include the most common characters
# (with the corresponding encodings to each language).
# - 'Charsets/Special' folder charset files will include special characters (with the
# corresponding encodings to each language).
# - 'Charsets/Combined' folder will contain all the characters from all the encodings
# of each language merged.
# - Duplicated results are removed (different encodings wich produce the same output).
# Not for Windows!!! Probably won't have iconv...
if ($^O eq 'MSWin32') {
die " Sorry, Windows systems are not supported\n";
}
my %languages = (
Arabic => [ 'ar', [ 'cp1256', 'ISO-8859-6' ] ],
Bulgarian => [ 'bg', [ 'cp1251', 'ISO-8859-5', 'KOI8-R' ] ], # Rub3nCT
Castilian => [ 'es-ES', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # dudux & Rub3nCT
Catalan => [ 'ca', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # dudux & Rub3nCT
English => [ 'en', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # atom
French => [ 'fr', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15', ] ], # Rub3nCT
German => [ 'de', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # atom
Greek => [ 'el', [ 'cp1253', 'ISO-8859-7' ] ], # m3g9tr0n
Hungarian => [ 'hu', [ 'cp1250', 'ISO-8859-2' ] ], # Immy
Italian => [ 'it', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # Rub3nCT
Latvian => [ 'lv', [ 'cp1257', 'ISO-8859-4', 'ISO-8859-13' ] ],
Lithuanian => [ 'lt', [ 'cp1257', 'ISO-8859-4', 'ISO-8859-13' ] ], # kt819gm
Persian => [ 'fa', [ 'cp1256', 'ISO-8859-6' ] ],
Portuguese => [ 'pt', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # Rub3nCT
Polish => [ 'pl', [ 'cp1250', 'ISO-8859-2' ] ], # K4r0lSz
Romanian => [ 'ro', [ 'cp1250', 'ISO-8859-2', 'ISO-8859-16' ] ],
Russian => [ 'ru', [ 'cp1251', 'ISO-8859-5', 'KOI8-R' ] ], # Rolf
Serbian => [ 'sr', [ 'cp1250', 'ISO-8859-5' ] ],
Slovak => [ 'sk', [ 'cp1250', 'ISO-8859-2' ] ], # Kuci
Spanish => [ 'es', [ 'cp1252', 'ISO-8859-1', 'ISO-8859-15' ] ], # dudux & Rub3nCT
Ukrainian => [ 'uk', [ 'cp1251', 'ISO-8859-5', 'KOI8-U' ] ],
);
foreach my $lang (sort keys %languages) {
for ('standard', 'special', 'combined') {
foreach my $encoding (@{$languages{$lang}[1]}) {
my $ISO639 = $languages{$lang}[0];
my $sub = \&{$_};
$sub->($encoding, $ISO639, $lang);
}
}
}
if (!-d 'UTF8') {
die
" UTF8 directory not found!!!\n Please place UTF-8 language files there...\n";
}
# To store MD5 of generated files and remove duplicated results
my %charsets;
my %combined;
#
# Create Standard encoding files for each language (including the most common characters)
#
sub standard
{
my ($encoding, $ISO639, $lang) = @_;
# Only if UTF-8 file exists
if (-e "UTF8/$lang.charset") {
# Make language directory if not exists
if (!-d "Charsets/Standard/$lang") {
system "mkdir -p Charsets/Standard/$lang";
}
# Create corresponding encoding
system
"iconv UTF8/$lang.charset -c -f utf8 -t $encoding > Charsets/Standard/$lang/$ISO639"
. "_$encoding.hcchr.tmp";
# Sort and remove duplicated characters using HEX values
my $tmp = "Charsets/Standard/$lang/$ISO639" . "_$encoding.hcchr.tmp";
open my $TMP, '<', $tmp;
my $chars
= <$TMP>; # Get first line of file (always contains only one line)
close $TMP;
unlink "$tmp";
my @chars = split (//, $chars);
my @sorted = HEX (@chars);
# Print characters to file
my $charset = "Charsets/Standard/$lang/$ISO639" . "_$encoding.hcchr";
open my $FINAL, '>', $charset;
foreach my $hextring (@sorted) {
my $string = pack (qq{H*}, qq{$hextring});
printf $FINAL $string;
}
close $FINAL;
# Remove if file is duplicated (different encodings may produce the same output)
my $file = "Charsets/Standard/$lang/$ISO639" . "_$encoding.hcchr";
open my $FH, '<', $file;
binmode ($FH);
my $MD5 = Digest::MD5->new->addfile ($FH)->hexdigest;
$charsets{$MD5}++;
if ($charsets{$MD5} > 1) {
unlink "$file";
}
else {
print " [+] $ISO639"
. "_$encoding.hcchr ("
. scalar @sorted
. " characters) generated!\n";
}
# Remove empty folders (rmdir doesn't remove non empty folders)
system "rmdir Charsets/Standard/$lang 2>/dev/null";
}
}
#
# Create Special encoding files for each language (including more special characters)
#
sub special
{
my ($encoding, $ISO639, $lang) = @_;
# Only if UTF-8 file exists
if (-e "UTF8/Special/$lang.charset") {
if (!-d "Charsets/Special/$lang") {
system "mkdir -p Charsets/Special/$lang";
}
# Create corresponding encoding
system
"iconv UTF8/Special/$lang.charset -c -f utf8 -t $encoding > Charsets/Special/$lang/$ISO639"
. "_$encoding-special.hcchr.tmp";
# Sort and remove duplicated characters using HEX values
my $tmp = "Charsets/Special/$lang/$ISO639"
. "_$encoding-special.hcchr.tmp";
open my $TMP, '<', $tmp;
my $chars = <$TMP>
; # Get first line of file (will always contain only one line)
close $TMP;
unlink "$tmp";
my @chars = split (//, $chars);
my @sorted = HEX (@chars);
# Print characters to file
my $charset
= "Charsets/Special/$lang/$ISO639" . "_$encoding-special.hcchr";
open my $FINAL, '>', $charset;
foreach my $hextring (@sorted) {
my $string = pack (qq{H*}, qq{$hextring});
printf $FINAL $string;
}
close $FINAL;
# Remove if file is duplicated (different encodings may produce the same output)
my $file
= "Charsets/Special/$lang/$ISO639" . "_$encoding-special.hcchr";
open my $FH, '<', $file;
binmode ($FH);
my $MD5 = Digest::MD5->new->addfile ($FH)->hexdigest;
$charsets{$MD5}++;
if ($charsets{$MD5} > 1) {
unlink "$file"; # Delete file if is duplicated
}
else {
print " [-] $ISO639"
. "_$encoding-special.hcchr ("
. scalar @sorted
. " characters) generated!\n";
}
# Remove empty folders (rmdir doesn't remove non empty folders)
system "rmdir Charsets/Special/$lang 2>/dev/null";
}
}
#
# Combine all the generated encodings of each language and create a Combined charset
# (without duplicated characters)
#
sub combined
{
my ($encoding, $ISO639, $lang) = @_;
if (-d "Charsets/Standard/$lang") {
# Make this only one time for each language
$combined{$ISO639}++;
if ($combined{$ISO639} == 1) {
# Copy all the Standard and Special generated .hcchr
if (!-d 'Charsets/Combined/Temp') {
system 'mkdir -p Charsets/Combined/Temp';
}
system
"cp Charsets/Standard/$lang/*.hcchr Charsets/Combined/Temp";
if (-d "Charsets/Special/$lang") {
system
"cp Charsets/Special/$lang/*.hcchr Charsets/Combined/Temp";
}
system
"cat Charsets/Combined/Temp/*.hcchr > Charsets/Combined/$lang.all";
my $in = "Charsets/Combined/$lang.all";
my $out = "Charsets/Combined/$lang.hcchr";
open my $IN, '<', $in;
open my $OUT, '>', $out;
# Sort and remove duplicated characters using HEX values
my $chars = <$IN>
; # Get first line of file (always contain only one line)
close $IN;
my @chars = split (//, $chars);
my @sorted = HEX (@chars);
# Print characters to file
foreach my $hextring (@sorted) {
my $string = pack (qq{H*}, qq{$hextring});
printf $OUT $string;
}
close $OUT;
# Remove if file is duplicated (different encodings may produce the same output)
my $file = "Charsets/Combined/$lang.hcchr";
open my $FH, '<', $file;
binmode ($FH);
my $MD5 = Digest::MD5->new->addfile ($FH)->hexdigest;
$charsets{$MD5}++;
if ($charsets{$MD5} > 1) {
unlink "$file";
}
else {
print " [*] $lang.hcchr with "
. scalar @sorted
. " uniq characters generated!\n\n";
}
# Delete temporal files
system 'rm -rf Charsets/Combined/Temp 2>/dev/null';
unlink "$in";
}
}
}
#
# Remove characters already included in hashcat default charset and duplicated characters
#
sub HEX
{
my %hashcat;
my @notincluded;
my @included = (
' ', '!', '"', '#', '$', '%', '&', '\'', '(', ')',
'*', '+', ',', '-', '.', '/', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', ':', ';', '<', '=',
'>', '?', '@', '[', '\\', ']', '^', '_', '`', '{',
'|', '}', '~', 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A',
'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z'
);
# Remove characters already included in hashcat default charset
@hashcat{@included} = ();
foreach my $char (@_) {
push (@notincluded, $char) if (!exists $hashcat{$char});
}
# Remove duplicated characters (based on their HEX values)
my %seen;
my @uniq;
foreach my $string (@notincluded) {
my $hextring = unpack (q{H*}, $string);
$seen{$hextring}++;
next if $seen{$hextring} > 1;
push @uniq, $hextring;
}
# Sort characters
my @sorted = sort { $a cmp $b } @uniq;
return @sorted;
}