Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hashcat
GitHub Repository: hashcat/hashcat
Path: blob/master/tools/test.sh
13181 views
1
#!/usr/bin/env bash
2
3
##
4
## Author......: See docs/credits.txt
5
## License.....: MIT
6
##
7
8
OPTS="--quiet --potfile-disable --logfile-disable"
9
10
FORCE=0
11
RUNTIME=400
12
13
TDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
14
15
# List of TrueCrypt modes which have test containers
16
TC_MODES="6211 6212 6213 6221 6222 6223 6231 6232 6233 6241 6242 6243 29311 29312 29313 29321 29322 29323 29331 29332 29333 29341 29342 29343"
17
18
# List of VeraCrypt modes which have test containers
19
VC_MODES="13711 13712 13713 13721 13722 13723 13731 13732 13733 13741 13742 13743 13751 13752 13753 13761 13762 13763 13771 13772 13773 13781 13782 13783 29411 29412 29413 29421 29422 29423 29431 29432 29433 29441 29442 29443 29451 29452 29453 29461 29462 29463 29471 29472 29473 29481 29482 29483"
20
21
# List of modes which return a different output hash format than the input hash format
22
NOCHECK_ENCODING="16800 22000"
23
24
# List of LUKS modes which have test containers
25
LUKS1_LEGACY_MODE="14600"
26
LUKS1_MODES="29511 29512 29513 29521 29522 29523 29531 29532 29533 29541 29542 29543"
27
LUKS1_ALL_MODES="${LUKS1_LEGACY_MODE} ${LUKS1_MODES}"
28
29
# List of LUKS2 modes which have test containers
30
LUKS2_MODES="34100"
31
32
LUKS_MODES="${LUKS1_MODES} ${LUKS2_MODES}"
33
34
# Cryptoloop mode which have test containers
35
CL_MODES="14511 14512 14513 14521 14522 14523 14531 14532 14533 14541 14542 14543 14551 14552 14553"
36
37
HASH_TYPES=$(ls "${TDIR}"/test_modules/*.pm | sed -E 's/.*m0*([0-9]+).pm/\1/')
38
HASH_TYPES="${HASH_TYPES} ${TC_MODES} ${VC_MODES} ${LUKS1_ALL_MODES} ${LUKS2_MODES} ${CL_MODES}"
39
HASH_TYPES=$(echo -n "${HASH_TYPES}" | tr ' ' '\n' | sort -u -n | tr '\n' ' ')
40
41
VECTOR_WIDTHS="1 2 4 8 16"
42
43
KEEP_GUESSING=$(grep -l OPTS_TYPE_SUGGEST_KG "${TDIR}"/../src/modules/module_*.c | sed -E 's/.*module_0*([0-9]+).c/\1/' | tr '\n' ' ')
44
HASHFILE_ONLY=$(grep -l OPTS_TYPE_BINARY_HASHFILE "${TDIR}"/../src/modules/module_*.c | sed -E 's/.*module_0*([0-9]+).c/\1/' | tr '\n' ' ')
45
SLOW_ALGOS=$( grep -l ATTACK_EXEC_OUTSIDE_KERNEL "${TDIR}"/../src/modules/module_*.c | sed -E 's/.*module_0*([0-9]+).c/\1/' | tr '\n' ' ')
46
47
# fake slow algos, due to specific password pattern (e.g. ?d from "mask_3" is invalid):
48
# ("only" drawback is that just -a 0 is tested with this workaround)
49
50
SLOW_ALGOS="${SLOW_ALGOS} 28501 28502 28503 28504 28505 28506 30901 30902 30903 30904 30905 30906 34700"
51
52
OUTD="test_$(date +%s)"
53
54
PACKAGE_CMD="7z a"
55
PACKAGE_FOLDER=""
56
57
EXTRACT_CMD="7z x"
58
59
mask_3[0]=""
60
mask_3[1]="?d"
61
mask_3[2]="?d?d"
62
mask_3[3]="?d?d?d"
63
mask_3[4]="?d?d?d?d"
64
mask_3[5]="?d?d?d?d?d"
65
mask_3[6]="?d?d?d?d?d?d"
66
mask_3[7]="?d?d?d?d?d?d?d"
67
mask_3[8]="?d?d?d?d?d?d?d?d"
68
mask_3[9]="?d?d?d?d?d?d?d?d?d"
69
mask_3[10]="?d?d?d?d?d?d?d?d?d?d"
70
mask_3[11]="?d?d?d?d?d?d?d?d?d?d?d"
71
mask_3[12]="?d?d?d?d?d?d?d?d?d?d?d?d"
72
mask_3[13]="?d?d?d?d?d?d?d?d?d?d?d?d?d"
73
mask_3[14]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d"
74
mask_3[15]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d"
75
mask_3[16]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d0"
76
mask_3[17]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d00"
77
mask_3[18]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d000"
78
mask_3[19]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d0000"
79
mask_3[20]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d00000"
80
mask_3[21]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d000000"
81
mask_3[22]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d0000000"
82
mask_3[23]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d00000000"
83
mask_3[24]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d000000000"
84
mask_3[25]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d0000000000"
85
mask_3[26]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d00000000000"
86
mask_3[27]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d000000000000"
87
mask_3[28]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d0000000000000"
88
mask_3[29]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d00000000000000"
89
mask_3[30]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d000000000000000"
90
mask_3[31]="?d?d?d?d?d?d?d?d?d?d?d?d?d?d?d0000000000000000"
91
92
mask_6[0]=""
93
mask_6[1]=""
94
mask_6[2]="?d"
95
mask_6[3]="?d?d"
96
mask_6[4]="?d?d"
97
mask_6[5]="?d?d?d"
98
mask_6[6]="?d?d?d"
99
mask_6[7]="?d?d?d?d"
100
mask_6[8]="?d?d?d?d"
101
mask_6[9]="?d?d?d?d?d"
102
mask_6[10]="?d?d?d?d?d"
103
mask_6[11]="?d?d?d?d?d?d"
104
mask_6[12]="?d?d?d?d?d?d"
105
mask_6[13]="?d?d?d?d?d?d?d"
106
mask_6[14]="?d?d?d?d?d?d?d"
107
mask_6[15]="?d?d?d?d?d?d?d?d"
108
mask_6[16]="?d?d?d?d?d?d?d?d"
109
mask_6[17]="?d?d?d?d?d?d?d?d0"
110
mask_6[18]="?d?d?d?d?d?d?d?d0"
111
mask_6[19]="?d?d?d?d?d?d?d?d00"
112
mask_6[20]="?d?d?d?d?d?d?d?d00"
113
mask_6[21]="?d?d?d?d?d?d?d?d000"
114
mask_6[22]="?d?d?d?d?d?d?d?d000"
115
mask_6[23]="?d?d?d?d?d?d?d?d0000"
116
mask_6[24]="?d?d?d?d?d?d?d?d0000"
117
mask_6[25]="?d?d?d?d?d?d?d?d00000"
118
mask_6[26]="?d?d?d?d?d?d?d?d00000"
119
mask_6[27]="?d?d?d?d?d?d?d?d000000"
120
mask_6[28]="?d?d?d?d?d?d?d?d000000"
121
mask_6[29]="?d?d?d?d?d?d?d?d0000000"
122
mask_6[30]="?d?d?d?d?d?d?d?d0000000"
123
mask_6[31]="?d?d?d?d?d?d?d?d00000000"
124
125
mask_7[0]=""
126
mask_7[1]=""
127
mask_7[2]="?d"
128
mask_7[3]="?d"
129
mask_7[4]="?d?d"
130
mask_7[5]="?d?d"
131
mask_7[6]="?d?d?d"
132
mask_7[7]="?d?d?d"
133
mask_7[8]="?d?d?d?d"
134
mask_7[9]="?d?d?d?d"
135
mask_7[10]="?d?d?d?d?d"
136
mask_7[11]="?d?d?d?d?d"
137
mask_7[12]="?d?d?d?d?d?d"
138
mask_7[13]="?d?d?d?d?d?d"
139
mask_7[14]="?d?d?d?d?d?d?d"
140
mask_7[15]="?d?d?d?d?d?d?d"
141
mask_7[16]="?d?d?d?d?d?d?d?d"
142
mask_7[17]="?d?d?d?d?d?d?d?d"
143
mask_7[18]="?d?d?d?d?d?d?d?d0"
144
mask_7[19]="?d?d?d?d?d?d?d?d0"
145
mask_7[20]="?d?d?d?d?d?d?d?d00"
146
mask_7[21]="?d?d?d?d?d?d?d?d00"
147
mask_7[22]="?d?d?d?d?d?d?d?d000"
148
mask_7[23]="?d?d?d?d?d?d?d?d000"
149
mask_7[24]="?d?d?d?d?d?d?d?d0000"
150
mask_7[25]="?d?d?d?d?d?d?d?d0000"
151
mask_7[26]="?d?d?d?d?d?d?d?d00000"
152
mask_7[27]="?d?d?d?d?d?d?d?d00000"
153
mask_7[28]="?d?d?d?d?d?d?d?d000000"
154
mask_7[29]="?d?d?d?d?d?d?d?d000000"
155
mask_7[30]="?d?d?d?d?d?d?d?d0000000"
156
mask_7[31]="?d?d?d?d?d?d?d?d0000000"
157
158
# Array lookup
159
# $1: value
160
# $2: array
161
# Returns 0 (SUCCESS) if the value is found, 1 otherwise
162
163
function is_in_array()
164
{
165
for e in "${@:2}"; do
166
[ "$e" = "$1" ] && return 0
167
done
168
169
return 1
170
}
171
172
function has_multi_hash()
173
{
174
# no multi hash checks for these modes (because we only have 1 hash for each of them)
175
if [ "${hash_type}" -eq 14000 ]; then
176
return 0;
177
elif [ "${hash_type}" -eq 14100 ]; then
178
return 0;
179
elif [ "${hash_type}" -eq 14600 ]; then
180
return 0;
181
elif [ "${hash_type}" -eq 14900 ]; then
182
return 0;
183
elif [ "${hash_type}" -eq 15400 ]; then
184
return 0;
185
fi
186
187
# all other modes have multi hash
188
return 1;
189
}
190
function init()
191
{
192
if [ "${PACKAGE}" -eq 1 ]; then
193
echo "[ ${OUTD} ] > Generate tests for hash type $hash_type."
194
else
195
echo "[ ${OUTD} ] > Init test for hash type $hash_type."
196
fi
197
198
rm -rf "${OUTD}/${hash_type}.sh" "${OUTD}/${hash_type}_passwords.txt" "${OUTD}/${hash_type}_hashes.txt"
199
200
# Exclude TrueCrypt, VeraCrypt and CryptoLoop testing modes
201
if is_in_array "${hash_type}" ${TC_MODES}; then
202
return 0
203
fi
204
if is_in_array "${hash_type}" ${VC_MODES}; then
205
return 0
206
fi
207
if is_in_array "${hash_type}" ${CL_MODES}; then
208
return 0
209
fi
210
211
if { is_in_array "$hash_type" ${LUKS1_ALL_MODES} || is_in_array "$hash_type" ${LUKS2_MODES}; } && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ; then
212
which 7z &>/dev/null
213
if [ $? -eq 1 ]; then
214
echo "ATTENTION: 7z is missing. Skipping download and extract luks test files."
215
return 0
216
fi
217
fi
218
219
#LUKS1
220
if is_in_array "$hash_type" ${LUKS1_ALL_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ; then
221
luks_tests_folder="${TDIR}/luks_tests/"
222
223
if [ ! -d "${luks_tests_folder}" ]; then
224
mkdir -p "${luks_tests_folder}"
225
fi
226
227
luks_first_test_file="${luks_tests_folder}/hashcat_ripemd160_aes_cbc-essiv_128.luks"
228
229
if [ ! -f "${luks_first_test_file}" ]; then
230
luks_tests="hashcat_luks_testfiles.7z"
231
luks_tests_url="https://hashcat.net/misc/example_hashes/${luks_tests}"
232
233
cd "${TDIR}" || exit
234
235
# if the file already exists, but was not successfully extracted, we assume it's a broken
236
# downloaded file and therefore it should be deleted
237
238
if [ -f "${luks_tests}" ]; then
239
rm -f "${luks_tests}"
240
fi
241
242
echo ""
243
echo "ATTENTION: the luks test files (for -m ${hash_type}) are currently missing on your system."
244
echo "They will be fetched from ${luks_tests_url}"
245
echo "Note: this needs to be done only once and could take a little bit to download/extract."
246
echo "These luks test files are not shipped directly with hashcat because the file sizes are"
247
echo "particularly large and therefore a bandwidth burner for users who do not run these tests."
248
echo ""
249
250
# download:
251
wget -q "${luks_tests_url}"
252
253
if [ $? -ne 0 ] || [ ! -f "${luks_tests}" ]; then
254
cd - >/dev/null
255
echo "ERROR: Could not fetch the luks test files from this url: ${luks_tests_url}"
256
return 0
257
fi
258
259
# extract:
260
261
${EXTRACT_CMD} "${luks_tests}" &>/dev/null
262
263
# cleanup:
264
265
rm -f "${luks_tests}"
266
cd - >/dev/null || exit
267
268
# just to be very sure, check again that (one of) the files now exist:
269
270
if [ ! -f "${luks_first_test_file}" ]; then
271
echo "ERROR: downloading and extracting ${luks_tests} into ${luks_tests_folder} did not complete successfully"
272
return 0
273
fi
274
fi
275
276
return 0
277
fi
278
279
280
#LUKS2
281
if is_in_array "$hash_type" ${LUKS2_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
282
luks2_tests_folder="${TDIR}/luks2_tests/"
283
284
if [ ! -d "${luks2_tests_folder}" ]; then
285
mkdir -p "${luks2_tests_folder}"
286
fi
287
288
luks2_first_test_file="${luks2_tests_folder}/luks2-aes-argon2id-t4-m16-p1-size20MiB.img"
289
290
if [ ! -f "${luks2_first_test_file}" ]; then
291
luks2_tests="luks2_tests.7z"
292
luks2_tests_url="https://hashcat.net/misc/example_hashes/${luks2_tests}"
293
294
cd "${TDIR}" || exit
295
296
# if the file already exists, but was not successfully extracted, we assume it's a broken
297
# downloaded file and therefore it should be deleted
298
299
if [ -f "${luks2_tests}" ]; then
300
rm -f "${luks2_tests}"
301
fi
302
303
echo ""
304
echo "ATTENTION: the luks2 test files (for -m ${hash_type}) are currently missing on your system."
305
echo "They will be fetched from ${luks2_tests_url}"
306
echo "Note: this needs to be done only once and could take a little bit to download/extract."
307
echo "These luks2 test files are not shipped directly with hashcat because the file sizes are"
308
echo "particularly large and therefore a bandwidth burner for users who do not run these tests."
309
echo ""
310
311
# download:
312
wget -q "${luks2_tests_url}"
313
314
if [ $? -ne 0 ] || [ ! -f "${luks2_tests}" ]; then
315
cd - >/dev/null
316
echo "ERROR: Could not fetch the luks2 test files from this url: ${luks2_tests_url}"
317
return 0
318
fi
319
320
# extract:
321
322
${EXTRACT_CMD} "${luks2_tests}" &>/dev/null
323
324
# cleanup:
325
326
rm -f "${luks2_tests}"
327
cd - >/dev/null || exit
328
329
# just to be very sure, check again that (one of) the files now exist:
330
331
if [ ! -f "${luks2_first_test_file}" ]; then
332
echo "ERROR: downloading and extracting ${luks2_tests} into ${luks2_tests_folder} did not complete successfully"
333
return 0
334
fi
335
fi
336
337
return 0 #which means this has been a success, we don't want to execute the remainder of this function
338
fi
339
340
# create list of password and hashes of same type
341
cmd_file=${OUTD}/${hash_type}.sh
342
343
grep " ${hash_type} '" "${OUTD}/all.sh" > "${cmd_file}" 2>/dev/null
344
345
# create separate list of password and hashes
346
sed 's/^echo *|.*$//' "${cmd_file}" | awk '{print $2}' > "${OUTD}/${hash_type}_passwords.txt"
347
sed 's/^echo *|/echo "" |/' "${cmd_file}" | awk '{t="";for(i=10;i<=NF;i++){if(t){t=t" "$i}else{t=$i}};print t}' | cut -d"'" -f2 > "${OUTD}/${hash_type}_hashes.txt"
348
349
if is_in_array "${hash_type}" ${LUKS_MODES}; then
350
# 34100 LUKS2 dynamically generates filenames, we need to cat those to get the hashes
351
mv "${OUTD}/${hash_type}_hashes.txt" "${OUTD}/${hash_type}_hashes.tmp"
352
cat "${OUTD}/${hash_type}_hashes.tmp" | while read f; do cat $f; done > "${OUTD}/${hash_type}_hashes.txt"
353
rm "${OUTD}/${hash_type}_hashes.tmp"
354
fi
355
356
if [ "${hash_type}" -eq 10300 ]; then
357
#cat ${OUTD}/${hash_type}.sh | cut -d' ' -f11- | cut -d"'" -f2 > ${OUTD}/${hash_type}_hashes.txt
358
cut -d"'" -f2 "${OUTD}/${hash_type}.sh" > "${OUTD}/${hash_type}_hashes.txt"
359
fi
360
361
# truncate dicts
362
rm -rf "${OUTD}/${hash_type}_dict1" "${OUTD}/${hash_type}_dict2"
363
touch "${OUTD}/${hash_type}_dict1" "${OUTD}/${hash_type}_dict2"
364
365
# minimum password length
366
367
min=1 # minimum line number from start of the file
368
min_offset=0 # minimum offset starting from ${min} lines
369
370
if [ "${hash_type}" -eq 2500 ]; then
371
min_offset=7 # means length 8, since we start with 0
372
elif [ "${hash_type}" -eq 14000 ]; then
373
min=0
374
min_offset=4
375
elif [ "${hash_type}" -eq 14100 ]; then
376
min=0
377
min_offset=3
378
elif [ "${hash_type}" -eq 14900 ]; then
379
min=0
380
min_offset=5
381
elif [ "${hash_type}" -eq 15400 ]; then
382
min=0
383
min_offset=3
384
elif [ "${hash_type}" -eq 16800 ]; then
385
min_offset=7 # means length 8, since we start with 0
386
elif [ "${hash_type}" -eq 22000 ]; then
387
min_offset=7 # means length 8, since we start with 0
388
fi
389
390
# foreach password entry split password in 2 (skip first entry, is len 1)
391
392
i=1
393
394
while read -r -u 9 pass; do
395
396
if [ ${i} -gt ${min} ]; then
397
398
# split password, 'i' is the len
399
p0=$((i / 2))
400
p1=$((p0 + 1))
401
402
# special case (passwords longer than expected)
403
pass_len=${#pass}
404
405
if [ "${pass_len}" -gt 1 ]; then
406
407
p1=$((p1 + min_offset))
408
p0=$((p0 + min_offset))
409
410
if [ "${p1}" -gt "${pass_len}" ]; then
411
p1=${pass_len}
412
p0=$((p1 - 1))
413
fi
414
415
# add splitted password to dicts
416
echo "${pass}" | cut -c -${p0} >> "${OUTD}/${hash_type}_dict1"
417
echo "${pass}" | cut -c ${p1}- >> "${OUTD}/${hash_type}_dict2"
418
elif [ "${pass_len}" -eq 1 ]; then
419
echo "${pass}" >> "${OUTD}/${hash_type}_dict1"
420
echo >> "${OUTD}/${hash_type}_dict2"
421
else
422
echo >> "${OUTD}/${hash_type}_dict1"
423
echo >> "${OUTD}/${hash_type}_dict2"
424
fi
425
426
fi
427
428
i=$((i + 1))
429
430
done 9< "${OUTD}/${hash_type}_passwords.txt"
431
432
min_len=0
433
fixed_len=0
434
435
if [ "${hash_type}" -eq 2500 ]; then
436
min_len=7 # means length 8, since we start with 0
437
elif [ "${hash_type}" -eq 14000 ]; then
438
min_len=7
439
elif [ "${hash_type}" -eq 14100 ]; then
440
min_len=23
441
elif [ "${hash_type}" -eq 14900 ]; then
442
min_len=9
443
elif [ "${hash_type}" -eq 15400 ]; then
444
min_len=31
445
elif [ "${hash_type}" -eq 16800 ]; then
446
min_len=7 # means length 8, since we start with 0
447
elif [ "${hash_type}" -eq 22000 ]; then
448
min_len=7 # means length 8, since we start with 0
449
elif [ "${hash_type}" -eq 33500 ]; then
450
fixed_len=5
451
elif [ "${hash_type}" -eq 33501 ]; then
452
min_len=5
453
fixed_len=9
454
elif [ "${hash_type}" -eq 33502 ]; then
455
min_len=5
456
fixed_len=13
457
fi
458
459
# generate multiple pass/hash foreach len (2 to 8)
460
if [ "${MODE}" -ge 1 ]; then
461
462
# no multi hash checks for these modes (because we only have 1 hash for each of them)
463
! has_multi_hash || return
464
465
i=2
466
467
while [ "$i" -lt 9 ]; do
468
469
cmd_file=${OUTD}/${hash_type}_multi_${i}.txt
470
471
rm -rf "${cmd_file}" "${OUTD}/${hash_type}_passwords_multi_${i}.txt" "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
472
rm -rf "${OUTD}/${hash_type}_dict1_multi_${i}" "${OUTD}/${hash_type}_dict2_multi_${i}"
473
touch "${OUTD}/${hash_type}_dict1_multi_${i}" "${OUTD}/${hash_type}_dict2_multi_${i}"
474
475
if [ "${fixed_len}" -ne 0 ]; then
476
if [ "${fixed_len}" -eq "${i}" ]; then
477
perl tools/test.pl single "${hash_type}" ${i} > "${cmd_file}"
478
else
479
perl tools/test.pl single "${hash_type}" ${fixed_len} > "${cmd_file}"
480
fi
481
else
482
perl tools/test.pl single "${hash_type}" ${i} > "${cmd_file}"
483
fi
484
485
sed 's/^echo *|.*$//' "${cmd_file}" | awk '{print $2}' > "${OUTD}/${hash_type}_passwords_multi_${i}.txt"
486
sed 's/^echo *|/echo "" |/' "${cmd_file}" | awk '{t="";for(i=10;i<=NF;i++){if(t){t=t" "$i}else{t=$i}};print t}' | cut -d"'" -f2 > "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
487
488
if is_in_array "${hash_type}" ${LUKS_MODES}; then
489
mv "${OUTD}/${hash_type}_hashes_multi_${i}.txt" "${OUTD}/${hash_type}_hashes_multi_${i}.tmp"
490
cat "${OUTD}/${hash_type}_hashes_multi_${i}.tmp" | while read f; do cat $f; done > "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
491
rm "${OUTD}/${hash_type}_hashes_multi_${i}.tmp"
492
fi
493
494
if [ "${hash_type}" -eq 10300 ]; then
495
#cat ${OUTD}/${hash_type}_multi_${i}.txt | cut -d' ' -f11- | cut -d"'" -f2 > ${OUTD}/${hash_type}_hashes_multi_${i}.txt
496
cut -d"'" -f2 "${OUTD}/${hash_type}_multi_${i}.txt" > "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
497
fi
498
499
# split password, 'i' is the len
500
p0=$((i / 2))
501
p1=$((p0 + 1))
502
503
p0=$((p0 + min_len))
504
p1=$((p1 + min_len))
505
506
while read -r -u 9 pass; do
507
508
# add splitted password to dicts
509
echo "${pass}" | cut -c -${p0} >> "${OUTD}/${hash_type}_dict1_multi_${i}"
510
echo "${pass}" | cut -c ${p1}- >> "${OUTD}/${hash_type}_dict2_multi_${i}"
511
512
done 9< "${OUTD}/${hash_type}_passwords_multi_${i}.txt"
513
514
i=$((i + 1))
515
516
done
517
518
fi
519
}
520
521
function status()
522
{
523
RET=$1
524
525
cnt=$((cnt + 1))
526
527
if [ "${RET}" -ne 0 ]; then
528
case ${RET} in
529
246)
530
echo "autotune failure, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
531
532
e_rs=$((e_rs + 1))
533
;;
534
535
248)
536
echo "skipped by runtime (mixed backend errors detected), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
537
538
e_rs=$((e_rs + 1))
539
;;
540
541
249)
542
echo "skipped by runtime (Invalid module_extra_buffer_size), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
543
544
e_rs=$((e_rs + 1))
545
;;
546
547
250)
548
echo "skipped by runtime (Too many compute units to keep minimum kernel accel limit), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
549
550
e_rs=$((e_rs + 1))
551
;;
552
553
251)
554
echo "skipped by runtime (main kernel build error), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
555
556
e_rs=$((e_rs + 1))
557
;;
558
559
252)
560
echo "skipped by runtime (memory hit limit), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
561
562
e_rs=$((e_rs + 1))
563
;;
564
565
253)
566
echo "skipped by runtime (module_unstable_warning), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
567
568
e_rs=$((e_rs + 1))
569
;;
570
571
1)
572
# next check should not be needed anymore (NEVER_CRACK with exit code EXHAUSTED):
573
# if is_in_array "${hash_type}" ${KEEP_GUESSING_ALGOS}; then
574
# return
575
# fi
576
577
echo "password not found, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
578
e_nf=$((e_nf + 1))
579
;;
580
581
4)
582
echo "timeout reached, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
583
584
e_to=$((e_to + 1))
585
;;
586
587
10)
588
if is_in_array "${hash_type}" ${KEEP_GUESSING_ALGOS}; then
589
return
590
fi
591
592
if [ "${pass_only}" -eq 1 ]; then
593
echo "plains not found in output, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
594
else
595
echo "hash:plains not matched in output, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.tx"t
596
fi
597
598
e_nm=$((e_nm + 1))
599
;;
600
601
20)
602
echo "grep out-of-memory (cannot check if plains match in output), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
603
604
e_ce=$((e_ce + 1))
605
e_nm=$((e_nm + 1))
606
;;
607
608
30)
609
echo "luks test files are missing, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
610
611
e_rs=$((e_rs + 1))
612
;;
613
614
*)
615
echo "! unhandled return code ${RET}, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
616
echo "! unhandled return code, see ${OUTD}/logfull.txt or ${OUTD}/test_report.log for details."
617
618
e_nf=$((e_nf + 1))
619
;;
620
621
esac
622
fi
623
}
624
625
function attack_0()
626
{
627
file_only=0
628
629
if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then
630
file_only=1
631
fi
632
633
# single hash
634
if [ "${MODE}" -ne 1 ]; then
635
636
e_ce=0
637
e_rs=0
638
e_to=0
639
e_nf=0
640
e_nm=0
641
cnt=0
642
643
echo "> Testing hash type $hash_type with attack mode 0, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
644
645
max=32
646
647
if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then
648
max=12
649
fi
650
651
i=0
652
653
while read -r -u 9 line; do
654
655
if [ "${i}" -ge ${max} ]; then
656
break
657
fi
658
659
hash="$(echo "${line}" | cut -d\' -f2)"
660
pass="$(echo "${line}" | cut -d' ' -f2)"
661
662
if [ -z "${hash}" ]; then
663
break
664
fi
665
666
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
667
668
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
669
670
if [ "${hash_type}" -ne 22000 ]; then
671
echo "${hash}" | base64 -d > "${temp_file}"
672
else
673
echo "${hash}" > "${temp_file}"
674
fi
675
676
hash="${temp_file}"
677
678
fi
679
680
pass_old=${pass}
681
682
if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key
683
pass=$(echo "${pass}" | cut -b 7-) # skip the first 6 chars
684
fi
685
686
CMD="echo ${pass} | ./${BIN} ${OPTS} -a 0 -m ${hash_type} '${hash}'"
687
688
echo -n "[ len $((i + 1)) ] " >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
689
690
output=$(echo "${pass}" | ./${BIN} ${OPTS} -a 0 -m ${hash_type} "${hash}" 2>&1)
691
692
ret=${?}
693
694
pass=${pass_old}
695
696
echo "${output}" >> "${OUTD}/logfull.txt"
697
698
if [ "${ret}" -eq 0 ]; then
699
if ! (is_in_array "${hash_type}" ${LUKS_MODES}); then
700
if [ "${pass_only}" -eq 1 ]; then
701
search=":${pass}"
702
else
703
search="${hash}:${pass}"
704
fi
705
706
echo "${output}" | grep -F "${search}" &>/dev/null
707
newRet=$?
708
fi
709
710
if [[ "${newRet}" -eq 2 ]]; then
711
# out-of-memory, workaround
712
713
if is_in_array "${hash_type}" ${LUKS_MODES}; then
714
search="$(cat ${hash} | tr -d '\n'):${pass}" #hash is a filename for 34100
715
echo "${output}" | grep -E '^\$luks\$' | head -1 > tmp_file_out #cracked hash from hashcat output
716
else
717
echo "${output}" | grep -v "^Unsupported\|^$" | head -1 > tmp_file_out #cracked hash from hashcat output
718
fi
719
720
echo "${search}" > tmp_file_search
721
722
# echo -e "head tmp_file_out=\t$(cat tmp_file_out | head -c80)"
723
# echo -e "head tmp_file_search=\t$(cat tmp_file_search | head -c80)"
724
# echo -e "tail tmp_file_out=\t$(cat tmp_file_out | tail -c80)"
725
# echo -e "tail tmp_file_search=\t$(cat tmp_file_search | tail -c80)"
726
out_md5=$(md5sum tmp_file_out | cut -d' ' -f1)
727
search_md5=$(md5sum tmp_file_search | cut -d' ' -f1)
728
# echo -e "out_md5=\t$out_md5"
729
# echo -e "search_md5=\t$search_md5"
730
# echo ""
731
732
rm tmp_file_out tmp_file_search
733
734
if [ "${out_md5}" == "${search_md5}" ]; then
735
newRet=0
736
else
737
newRet=10
738
fi
739
fi
740
741
if [[ "${newRet}" -ne 0 ]]; then
742
if [ "${newRet}" -eq 2 ]; then
743
ret=20
744
else
745
ret=10
746
fi
747
fi
748
749
fi
750
751
status ${ret}
752
753
i=$((i + 1))
754
755
done 9< "${OUTD}/${hash_type}.sh"
756
757
msg="OK"
758
759
if [ "${e_ce}" -ne 0 ]; then
760
msg="Compare Error"
761
elif [ "${e_rs}" -ne 0 ]; then
762
msg="Skip"
763
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
764
msg="Error"
765
elif [ "${e_to}" -ne 0 ]; then
766
msg="Warning"
767
fi
768
769
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 0, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
770
fi
771
772
# multihash
773
if [ "${MODE}" -ne 0 ]; then
774
775
# no multi hash checks for these modes (because we only have 1 hash for each of them)
776
! has_multi_hash || return
777
778
e_ce=0
779
e_rs=0
780
e_to=0
781
e_nf=0
782
e_nm=0
783
cnt=0
784
785
echo "> Testing hash type $hash_type with attack mode 0, markov ${MARKOV}, multi hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
786
787
hash_file=${OUTD}/${hash_type}_hashes.txt
788
789
# if file_only -> decode all base64 "hashes" and put them in the temporary file
790
791
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
792
793
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
794
rm -f "${temp_file}"
795
796
hash_file=${temp_file}
797
798
while read -r file_only_hash; do
799
800
if [ "${hash_type}" -ne 22000 ]; then
801
echo -n "${file_only_hash}" | base64 -d >> "${temp_file}"
802
else
803
echo "${file_only_hash}" >> "${temp_file}"
804
fi
805
806
done < "${OUTD}/${hash_type}_hashes.txt"
807
808
fi
809
810
CMD="cat ${OUTD}/${hash_type}_passwords.txt | ./${BIN} ${OPTS} -a 0 -m ${hash_type} ${hash_file}"
811
812
output=$(./${BIN} ${OPTS} -a 0 -m ${hash_type} ${hash_file} < ${OUTD}/${hash_type}_passwords.txt 2>&1)
813
814
ret=${?}
815
816
echo "${output}" >> "${OUTD}/logfull.txt"
817
818
if [ "${ret}" -eq 0 ]; then
819
820
i=1
821
822
while read -r -u 9 hash; do
823
824
pass=$(sed -n ${i}p "${OUTD}/${hash_type}_passwords.txt")
825
826
if is_in_array "${hash_type}" ${LUKS_MODES}; then
827
if [ "${pass_only}" -eq 1 ]; then
828
search=":${pass}"
829
else
830
search="${hash}:${pass}"
831
fi
832
833
echo "${output}" | grep -F "${search}" &>/dev/null
834
835
newRet=$?
836
fi
837
838
if is_in_array "${hash_type}" ${LUKS_MODES}; then
839
search="$(echo ${hash} | tr -d '\n'):${pass}" #hash is read from file already
840
to_search_in_out="$(echo ${hash} | head -c 200)"
841
echo "${output}" | grep -F "$to_search_in_out" | head -1 > tmp_file_out #cracked hash from hashcat output
842
echo "${search}" > tmp_file_search
843
844
# echo -e "head tmp_file_out=\t$(cat tmp_file_out | head -c80)"
845
# echo -e "head tmp_file_search=\t$(cat tmp_file_search | head -c80)"
846
# echo -e "tail tmp_file_out=\t$(cat tmp_file_out | tail -c80)"
847
# echo -e "tail tmp_file_search=\t$(cat tmp_file_search | tail -c80)"
848
out_md5=$(md5sum tmp_file_out | cut -d' ' -f1)
849
search_md5=$(md5sum tmp_file_search | cut -d' ' -f1)
850
# echo -e "out_md5=\t$out_md5"
851
# echo -e "search_md5=\t$search_md5"
852
# echo ""
853
854
rm tmp_file_out tmp_file_search
855
856
if [ "${out_md5}" == "${search_md5}" ]; then
857
newRet=0
858
else
859
newRet=10
860
fi
861
fi
862
863
if [ "${newRet}" -ne 0 ]; then
864
if [ "${newRet}" -eq 2 ]; then
865
ret=20
866
else
867
ret=10
868
fi
869
870
break
871
fi
872
873
i=$((i + 1))
874
875
done 9< "${OUTD}/${hash_type}_hashes.txt"
876
877
fi
878
879
status ${ret}
880
881
msg="OK"
882
883
if [ "${e_ce}" -ne 0 ]; then
884
msg="Compare Error"
885
elif [ "${e_rs}" -ne 0 ]; then
886
msg="Skip"
887
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
888
msg="Error"
889
elif [ "${e_to}" -ne 0 ]; then
890
msg="Warning"
891
fi
892
893
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 0, Mode multi, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
894
fi
895
}
896
897
function attack_1()
898
{
899
file_only=0
900
901
if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then
902
file_only=1
903
fi
904
905
# single hash
906
if [ "${MODE}" -ne 1 ]; then
907
908
e_ce=0
909
e_rs=0
910
e_to=0
911
e_nf=0
912
e_nm=0
913
cnt=0
914
915
min=1
916
max=8
917
918
if [ "${hash_type}" -eq 14000 ]; then
919
min=0
920
max=5
921
elif [ "${hash_type}" -eq 14100 ]; then
922
min=0
923
max=5
924
elif [ "${hash_type}" -eq 14900 ]; then
925
min=0
926
max=5
927
elif [ "${hash_type}" -eq 15400 ]; then
928
min=0
929
max=5
930
elif [ "${hash_type}" -eq 20510 ]; then
931
min=2
932
fi
933
934
echo "> Testing hash type $hash_type with attack mode 1, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
935
936
i=1
937
while read -r -u 9 hash; do
938
939
if [ $i -gt ${min} ]; then
940
941
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
942
943
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
944
945
if [ "${hash_type}" -ne 22000 ]; then
946
echo "${hash}" | base64 -d > "${temp_file}"
947
else
948
echo "${hash}" > "${temp_file}"
949
fi
950
951
hash="${temp_file}"
952
953
fi
954
955
line_nr=1
956
957
if [ "$min" -eq 0 ]; then
958
line_nr=$i
959
elif [ "${i}" -gt 1 ]; then
960
line_nr=$((i - 1))
961
fi
962
963
dict1="${OUTD}/${hash_type}_dict1"
964
dict2="${OUTD}/${hash_type}_dict2"
965
966
if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key
967
line_dict1=$(sed -n ${line_nr}p "${dict1}")
968
line_dict2=$(sed -n ${line_nr}p "${dict2}")
969
line_num=$(wc -l "${dict1}" | sed -E 's/ *([0-9]+) .*$/\1/')
970
971
line_dict1_orig=${line_dict1}
972
line_dict2_orig=${line_dict2}
973
974
if [ "${#line_dict1}" -ge 6 ]; then
975
line_dict1=$(echo "${line_dict1}" | cut -b 7-) # skip the first 6 chars
976
else
977
# we need to also "steal" some chars from the second dict
978
num_to_steal=$((6 - ${#line_dict1}))
979
num_steal_start=$((num_to_steal + 1))
980
981
if [ "${#line_dict2}" -ge 6 ]; then
982
num_to_steal_new=$(((${#line_dict2} - num_to_steal) / 2))
983
984
if [ "${num_to_steal_new}" -gt ${num_to_steal} ]; then
985
num_to_steal=${num_to_steal_new}
986
fi
987
fi
988
989
line_chars_stolen=$(echo "${line_dict2}" | cut -b -${num_to_steal} | cut -b ${num_steal_start}-)
990
991
line_dict1="${line_chars_stolen}"
992
line_dict2=$(echo "${line_dict2}" | cut -b $((num_to_steal + 1))-)
993
fi
994
995
# finally, modify the dicts accordingly:
996
997
tmp_file="${dict1}_mod"
998
head -n $((line_nr - 1)) "${dict1}" > "${tmp_file}"
999
echo "${line_dict1}" >> "${tmp_file}"
1000
tail -n $((line_num - line_nr - 1)) "${dict1}" >> "${tmp_file}"
1001
1002
dict1=${tmp_file}
1003
1004
tmp_file="${dict2}_mod"
1005
1006
head -n $((line_nr - 1)) "${dict2}" > "${tmp_file}"
1007
echo "${line_dict2}" >> "${tmp_file}"
1008
tail -n $((line_num - line_nr - 1)) "${dict2}" >> "${tmp_file}"
1009
1010
dict2=${tmp_file}
1011
fi
1012
1013
CMD="./${BIN} ${OPTS} -a 1 -m ${hash_type} '${hash}' ${dict1} ${dict2}"
1014
1015
echo -n "[ len $i ] " >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1016
1017
output=$(./${BIN} ${OPTS} -a 1 -m ${hash_type} "${hash}" ${dict1} ${dict2} 2>&1)
1018
1019
ret=${?}
1020
1021
echo "${output}" >> "${OUTD}/logfull.txt"
1022
1023
if [ "${ret}" -eq 0 ]; then
1024
1025
line_dict1=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict1")
1026
line_dict2=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict2")
1027
1028
if [ "${pass_only}" -eq 1 ]; then
1029
search=":${line_dict1}${line_dict2}"
1030
else
1031
search="${hash}:${line_dict1}${line_dict2}"
1032
fi
1033
1034
echo "${output}" | grep -F "${search}" &>/dev/null
1035
1036
newRet=$?
1037
1038
if [ "${newRet}" -eq 2 ]; then
1039
1040
# out-of-memory, workaround
1041
1042
echo "${output}" | grep -v "^Unsupported\|^$" | head -1 > tmp_file_out
1043
echo "${search}" > tmp_file_search
1044
1045
out_md5=$(md5sum tmp_file_out | cut -d' ' -f1)
1046
search_md5=$(md5sum tmp_file_search | cut -d' ' -f1)
1047
1048
rm tmp_file_out tmp_file_search
1049
1050
if [ "${out_md5}" == "${search_md5}" ]; then
1051
newRet=0
1052
fi
1053
fi
1054
1055
if [ "${newRet}" -ne 0 ]; then
1056
if [ "${newRet}" -eq 2 ]; then
1057
ret=20
1058
else
1059
ret=10
1060
fi
1061
fi
1062
1063
fi
1064
1065
status ${ret}
1066
1067
fi
1068
1069
if [ $i -eq ${max} ]; then break; fi
1070
1071
i=$((i + 1))
1072
1073
done 9< "${OUTD}/${hash_type}_hashes.txt"
1074
1075
msg="OK"
1076
1077
if [ "${e_ce}" -ne 0 ]; then
1078
msg="Compare Error"
1079
elif [ "${e_rs}" -ne 0 ]; then
1080
msg="Skip"
1081
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
1082
msg="Error"
1083
elif [ "${e_to}" -ne 0 ]; then
1084
msg="Warning"
1085
fi
1086
1087
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 1, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
1088
fi
1089
1090
# multihash
1091
if [ "${MODE}" -ne 0 ]; then
1092
1093
# no multi hash checks for these modes (because we only have 1 hash for each of them)
1094
! has_multi_hash || return
1095
1096
e_ce=0
1097
e_rs=0
1098
e_to=0
1099
e_nf=0
1100
e_nm=0
1101
cnt=0
1102
1103
offset=7
1104
1105
if [ "${hash_type}" -eq 5800 ]; then
1106
offset=6
1107
elif [ "${hash_type}" -eq 3000 ]; then
1108
offset=6
1109
fi
1110
1111
hash_file=${OUTD}/${hash_type}_multihash_combi.txt
1112
1113
tail -n ${offset} "${OUTD}/${hash_type}_hashes.txt" > "${hash_file}"
1114
1115
# if file_only -> decode all base64 "hashes" and put them in the temporary file
1116
1117
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
1118
1119
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
1120
rm -f "${temp_file}"
1121
1122
hash_file=${temp_file}
1123
1124
while read -r file_only_hash; do
1125
1126
if [ "${hash_type}" -ne 22000 ]; then
1127
echo -n "${file_only_hash}" | base64 -d >> "${temp_file}"
1128
else
1129
echo "${file_only_hash}" >> "${temp_file}"
1130
fi
1131
1132
done < "${OUTD}/${hash_type}_multihash_combi.txt"
1133
1134
fi
1135
1136
CMD="./${BIN} ${OPTS} -a 1 -m ${hash_type} ${hash_file} ${OUTD}/${hash_type}_dict1 ${OUTD}/${hash_type}_dict2"
1137
1138
echo "> Testing hash type $hash_type with attack mode 1, markov ${MARKOV}, multi hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1139
1140
output=$(./${BIN} ${OPTS} -a 1 -m ${hash_type} ${hash_file} ${OUTD}/${hash_type}_dict1 ${OUTD}/${hash_type}_dict2 2>&1)
1141
1142
ret=${?}
1143
1144
echo "${output}" >> "${OUTD}/logfull.txt"
1145
1146
if [ "${ret}" -eq 0 ]; then
1147
1148
i=0
1149
1150
while read -r -u 9 hash; do
1151
1152
line_nr=1
1153
1154
if [ "${offset}" -gt ${i} ]; then
1155
line_nr=$((offset - i))
1156
fi
1157
1158
line_dict1=$(tail -n ${line_nr} "${OUTD}/${hash_type}_dict1" | head -1)
1159
line_dict2=$(tail -n ${line_nr} "${OUTD}/${hash_type}_dict2" | head -1)
1160
1161
if [ "${pass_only}" -eq 1 ]; then
1162
search=":${line_dict1}${line_dict2}"
1163
else
1164
search="${hash}:${line_dict1}${line_dict2}"
1165
fi
1166
1167
echo "${output}" | grep -F "${search}" &>/dev/null
1168
1169
newRet=$?
1170
1171
if [ "${newRet}" -ne 0 ]; then
1172
if [ "${newRet}" -eq 2 ]; then
1173
ret=20
1174
else
1175
ret=10
1176
fi
1177
1178
break
1179
fi
1180
1181
i=$((i + 1))
1182
1183
done 9< "${OUTD}/${hash_type}_multihash_combi.txt"
1184
fi
1185
1186
status ${ret}
1187
1188
msg="OK"
1189
1190
if [ "${e_ce}" -ne 0 ]; then
1191
msg="Compare Error"
1192
elif [ "${e_rs}" -ne 0 ]; then
1193
msg="Skip"
1194
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
1195
msg="Error"
1196
elif [ "${e_to}" -ne 0 ]; then
1197
msg="Warning"
1198
fi
1199
1200
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 1, Mode multi, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
1201
fi
1202
}
1203
1204
function attack_3()
1205
{
1206
file_only=0
1207
1208
if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then
1209
file_only=1
1210
fi
1211
1212
# single hash
1213
if [ "${MODE}" -ne 1 ]; then
1214
1215
e_ce=0
1216
e_rs=0
1217
e_to=0
1218
e_nf=0
1219
e_nm=0
1220
cnt=0
1221
1222
echo "> Testing hash type $hash_type with attack mode 3, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1223
1224
max=8
1225
1226
# some algos have a minimum password length
1227
1228
if [ "${hash_type}" -eq 2500 ]; then
1229
max=7
1230
elif [ "${hash_type}" -eq 14000 ]; then
1231
max=1
1232
elif [ "${hash_type}" -eq 14100 ]; then
1233
max=1
1234
elif [ "${hash_type}" -eq 14900 ]; then
1235
max=1
1236
elif [ "${hash_type}" -eq 15400 ]; then
1237
max=1
1238
elif [ "${hash_type}" -eq 16800 ]; then
1239
max=7
1240
elif [ "${hash_type}" -eq 22000 ]; then
1241
max=7
1242
fi
1243
1244
i=1
1245
1246
while read -r -u 9 hash; do
1247
1248
if [ "${i}" -gt 6 ]; then
1249
if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then
1250
break
1251
fi
1252
fi
1253
1254
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
1255
1256
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
1257
1258
if [ "${hash_type}" -ne 22000 ]; then
1259
echo "${hash}" | base64 -d > "${temp_file}"
1260
else
1261
echo "${hash}" > "${temp_file}"
1262
fi
1263
1264
hash="${temp_file}"
1265
fi
1266
1267
# construct a meaningful mask from the password itself:
1268
1269
dict="${OUTD}/${hash_type}_passwords.txt"
1270
1271
pass=$(sed -n ${i}p "${dict}")
1272
1273
# passwords can't be smaller than mask in -a 3 = mask attack
1274
1275
if [ "${#pass}" -lt ${i} ]; then
1276
i=$((i + 1))
1277
continue
1278
fi
1279
1280
pass_part_2=$(echo -n "${pass}" | cut -b $((i + 1))-)
1281
1282
mask=""
1283
1284
if [ "${hash_type}" -eq 14000 ]; then
1285
mask="${pass}"
1286
elif [ "${hash_type}" -eq 14100 ]; then
1287
mask="${pass}"
1288
else
1289
for i in $(seq 1 ${i}); do
1290
mask="${mask}?d"
1291
done
1292
1293
mask="${mask}${pass_part_2}"
1294
fi
1295
1296
if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key
1297
if [ "${i}" -le 1 ]; then
1298
i=$((i + 1))
1299
continue
1300
fi
1301
1302
cut_pos=$((i * 2 + 6 - i + 1)) # skip it in groups of 2 ("?d"), at least 6, offset +1 for cut to work
1303
1304
if [ "${i}" -gt 6 ]; then
1305
cut_pos=13 # 6 * ?d + 1 (6 * 2 + 1)
1306
fi
1307
1308
mask=$(echo "${mask}" | cut -b ${cut_pos}-)
1309
fi
1310
1311
CMD="./${BIN} ${OPTS} -a 3 -m ${hash_type} '${hash}' ${mask}"
1312
1313
echo -n "[ len $i ] " >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1314
1315
output=$(./${BIN} ${OPTS} -a 3 -m ${hash_type} "${hash}" ${mask} 2>&1)
1316
1317
ret=${?}
1318
1319
echo "${output}" >> "${OUTD}/logfull.txt"
1320
1321
if [ "${ret}" -eq 0 ]; then
1322
1323
line_dict=$(sed -n ${i}p "${dict}")
1324
1325
1326
if is_in_array "${hash_type}" ${LUKS_MODES}; then
1327
if [ "${pass_only}" -eq 1 ]; then
1328
search=":${line_dict}"
1329
else
1330
search="$(cat ${hash} | tr -d '\n'):${line_dict}" #hash is a filename for 34100
1331
fi
1332
else
1333
if [ "${pass_only}" -eq 1 ]; then
1334
search=":${line_dict}"
1335
else
1336
search="${hash}:${line_dict}"
1337
fi
1338
fi
1339
1340
echo "${output}" | grep -F "${search}" &>/dev/null
1341
1342
newRet=$?
1343
1344
if [ "${newRet}" -eq 2 ]; then
1345
1346
# out-of-memory, workaround
1347
1348
echo "${output}" | grep -v "^Unsupported\|^$" | head -1 > tmp_file_out
1349
echo "${search}" > tmp_file_search
1350
1351
out_md5=$(md5sum tmp_file_out | cut -d' ' -f1)
1352
search_md5=$(md5sum tmp_file_search | cut -d' ' -f1)
1353
1354
rm tmp_file_out tmp_file_search
1355
1356
if [ "${out_md5}" == "${search_md5}" ]; then
1357
newRet=0
1358
fi
1359
fi
1360
1361
if [ "${newRet}" -ne 0 ]; then
1362
if [ "${newRet}" -eq 2 ]; then
1363
ret=20
1364
else
1365
ret=10
1366
fi
1367
fi
1368
1369
fi
1370
1371
status ${ret}
1372
1373
if [ $i -eq ${max} ]; then break; fi
1374
1375
i=$((i + 1))
1376
1377
done 9< "${OUTD}/${hash_type}_hashes.txt"
1378
1379
msg="OK"
1380
1381
if [ "${e_ce}" -ne 0 ]; then
1382
msg="Compare Error"
1383
elif [ "${e_rs}" -ne 0 ]; then
1384
msg="Skip"
1385
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
1386
msg="Error"
1387
elif [ "${e_to}" -ne 0 ]; then
1388
msg="Warning"
1389
fi
1390
1391
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 3, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
1392
fi
1393
1394
# multihash
1395
if [ "${MODE}" -ne 0 ]; then
1396
1397
# no multi hash checks for these modes (because we only have 1 hash for each of them)
1398
! has_multi_hash || return
1399
1400
e_ce=0
1401
e_rs=0
1402
e_to=0
1403
e_nf=0
1404
e_nm=0
1405
cnt=0
1406
1407
increment_max=8
1408
1409
if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then
1410
increment_max=5
1411
fi
1412
1413
increment_min=1
1414
1415
if [ "${hash_type}" -eq 2500 ]; then
1416
increment_min=8
1417
increment_max=9
1418
fi
1419
1420
if [ "${hash_type}" -eq 16800 ]; then
1421
increment_min=8
1422
increment_max=9
1423
fi
1424
1425
if [ "${hash_type}" -eq 22000 ]; then
1426
increment_min=8
1427
increment_max=9
1428
fi
1429
1430
# if file_only -> decode all base64 "hashes" and put them in the temporary file
1431
1432
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
1433
1434
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
1435
rm -f "${temp_file}"
1436
1437
hash_file=${temp_file}
1438
1439
while read -r file_only_hash; do
1440
1441
if [ "${hash_type}" -ne 22000 ]; then
1442
echo -n "${file_only_hash}" | base64 -d >> "${temp_file}"
1443
else
1444
echo "${file_only_hash}" >> "${temp_file}"
1445
fi
1446
1447
done < "${OUTD}/${hash_type}_multihash_bruteforce.txt"
1448
1449
fi
1450
1451
hash_file=${OUTD}/${hash_type}_multihash_bruteforce.txt
1452
1453
tail_hashes=$(awk "length >= ${increment_min} && length <= ${increment_max}" "${OUTD}/${hash_type}_passwords.txt" | wc -l)
1454
head_hashes=$(awk "length <= ${increment_max}" "${OUTD}/${hash_type}_passwords.txt" | wc -l)
1455
1456
# in very rare cases (e.g. without -O and long passwords) we need to use .hcmask files with the passwords in it
1457
# otherwise there are no good masks we can test for such long passwords
1458
1459
need_hcmask=0
1460
1461
if [ "${tail_hashes}" -gt "${head_hashes}" ]; then
1462
need_hcmask=1
1463
fi
1464
1465
if [ "${tail_hashes}" -lt 1 ]; then
1466
need_hcmask=1
1467
fi
1468
1469
if [ ${need_hcmask} -eq 0 ]; then
1470
head -n "${head_hashes}" "${OUTD}/${hash_type}_hashes.txt" | tail -n "${tail_hashes}" > "${hash_file}"
1471
else
1472
tail_hashes=$(awk "length >= ${increment_min}" "${OUTD}/${hash_type}_passwords.txt" | wc -l)
1473
1474
if [ "${tail_hashes}" -lt 1 ]; then
1475
return
1476
fi
1477
1478
tail -n "${tail_hashes}" "${OUTD}/${hash_type}_hashes.txt" > "${hash_file}"
1479
fi
1480
1481
mask_pos=8
1482
1483
if [ "${increment_min}" -gt ${mask_pos} ]; then
1484
mask_pos=${increment_min}
1485
fi
1486
1487
mask=""
1488
cracks_offset=0
1489
1490
if [ ${need_hcmask} -eq 0 ]; then
1491
cracks_offset=$((head_hashes - tail_hashes))
1492
1493
mask=${mask_3[${mask_pos}]}
1494
else
1495
num_hashes=$(wc -l < "${OUTD}/${hash_type}_hashes.txt")
1496
cracks_offset=$((num_hashes - tail_hashes))
1497
1498
mask=${OUTD}/${hash_type}_passwords.txt # fake hcmask file (i.e. the original dict)
1499
fi
1500
1501
custom_charsets=""
1502
1503
# modify "default" mask if needed (and set custom charset to reduce keyspace)
1504
1505
if [ "${hash_type}" -eq 2500 ]; then
1506
1507
mask="?d?d?d?d?d?1?2?3?4"
1508
1509
charset_1=""
1510
charset_2=""
1511
charset_3=""
1512
charset_4=""
1513
1514
# check positions (here we assume that mask is always composed of non literal chars
1515
# i.e. something like ?d?l?u?s?1 is possible, but ?d?dsuffix not
1516
charset_1_pos=$(expr index "${mask}" 1)
1517
charset_2_pos=$(expr index "${mask}" 2)
1518
charset_3_pos=$(expr index "${mask}" 3)
1519
charset_4_pos=$(expr index "${mask}" 4)
1520
1521
# divide each charset position by 2 since each of them occupies 2 positions in the mask
1522
1523
charset_1_pos=$((charset_1_pos / 2))
1524
charset_2_pos=$((charset_2_pos / 2))
1525
charset_3_pos=$((charset_3_pos / 2))
1526
charset_4_pos=$((charset_4_pos / 2))
1527
1528
i=1
1529
1530
while read -r -u 9 hash; do
1531
1532
pass=$(sed -n ${i}p "${OUTD}/${hash_type}_passwords.txt")
1533
1534
# charset 1
1535
char=$(echo "${pass}" | cut -b ${charset_1_pos})
1536
charset_1=$(printf "%s\n%s\n" "${charset_1}" "${char}")
1537
1538
# charset 2
1539
char=$(echo "${pass}" | cut -b ${charset_2_pos})
1540
charset_2=$(printf "%s\n%s\n" "${charset_2}" "${char}")
1541
1542
# charset 3
1543
char=$(echo "${pass}" | cut -b ${charset_3_pos})
1544
charset_3=$(printf "%s\n%s\n" "${charset_3}" "${char}")
1545
1546
# charset 4
1547
char=$(echo "${pass}" | cut -b ${charset_4_pos})
1548
charset_4=$(printf "%s\n%s\n" "${charset_4}" "${char}")
1549
1550
i=$((i + 1))
1551
1552
done 9< "${OUTD}/${hash_type}_multihash_bruteforce.txt"
1553
1554
# just make sure that all custom charset fields are initialized
1555
1556
if [ -z "${charset_1}" ]; then
1557
charset_1="1"
1558
fi
1559
1560
if [ -z "${charset_2}" ]; then
1561
charset_2="2"
1562
fi
1563
1564
if [ -z "${charset_3}" ]; then
1565
charset_3="3"
1566
fi
1567
1568
if [ -z "${charset_4}" ]; then
1569
charset_4="4"
1570
fi
1571
1572
# unique and remove new lines
1573
1574
charset_1=$(echo "${charset_1}" | sort -u | tr -d '\n')
1575
charset_2=$(echo "${charset_2}" | sort -u | tr -d '\n')
1576
charset_3=$(echo "${charset_3}" | sort -u | tr -d '\n')
1577
charset_4=$(echo "${charset_4}" | sort -u | tr -d '\n')
1578
1579
custom_charsets="-1 ${charset_1} -2 ${charset_2} -3 ${charset_3} -4 ${charset_4}"
1580
fi
1581
1582
if [ "${hash_type}" -eq 16800 ]; then
1583
1584
mask="?d?d?d?d?d?1?2?3?4"
1585
1586
charset_1=""
1587
charset_2=""
1588
charset_3=""
1589
charset_4=""
1590
1591
# check positions (here we assume that mask is always composed of non literal chars
1592
# i.e. something like ?d?l?u?s?1 is possible, but ?d?dsuffix not
1593
charset_1_pos=$(expr index "${mask}" 1)
1594
charset_2_pos=$(expr index "${mask}" 2)
1595
charset_3_pos=$(expr index "${mask}" 3)
1596
charset_4_pos=$(expr index "${mask}" 4)
1597
1598
# divide each charset position by 2 since each of them occupies 2 positions in the mask
1599
1600
charset_1_pos=$((charset_1_pos / 2))
1601
charset_2_pos=$((charset_2_pos / 2))
1602
charset_3_pos=$((charset_3_pos / 2))
1603
charset_4_pos=$((charset_4_pos / 2))
1604
1605
i=1
1606
1607
while read -r -u 9 hash; do
1608
1609
pass=$(sed -n ${i}p "${OUTD}/${hash_type}_passwords.txt")
1610
1611
# charset 1
1612
char=$(echo "${pass}" | cut -b ${charset_1_pos})
1613
charset_1=$(printf "%s\n%s\n" "${charset_1}" "${char}")
1614
1615
# charset 2
1616
char=$(echo "${pass}" | cut -b ${charset_2_pos})
1617
charset_2=$(printf "%s\n%s\n" "${charset_2}" "${char}")
1618
1619
# charset 3
1620
char=$(echo "${pass}" | cut -b ${charset_3_pos})
1621
charset_3=$(printf "%s\n%s\n" "${charset_3}" "${char}")
1622
1623
# charset 4
1624
char=$(echo "${pass}" | cut -b ${charset_4_pos})
1625
charset_4=$(printf "%s\n%s\n" "${charset_4}" "${char}")
1626
1627
i=$((i + 1))
1628
1629
done 9< "${OUTD}/${hash_type}_multihash_bruteforce.txt"
1630
1631
# just make sure that all custom charset fields are initialized
1632
1633
if [ -z "${charset_1}" ]; then
1634
charset_1="1"
1635
fi
1636
1637
if [ -z "${charset_2}" ]; then
1638
charset_2="2"
1639
fi
1640
1641
if [ -z "${charset_3}" ]; then
1642
charset_3="3"
1643
fi
1644
1645
if [ -z "${charset_4}" ]; then
1646
charset_4="4"
1647
fi
1648
1649
# unique and remove new lines
1650
1651
charset_1=$(echo "${charset_1}" | sort -u | tr -d '\n')
1652
charset_2=$(echo "${charset_2}" | sort -u | tr -d '\n')
1653
charset_3=$(echo "${charset_3}" | sort -u | tr -d '\n')
1654
charset_4=$(echo "${charset_4}" | sort -u | tr -d '\n')
1655
1656
custom_charsets="-1 ${charset_1} -2 ${charset_2} -3 ${charset_3} -4 ${charset_4}"
1657
fi
1658
1659
if [ "${hash_type}" -eq 22000 ]; then
1660
1661
mask="?d?d?d?d?d?1?2?3?4"
1662
1663
charset_1=""
1664
charset_2=""
1665
charset_3=""
1666
charset_4=""
1667
1668
# check positions (here we assume that mask is always composed of non literal chars
1669
# i.e. something like ?d?l?u?s?1 is possible, but ?d?dsuffix not
1670
charset_1_pos=$(expr index "${mask}" 1)
1671
charset_2_pos=$(expr index "${mask}" 2)
1672
charset_3_pos=$(expr index "${mask}" 3)
1673
charset_4_pos=$(expr index "${mask}" 4)
1674
1675
# divide each charset position by 2 since each of them occupies 2 positions in the mask
1676
1677
charset_1_pos=$((charset_1_pos / 2))
1678
charset_2_pos=$((charset_2_pos / 2))
1679
charset_3_pos=$((charset_3_pos / 2))
1680
charset_4_pos=$((charset_4_pos / 2))
1681
1682
i=1
1683
1684
while read -r -u 9 hash; do
1685
1686
pass=$(sed -n ${i}p "${OUTD}/${hash_type}_passwords.txt")
1687
1688
# charset 1
1689
char=$(echo "${pass}" | cut -b ${charset_1_pos})
1690
charset_1=$(printf "%s\n%s\n" "${charset_1}" "${char}")
1691
1692
# charset 2
1693
char=$(echo "${pass}" | cut -b ${charset_2_pos})
1694
charset_2=$(printf "%s\n%s\n" "${charset_2}" "${char}")
1695
1696
# charset 3
1697
char=$(echo "${pass}" | cut -b ${charset_3_pos})
1698
charset_3=$(printf "%s\n%s\n" "${charset_3}" "${char}")
1699
1700
# charset 4
1701
char=$(echo "${pass}" | cut -b ${charset_4_pos})
1702
charset_4=$(printf "%s\n%s\n" "${charset_4}" "${char}")
1703
1704
i=$((i + 1))
1705
1706
done 9< "${OUTD}/${hash_type}_multihash_bruteforce.txt"
1707
1708
# just make sure that all custom charset fields are initialized
1709
1710
if [ -z "${charset_1}" ]; then
1711
charset_1="1"
1712
fi
1713
1714
if [ -z "${charset_2}" ]; then
1715
charset_2="2"
1716
fi
1717
1718
if [ -z "${charset_3}" ]; then
1719
charset_3="3"
1720
fi
1721
1722
if [ -z "${charset_4}" ]; then
1723
charset_4="4"
1724
fi
1725
1726
# unique and remove new lines
1727
1728
charset_1=$(echo "${charset_1}" | sort -u | tr -d '\n')
1729
charset_2=$(echo "${charset_2}" | sort -u | tr -d '\n')
1730
charset_3=$(echo "${charset_3}" | sort -u | tr -d '\n')
1731
charset_4=$(echo "${charset_4}" | sort -u | tr -d '\n')
1732
1733
custom_charsets="-1 ${charset_1} -2 ${charset_2} -3 ${charset_3} -4 ${charset_4}"
1734
fi
1735
1736
increment_charset_opts=""
1737
1738
if [ ${need_hcmask} -eq 0 ]; then # the "normal" case without .hcmask file
1739
increment_charset_opts="--increment --increment-min ${increment_min} --increment-max ${increment_max}"
1740
1741
if [ -n "${custom_charsets}" ]; then
1742
increment_charset_opts="${increment_charset_opts} ${custom_charsets}"
1743
fi
1744
fi
1745
1746
CMD="./${BIN} ${OPTS} -a 3 -m ${hash_type} ${increment_charset_opts} ${hash_file} ${mask} "
1747
1748
echo "> Testing hash type $hash_type with attack mode 3, markov ${MARKOV}, multi hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1749
1750
output=$(./${BIN} ${OPTS} -a 3 -m ${hash_type} ${increment_charset_opts} ${hash_file} ${mask} 2>&1)
1751
1752
ret=${?}
1753
1754
echo "${output}" >> "${OUTD}/logfull.txt"
1755
1756
if [ "${ret}" -eq 0 ]; then
1757
1758
i=1
1759
1760
while read -r -u 9 hash; do
1761
line_nr=$((i + cracks_offset))
1762
1763
pass=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_passwords.txt")
1764
1765
if [ "${pass_only}" -eq 1 ]; then
1766
search=":${pass}"
1767
else
1768
search="${hash}:${pass}"
1769
fi
1770
1771
echo "${output}" | grep -F "${search}" &>/dev/null
1772
1773
newRet=$?
1774
1775
if [ "${newRet}" -ne 0 ]; then
1776
if [ "${newRet}" -eq 2 ]; then
1777
ret=20
1778
else
1779
ret=10
1780
fi
1781
1782
break
1783
fi
1784
1785
i=$((i + 1))
1786
1787
done 9< "${OUTD}/${hash_type}_multihash_bruteforce.txt"
1788
1789
fi
1790
1791
status ${ret}
1792
1793
msg="OK"
1794
1795
if [ "${e_ce}" -ne 0 ]; then
1796
msg="Compare Error"
1797
elif [ "${e_rs}" -ne 0 ]; then
1798
msg="Skip"
1799
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
1800
msg="Error"
1801
elif [ "${e_to}" -ne 0 ]; then
1802
msg="Warning"
1803
fi
1804
1805
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 3, Mode multi, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
1806
fi
1807
}
1808
1809
function attack_6()
1810
{
1811
file_only=0
1812
1813
if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then
1814
file_only=1
1815
fi
1816
1817
# single hash
1818
if [ "${MODE}" -ne 1 ]; then
1819
1820
e_ce=0
1821
e_rs=0
1822
e_to=0
1823
e_nf=0
1824
e_nm=0
1825
cnt=0
1826
1827
echo "> Testing hash type $hash_type with attack mode 6, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1828
1829
min=1
1830
max=8
1831
mask_offset=0
1832
1833
if [ "${hash_type}" -eq 2500 ]; then
1834
max=6
1835
elif [ "${hash_type}" -eq 14000 ]; then
1836
min=0
1837
max=1
1838
mask_offset=4
1839
elif [ "${hash_type}" -eq 14100 ]; then
1840
min=0
1841
max=1
1842
mask_offset=21
1843
elif [ "${hash_type}" -eq 14900 ]; then
1844
min=0
1845
max=1
1846
mask_offset=5
1847
elif [ "${hash_type}" -eq 15400 ]; then
1848
min=0
1849
max=1
1850
mask_offset=29
1851
elif [ "${hash_type}" -eq 16800 ]; then
1852
max=6
1853
elif [ "${hash_type}" -eq 22000 ]; then
1854
max=6
1855
fi
1856
1857
# special case: we need to split the first line
1858
1859
if [ "${min}" -eq 0 ]; then
1860
pass_part_1=$(sed -n 1p "${OUTD}/${hash_type}_dict1")
1861
pass_part_2=$(sed -n 1p "${OUTD}/${hash_type}_dict2")
1862
1863
pass="${pass_part_1}${pass_part_2}"
1864
1865
echo -n "${pass}" | cut -b -$((mask_offset + 0)) > "${OUTD}/${hash_type}_dict1_custom"
1866
echo -n "${pass}" | cut -b $((mask_offset + 1))- > "${OUTD}/${hash_type}_dict2_custom"
1867
1868
mask_custom=""
1869
1870
for i in $(seq 1 $((${#pass} - mask_offset))); do
1871
1872
if [ "${hash_type}" -eq 14000 ]; then
1873
char=$(echo -n "${pass}" | cut -b $((i + mask_offset)))
1874
mask_custom="${mask_custom}${char}"
1875
elif [ "${hash_type}" -eq 14100 ]; then
1876
char=$(echo -n "${pass}" | cut -b $((i + mask_offset)))
1877
mask_custom="${mask_custom}${char}"
1878
else
1879
mask_custom="${mask_custom}?d"
1880
fi
1881
1882
done
1883
fi
1884
1885
i=1
1886
1887
while read -r -u 9 hash; do
1888
1889
if [ "${i}" -gt 6 ]; then
1890
if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then
1891
break
1892
fi
1893
fi
1894
1895
if [ ${i} -gt ${min} ]; then
1896
1897
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
1898
1899
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
1900
1901
if [ "${hash_type}" -ne 22000 ]; then
1902
echo "${hash}" | base64 -d > "${temp_file}"
1903
else
1904
echo "${hash}" > "${temp_file}"
1905
fi
1906
1907
hash="${temp_file}"
1908
1909
fi
1910
1911
dict1=${OUTD}/${hash_type}_dict1
1912
dict2=${OUTD}/${hash_type}_dict2
1913
1914
dict1_a6=${OUTD}/${hash_type}_dict1_a6
1915
1916
cp "${dict1}" "${dict1_a6}"
1917
1918
pass=$(sed -n ${i}p "${OUTD}/${hash_type}_passwords.txt")
1919
1920
if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key
1921
pass=$(echo "${pass}" | cut -b 7-) # skip the first 6 chars
1922
fi
1923
1924
if [ ${#pass} -le ${i} ]; then
1925
i=$((i + 1))
1926
continue
1927
fi
1928
1929
echo "${pass}" | cut -b -$((${#pass} - i)) >> "${dict1_a6}"
1930
1931
# the block below is just a fancy way to do a "shuf" (or sort -R) because macOS doesn't really support it natively
1932
# we do not really need a shuf, but it's actually better for testing purposes
1933
1934
rm -f "${dict1_a6}.txt" # temporary file
1935
1936
line_num=$(wc -l "${dict1_a6}" | sed -E 's/ *([0-9]+) .*$/\1/')
1937
1938
sorted_lines=$(seq 1 "${line_num}")
1939
1940
for lines in $(seq 1 "${line_num}"); do
1941
1942
random_num=$((RANDOM % line_num))
1943
random_num=$((random_num + 1)) # sed -n [n]p starts counting with 1 (not 0)
1944
1945
random_line=$(echo -n "${sorted_lines}" | sed -n ${random_num}p)
1946
1947
sed -n ${random_line}p "${dict1_a6}" >> "${dict1_a6}.txt"
1948
1949
# update the temp list of lines
1950
1951
sorted_lines=$(echo -n "${sorted_lines}" | grep -v "^${random_line}$")
1952
1953
line_num=$((line_num - 1))
1954
1955
done
1956
1957
mv "${dict1_a6}.txt" "${dict1_a6}"
1958
1959
# end of shuf/sort -R
1960
1961
mask=""
1962
1963
for j in $(seq 1 ${i}); do
1964
mask="${mask}?d"
1965
done
1966
1967
CMD="./${BIN} ${OPTS} -a 6 -m ${hash_type} '${hash}' ${dict1_a6} ${mask}"
1968
1969
echo -n "[ len $i ] " >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
1970
1971
output=$(./${BIN} ${OPTS} -a 6 -m ${hash_type} "${hash}" ${dict1_a6} ${mask} 2>&1)
1972
1973
ret=${?}
1974
1975
echo "${output}" >> "${OUTD}/logfull.txt"
1976
1977
if [ "${ret}" -eq 0 ]; then
1978
1979
line_nr=1
1980
1981
if [ "${i}" -gt 1 ]; then
1982
line_nr=$((i - 1))
1983
fi
1984
1985
line_dict1=$(sed -n ${line_nr}p "${dict1}")
1986
line_dict2=$(sed -n ${line_nr}p "${dict2}")
1987
1988
if [ "${pass_only}" -eq 1 ]; then
1989
search=":${line_dict1}${line_dict2}"
1990
else
1991
search="${hash}:${line_dict1}${line_dict2}"
1992
fi
1993
1994
echo "${output}" | grep -F "${search}" &>/dev/null
1995
1996
newRet=$?
1997
1998
if [ "${newRet}" -eq 2 ]; then
1999
2000
# out-of-memory, workaround
2001
2002
echo "${output}" | grep -v "^Unsupported\|^$" | head -1 > tmp_file_out
2003
echo "${search}" > tmp_file_search
2004
2005
out_md5=$(md5sum tmp_file_out | cut -d' ' -f1)
2006
search_md5=$(md5sum tmp_file_search | cut -d' ' -f1)
2007
2008
rm tmp_file_out tmp_file_search
2009
2010
if [ "${out_md5}" == "${search_md5}" ]; then
2011
newRet=0
2012
fi
2013
fi
2014
2015
if [ "${newRet}" -ne 0 ]; then
2016
if [ "${newRet}" -eq 2 ]; then
2017
ret=20
2018
else
2019
ret=10
2020
fi
2021
fi
2022
2023
fi
2024
2025
status ${ret}
2026
fi
2027
2028
if [ "${i}" -eq ${max} ]; then break; fi
2029
2030
i=$((i + 1))
2031
2032
done 9< "${OUTD}/${hash_type}_hashes.txt"
2033
2034
msg="OK"
2035
2036
if [ "${e_ce}" -ne 0 ]; then
2037
msg="Compare Error"
2038
elif [ "${e_rs}" -ne 0 ]; then
2039
msg="Skip"
2040
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
2041
msg="Error"
2042
elif [ "${e_to}" -ne 0 ]; then
2043
msg="Warning"
2044
fi
2045
2046
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 6, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
2047
2048
rm -f "${OUTD}/${hash_type}_dict1_custom"
2049
rm -f "${OUTD}/${hash_type}_dict2_custom"
2050
fi
2051
2052
# multihash
2053
if [ "${MODE}" -ne 0 ]; then
2054
2055
# no multi hash checks for these modes (because we only have 1 hash for each of them)
2056
! has_multi_hash || return
2057
2058
e_ce=0
2059
e_rs=0
2060
e_to=0
2061
e_nf=0
2062
e_nm=0
2063
cnt=0
2064
2065
min=1
2066
max=9
2067
2068
if [ "${hash_type}" -eq 2500 ]; then
2069
max=5
2070
elif [ "${hash_type}" -eq 3000 ]; then
2071
max=8
2072
elif [ "${hash_type}" -eq 7700 ] || [ "${hash_type}" -eq 7701 ]; then
2073
max=8
2074
elif [ "${hash_type}" -eq 8500 ]; then
2075
max=8
2076
elif [ "${hash_type}" -eq 16800 ]; then
2077
max=5
2078
elif [ "${hash_type}" -eq 22000 ]; then
2079
max=5
2080
elif [ "${hash_type}" -eq 33500 ]; then
2081
min=5
2082
elif [ "${hash_type}" -eq 33501 ]; then
2083
min=8
2084
elif [ "${hash_type}" -eq 33502 ]; then
2085
min=8
2086
fi
2087
2088
if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then
2089
max=5
2090
if [ "${hash_type}" -eq 3200 ]; then
2091
max=3
2092
fi
2093
fi
2094
2095
i=2
2096
while [ "$i" -lt "$max" ]; do
2097
2098
if [ "$i" -lt "$min" ]; then
2099
i=$((i + 1))
2100
continue
2101
fi
2102
2103
hash_file=${OUTD}/${hash_type}_hashes_multi_${i}.txt
2104
2105
# if file_only -> decode all base64 "hashes" and put them in the temporary file
2106
2107
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
2108
2109
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
2110
rm -f "${temp_file}"
2111
2112
hash_file=${temp_file}
2113
2114
while read -r file_only_hash; do
2115
2116
if [ "${hash_type}" -ne 22000 ]; then
2117
echo -n "${file_only_hash}" | base64 -d >> "${temp_file}"
2118
else
2119
echo "${file_only_hash}" >> "${temp_file}"
2120
fi
2121
2122
done < "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
2123
2124
fi
2125
2126
mask=${mask_6[$i]}
2127
2128
CMD="./${BIN} ${OPTS} -a 6 -m ${hash_type} ${hash_file} ${OUTD}/${hash_type}_dict1_multi_${i} ${mask}"
2129
2130
echo "> Testing hash type $hash_type with attack mode 6, markov ${MARKOV}, multi hash with word len ${i}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
2131
2132
output=$(./${BIN} ${OPTS} -a 6 -m ${hash_type} ${hash_file} ${OUTD}/${hash_type}_dict1_multi_${i} ${mask} 2>&1)
2133
2134
ret=${?}
2135
2136
echo "${output}" >> "${OUTD}/logfull.txt"
2137
2138
if [ "${ret}" -eq 0 ]; then
2139
2140
j=1
2141
2142
while read -r -u 9 hash; do
2143
2144
line_dict1=$(sed -n ${j}p "${OUTD}/${hash_type}_dict1_multi_${i}")
2145
line_dict2=$(sed -n ${j}p "${OUTD}/${hash_type}_dict2_multi_${i}")
2146
2147
if [ "${pass_only}" -eq 1 ]; then
2148
search=":${line_dict1}${line_dict2}"
2149
else
2150
search="${hash}:${line_dict1}${line_dict2}"
2151
fi
2152
2153
echo "${output}" | grep -F "${search}" &>/dev/null
2154
2155
newRet=$?
2156
2157
if [ "${newRet}" -ne 0 ]; then
2158
if [ "${newRet}" -eq 2 ]; then
2159
ret=20
2160
else
2161
ret=10
2162
fi
2163
2164
break
2165
fi
2166
2167
j=$((j + 1))
2168
2169
done 9< "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
2170
fi
2171
2172
status ${ret}
2173
i=$((i + 1))
2174
2175
done
2176
2177
msg="OK"
2178
2179
if [ "${e_ce}" -ne 0 ]; then
2180
msg="Compare Error"
2181
elif [ "${e_rs}" -ne 0 ]; then
2182
msg="Skip"
2183
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
2184
msg="Error"
2185
elif [ "${e_to}" -ne 0 ]; then
2186
msg="Warning"
2187
fi
2188
2189
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 6, Mode multi, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
2190
fi
2191
}
2192
2193
function attack_7()
2194
{
2195
file_only=0
2196
2197
if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then
2198
file_only=1
2199
fi
2200
2201
# single hash
2202
if [ "${MODE}" -ne 1 ]; then
2203
2204
e_ce=0
2205
e_rs=0
2206
e_to=0
2207
e_nf=0
2208
e_nm=0
2209
cnt=0
2210
2211
echo "> Testing hash type $hash_type with attack mode 7, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
2212
2213
min=1
2214
max=8
2215
2216
mask_offset=0
2217
2218
if [ "${hash_type}" -eq 2500 ]; then
2219
max=5
2220
elif [ "${hash_type}" -eq 14000 ]; then
2221
mask_offset=4
2222
min=0
2223
max=1
2224
elif [ "${hash_type}" -eq 14100 ]; then
2225
mask_offset=3
2226
min=0
2227
max=1
2228
elif [ "${hash_type}" -eq 14900 ]; then
2229
mask_offset=5
2230
min=0
2231
max=1
2232
elif [ "${hash_type}" -eq 15400 ]; then
2233
mask_offset=3
2234
min=0
2235
max=1
2236
elif [ "${hash_type}" -eq 16800 ]; then
2237
max=5
2238
elif [ "${hash_type}" -eq 22000 ]; then
2239
max=5
2240
fi
2241
2242
# special case: we need to split the first line
2243
2244
if [ "${min}" -eq 0 ]; then
2245
2246
pass_part_1=$(sed -n 1p "${OUTD}/${hash_type}_dict1")
2247
pass_part_2=$(sed -n 1p "${OUTD}/${hash_type}_dict2")
2248
2249
pass="${pass_part_1}${pass_part_2}"
2250
2251
echo -n "${pass}" | cut -b -$((mask_offset + 0)) > "${OUTD}/${hash_type}_dict1_custom"
2252
echo -n "${pass}" | cut -b $((mask_offset + 1))- > "${OUTD}/${hash_type}_dict2_custom"
2253
2254
mask_custom=""
2255
2256
for i in $(seq 1 ${mask_offset}); do
2257
2258
if [ "${hash_type}" -eq 14000 ]; then
2259
char=$(echo -n "${pass}" | cut -b ${i})
2260
mask_custom="${mask_custom}${char}"
2261
elif [ "${hash_type}" -eq 14100 ]; then
2262
char=$(echo -n "${pass}" | cut -b ${i})
2263
mask_custom="${mask_custom}${char}"
2264
else
2265
mask_custom="${mask_custom}?d"
2266
fi
2267
2268
done
2269
2270
fi
2271
2272
i=1
2273
2274
while read -r -u 9 hash; do
2275
2276
if [ ${i} -gt ${min} ]; then
2277
2278
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
2279
2280
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
2281
2282
if [ "${hash_type}" -ne 22000 ]; then
2283
echo "${hash}" | base64 -d > "${temp_file}"
2284
else
2285
echo "${hash}" > "${temp_file}"
2286
fi
2287
2288
hash="${temp_file}"
2289
2290
fi
2291
2292
mask=${mask_7[$i]}
2293
2294
# adjust mask if needed
2295
2296
line_nr=1
2297
2298
if [ "${i}" -gt 1 ]; then
2299
line_nr=$((i - 1))
2300
fi
2301
2302
if [ "${hash_type}" -eq 2500 ]; then
2303
2304
pass_part_1=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict1")
2305
pass_part_2=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict2")
2306
2307
pass_part_2_len=${#pass_part_2}
2308
2309
pass=${pass_part_1}${pass_part_2}
2310
2311
pass_len=${#pass}
2312
2313
# add first x chars of password to mask and append the (old) mask
2314
2315
mask_len=${#mask}
2316
mask_len=$((mask_len / 2))
2317
2318
mask_prefix=$(echo ${pass} | cut -b -$((pass_len - mask_len - pass_part_2_len)))
2319
mask=${mask_prefix}${mask}
2320
2321
fi
2322
2323
if [ "${hash_type}" -eq 16800 ]; then
2324
2325
pass_part_1=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict1")
2326
pass_part_2=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict2")
2327
2328
pass_part_2_len=${#pass_part_2}
2329
2330
pass=${pass_part_1}${pass_part_2}
2331
pass_len=${#pass}
2332
2333
# add first x chars of password to mask and append the (old) mask
2334
2335
mask_len=${#mask}
2336
mask_len=$((mask_len / 2))
2337
2338
mask_prefix=$(echo "${pass}" | cut -b -$((pass_len - mask_len - pass_part_2_len)))
2339
mask=${mask_prefix}${mask}
2340
2341
fi
2342
2343
if [ "${hash_type}" -eq 22000 ]; then
2344
2345
pass_part_1=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict1")
2346
pass_part_2=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict2")
2347
2348
pass_part_2_len=${#pass_part_2}
2349
2350
pass=${pass_part_1}${pass_part_2}
2351
pass_len=${#pass}
2352
2353
# add first x chars of password to mask and append the (old) mask
2354
2355
mask_len=${#mask}
2356
mask_len=$((mask_len / 2))
2357
2358
mask_prefix=$(echo "${pass}" | cut -b -$((pass_len - mask_len - pass_part_2_len)))
2359
mask=${mask_prefix}${mask}
2360
2361
fi
2362
2363
if [ "${hash_type}" -eq 20510 ]; then
2364
2365
pass_part_1=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict1")
2366
pass_part_2=$(sed -n ${line_nr}p "${OUTD}/${hash_type}_dict2")
2367
2368
pass=${pass_part_1}${pass_part_2}
2369
2370
pass_len=${#pass}
2371
2372
if [ "${pass_len}" -le 6 ]; then
2373
i=$((i + 1))
2374
continue
2375
fi
2376
2377
pass_old=${pass}
2378
2379
pass=$(echo "${pass}" | cut -b 7-) # skip the first 6 chars
2380
2381
mask_len=$((${#mask} / 2))
2382
2383
echo "${pass_old}" | cut -b -$((6 + mask_len)) > "${OUTD}/${hash_type}_dict1_custom"
2384
echo "${pass}" | cut -b $((mask_len + 1))- > "${OUTD}/${hash_type}_dict2_custom"
2385
2386
min=0 # hack to use the custom dict
2387
mask_custom=${mask}
2388
2389
fi
2390
2391
dict1=${OUTD}/${hash_type}_dict1
2392
dict2=${OUTD}/${hash_type}_dict2
2393
2394
if [ "${min}" -eq 0 ]; then
2395
mask=${mask_custom}
2396
2397
dict1=${OUTD}/${hash_type}_dict1_custom
2398
dict2=${OUTD}/${hash_type}_dict2_custom
2399
fi
2400
2401
CMD="./${BIN} ${OPTS} -a 7 -m ${hash_type} '${hash}' ${mask} ${dict2}"
2402
2403
echo -n "[ len $i ] " >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
2404
2405
output=$(./${BIN} ${OPTS} -a 7 -m ${hash_type} "${hash}" ${mask} ${dict2} 2>&1)
2406
2407
ret=${?}
2408
2409
echo "${output}" >> "${OUTD}/logfull.txt"
2410
2411
if [ "${ret}" -eq 0 ]; then
2412
2413
line_nr=1
2414
2415
if [ "${i}" -gt 1 ]; then
2416
line_nr=$((i - 1))
2417
fi
2418
2419
line_dict1=$(sed -n ${line_nr}p "${dict1}")
2420
line_dict2=$(sed -n ${line_nr}p "${dict2}")
2421
2422
if [ "${pass_only}" -eq 1 ]; then
2423
search=":${line_dict1}${line_dict2}"
2424
else
2425
search="${hash}:${line_dict1}${line_dict2}"
2426
fi
2427
2428
echo "${output}" | grep -F "${search}" &>/dev/null
2429
2430
newRet=$?
2431
2432
if [ "${newRet}" -eq 2 ]; then
2433
2434
# out-of-memory, workaround
2435
2436
echo "${output}" | grep -v "^Unsupported\|^$" | head -1 > tmp_file_out
2437
echo "${search}" > tmp_file_search
2438
2439
out_md5=$(md5sum tmp_file_out | cut -d' ' -f1)
2440
search_md5=$(md5sum tmp_file_search | cut -d' ' -f1)
2441
2442
rm tmp_file_out tmp_file_search
2443
2444
if [ "${out_md5}" == "${search_md5}" ]; then
2445
newRet=0
2446
fi
2447
fi
2448
2449
if [ "${newRet}" -ne 0 ]; then
2450
if [ "${newRet}" -eq 2 ]; then
2451
ret=20
2452
else
2453
ret=10
2454
fi
2455
fi
2456
2457
fi
2458
2459
status ${ret}
2460
fi
2461
2462
if [ $i -eq ${max} ]; then break; fi
2463
2464
i=$((i + 1))
2465
2466
done 9< "${OUTD}/${hash_type}_hashes.txt"
2467
2468
msg="OK"
2469
2470
if [ "${e_ce}" -ne 0 ]; then
2471
msg="Compare Error"
2472
elif [ "${e_rs}" -ne 0 ]; then
2473
msg="Skip"
2474
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
2475
msg="Error"
2476
elif [ "${e_to}" -ne 0 ]; then
2477
msg="Warning"
2478
fi
2479
2480
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 7, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
2481
2482
rm -f "${OUTD}/${hash_type}_dict1_custom"
2483
rm -f "${OUTD}/${hash_type}_dict2_custom"
2484
fi
2485
2486
# multihash
2487
if [ "${MODE}" -ne 0 ]; then
2488
2489
# no multi hash checks for these modes (because we only have 1 hash for each of them)
2490
! has_multi_hash || return
2491
2492
e_ce=0
2493
e_rs=0
2494
e_to=0
2495
e_nf=0
2496
e_nm=0
2497
cnt=0
2498
2499
max=9
2500
2501
if [ "${hash_type}" -eq 2500 ]; then
2502
max=5
2503
elif [ "${hash_type}" -eq 3000 ]; then
2504
max=8
2505
elif [ "${hash_type}" -eq 7700 ] || [ "${hash_type}" -eq 7701 ]; then
2506
max=8
2507
elif [ "${hash_type}" -eq 8500 ]; then
2508
max=8
2509
elif [ "${hash_type}" -eq 14000 ]; then
2510
max=5
2511
elif [ "${hash_type}" -eq 14100 ]; then
2512
max=5
2513
elif [ "${hash_type}" -eq 14900 ]; then
2514
max=5
2515
elif [ "${hash_type}" -eq 15400 ]; then
2516
max=5
2517
elif [ "${hash_type}" -eq 16800 ]; then
2518
max=5
2519
elif [ "${hash_type}" -eq 22000 ]; then
2520
max=5
2521
elif [ "${hash_type}" -eq 33500 ]; then
2522
min=5
2523
elif [ "${hash_type}" -eq 33501 ]; then
2524
max=3
2525
elif [ "${hash_type}" -eq 33502 ]; then
2526
max=3
2527
fi
2528
2529
if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then
2530
max=7
2531
if [ "${hash_type}" -eq 3200 ]; then
2532
max=4
2533
fi
2534
fi
2535
2536
i=2
2537
while [ "$i" -lt "$max" ]; do
2538
2539
hash_file=${OUTD}/${hash_type}_hashes_multi_${i}.txt
2540
dict_file=${OUTD}/${hash_type}_dict2_multi_${i}
2541
2542
if [ "${hash_type}" -eq 40001 ]; then
2543
mask=${mask_7[((i+10))]}
2544
elif [ "${hash_type}" -eq 40002 ]; then
2545
mask=${mask_7[((i+10))]}
2546
else
2547
mask=${mask_7[$i]}
2548
fi
2549
2550
# if file_only -> decode all base64 "hashes" and put them in the temporary file
2551
2552
if [ "${file_only}" -eq 1 ] && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
2553
2554
temp_file="${OUTD}/${hash_type}_filebased_only_temp.txt"
2555
rm -f "${temp_file}"
2556
2557
hash_file=${temp_file}
2558
2559
while read -r file_only_hash; do
2560
2561
if [ "${hash_type}" -ne 22000 ]; then
2562
echo -n "${file_only_hash}" | base64 -d >> "${temp_file}"
2563
else
2564
echo "${file_only_hash}" >> "${temp_file}"
2565
fi
2566
2567
done < "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
2568
2569
# a little hack: since we don't want to have a very large mask (and wpa has minimum length of 8),
2570
# we need to create a temporary dict file on-the-fly and use it like this: [small mask] [long(er) words in dict]
2571
2572
dict_file=${OUTD}/${hash_type}_dict2_multi_${i}_longer
2573
rm -f "${dict_file}"
2574
2575
mask_len=${#mask}
2576
mask_len=$((mask_len / 2))
2577
2578
j=1
2579
2580
while read -r -u 9 hash; do
2581
2582
pass_part_1=$(sed -n ${j}p "${OUTD}/${hash_type}_dict1_multi_${i}")
2583
pass_part_2=$(sed -n ${j}p "${OUTD}/${hash_type}_dict2_multi_${i}")
2584
2585
pass="${pass_part_1}${pass_part_2}"
2586
2587
pass_suffix=$(echo "${pass}" | cut -b $((mask_len + 1))-)
2588
2589
echo "${pass_suffix}" >> "${dict_file}"
2590
2591
j=$((j + 1))
2592
2593
done 9< "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
2594
2595
fi
2596
2597
CMD="./${BIN} ${OPTS} -a 7 -m ${hash_type} ${hash_file} ${mask} ${dict_file}"
2598
2599
echo "> Testing hash type $hash_type with attack mode 7, markov ${MARKOV}, multi hash with word len ${i}." >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
2600
2601
output=$(./${BIN} ${OPTS} -a 7 -m ${hash_type} ${hash_file} ${mask} ${dict_file} 2>&1)
2602
2603
ret=${?}
2604
2605
echo "${output}" >> "${OUTD}/logfull.txt"
2606
2607
if [ "${ret}" -eq 0 ]; then
2608
2609
j=1
2610
2611
while read -r -u 9 hash; do
2612
2613
line_dict1=$(sed -n ${j}p "${OUTD}/${hash_type}_dict1_multi_${i}")
2614
line_dict2=$(sed -n ${j}p "${OUTD}/${hash_type}_dict2_multi_${i}")
2615
2616
if [ "${pass_only}" -eq 1 ]; then
2617
search=":${line_dict1}${line_dict2}"
2618
else
2619
search="${hash}:${line_dict1}${line_dict2}"
2620
fi
2621
2622
echo "${output}" | grep -F "${search}" &>/dev/null
2623
2624
newRet=$?
2625
2626
if [ "${newRet}" -ne 0 ]; then
2627
if [ "${newRet}" -eq 2 ]; then
2628
ret=20
2629
else
2630
ret=10
2631
fi
2632
2633
break
2634
fi
2635
2636
j=$((j + 1))
2637
2638
done 9< "${OUTD}/${hash_type}_hashes_multi_${i}.txt"
2639
fi
2640
2641
status ${ret}
2642
i=$((i + 1))
2643
2644
done
2645
2646
msg="OK"
2647
2648
if [ "${e_ce}" -ne 0 ]; then
2649
msg="Compare Error"
2650
elif [ "${e_rs}" -ne 0 ]; then
2651
msg="Skip"
2652
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
2653
msg="Error"
2654
elif [ "${e_to}" -ne 0 ]; then
2655
msg="Warning"
2656
fi
2657
2658
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 7, Mode multi, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
2659
fi
2660
}
2661
2662
function cryptoloop_test()
2663
{
2664
hashType=$1
2665
keySize=$2
2666
CMD="unset"
2667
2668
mkdir -p ${OUTD}/cl_tests
2669
chmod u+x "${TDIR}/cryptoloop2hashcat.py"
2670
2671
case $hashType in
2672
2673
14511)
2674
case $keySize in
2675
128|192|256)
2676
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha1_aes_${keySize}.img\" --hash sha1 --cipher aes --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha1_aes_${keySize}.hash
2677
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha1_aes_${keySize}.hash hashca?l"
2678
;;
2679
esac
2680
;;
2681
2682
14512)
2683
case $keySize in
2684
128|192|256)
2685
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha1_serpent_${keySize}.img\" --hash sha1 --cipher serpent --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha1_serpent_${keySize}.hash
2686
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha1_serpent_${keySize}.hash hashca?l"
2687
;;
2688
esac
2689
;;
2690
2691
14513)
2692
case $keySize in
2693
128|192|256)
2694
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha1_twofish_${keySize}.img\" --hash sha1 --cipher twofish --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha1_twofish_${keySize}.hash
2695
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha1_twofish_${keySize}.hash hashca?l"
2696
;;
2697
esac
2698
;;
2699
2700
14521)
2701
case $keySize in
2702
128|192|256)
2703
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha256_aes_${keySize}.img\" --hash sha256 --cipher aes --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha256_aes_${keySize}.hash
2704
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha256_aes_${keySize}.hash hashca?l"
2705
;;
2706
esac
2707
;;
2708
2709
14522)
2710
case $keySize in
2711
128|192|256)
2712
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha256_serpent_${keySize}.img\" --hash sha256 --cipher serpent --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha256_serpent_${keySize}.hash
2713
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha256_serpent_${keySize}.hash hashca?l"
2714
;;
2715
esac
2716
;;
2717
2718
14523)
2719
case $keySize in
2720
128|192|256)
2721
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha256_twofish_${keySize}.img\" --hash sha256 --cipher twofish --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha256_twofish_${keySize}.hash
2722
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha256_twofish_${keySize}.hash hashca?l"
2723
;;
2724
esac
2725
;;
2726
2727
14531)
2728
case $keySize in
2729
128|192|256)
2730
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha512_aes_${keySize}.img\" --hash sha512 --cipher aes --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha512_aes_${keySize}.hash
2731
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha512_aes_${keySize}.hash hashca?l"
2732
;;
2733
esac
2734
;;
2735
2736
14532)
2737
case $keySize in
2738
128|192|256)
2739
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha512_serpent_${keySize}.img\" --hash sha512 --cipher serpent --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha512_serpent_${keySize}.hash
2740
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha512_serpent_${keySize}.hash hashca?l"
2741
;;
2742
esac
2743
;;
2744
2745
14533)
2746
case $keySize in
2747
128|192|256)
2748
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_sha512_twofish_${keySize}.img\" --hash sha512 --cipher twofish --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_sha512_twofish_${keySize}.hash
2749
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_sha512_twofish_${keySize}.hash hashca?l"
2750
;;
2751
esac
2752
;;
2753
2754
14541)
2755
case $keySize in
2756
128|192|256)
2757
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_ripemd160_aes_${keySize}.img\" --hash ripemd160 --cipher aes --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_ripemd160_aes_${keySize}.hash
2758
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_ripemd160_aes_${keySize}.hash hashca?l"
2759
;;
2760
esac
2761
;;
2762
2763
14542)
2764
case $keySize in
2765
128|192|256)
2766
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_ripemd160_serpent_${keySize}.img\" --hash ripemd160 --cipher serpent --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_ripemd160_serpent_${keySize}.hash
2767
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_ripemd160_serpent_${keySize}.hash hashca?l"
2768
;;
2769
esac
2770
;;
2771
2772
14543)
2773
case $keySize in
2774
128|192|256)
2775
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_ripemd160_twofish_${keySize}.img\" --hash ripemd160 --cipher twofish --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_ripemd160_twofish_${keySize}.hash
2776
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_ripemd160_twofish_${keySize}.hash hashca?l"
2777
;;
2778
esac
2779
;;
2780
2781
14551)
2782
case $keySize in
2783
128|192|256)
2784
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_whirlpool_aes_${keySize}.img\" --hash whirlpool --cipher aes --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_whirlpool_aes_${keySize}.hash
2785
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_whirlpool_aes_${keySize}.hash hashca?l"
2786
;;
2787
esac
2788
;;
2789
2790
14552)
2791
case $keySize in
2792
128|192|256)
2793
eval \"${TDIR}/cryptoloop2hashcat.py\" --source \"${TDIR}/cl_tests/hashcat_whirlpool_serpent_${keySize}.img\" --hash whirlpool --cipher serpent --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_whirlpool_serpent_${keySize}.hash
2794
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_whirlpool_serpent_${keySize}.hash hashca?l"
2795
;;
2796
esac
2797
;;
2798
2799
14553)
2800
case $keySize in
2801
128|192|256)
2802
eval \"${TDIR}/cryptoloop2hashcat.py --source ${TDIR}/cl_tests/hashcat_whirlpool_twofish_${keySize}.img\" --hash whirlpool --cipher twofish --keysize ${keySize} > ${OUTD}/cl_tests/hashcat_whirlpool_twofish_${keySize}.hash
2803
CMD="./${BIN} ${OPTS} -a 3 -m 14500 ${OUTD}/cl_tests/hashcat_whirlpool_twofish_${keySize}.hash hashca?l"
2804
;;
2805
esac
2806
;;
2807
esac
2808
2809
if [ ${#CMD} -gt 5 ]; then
2810
echo "> Testing hash type $hashType with attack mode 3, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Key-Size ${keySize}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
2811
2812
output=$(${CMD} 2>&1)
2813
2814
ret=${?}
2815
2816
echo "${output}" >> "${OUTD}/logfull.txt"
2817
2818
e_ce=0
2819
e_rs=0
2820
e_to=0
2821
e_nf=0
2822
e_nm=0
2823
cnt=0
2824
2825
status ${ret}
2826
2827
cnt=1
2828
2829
msg="OK"
2830
2831
if [ "${e_ce}" -ne 0 ]; then
2832
msg="Compare Error"
2833
elif [ "${e_rs}" -ne 0 ]; then
2834
msg="Skip"
2835
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
2836
msg="Error"
2837
elif [ "${e_to}" -ne 0 ]; then
2838
msg="Warning"
2839
fi
2840
2841
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 3, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Key-Size ${keySize} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
2842
fi
2843
}
2844
2845
function truecrypt_test()
2846
{
2847
hashType=$1
2848
tcMode=$2
2849
CMD="unset"
2850
2851
mkdir -p ${OUTD}/tc_tests
2852
chmod u+x "${TDIR}/truecrypt2hashcat.py"
2853
2854
case $hashType in
2855
2856
6211)
2857
case $tcMode in
2858
0)
2859
CMD="./${BIN} ${OPTS} -a 3 -m 6211 '${TDIR}/tc_tests/hashcat_ripemd160_aes.tc' hashca?l"
2860
;;
2861
1)
2862
CMD="./${BIN} ${OPTS} -a 3 -m 6211 '${TDIR}/tc_tests/hashcat_ripemd160_serpent.tc' hashca?l"
2863
;;
2864
2)
2865
CMD="./${BIN} ${OPTS} -a 3 -m 6211 '${TDIR}/tc_tests/hashcat_ripemd160_twofish.tc' hashca?l"
2866
;;
2867
esac
2868
;;
2869
2870
6212)
2871
case $tcMode in
2872
0)
2873
CMD="./${BIN} ${OPTS} -a 3 -m 6212 '${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish.tc' hashca?l"
2874
;;
2875
1)
2876
CMD="./${BIN} ${OPTS} -a 3 -m 6212 '${TDIR}/tc_tests/hashcat_ripemd160_serpent-aes.tc' hashca?l"
2877
;;
2878
2)
2879
CMD="./${BIN} ${OPTS} -a 3 -m 6212 '${TDIR}/tc_tests/hashcat_ripemd160_twofish-serpent.tc' hashca?l"
2880
;;
2881
esac
2882
;;
2883
2884
6213)
2885
case $tcMode in
2886
0)
2887
CMD="./${BIN} ${OPTS} -a 3 -m 6213 '${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish-serpent.tc' hashca?l"
2888
;;
2889
1)
2890
CMD="./${BIN} ${OPTS} -a 3 -m 6213 '${TDIR}/tc_tests/hashcat_ripemd160_serpent-twofish-aes.tc' hashca?l"
2891
;;
2892
esac
2893
;;
2894
2895
6221)
2896
case $tcMode in
2897
0)
2898
CMD="./${BIN} ${OPTS} -a 3 -m 6221 '${TDIR}/tc_tests/hashcat_sha512_aes.tc' hashca?l"
2899
;;
2900
1)
2901
CMD="./${BIN} ${OPTS} -a 3 -m 6221 '${TDIR}/tc_tests/hashcat_sha512_serpent.tc' hashca?l"
2902
;;
2903
2)
2904
CMD="./${BIN} ${OPTS} -a 3 -m 6221 '${TDIR}/tc_tests/hashcat_sha512_twofish.tc' hashca?l"
2905
;;
2906
esac
2907
;;
2908
2909
6222)
2910
case $tcMode in
2911
0)
2912
CMD="./${BIN} ${OPTS} -a 3 -m 6222 '${TDIR}/tc_tests/hashcat_sha512_aes-twofish.tc' hashca?l"
2913
;;
2914
1)
2915
CMD="./${BIN} ${OPTS} -a 3 -m 6222 '${TDIR}/tc_tests/hashcat_sha512_serpent-aes.tc' hashca?l"
2916
;;
2917
2)
2918
CMD="./${BIN} ${OPTS} -a 3 -m 6222 '${TDIR}/tc_tests/hashcat_sha512_twofish-serpent.tc' hashca?l"
2919
;;
2920
esac
2921
;;
2922
2923
6223)
2924
case $tcMode in
2925
0)
2926
CMD="./${BIN} ${OPTS} -a 3 -m 6223 '${TDIR}/tc_tests/hashcat_sha512_aes-twofish-serpent.tc' hashca?l"
2927
;;
2928
1)
2929
CMD="./${BIN} ${OPTS} -a 3 -m 6223 '${TDIR}/tc_tests/hashcat_sha512_serpent-twofish-aes.tc' hashca?l"
2930
;;
2931
esac
2932
;;
2933
2934
6231)
2935
case $tcMode in
2936
0)
2937
CMD="./${BIN} ${OPTS} -a 3 -m 6231 '${TDIR}/tc_tests/hashcat_whirlpool_aes.tc' hashca?l"
2938
;;
2939
1)
2940
CMD="./${BIN} ${OPTS} -a 3 -m 6231 '${TDIR}/tc_tests/hashcat_whirlpool_serpent.tc' hashca?l"
2941
;;
2942
2)
2943
CMD="./${BIN} ${OPTS} -a 3 -m 6231 '${TDIR}/tc_tests/hashcat_whirlpool_twofish.tc' hashca?l"
2944
;;
2945
esac
2946
;;
2947
2948
6232)
2949
case $tcMode in
2950
0)
2951
CMD="./${BIN} ${OPTS} -a 3 -m 6232 '${TDIR}/tc_tests/hashcat_whirlpool_aes-twofish.tc' hashca?l"
2952
;;
2953
1)
2954
CMD="./${BIN} ${OPTS} -a 3 -m 6232 '${TDIR}/tc_tests/hashcat_whirlpool_serpent-aes.tc' hashca?l"
2955
;;
2956
2)
2957
CMD="./${BIN} ${OPTS} -a 3 -m 6232 '${TDIR}/tc_tests/hashcat_whirlpool_twofish-serpent.tc' hashca?l"
2958
;;
2959
esac
2960
;;
2961
2962
6233)
2963
case $tcMode in
2964
0)
2965
CMD="./${BIN} ${OPTS} -a 3 -m 6233 '${TDIR}/tc_tests/hashcat_whirlpool_aes-twofish-serpent.tc' hashca?l"
2966
;;
2967
1)
2968
CMD="./${BIN} ${OPTS} -a 3 -m 6233 '${TDIR}/tc_tests/hashcat_whirlpool_serpent-twofish-aes.tc' hashca?l"
2969
;;
2970
esac
2971
;;
2972
2973
6241)
2974
case $tcMode in
2975
0)
2976
CMD="./${BIN} ${OPTS} -a 3 -m 6241 '${TDIR}/tc_tests/hashcat_ripemd160_aes_boot.tc' hashca?l"
2977
;;
2978
1)
2979
CMD="./${BIN} ${OPTS} -a 3 -m 6241 '${TDIR}/tc_tests/hashcat_ripemd160_serpent_boot.tc' hashca?l"
2980
;;
2981
2)
2982
CMD="./${BIN} ${OPTS} -a 3 -m 6241 '${TDIR}/tc_tests/hashcat_ripemd160_twofish_boot.tc' hashca?l"
2983
;;
2984
esac
2985
;;
2986
2987
6242)
2988
case $tcMode in
2989
0)
2990
CMD="./${BIN} ${OPTS} -a 3 -m 6242 '${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish_boot.tc' hashca?l"
2991
;;
2992
1)
2993
CMD="./${BIN} ${OPTS} -a 3 -m 6242 '${TDIR}/tc_tests/hashcat_ripemd160_serpent-aes_boot.tc' hashca?l"
2994
;;
2995
esac
2996
;;
2997
2998
6243)
2999
case $tcMode in
3000
0)
3001
CMD="./${BIN} ${OPTS} -a 3 -m 6243 '${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish-serpent_boot.tc' hashca?l"
3002
;;
3003
esac
3004
;;
3005
3006
29311)
3007
case $tcMode in
3008
0)
3009
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_aes.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_aes.hash
3010
CMD="./${BIN} ${OPTS} -a 3 -m 29311 '${OUTD}/tc_tests/hashcat_ripemd160_aes.hash' hashca?l"
3011
;;
3012
1)
3013
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_serpent.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_serpent.hash
3014
CMD="./${BIN} ${OPTS} -a 3 -m 29311 '${OUTD}/tc_tests/hashcat_ripemd160_serpent.hash' hashca?l"
3015
;;
3016
2)
3017
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_twofish.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_twofish.hash
3018
CMD="./${BIN} ${OPTS} -a 3 -m 29311 '${OUTD}/tc_tests/hashcat_ripemd160_twofish.hash' hashca?l"
3019
;;
3020
esac
3021
;;
3022
3023
29312)
3024
case $tcMode in
3025
0)
3026
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish.hash
3027
CMD="./${BIN} ${OPTS} -a 3 -m 29312 '${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish.hash' hashca?l"
3028
;;
3029
1)
3030
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_serpent-aes.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_serpent-aes.hash
3031
CMD="./${BIN} ${OPTS} -a 3 -m 29312 '${OUTD}/tc_tests/hashcat_ripemd160_serpent-aes.hash' hashca?l"
3032
;;
3033
2)
3034
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_twofish-serpent.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_twofish-serpent.hash
3035
CMD="./${BIN} ${OPTS} -a 3 -m 29312 '${OUTD}/tc_tests/hashcat_ripemd160_twofish-serpent.hash' hashca?l"
3036
;;
3037
esac
3038
;;
3039
3040
29313)
3041
case $tcMode in
3042
0)
3043
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish-serpent.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish-serpent.hash
3044
CMD="./${BIN} ${OPTS} -a 3 -m 29313 '${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish-serpent.hash' hashca?l"
3045
;;
3046
1)
3047
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_serpent-twofish-aes.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_serpent-twofish-aes.hash
3048
CMD="./${BIN} ${OPTS} -a 3 -m 29313 '${OUTD}/tc_tests/hashcat_ripemd160_serpent-twofish-aes.hash' hashca?l"
3049
;;
3050
esac
3051
;;
3052
3053
29321)
3054
case $tcMode in
3055
0)
3056
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_aes.tc\" > ${OUTD}/tc_tests/hashcat_sha512_aes.hash
3057
CMD="./${BIN} ${OPTS} -a 3 -m 29321 '${OUTD}/tc_tests/hashcat_sha512_aes.hash' hashca?l"
3058
;;
3059
1)
3060
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_serpent.tc\" > ${OUTD}/tc_tests/hashcat_sha512_serpent.hash
3061
CMD="./${BIN} ${OPTS} -a 3 -m 29321 '${OUTD}/tc_tests/hashcat_sha512_serpent.hash' hashca?l"
3062
;;
3063
2)
3064
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_twofish.tc\" > ${OUTD}/tc_tests/hashcat_sha512_twofish.hash
3065
CMD="./${BIN} ${OPTS} -a 3 -m 29321 '${OUTD}/tc_tests/hashcat_sha512_twofish.hash' hashca?l"
3066
;;
3067
esac
3068
;;
3069
3070
29322)
3071
case $tcMode in
3072
0)
3073
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_aes-twofish.tc\" > ${OUTD}/tc_tests/hashcat_sha512_aes-twofish.hash
3074
CMD="./${BIN} ${OPTS} -a 3 -m 29322 '${OUTD}/tc_tests/hashcat_sha512_aes-twofish.hash' hashca?l"
3075
;;
3076
1)
3077
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_serpent-aes.tc\" > ${OUTD}/tc_tests/hashcat_sha512_serpent-aes.hash
3078
CMD="./${BIN} ${OPTS} -a 3 -m 29322 '${OUTD}/tc_tests/hashcat_sha512_serpent-aes.hash' hashca?l"
3079
;;
3080
2)
3081
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_twofish-serpent.tc\" > ${OUTD}/tc_tests/hashcat_sha512_twofish-serpent.hash
3082
CMD="./${BIN} ${OPTS} -a 3 -m 29322 '${OUTD}/tc_tests/hashcat_sha512_twofish-serpent.hash' hashca?l"
3083
;;
3084
esac
3085
;;
3086
3087
29323)
3088
case $tcMode in
3089
0)
3090
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_aes-twofish-serpent.tc\" > ${OUTD}/tc_tests/hashcat_sha512_aes-twofish-serpent.hash
3091
CMD="./${BIN} ${OPTS} -a 3 -m 29323 '${OUTD}/tc_tests/hashcat_sha512_aes-twofish-serpent.hash' hashca?l"
3092
;;
3093
1)
3094
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_sha512_serpent-twofish-aes.tc\" > ${OUTD}/tc_tests/hashcat_sha512_serpent-twofish-aes.hash
3095
CMD="./${BIN} ${OPTS} -a 3 -m 29323 '${OUTD}/tc_tests/hashcat_sha512_serpent-twofish-aes.hash' hashca?l"
3096
;;
3097
esac
3098
;;
3099
3100
29331)
3101
case $tcMode in
3102
0)
3103
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_aes.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_aes.hash
3104
CMD="./${BIN} ${OPTS} -a 3 -m 29331 '${OUTD}/tc_tests/hashcat_whirlpool_aes.hash' hashca?l"
3105
;;
3106
1)
3107
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_serpent.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_serpent.hash
3108
CMD="./${BIN} ${OPTS} -a 3 -m 29331 '${OUTD}/tc_tests/hashcat_whirlpool_serpent.hash' hashca?l"
3109
;;
3110
2)
3111
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_twofish.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_twofish.hash
3112
CMD="./${BIN} ${OPTS} -a 3 -m 29331 '${OUTD}/tc_tests/hashcat_whirlpool_twofish.hash' hashca?l"
3113
;;
3114
esac
3115
;;
3116
3117
29332)
3118
case $tcMode in
3119
0)
3120
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_aes-twofish.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_aes-twofish.hash
3121
CMD="./${BIN} ${OPTS} -a 3 -m 29332 '${OUTD}/tc_tests/hashcat_whirlpool_aes-twofish.hash' hashca?l"
3122
;;
3123
1)
3124
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_serpent-aes.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_serpent-aes.hash
3125
CMD="./${BIN} ${OPTS} -a 3 -m 29332 '${OUTD}/tc_tests/hashcat_whirlpool_serpent-aes.hash' hashca?l"
3126
;;
3127
2)
3128
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_twofish-serpent.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_twofish-serpent.hash
3129
CMD="./${BIN} ${OPTS} -a 3 -m 29332 '${OUTD}/tc_tests/hashcat_whirlpool_twofish-serpent.hash' hashca?l"
3130
;;
3131
esac
3132
;;
3133
3134
29333)
3135
case $tcMode in
3136
0)
3137
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_aes-twofish-serpent.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_aes-twofish-serpent.hash
3138
CMD="./${BIN} ${OPTS} -a 3 -m 29333 '${OUTD}/tc_tests/hashcat_whirlpool_aes-twofish-serpent.hash' hashca?l"
3139
;;
3140
1)
3141
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_whirlpool_serpent-twofish-aes.tc\" > ${OUTD}/tc_tests/hashcat_whirlpool_serpent-twofish-aes.hash
3142
CMD="./${BIN} ${OPTS} -a 3 -m 29333 '${OUTD}/tc_tests/hashcat_whirlpool_serpent-twofish-aes.hash' hashca?l"
3143
;;
3144
esac
3145
;;
3146
3147
29341)
3148
case $tcMode in
3149
0)
3150
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_aes_boot.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_aes_boot.hash
3151
CMD="./${BIN} ${OPTS} -a 3 -m 29341 '${OUTD}/tc_tests/hashcat_ripemd160_aes_boot.hash' hashca?l"
3152
;;
3153
1)
3154
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_serpent_boot.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_serpent_boot.hash
3155
CMD="./${BIN} ${OPTS} -a 3 -m 29341 '${OUTD}/tc_tests/hashcat_ripemd160_serpent_boot.hash' hashca?l"
3156
;;
3157
2)
3158
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_twofish_boot.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_twofish_boot.hash
3159
CMD="./${BIN} ${OPTS} -a 3 -m 29341 '${OUTD}/tc_tests/hashcat_ripemd160_twofish_boot.hash' hashca?l"
3160
;;
3161
esac
3162
;;
3163
3164
29342)
3165
case $tcMode in
3166
0)
3167
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish_boot.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish_boot.hash
3168
CMD="./${BIN} ${OPTS} -a 3 -m 29342 '${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish_boot.hash' hashca?l"
3169
;;
3170
1)
3171
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_serpent-aes_boot.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_serpent-aes_boot.hash
3172
CMD="./${BIN} ${OPTS} -a 3 -m 29342 '${OUTD}/tc_tests/hashcat_ripemd160_serpent-aes_boot.hash' hashca?l"
3173
;;
3174
esac
3175
;;
3176
3177
29343)
3178
case $tcMode in
3179
0)
3180
eval \"${TDIR}/truecrypt2hashcat.py\" \"${TDIR}/tc_tests/hashcat_ripemd160_aes-twofish-serpent_boot.tc\" > ${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish-serpent_boot.hash
3181
CMD="./${BIN} ${OPTS} -a 3 -m 29343 '${OUTD}/tc_tests/hashcat_ripemd160_aes-twofish-serpent_boot.hash' hashca?l"
3182
;;
3183
esac
3184
;;
3185
esac
3186
3187
if [ ${#CMD} -gt 5 ]; then
3188
echo "> Testing hash type $hashType with attack mode 3, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, tcMode ${tcMode}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
3189
3190
output=$(eval ${CMD} 2>&1)
3191
3192
ret=${?}
3193
3194
echo "${output}" >> "${OUTD}/logfull.txt"
3195
3196
e_ce=0
3197
e_rs=0
3198
e_to=0
3199
e_nf=0
3200
e_nm=0
3201
cnt=0
3202
3203
status ${ret}
3204
3205
cnt=1
3206
3207
msg="OK"
3208
3209
if [ "${e_ce}" -ne 0 ]; then
3210
msg="Compare Error"
3211
elif [ "${e_rs}" -ne 0 ]; then
3212
msg="Skip"
3213
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
3214
msg="Error"
3215
elif [ "${e_to}" -ne 0 ]; then
3216
msg="Warning"
3217
fi
3218
3219
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 3, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, tcMode ${tcMode} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
3220
fi
3221
}
3222
3223
# Compose and execute hashcat command on a VeraCrypt test container
3224
# Must not be called for hash types other than 137XY/294XY
3225
# $1: cipher variation, can be 0-6
3226
function veracrypt_test()
3227
{
3228
cipher_variation=$1
3229
3230
hash_function=""
3231
3232
hash_digit="${hash_type:3:1}"
3233
[ "$hash_digit" -eq "1" ] && hash_function="ripemd160"
3234
[ "$hash_digit" -eq "2" ] && hash_function="sha512"
3235
[ "$hash_digit" -eq "3" ] && hash_function="whirlpool"
3236
[ "$hash_digit" -eq "5" ] && hash_function="sha256"
3237
[ "$hash_digit" -eq "7" ] && hash_function="streebog"
3238
3239
[ -n "$hash_function" ] || return
3240
3241
cipher_cascade=""
3242
3243
cipher_digit="${hash_type:4:1}"
3244
case $cipher_digit in
3245
1)
3246
[ "$cipher_variation" -eq "0" ] && cipher_cascade="aes"
3247
[ "$cipher_variation" -eq "1" ] && cipher_cascade="serpent"
3248
[ "$cipher_variation" -eq "2" ] && cipher_cascade="twofish"
3249
[ "$cipher_variation" -eq "3" ] && cipher_cascade="camellia"
3250
[ "$cipher_variation" -eq "5" ] && cipher_cascade="kuznyechik"
3251
;;
3252
2)
3253
[ "$cipher_variation" -eq "0" ] && cipher_cascade="aes-twofish"
3254
[ "$cipher_variation" -eq "1" ] && cipher_cascade="serpent-aes"
3255
[ "$cipher_variation" -eq "2" ] && cipher_cascade="twofish-serpent"
3256
[ "$cipher_variation" -eq "3" ] && cipher_cascade="camellia-kuznyechik"
3257
[ "$cipher_variation" -eq "4" ] && cipher_cascade="camellia-serpent"
3258
[ "$cipher_variation" -eq "5" ] && cipher_cascade="kuznyechik-aes"
3259
[ "$cipher_variation" -eq "6" ] && cipher_cascade="kuznyechik-twofish"
3260
;;
3261
3)
3262
[ "$cipher_variation" -eq "0" ] && cipher_cascade="aes-twofish-serpent"
3263
[ "$cipher_variation" -eq "1" ] && cipher_cascade="serpent-twofish-aes"
3264
[ "$cipher_variation" -eq "5" ] && cipher_cascade="kuznyechik-serpent-camellia"
3265
;;
3266
esac
3267
3268
[ -n "$cipher_cascade" ] || return
3269
3270
filename="${TDIR}/vc_tests/hashcat_${hash_function}_${cipher_cascade}.vc"
3271
3272
# The hash-cipher combination might be invalid (e.g. RIPEMD-160 + Kuznyechik)
3273
[ -f "${filename}" ] || return
3274
3275
case "${hash_type:0:3}" in
3276
137)
3277
CMD="./${BIN} ${OPTS} -a 3 -m ${hash_type} '${filename}' hashc?lt"
3278
;;
3279
3280
294)
3281
mkdir -p ${OUTD}/vc_tests
3282
chmod u+x "${TDIR}/veracrypt2hashcat.py"
3283
3284
eval \"${TDIR}/veracrypt2hashcat.py\" \"${TDIR}/vc_tests/hashcat_${hash_function}_${cipher_cascade}.vc\" > ${OUTD}/vc_tests/hashcat_${hash_function}_${cipher_cascade}.hash
3285
CMD="./${BIN} ${OPTS} -a 3 -m ${hash_type} '${OUTD}/vc_tests/hashcat_${hash_function}_${cipher_cascade}.hash' hashc?lt"
3286
;;
3287
esac
3288
3289
echo "> Testing hash type ${hash_type} with attack mode 0, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Cipher ${cipher_cascade}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
3290
3291
output=$(eval ${CMD} 2>&1)
3292
3293
ret=${?}
3294
3295
echo "${output}" >> "${OUTD}/logfull.txt"
3296
3297
e_ce=0
3298
e_rs=0
3299
e_to=0
3300
e_nf=0
3301
e_nm=0
3302
cnt=0
3303
3304
status ${ret}
3305
3306
cnt=1
3307
3308
msg="OK"
3309
3310
if [ "${e_ce}" -ne 0 ]; then
3311
msg="Compare Error"
3312
elif [ "${e_rs}" -ne 0 ]; then
3313
msg="Skip"
3314
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
3315
msg="Error"
3316
elif [ "${e_to}" -ne 0 ]; then
3317
msg="Warning"
3318
fi
3319
3320
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack 0, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Cipher ${cipher_cascade} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
3321
}
3322
3323
function luks_test()
3324
{
3325
hashType=$1
3326
attackType=$2
3327
3328
# if -m all was set let us default to -a 3 only. You could specify the attack type directly, e.g. -m 0
3329
# the problem with defaulting to all=0,1,3,6,7 is that it could take way too long
3330
3331
if [ "${attackType}" -eq 65535 ]; then
3332
attackType=3
3333
fi
3334
3335
mkdir -p "${OUTD}/luks_tests"
3336
chmod u+x "${TDIR}/luks2hashcat.py"
3337
3338
for luksMode in "cbc-essiv" "cbc-plain64" "xts-plain64"; do
3339
for luksKeySize in "128" "256" "512"; do
3340
CMD="unset"
3341
3342
# filter out not supported combinations:
3343
3344
case "${luksKeySize}" in
3345
128)
3346
case "${luksMode}" in
3347
cbc-essiv|cbc-plain64)
3348
;;
3349
*)
3350
continue
3351
;;
3352
esac
3353
;;
3354
256)
3355
case "${luksMode}" in
3356
cbc-essiv|cbc-plain64|xts-plain64)
3357
;;
3358
*)
3359
continue
3360
;;
3361
esac
3362
;;
3363
512)
3364
case "${luksMode}" in
3365
xts-plain64)
3366
;;
3367
*)
3368
continue
3369
;;
3370
esac
3371
;;
3372
esac
3373
3374
case $hashType in
3375
29511)
3376
luksHash="sha1"
3377
luksCipher="aes"
3378
;;
3379
3380
29512)
3381
luksHash="sha1"
3382
luksCipher="serpent"
3383
;;
3384
3385
29513)
3386
luksHash="sha1"
3387
luksCipher="twofish"
3388
;;
3389
3390
29521)
3391
luksHash="sha256"
3392
luksCipher="aes"
3393
;;
3394
3395
29522)
3396
luksHash="sha256"
3397
luksCipher="serpent"
3398
;;
3399
3400
29523)
3401
luksHash="sha256"
3402
luksCipher="twofish"
3403
;;
3404
3405
29531)
3406
luksHash="sha512"
3407
luksCipher="aes"
3408
;;
3409
3410
29532)
3411
luksHash="sha512"
3412
luksCipher="serpent"
3413
;;
3414
3415
29533)
3416
luksHash="sha512"
3417
luksCipher="twofish"
3418
;;
3419
3420
29541)
3421
luksHash="ripemd160"
3422
luksCipher="aes"
3423
;;
3424
3425
29542)
3426
luksHash="ripemd160"
3427
luksCipher="serpent"
3428
;;
3429
3430
29543)
3431
luksHash="ripemd160"
3432
luksCipher="twofish"
3433
;;
3434
3435
esac
3436
3437
luksMainMask="?l"
3438
luksMask="${luksMainMask}"
3439
3440
# for combination or hybrid attacks
3441
luksPassPartFile1="${OUTD}/${hashType}_dict1"
3442
luksPassPartFile2="${OUTD}/${hashType}_dict2"
3443
3444
luksContainer="${TDIR}/luks_tests/hashcat_${luksHash}_${luksCipher}_${luksMode}_${luksKeySize}.luks"
3445
luksHashFile="${OUTD}/luks_tests/hashcat_${luksHash}_${luksCipher}_${luksMode}_${luksKeySize}.hash"
3446
3447
case $attackType in
3448
0)
3449
CMD="./${BIN} ${OPTS} -a 0 -m ${hashType} '${luksHashFile}' '${TDIR}/luks_tests/pw'"
3450
;;
3451
1)
3452
luksPassPart1Len=$((${#LUKS_PASSWORD} / 2))
3453
luksPassPart2Start=$((luksPassPart1Len + 1))
3454
3455
echo "${LUKS_PASSWORD}" | cut -c-${luksPassPart1Len} > "${luksPassPartFile1}" 2>/dev/null
3456
echo "${LUKS_PASSWORD}" | cut -c${luksPassPart2Start}- > "${luksPassPartFile2}" 2>/dev/null
3457
3458
CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} '${luksHashFile}' ${luksPassPartFile1} ${luksPassPartFile2}"
3459
;;
3460
3)
3461
luksMaskFixedLen=$((${#LUKS_PASSWORD} - 1))
3462
3463
luksMask="$(echo "${LUKS_PASSWORD}" | cut -c-${luksMaskFixedLen} 2>/dev/null)"
3464
luksMask="${luksMask}${luksMainMask}"
3465
3466
CMD="./${BIN} ${OPTS} -a 3 -m ${hashType} '${luksHashFile}' ${luksMask}"
3467
;;
3468
6)
3469
luksPassPart1Len=$((${#LUKS_PASSWORD} - 1))
3470
3471
echo "${LUKS_PASSWORD}" | cut -c-${luksPassPart1Len} > "${luksPassPartFile1}" 2>/dev/null
3472
3473
CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} '${luksHashFile}' ${luksPassPartFile1} ${luksMask}"
3474
;;
3475
7)
3476
echo "${LUKS_PASSWORD}" | cut -c2- > "${luksPassPartFile1}" 2>/dev/null
3477
3478
CMD="./${BIN} ${OPTS} -a 7 -m ${hashType} '${luksHashFile}' ${luksMask} ${luksPassPartFile1}"
3479
;;
3480
esac
3481
3482
eval \"${TDIR}/luks2hashcat.py\" \"${luksContainer}\" > "${luksHashFile}"
3483
3484
luksMode="${luksHash}-${luksCipher}-${luksMode}-${luksKeySize}"
3485
3486
if [ -n "${CMD}" ] && [ ${#CMD} -gt 5 ]; then
3487
echo "> Testing hash type ${hashType} with attack mode ${attackType}, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Luks-Mode ${luksMode}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
3488
3489
if [ -f "${luks_first_test_file}" ]; then
3490
output=$(eval ${CMD} 2>&1)
3491
ret=${?}
3492
3493
echo "${output}" >> "${OUTD}/logfull.txt"
3494
else
3495
ret=30
3496
fi
3497
3498
e_ce=0
3499
e_rs=0
3500
e_to=0
3501
e_nf=0
3502
e_nm=0
3503
cnt=0
3504
3505
status ${ret}
3506
3507
cnt=1
3508
3509
msg="OK"
3510
3511
if [ "${e_ce}" -ne 0 ]; then
3512
msg="Compare Error"
3513
elif [ "${e_rs}" -ne 0 ]; then
3514
msg="Skip"
3515
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
3516
msg="Error"
3517
elif [ "${e_to}" -ne 0 ]; then
3518
msg="Warning"
3519
fi
3520
3521
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack ${attackType}, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Luks-Mode ${luksMode} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
3522
3523
status ${ret}
3524
fi
3525
done
3526
done
3527
}
3528
3529
function luks_legacy_test()
3530
{
3531
hashType=$1
3532
attackType=$2
3533
3534
# if -m all was set let us default to -a 3 only. You could specify the attack type directly, e.g. -m 0
3535
# the problem with defaulting to all=0,1,3,6,7 is that it could take way too long
3536
3537
if [ "${attackType}" -eq 65535 ]; then
3538
attackType=3
3539
fi
3540
3541
#LUKS_HASHES="sha1 sha256 sha512 ripemd160 whirlpool"
3542
LUKS_HASHES="sha1 sha256 sha512 ripemd160"
3543
LUKS_CIPHERS="aes serpent twofish"
3544
LUKS_CIPHER_MODES="cbc-essiv cbc-plain64 xts-plain64"
3545
LUKS_KEYSIZES="128 256 512"
3546
3547
LUKS_PASSWORD=$(cat "${TDIR}/luks_tests/pw" 2>/dev/null)
3548
3549
for luks_h in ${LUKS_HASHES}; do
3550
for luks_c in ${LUKS_CIPHERS}; do
3551
for luks_m in ${LUKS_CIPHER_MODES}; do
3552
for luks_k in ${LUKS_KEYSIZES}; do
3553
3554
CMD=""
3555
3556
# filter out not supported combinations:
3557
3558
case "${luks_k}" in
3559
128)
3560
case "${luks_m}" in
3561
cbc-essiv|cbc-plain64)
3562
;;
3563
*)
3564
continue
3565
;;
3566
esac
3567
;;
3568
256)
3569
case "${luks_m}" in
3570
cbc-essiv|cbc-plain64|xts-plain64)
3571
;;
3572
*)
3573
continue
3574
;;
3575
esac
3576
;;
3577
512)
3578
case "${luks_m}" in
3579
xts-plain64)
3580
;;
3581
*)
3582
continue
3583
;;
3584
esac
3585
;;
3586
esac
3587
3588
luks_mode="${luks_h}-${luks_c}-${luks_m}-${luks_k}"
3589
luks_file="${TDIR}/luks_tests/hashcat_${luks_h}_${luks_c}_${luks_m}_${luks_k}.luks"
3590
luks_main_mask="?l"
3591
luks_mask="${luks_main_mask}"
3592
3593
# for combination or hybrid attacks
3594
luks_pass_part_file1="${OUTD}/${hashType}_dict1"
3595
luks_pass_part_file2="${OUTD}/${hashType}_dict2"
3596
3597
case $attackType in
3598
0)
3599
CMD="./${BIN} ${OPTS} -a 0 -m ${hashType} '${luks_file}' '${TDIR}/luks_tests/pw'"
3600
;;
3601
1)
3602
luks_pass_part1_len=$((${#LUKS_PASSWORD} / 2))
3603
luks_pass_part2_start=$((luks_pass_part1_len + 1))
3604
3605
echo "${LUKS_PASSWORD}" | cut -c-${luks_pass_part1_len} > "${luks_pass_part_file1}" 2>/dev/null
3606
echo "${LUKS_PASSWORD}" | cut -c${luks_pass_part2_start}- > "${luks_pass_part_file2}" 2>/dev/null
3607
3608
CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} '${luks_file}' ${luks_pass_part_file1} ${luks_pass_part_file2}"
3609
;;
3610
3)
3611
luks_mask_fixed_len=$((${#LUKS_PASSWORD} - 1))
3612
3613
luks_mask="$(echo "${LUKS_PASSWORD}" | cut -c-${luks_mask_fixed_len} 2>/dev/null)"
3614
luks_mask="${luks_mask}${luks_main_mask}"
3615
3616
CMD="./${BIN} ${OPTS} -a 3 -m ${hashType} '${luks_file}' ${luks_mask}"
3617
;;
3618
6)
3619
luks_pass_part1_len=$((${#LUKS_PASSWORD} - 1))
3620
3621
echo "${LUKS_PASSWORD}" | cut -c-${luks_pass_part1_len} > "${luks_pass_part_file1}" 2>/dev/null
3622
3623
CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} '${luks_file}' ${luks_pass_part_file1} ${luks_mask}"
3624
;;
3625
7)
3626
echo "${LUKS_PASSWORD}" | cut -c2- > "${luks_pass_part_file1}" 2>/dev/null
3627
3628
CMD="./${BIN} ${OPTS} -a 7 -m ${hashType} '${luks_file}' ${luks_mask} ${luks_pass_part_file1}"
3629
;;
3630
esac
3631
3632
if [ -n "${CMD}" ]; then
3633
echo "> Testing hash type ${hashType} with attack mode ${attackType}, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, luksMode ${luks_mode}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
3634
3635
if [ -f "${luks_first_test_file}" ]; then
3636
output=$(eval ${CMD} 2>&1)
3637
ret=${?}
3638
3639
echo "${output}" >> "${OUTD}/logfull.txt"
3640
else
3641
ret=30
3642
fi
3643
3644
e_ce=0
3645
e_rs=0
3646
e_to=0
3647
e_nf=0
3648
e_nm=0
3649
cnt=0
3650
3651
status ${ret}
3652
3653
cnt=1
3654
3655
msg="OK"
3656
3657
if [ "${e_ce}" -ne 0 ]; then
3658
msg="Compare Error"
3659
elif [ "${e_rs}" -ne 0 ]; then
3660
msg="Skip"
3661
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
3662
msg="Error"
3663
elif [ "${e_to}" -ne 0 ]; then
3664
msg="Warning"
3665
fi
3666
3667
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack ${attackType}, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, luksMode ${luks_mode} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
3668
3669
status ${ret}
3670
fi
3671
done
3672
done
3673
done
3674
done
3675
}
3676
3677
3678
3679
function luks2_test()
3680
{
3681
local LUKS2_PASSWORD=$(cat "${TDIR}/luks2_tests/pw" 2>/dev/null)
3682
3683
hashType=$1
3684
attackType=$2
3685
3686
# if -m all was set let us default to -a 3 only. You could specify the attack type directly, e.g. -m 0
3687
# the problem with defaulting to all=0,1,3,6,7 is that it could take way too long
3688
3689
if [ "${attackType}" -eq 65535 ]; then
3690
attackType=3
3691
fi
3692
3693
chmod u+x "${TDIR}/luks2hashcat.py"
3694
3695
for luks2File in $(ls ${TDIR}/luks2_tests | grep "img$"); do
3696
luksMainMask="?l"
3697
luksMask="${luksMainMask}"
3698
3699
# for combination or hybrid attacks
3700
luksPassPartFile1="${OUTD}/${hashType}_dict1"
3701
luksPassPartFile2="${OUTD}/${hashType}_dict2"
3702
3703
luksContainer="${TDIR}/luks2_tests/${luks2File}"
3704
3705
mkdir -p "${OUTD}/luks2_tests"
3706
luksHashFile="${OUTD}/luks2_tests/${luks2File}.hash"
3707
3708
case $attackType in
3709
0)
3710
CMD="./${BIN} ${OPTS} -a 0 -m ${hashType} '${luksHashFile}' '${TDIR}/luks2_tests/pw'"
3711
;;
3712
1)
3713
luksPassPart1Len=$((${#LUKS2_PASSWORD} / 2))
3714
luksPassPart2Start=$((luksPassPart1Len + 1))
3715
3716
echo "${LUKS2_PASSWORD}" | cut -c-${luksPassPart1Len} > "${luksPassPartFile1}" 2>/dev/null
3717
echo "${LUKS2_PASSWORD}" | cut -c${luksPassPart2Start}- > "${luksPassPartFile2}" 2>/dev/null
3718
3719
CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} '${luksHashFile}' ${luksPassPartFile1} ${luksPassPartFile2}"
3720
;;
3721
3)
3722
luksMaskFixedLen=$((${#LUKS2_PASSWORD} - 1))
3723
3724
luksMask="$(echo "${LUKS2_PASSWORD}" | cut -c-${luksMaskFixedLen} 2>/dev/null)"
3725
luksMask="${luksMask}${luksMainMask}"
3726
3727
CMD="./${BIN} ${OPTS} -a 3 -m ${hashType} '${luksHashFile}' ${luksMask}"
3728
;;
3729
6)
3730
luksPassPart1Len=$((${#LUKS2_PASSWORD} - 1))
3731
3732
echo "${LUKS2_PASSWORD}" | cut -c-${luksPassPart1Len} > "${luksPassPartFile1}" 2>/dev/null
3733
3734
CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} '${luksHashFile}' ${luksPassPartFile1} ${luksMask}"
3735
;;
3736
7)
3737
echo "${LUKS2_PASSWORD}" | cut -c2- > "${luksPassPartFile1}" 2>/dev/null
3738
3739
CMD="./${BIN} ${OPTS} -a 7 -m ${hashType} '${luksHashFile}' ${luksMask} ${luksPassPartFile1}"
3740
;;
3741
esac
3742
3743
eval \"${TDIR}/luks2hashcat.py\" \"${luksContainer}\" > "${luksHashFile}"
3744
3745
luksMode="$(basename "$luksContainer" .img)"
3746
3747
if [ -n "${CMD}" ] && [ ${#CMD} -gt 5 ]; then
3748
echo "> Testing hash type ${hashType} with attack mode ${attackType}, markov ${MARKOV}, single hash, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, LUKS2-mode ${luksMode}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt"
3749
3750
if [ -f "${luks2_first_test_file}" ]; then
3751
output=$(eval ${CMD} 2>&1)
3752
ret=${?}
3753
3754
echo "${output}" >> "${OUTD}/logfull.txt"
3755
else
3756
ret=30
3757
fi
3758
3759
e_ce=0
3760
e_rs=0
3761
e_to=0
3762
e_nf=0
3763
e_nm=0
3764
cnt=0
3765
3766
status ${ret}
3767
3768
cnt=1
3769
3770
msg="OK"
3771
3772
if [ "${e_ce}" -ne 0 ]; then
3773
msg="Compare Error"
3774
elif [ "${e_rs}" -ne 0 ]; then
3775
msg="Skip"
3776
elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ] || [ "${cnt}" -eq 0 ]; then
3777
msg="Error"
3778
elif [ "${e_to}" -ne 0 ]; then
3779
msg="Warning"
3780
fi
3781
3782
echo "[ ${OUTD} ] [ Type ${hash_type}, Attack ${attackType}, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, LUKS2-mode ${luksMode} ] > $msg : ${e_nf}/${cnt} not found, ${e_nm}/${cnt} not matched, ${e_to}/${cnt} timeout, ${e_rs}/${cnt} skipped"
3783
3784
status ${ret}
3785
fi
3786
done
3787
}
3788
3789
3790
function usage()
3791
{
3792
cat << EOF
3793
> Usage : ${0} <options>
3794
3795
OPTIONS:
3796
3797
-V Backend vector-width (either 1, 2, 4 or 8), overrides value from device query :
3798
'1' => vector-width 1
3799
'2' => vector-width 2 (default)
3800
'4' => vector-width 4
3801
'8' => vector-width 8
3802
'all' => test sequentially vector-width ${VECTOR_WIDTHS}
3803
3804
-t Select test mode :
3805
'single' => single hash (default)
3806
'multi' => multi hash
3807
'all' => single and multi hash
3808
3809
-m Select hash type :
3810
'all' => all hash type supported
3811
(int) => hash type integer code (default : 0)
3812
(int)-(int) => hash type integer range
3813
3814
-a Select attack mode :
3815
'all' => all attack modes
3816
(int) => attack mode integer code (default : 0)
3817
3818
-x Select cpu architecture :
3819
'32' => 32 bit architecture
3820
'64' => 64 bit architecture (default)
3821
3822
-o Select operating system :
3823
'win' => Windows operating system (use .exe file extension)
3824
'linux' => Linux operating system (use .bin file extension)
3825
'macos' => macOS operating system (use .app file extension)
3826
3827
-d Select the Backend device :
3828
(int)[,int] => comma separated list of devices (default : 1)
3829
3830
-D Select the OpenCL device types :
3831
'1' => CPU
3832
'2' => GPU (default)
3833
'3' => FPGA, DSP, Co-Processor
3834
(int)[,int] => multiple comma separated device types from the list above
3835
3836
-O Use optimized kernels (default : -O)
3837
3838
-P Use pure kernels instead of optimized kernels (default : -O)
3839
3840
-s Use this session name instead of the default one (default : "hashcat")
3841
3842
-c Disables markov-chains
3843
3844
-f Use --force to ignore hashcat warnings (default : disabled)
3845
3846
-r Setup max runtime limit (default: 400)
3847
3848
-p Package the tests into a .7z file
3849
3850
-F Use this folder as test folder instead of the default one
3851
(string) => path to folder
3852
3853
-I Use this folder as input/output folder for packaged tests
3854
(string) => path to folder
3855
3856
-g Generate crypto-containers on-the-fly (requires sudo)
3857
3858
-h Show this help
3859
3860
EOF
3861
3862
exit 1
3863
}
3864
3865
BIN="hashcat"
3866
MARKOV="enabled"
3867
ATTACK=0
3868
MODE=0
3869
DEVICE_TYPE="null"
3870
KERNEL_TYPE="Optimized"
3871
VECTOR="default"
3872
HT=0
3873
PACKAGE=0
3874
OPTIMIZED=1
3875
GENERATE_CONTAINERS=0
3876
3877
while getopts "V:t:m:a:b:hcpd:x:o:d:D:F:POI:s:fr:g" opt; do
3878
3879
case ${opt} in
3880
"V")
3881
if [ "${OPTARG}" = "1" ]; then
3882
VECTOR=1
3883
elif [ "${OPTARG}" = "2" ]; then
3884
VECTOR=2
3885
elif [ "${OPTARG}" = "4" ]; then
3886
VECTOR=4
3887
elif [ "${OPTARG}" = "8" ]; then
3888
VECTOR=8
3889
elif [ "${OPTARG}" = "16" ]; then
3890
VECTOR=16
3891
elif [ "${OPTARG}" = "all" ]; then
3892
VECTOR="all"
3893
else
3894
usage
3895
fi
3896
;;
3897
3898
"t")
3899
if [ "${OPTARG}" = "single" ]; then
3900
MODE=0
3901
elif [ "${OPTARG}" = "multi" ]; then
3902
MODE=1
3903
elif [ "${OPTARG}" = "all" ]; then
3904
MODE=2
3905
else
3906
usage
3907
fi
3908
;;
3909
3910
"m")
3911
if [ "${OPTARG}" = "all" ]; then
3912
HT=65535
3913
else
3914
HT=${OPTARG}
3915
fi
3916
;;
3917
3918
"a")
3919
if [ "${OPTARG}" = "all" ]; then
3920
ATTACK=65535
3921
elif [ "${OPTARG}" = "0" ]; then
3922
ATTACK=0
3923
elif [ "${OPTARG}" = "1" ]; then
3924
ATTACK=1
3925
elif [ "${OPTARG}" = "3" ]; then
3926
ATTACK=3
3927
elif [ "${OPTARG}" = "6" ]; then
3928
ATTACK=6
3929
elif [ "${OPTARG}" = "7" ]; then
3930
ATTACK=7
3931
else
3932
usage
3933
fi
3934
;;
3935
3936
"c")
3937
OPTS="${OPTS} --markov-disable"
3938
MARKOV="disabled"
3939
;;
3940
3941
"I")
3942
PACKAGE_FOLDER=$( echo "${OPTARG}" | sed 's!/$!!g' )
3943
;;
3944
3945
"s")
3946
OPTS="${OPTS} --session \"${OPTARG}\""
3947
;;
3948
3949
"p")
3950
PACKAGE=1
3951
;;
3952
3953
"x")
3954
if [ "${OPTARG}" = "32" ]; then
3955
ARCHITECTURE=32
3956
elif [ "${OPTARG}" = "64" ]; then
3957
ARCHITECTURE=64
3958
else
3959
usage
3960
fi
3961
;;
3962
3963
"o")
3964
if [ "${OPTARG}" = "win" ]; then
3965
EXTENSION="exe"
3966
elif [ "${OPTARG}" = "linux" ]; then
3967
EXTENSION="bin"
3968
elif [ "${OPTARG}" = "macos" ]; then
3969
EXTENSION="app"
3970
else
3971
usage
3972
fi
3973
;;
3974
3975
"O")
3976
# optimized is already default, ignore it
3977
;;
3978
3979
"d")
3980
OPTS="${OPTS} -d ${OPTARG}"
3981
;;
3982
3983
"D")
3984
if [ "${OPTARG}" = "1" ]; then
3985
OPTS="${OPTS} -D 1"
3986
DEVICE_TYPE="Cpu"
3987
elif [ "${OPTARG}" = "2" ]; then
3988
OPTS="${OPTS} -D 2"
3989
DEVICE_TYPE="Gpu"
3990
else
3991
OPTS="${OPTS} -D ${OPTARG}"
3992
DEVICE_TYPE="Cpu + Gpu"
3993
fi
3994
;;
3995
3996
"F")
3997
OUTD=$( echo "${OPTARG}" | sed 's!/$!!g' )
3998
;;
3999
4000
"P")
4001
OPTIMIZED=0
4002
KERNEL_TYPE="Pure"
4003
;;
4004
4005
"f")
4006
FORCE=1
4007
;;
4008
4009
"r")
4010
RUNTIME=${OPTARG}
4011
;;
4012
4013
"g")
4014
GENERATE_CONTAINERS=1
4015
;;
4016
4017
\?)
4018
usage
4019
;;
4020
4021
"h")
4022
usage
4023
;;
4024
esac
4025
4026
done
4027
4028
# handle Apple Silicon
4029
4030
IS_APPLE_SILICON=0
4031
4032
if [ $(uname) == "Darwin" ]; then
4033
BIN_sysctl=$(which sysctl)
4034
if [ $? -eq 0 ]; then
4035
CPU_TYPE=$(sysctl hw.cputype | awk '{print $2}')
4036
4037
if [ ${CPU_TYPE} -eq 16777228 ]; then
4038
IS_APPLE_SILICON=1
4039
fi
4040
fi
4041
fi
4042
4043
export IS_OPTIMIZED=${OPTIMIZED}
4044
4045
if [ "${OPTIMIZED}" -eq 1 ]; then
4046
OPTS="${OPTS} -O"
4047
fi
4048
4049
# set max-runtime
4050
4051
OPTS="${OPTS} --runtime ${RUNTIME}"
4052
4053
# set default device-type to CPU with Apple Intel, else GPU
4054
4055
if [ "${DEVICE_TYPE}" = "null" ]; then
4056
if [ $(uname) == "Darwin" ] && [ ${IS_APPLE_SILICON} -eq 0 ]; then
4057
OPTS="${OPTS} -D 1"
4058
DEVICE_TYPE="Cpu"
4059
else
4060
OPTS="${OPTS} -D 2"
4061
DEVICE_TYPE="Gpu"
4062
fi
4063
fi
4064
4065
if [ ${FORCE} -eq 1 ]; then
4066
OPTS="${OPTS} --force"
4067
fi
4068
4069
if [ -n "${ARCHITECTURE}" ]; then
4070
BIN="${BIN}${ARCHITECTURE}"
4071
fi
4072
4073
if [ -n "${EXTENSION}" ]; then
4074
BIN="${BIN}.${EXTENSION}"
4075
fi
4076
4077
if [ -n "${PACKAGE_FOLDER}" ]; then
4078
if [ ! -e "${PACKAGE_FOLDER}" ]; then
4079
echo "! folder '${PACKAGE_FOLDER}' does not exist"
4080
exit 1
4081
fi
4082
fi
4083
4084
if [ "${PACKAGE}" -eq 0 ] || [ -z "${PACKAGE_FOLDER}" ]; then
4085
4086
# check existence of binary
4087
if [ ! -e "${BIN}" ]; then
4088
echo "! ${BIN} not found, please build binary before run test."
4089
exit 1
4090
fi
4091
4092
HT_MIN=0
4093
HT_MAX=0
4094
4095
if echo -n "${HT}" | grep -q '^[0-9]\+$'; then
4096
HT_MIN=${HT}
4097
HT_MAX=${HT}
4098
elif echo -n "${HT}" | grep -q '^[0-9]\+-[1-9][0-9]*$'; then
4099
HT_MIN=$(echo -n ${HT} | sed "s/-.*//")
4100
HT_MAX=$(echo -n ${HT} | sed "s/.*-//")
4101
4102
if [ "${HT_MIN}" -gt "${HT_MAX}" ]; then
4103
echo "! hash type range -m ${HT} is not valid ..."
4104
usage
4105
fi
4106
else
4107
echo "! hash type is not a number ..."
4108
usage
4109
fi
4110
4111
HT=${HT_MIN}
4112
4113
# filter by hash_type
4114
if [ "${HT}" -ne 65535 ]; then
4115
4116
# validate filter
4117
4118
if ! is_in_array "${HT_MIN}" ${HASH_TYPES}; then
4119
echo "! invalid hash type selected ..."
4120
usage
4121
fi
4122
4123
if ! is_in_array "${HT_MAX}" ${HASH_TYPES}; then
4124
echo "! invalid hash type selected ..."
4125
usage
4126
fi
4127
fi
4128
4129
4130
if [[ "${GENERATE_CONTAINERS}" -eq 1 ]]; then
4131
if sudo -n true 2>/dev/null; then
4132
true
4133
else
4134
echo "We'll need sudo to generate crypto-containers on-the-fly"
4135
fi
4136
fi
4137
4138
if [ -z "${PACKAGE_FOLDER}" ]; then
4139
4140
# make new dir
4141
mkdir -p "${OUTD}"
4142
4143
# generate random test entry
4144
if [ "${HT}" -eq 65535 ]; then
4145
for TMP_HT in ${HASH_TYPES}; do
4146
4147
if ! ( is_in_array "${TMP_HT}" ${LUKS1_ALL_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ); then
4148
if ! ( is_in_array "${TMP_HT}" ${LUKS2_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ); then
4149
if ! is_in_array "${TMP_HT}" ${TC_MODES}; then
4150
if ! is_in_array "${TMP_HT}" ${VC_MODES}; then
4151
if ! is_in_array "${TMP_HT}" ${CL_MODES}; then
4152
perl tools/test.pl single "${TMP_HT}" >> "${OUTD}/all.sh"
4153
fi
4154
fi
4155
fi
4156
fi
4157
fi
4158
4159
done
4160
else
4161
for TMP_HT in $(seq "${HT_MIN}" "${HT_MAX}"); do
4162
if ! is_in_array "${TMP_HT}" ${HASH_TYPES}; then
4163
continue
4164
fi
4165
4166
if ! ( is_in_array "${TMP_HT}" ${LUKS1_ALL_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ); then
4167
if ! ( is_in_array "${TMP_HT}" ${LUKS2_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ); then
4168
if ! is_in_array "${TMP_HT}" ${TC_MODES}; then
4169
if ! is_in_array "${TMP_HT}" ${VC_MODES}; then
4170
if ! is_in_array "${TMP_HT}" ${CL_MODES}; then
4171
perl tools/test.pl single "${TMP_HT}" >> "${OUTD}/all.sh"
4172
fi
4173
fi
4174
fi
4175
fi
4176
fi
4177
done
4178
fi
4179
4180
else
4181
4182
OUTD=${PACKAGE_FOLDER}
4183
4184
fi
4185
4186
rm -rf "${OUTD}/logfull.txt" && touch "${OUTD}/logfull.txt"
4187
4188
# populate array of hash types where we only should check if pass is in output (not both hash:pass)
4189
IFS=';' read -ra PASS_ONLY <<< "${HASHFILE_ONLY} ${NOCHECK_ENCODING}"
4190
IFS=';' read -ra TIMEOUT_ALGOS <<< "${SLOW_ALGOS}"
4191
4192
IFS=';' read -ra KEEP_GUESSING_ALGOS <<< "${KEEP_GUESSING}"
4193
4194
# for these particular algos we need to save the output to a temporary file
4195
IFS=';' read -ra FILE_BASED_ALGOS <<< "${HASHFILE_ONLY}"
4196
4197
for hash_type in $HASH_TYPES; do
4198
4199
if [ "${HT}" -ne 65535 ]; then
4200
# check if the loop variable "hash_type" is between HT_MIN and HT_MAX (both included)
4201
4202
if [ "${hash_type}" -lt "${HT_MIN}" ]; then
4203
continue
4204
elif [ "${hash_type}" -gt "${HT_MAX}" ]; then
4205
# we are done because hash_type is larger than range:
4206
break
4207
fi
4208
fi
4209
4210
if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key
4211
if [ "${MODE}" -eq 1 ]; then # if "multi" was forced we need to skip it
4212
if [ "${HT_MIN}" -eq 20510 ]; then
4213
if [ "${HT_MAX}" -eq 20510 ]; then
4214
echo "ERROR: -m 20510 = PKZIP Master Key can only be run with a single hash"
4215
fi
4216
fi
4217
4218
continue
4219
fi
4220
fi
4221
4222
# skip deprecated hash-types
4223
if [ "${hash_type}" -eq 2500 ] || [ "${hash_type}" -eq 2501 ] || [ "${hash_type}" -eq 16800 ] || [ "${hash_type}" -eq 16801 ] ; then
4224
continue
4225
fi
4226
4227
# test.pl produce wrong hashes with Apple
4228
# would be necessary to investigate to understand why
4229
if [ "${hash_type}" -eq 1800 ]; then
4230
if [[ "$OSTYPE" == "darwin"* ]]; then
4231
continue
4232
fi
4233
fi
4234
4235
# Digest::BLAKE2 is broken on Apple Silicon
4236
if [ "${hash_type}" -eq 600 ]; then
4237
if [ "${IS_APPLE_SILICON}" -eq 1 ]; then
4238
continue
4239
fi
4240
fi
4241
4242
# Digest::GOST is broken on Apple Silicon
4243
if [ "${hash_type}" -eq 6900 ]; then
4244
if [ "${IS_APPLE_SILICON}" -eq 1 ]; then
4245
continue
4246
fi
4247
fi
4248
4249
# Crypt::GCrypt is broken on Apple
4250
if [ "${hash_type}" -eq 18600 ]; then
4251
if [[ "$OSTYPE" == "darwin"* ]]; then
4252
continue
4253
fi
4254
fi
4255
4256
if [ -z "${PACKAGE_FOLDER}" ]; then
4257
# init test data
4258
init
4259
else
4260
echo "[ ${OUTD} ] > Run packaged test for hash type $hash_type."
4261
fi
4262
4263
if [ "${PACKAGE}" -eq 0 ]; then
4264
4265
# should we check only the pass?
4266
pass_only=0
4267
is_in_array "${hash_type}" ${PASS_ONLY} && pass_only=1
4268
4269
IS_SLOW=0
4270
is_in_array "${hash_type}" ${SLOW_ALGOS} && IS_SLOW=1
4271
4272
# we use phpass as slow hash for testing the AMP kernel
4273
[ "${hash_type}" -eq 400 ] && IS_SLOW=0
4274
4275
OPTS_OLD=${OPTS}
4276
VECTOR_OLD=${VECTOR}
4277
MODE_OLD=${MODE}
4278
4279
if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key
4280
if [ "${MODE}" -eq 1 ]; then # if "multi" was forced we need to skip it
4281
continue
4282
fi
4283
4284
MODE=0 # force single only
4285
fi
4286
4287
for CUR_WIDTH in $VECTOR_WIDTHS; do
4288
4289
if [ "${VECTOR_OLD}" = "all" ] || [ "${VECTOR_OLD}" = "default" ] || [ "${VECTOR_OLD}" = "${CUR_WIDTH}" ]; then
4290
4291
if [ "${VECTOR_OLD}" = "default" ] && \
4292
[ "${CUR_WIDTH}" != "1" ] && \
4293
[ "${CUR_WIDTH}" != "4" ]; then
4294
4295
continue
4296
fi
4297
4298
VECTOR=${CUR_WIDTH}
4299
OPTS="${OPTS_OLD} --backend-vector-width ${VECTOR}"
4300
4301
# Slow hashes only have a single kernel to test, so we only test with a0
4302
if [ ${IS_SLOW} -eq 1 ]; then
4303
4304
# Look up if this is one of supported VeraCrypt modes
4305
if is_in_array "${hash_type}" ${VC_MODES}; then
4306
veracrypt_test 0 # aes
4307
veracrypt_test 1 # serpent
4308
veracrypt_test 2 # twofish
4309
veracrypt_test 3 # camellia
4310
veracrypt_test 4 # camellia (alternative cascade)
4311
veracrypt_test 5 # kuznyechik
4312
veracrypt_test 6 # kuznyechik (alternative cascade)
4313
elif is_in_array "${hash_type}" ${TC_MODES}; then
4314
# run truecrypt tests
4315
truecrypt_test "${hash_type}" 0
4316
truecrypt_test "${hash_type}" 1
4317
truecrypt_test "${hash_type}" 2
4318
elif is_in_array "${hash_type}" ${LUKS1_ALL_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ; then
4319
# run luks tests
4320
if [ ${hash_type} -eq 14600 ]; then
4321
# for legacy mode
4322
luks_legacy_test "${hash_type}" ${ATTACK}
4323
else
4324
# for new modes
4325
luks_test "${hash_type}" ${ATTACK}
4326
fi
4327
elif is_in_array "${hash_type}" ${LUKS2_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
4328
# run luks2 tests
4329
luks2_test "${hash_type}" ${ATTACK}
4330
else
4331
# run attack mode 0 (stdin)
4332
if [ ${ATTACK} -eq 65535 ] || [ ${ATTACK} -eq 0 ]; then attack_0; fi
4333
fi
4334
4335
else
4336
4337
if is_in_array "${hash_type}" ${CL_MODES}; then
4338
# run cryptoloop tests
4339
cryptoloop_test "${hash_type}" 128
4340
cryptoloop_test "${hash_type}" 192
4341
cryptoloop_test "${hash_type}" 256
4342
else
4343
# run attack mode 0 (stdin)
4344
if [ ${ATTACK} -eq 65535 ] || [ ${ATTACK} -eq 0 ]; then attack_0; fi
4345
4346
# run attack mode 1 (combinator)
4347
if [ ${ATTACK} -eq 65535 ] || [ ${ATTACK} -eq 1 ]; then attack_1; fi
4348
4349
# run attack mode 3 (bruteforce)
4350
if [ ${ATTACK} -eq 65535 ] || [ ${ATTACK} -eq 3 ]; then attack_3; fi
4351
4352
# run attack mode 6 (dict+mask)
4353
if [ ${ATTACK} -eq 65535 ] || [ ${ATTACK} -eq 6 ]; then attack_6; fi
4354
4355
# run attack mode 7 (mask+dict)
4356
if [ ${ATTACK} -eq 65535 ] || [ ${ATTACK} -eq 7 ]; then attack_7; fi
4357
fi
4358
4359
fi
4360
fi
4361
done
4362
OPTS="${OPTS_OLD}"
4363
VECTOR="${VECTOR_OLD}"
4364
MODE=${MODE_OLD}
4365
fi
4366
done
4367
4368
else
4369
4370
OUTD=${PACKAGE_FOLDER}
4371
4372
fi
4373
4374
# fix logfile
4375
if [ "${PACKAGE}" -eq 0 ]; then
4376
cat -vet "${OUTD}/logfull.txt" | sed -e 's/\^M \^M//g' | sed -e 's/\$$//g' > "${OUTD}/test_report.log"
4377
fi
4378
4379
rm -rf "${OUTD}/logfull.txt"
4380
4381
if [ "${PACKAGE}" -eq 1 ]; then
4382
4383
echo "[ ${OUTD} ] > Generate package ${OUTD}/${OUTD}.7z"
4384
4385
cp "${BASH_SOURCE[0]}" "${OUTD}/test.sh"
4386
4387
copy_luks_dir=0
4388
copy_luks2_dir=0
4389
copy_tc_dir=0
4390
copy_vc_dir=0
4391
copy_cl_dir=0
4392
4393
if [ "${HT}" -eq 65535 ]; then
4394
copy_luks_dir=1
4395
copy_luks2_dir=1
4396
copy_tc_dir=1
4397
copy_vc_dir=1
4398
copy_cl_dir=1
4399
else
4400
for TMP_HT in $(seq "${HT_MIN}" "${HT_MAX}"); do
4401
if is_in_array "${TMP_HT}" ${LUKS1_ALL_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]] ; then
4402
copy_luks_dir=1
4403
elif is_in_array "${TMP_HT}" ${LUKS2_MODES} && [[ "${GENERATE_CONTAINERS}" -eq 0 ]]; then
4404
copy_luks2_dir=1
4405
elif is_in_array "${TMP_HT}" ${TC_MODES}; then
4406
copy_tc_dir=1
4407
elif is_in_array "${TMP_HT}" ${VC_MODES}; then
4408
copy_vc_dir=1
4409
elif is_in_array "${TMP_HT}" ${CL_MODES}; then
4410
copy_cl_dir=1
4411
fi
4412
done
4413
fi
4414
4415
if [ "${copy_luks_dir}" -eq 1 ]; then
4416
mkdir "${OUTD}/luks_tests/"
4417
cp ${TDIR}/luks_tests/* "${OUTD}/luks_tests/"
4418
fi
4419
4420
if [ "${copy_luks2_dir}" -eq 1 ]; then
4421
mkdir "${OUTD}/luks2_tests/"
4422
cp ${TDIR}/luks2_tests/* "${OUTD}/luks2_tests/"
4423
fi
4424
4425
if [ "${copy_tc_dir}" -eq 1 ]; then
4426
mkdir "${OUTD}/tc_tests/"
4427
cp ${TDIR}/tc_tests/* "${OUTD}/tc_tests/"
4428
fi
4429
4430
if [ "${copy_vc_dir}" -eq 1 ]; then
4431
mkdir "${OUTD}/vc_tests/"
4432
cp ${TDIR}/vc_tests/* "${OUTD}/vc_tests/"
4433
fi
4434
4435
if [ "${copy_cl_dir}" -eq 1 ]; then
4436
mkdir "${OUTD}/cl_tests/"
4437
cp ${TDIR}/cl_tests/* "${OUTD}/cl_tests/"
4438
fi
4439
4440
# if we package from a given folder, we need to check if e.g. the files needed for multi mode are there
4441
4442
if [ -n "${PACKAGE_FOLDER}" ]; then
4443
4444
MODE=2
4445
4446
ls "${PACKAGE_FOLDER}"/*multi* &>/dev/null
4447
4448
if [ "${?}" -ne 0 ]; then
4449
MODE=0
4450
fi
4451
4452
HT=$(grep -o -- "-m *[0-9]*" "${PACKAGE_FOLDER}/all.sh" | sort -u | sed 's/-m //' 2> /dev/null)
4453
4454
if [ -n "${HT}" ]; then
4455
HT_COUNT=$(echo "${HT}" | wc -l)
4456
4457
if [ "${HT_COUNT}" -gt 1 ]; then
4458
HT=65535
4459
fi
4460
fi
4461
4462
#ATTACK=65535 # more appropriate ?
4463
fi
4464
4465
# for convenience: 'run package' is default action for packaged test.sh ( + add other defaults too )
4466
4467
SED_IN_PLACE='-i'
4468
4469
UNAME=$(uname -s)
4470
4471
# of course macOS requires us to implement a special case (sed -i "" for the backup file)
4472
if [ "${UNAME}" = "Darwin" ] ; then
4473
SED_IN_PLACE='-i ""'
4474
fi
4475
4476
HT_PACKAGED=${HT}
4477
4478
if [ "${HT_MIN}" -ne "${HT_MAX}" ]; then
4479
HT_PACKAGED=${HT_MIN}-${HT_MAX}
4480
fi
4481
4482
HASH_TYPES_PACKAGED=$( echo "${HASH_TYPES}" | tr '\n' ' ' | sed 's/ *$//')
4483
HASHFILE_ONLY_PACKAGED=$(echo "${HASHFILE_ONLY}" | tr '\n' ' ' | sed 's/ *$//')
4484
KEEP_GUESSING_PACKAGED=$(echo "${KEEP_GUESSING}" | tr '\n' ' ' | sed 's/ *$//')
4485
SLOW_ALGOS_PACKAGED=$( echo "${SLOW_ALGOS}" | tr '\n' ' ' | sed 's/ *$//')
4486
4487
sed "${SED_IN_PLACE}" -e 's/^\(PACKAGE_FOLDER\)=""/\1="$( echo "${BASH_SOURCE[0]}" | sed \"s!test.sh\\$!!\" )"/' \
4488
-e "s/^\(HASH_TYPES\)=\$(.*/\1=\"${HASH_TYPES_PACKAGED}\"/" \
4489
-e "s/^\(HASHFILE_ONLY\)=\$(.*/\1=\"${HASHFILE_ONLY_PACKAGED}\"/" \
4490
-e "s/^\(KEEP_GUESSING\)=\$(.*/\1=\"${KEEP_GUESSING_PACKAGED}\"/" \
4491
-e "s/^\(SLOW_ALGOS\)=\$(.*/\1=\"${SLOW_ALGOS_PACKAGED}\"/" \
4492
-e "s/^\(HT\)=0/\1=${HT_PACKAGED}/" \
4493
-e "s/^\(MODE\)=0/\1=${MODE}/" \
4494
-e "s/^\(ATTACK\)=0/\1=${ATTACK}/" \
4495
"${OUTD}/test.sh"
4496
4497
${PACKAGE_CMD} "${OUTD}/${OUTD}.7z" "${OUTD}/" &>/dev/null
4498
fi
4499
4500