4 _oclHashcat_get_permutations
()
7 oclHashcat_devices_permutation
=""
9 # Formula: Sum (k=1...num_devices) (num_devices! / (k! * (num_devices - k)!))
10 # or ofc (2 ^ num_devices) - 1
11 if [ "${num_devices}" -gt 0 ]; then
13 oclHashcat_devices_permutation
=$
(seq 1 $num_devices)
17 for k
in $
(seq 2 $num_devices); do
19 if [ "${k}" -eq ${num_devices} ];then
21 oclHashcat_devices_permutation
="${oclHashcat_devices_permutation} $(seq 1 $num_devices | tr '\n' ',' | sed 's/, *$//')"
26 local max_pos
=$
((num_devices
- ${k} + 1))
28 for j
in $
(seq 1 ${max_pos}); do
30 local max_value
=$
((j
+ ${k} - 1))
36 for l
in $
(seq ${j} ${max_value}); do
38 if [ ${l} -gt ${j} ]; then
42 out_str
=${out_str}${l}
48 local max_device
=$
((num_devices
+ 1))
51 while [ "${chg_len}" -lt ${last} ]; do
53 local had_pos_changed
=${pos_changed}
54 local old_chg_len
=${chg_len}
56 local idx
=$
(((k
- chg_len
)))
57 local cur_num
=$
(echo ${out_str} | cut
-d, -f ${idx})
58 local next_num
=$
((cur_num
+ 1))
60 if [ "${pos_changed}" -eq 0 ]; then
62 oclHashcat_devices_permutation
="${oclHashcat_devices_permutation} ${out_str}"
70 if [ "${next_num}" -lt ${max_device} -a "${next_num}" -le "${num_devices}" ]; then
72 out_str
=$
(echo ${out_str} | sed "s/,${cur_num},/,${next_num},/;s/,${cur_num}\$/,${next_num}/")
78 chg_len=$((chg_len + 1))
82 if [ "${had_pos_changed}" -eq 1 ];then
87 for m in $(seq 1 ${old_chg_len}); do
89 local reset_idx=$((k - ${old_chg_len} + ${m}))
90 local last_num=$(echo ${out_str} | cut -d, -f ${reset_idx})
91 next_num=$((next_num + 1))
93 if [ "${next_num}" -lt ${max_device} -a "${next_num}" -le "${num_devices}" ]; then
95 out_str=$(echo ${out_str} | sed "s/,${last_num},/,${next_num},/;s/,${last_num}\$/,${next_num}/")
96 max_device
=$
((next_num
+ 2))
97 changed
=$
((changed
+ 1))
105 if [ "${changed}" -gt 0 ]; then
107 max_device
=$
((num_devices
+ 1))
124 _oclHashcat_gpu_devices
()
128 if which clinfo
&> /dev
/null
; then
130 num_devices
=$
(clinfo
2>/dev
/null |
grep -c CL_DEVICE_TYPE_GPU
2> /dev
/null
)
132 elif which nvidia-smi
&> /dev
/null
; then
134 num_devices
=$
(nvidia-smi
--list-gpus |
wc -l)
138 return ${num_devices}
141 _oclHashcat_cpu_devices
()
145 if [ -f "/proc/cpuinfo" ]; then
147 num_devices
=$
(cat /proc
/cpuinfo |
grep -c processor
2> /dev
/null
)
151 return ${num_devices}
154 _oclHashcat_contains
()
159 if echo "${haystack}" |
grep -q " ${needle} " 2> /dev
/null
; then
161 elif echo "${haystack}" |
grep -q "^${needle} " 2> /dev
/null
; then
163 elif echo "${haystack}" |
grep -q " ${needle}\$" 2> /dev
/null
; then
174 local HASH_MODES
="0 10 11 12 20 21 22 23 30 40 50 60 100 101 110 111 112 120 121 122 124 130 131 132 133 140 141 150 160 190 200 300 400 500 501 900 1000 1100 1400 1410 1420 1421 1430 1440 1441 1450 1460 1500 1600 1700 1710 1711 1720 1722 1730 1731 1740 1750 1760 1800 2100 2400 2410 2500 2600 2611 2612 2711 2811 3000 3100 3200 3710 3711 3800 4300 4400 4500 4700 4800 4900 5000 5100 5200 5300 5400 5500 5600 5700 5800 6000 6100 6211 6221 6231 6241 6300 6400 6500 6600 6700 6800 6900 7100 7200 7300 7400 7500 7600 7700 7800 7900 8000 8100 8200 8300 8400 8500 8600 8700 8900 9000 9100 9200 9300 9400 9500 9600 9700 9710 9720 9800 9810 9820 9900 10000 10100 10200 10300 10400 10410 10420 10500 10600 10700 10800 10900 11000 11100 11200 11300 11400 11500 11600 11700 11800 11900 12000 12100 12200 12300 12400 12500 12600"
175 local ATTACK_MODES
="0 1 3 6 7"
176 local OUTFILE_FORMATS
="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
177 local BENCHMARK_MODE
="0 1"
178 local DEBUG_MODE
="1 2 3 4"
179 local WORKLOAD_PROFILE
="1 2 3"
180 local GPU_ACCEL
="1 8 16 24 32 40 48 56 64 62 80 88 96 104 112 120 128 136 144 152 160"
181 local GPU_LOOPS
="8 16 32 64 128 256 512 1024"
182 local HIDDEN_FILES
="exe|bin|pot|hcstat|dictstat|accepted|sh|cmd|bat|restore"
183 local HIDDEN_FILES_AGGRESIVE
="exe|bin|pot|hcstat|dictstat|hcmask|hcchr|accepted|sh|cmd|restore"
184 local BUILD_IN_CHARSETS
='?l ?u ?d ?a ?b ?s'
186 local SHORT_OPTS
="-m -a -V -v -h -b -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -i -s -l"
187 local LONG_OPTS
="--hash-type --attack-mode --version --help --eula --quiet --benchmark --benchmark-mode --hex-salt --hex-wordlist --hex-charset --force --status --status-timer --status-automat --loopback --weak-hash-threshold --markov-hcstat --markov-disable --markov-classic --markov-threshold --runtime --session --restore --restore-disable --outfile --outfile-format --outfile-autohex-disable --outfile-check-timer --outfile-check-dir --separator --show --left --username --remove --remove-timer --potfile-disable --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --gpu-async --gpu-devices --workload-profile --gpu-accel --gpu-loops --gpu-temp-disable --gpu-temp-abort --gpu-temp-retain --powertune-enable --skip --limit --keyspace --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --rules-cleanup --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment --increment-min --increment-max --logfile-disable --scrypt-tmto --truecrypt-keyfiles"
188 local OPTIONS
="-m -a -t -o -p -c -d -w -n -u -j -k -r -g -1 -2 -3 -4 -s -l --hash-type --attack-mode --benchmark-mode --status-timer --markov-hcstat --markov-threshold --runtime --session --timer --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --gpu-devices --workload-profile --gpu-accel --gpu-loops --gpu-temp-abort --gpu-temp-retain -disable --skip --limit --rule-left --rule-right --rules-file --generate-rules --generate-rules-func-min --generate-rules-func-max --generate-rules-seed --custom-charset1 --custom-charset2 --custom-charset3 --custom-charset4 --increment-min --increment-max --scrypt-tmto --truecrypt-keyfiles"
191 local cur
="${COMP_WORDS[COMP_CWORD]}"
192 local prev
="${COMP_WORDS[COMP_CWORD-1]}"
194 # if cur is just '=', ignore the '=' and treat it as only the prev was provided
195 if [[ "${cur}" == '=' ]]; then
199 elif [[ "${prev}" == '=' ]]; then
201 if [ "${COMP_CWORD}" -gt 2 ]; then
203 prev
="${COMP_WORDS[COMP_CWORD-2]}"
212 COMPREPLY
=($
(compgen
-W "${HASH_MODES}" -- ${cur}))
217 COMPREPLY
=($
(compgen
-W "${ATTACK_MODES}" -- ${cur}))
222 COMPREPLY
=($
(compgen
-W "${OUTFILE_FORMATS}" -- ${cur}))
227 COMPREPLY
=($
(compgen
-W "${BENCHMARK_MODE}" -- ${cur}))
231 -w|
--workload-profile)
232 COMPREPLY
=($
(compgen
-W "${WORKLOAD_PROFILE}" -- ${cur}))
237 COMPREPLY
=($
(compgen
-W "${GPU_ACCEL}" -- ${cur}))
242 COMPREPLY
=($
(compgen
-W "${GPU_LOOPS}" -- ${cur}))
246 -o|
--outfile|
-r|
--rules-file|
--debug-file)
247 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
248 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur})) # or $(compgen -f -X '*.+('${HIDDEN_FILES_AGGRESIVE}')' -- ${cur})
253 local files=$(ls -d ${cur}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev/null)
254 COMPREPLY=($(compgen -W "${files}" -- ${cur})) # or $(compgen -f -X '*.+('${HIDDEN_FILES_AGGRESIVE}')' -- ${cur})
259 _oclHashcat_gpu_devices
260 local num_devices
=${?}
262 _oclHashcat_get_permutations
${num_devices}
264 COMPREPLY
=($
(compgen
-W "${oclHashcat_devices_permutation}" -- ${cur}))
269 _oclHashcat_cpu_devices
270 local num_devices
=${?}
272 _oclHashcat_get_permutations
${num_devices}
274 COMPREPLY
=($
(compgen
-W "${oclHashcat_devices_permutation}" -- ${cur}))
278 -1|
-2|
-3|
-4|
--custom-charset1|
--custom-charset2|
--custom-charset3|
--custom-charset4)
279 local mask
=${BUILD_IN_CHARSETS}
281 if [ -e "${cur}" ]; then # should be hcchr file (but not enforced)
283 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
288 if [ -n "${cur}" ]; then
290 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
292 mask
="${mask} ${cur_var}"
296 if ! echo ${cur} |
grep -q ${h} 2> /dev
/null
; then
298 if echo ${cur} |
grep -q '?a' 2> /dev
/null
; then
300 if [[ "${h}" == "?l" ]] ; then
302 elif [[ "${h}" == "?u" ]] ; then
304 elif [[ "${h}" == "?d" ]] ; then
306 elif [[ "${h}" == "?s" ]] ; then
308 elif [[ "${h}" == "?b" ]] ; then
314 mask
="${mask} ${cur_var}${h}"
321 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
323 mask
="${mask} ${files}"
325 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
330 --status-timer|
--markov-threshold|
--runtime|
--session|
--separator|
--segment-size|
--rule-left|
--rule-right| \
331 --gpu-temp-abort|
--gpu-temp-retain|
--generate-rules|
--generate-rules-func-min|
--generate-rules-func-max| \
332 --increment-min|
--increment-max|
--remove-timer|
--bitmap-min|
--bitmap-max|
--skip|
--limit|
--generate-rules-seed)
337 COMPREPLY
=($
(compgen
-W "${DEBUG_MODE}" -- ${cur}))
341 --truecrypt-keyfiles)
342 # first: remove the quotes such that file matching is possible
344 local cur_part0
=$
(echo "${cur}" |
grep -Eo '^("|'"'"')')
346 local cur_mod
=$
(echo "${cur}" |
sed 's/^["'"'"']//')
347 local cur_part1
=$
(echo "${cur_mod}" |
grep ',' 2> /dev
/null |
sed 's/^\(.*, *\)[^,]*$/\1/')
348 local cur_part2
=$
(echo "${cur_mod}" |
sed 's/^.*, *\([^,]*\)$/\1/')
350 # generate lines with the file name and a duplicate of it with a comma at the end
352 local files
=$
(ls -d ${cur_part2}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev/null | sed 's/^\(.*\)$/\1\n\1,\n/' | sed "s/^/${cur_part0}${cur_part1}/" | sed "s/$/${cur_part0}/")
353 COMPREPLY=($(compgen -W "${files}" -- ${cur}))
358 # allow also the VARIANTS w/o spaces
359 # we could use compgen -P prefix, but for some reason it doesn't seem to work always
364 local hash_modes_var="$
(echo -n "-m ${HASH_MODES}" |
sed 's/ / -m/g')"
365 COMPREPLY=($(compgen -W "${hash_modes_var}" -- ${cur}))
370 local attack_modes_var="$
(echo -n "-a ${ATTACK_MODES}" |
sed 's/ / -a/g')"
371 COMPREPLY=($(compgen -W "${attack_modes_var}" -- ${cur}))
376 local workload_profile_var="$
(echo -n "-w ${WORKLOAD_PROFILE}" |
sed 's/ / -w/g')"
377 COMPREPLY=($(compgen -W "${workload_profile_var}" -- ${cur}))
382 local gpu_accel_var="$
(echo -n "-n ${GPU_ACCEL}" |
sed 's/ / -n/g')"
383 COMPREPLY=($(compgen -W "${gpu_accel_var}" -- ${cur}))
388 local gpu_loops_var="$
(echo -n "-u ${GPU_LOOPS}" |
sed 's/ / -u/g')"
389 COMPREPLY=($(compgen -W "${gpu_loops_var}" -- ${cur}))
394 local outfile_var=$(ls -d ${cur:2}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev/null)
395 outfile_var="$
(echo -e "\n${outfile_var}" |
sed 's/^/-o/g')"
396 COMPREPLY=($(compgen -W "${outfile_var}" -- ${cur}))
401 local outfile_var=$(ls -d ${cur:2}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev/null)
402 outfile_var="$
(echo -e "\n${outfile_var}" |
sed 's/^/-r/g')"
403 COMPREPLY=($(compgen -W "${outfile_var}" -- ${cur}))
408 _oclHashcat_gpu_devices
409 local num_devices=${?}
411 _oclHashcat_get_permutations ${num_devices}
413 local gpu_devices_var="$
(echo " "${oclHashcat_devices_permutation} |
sed 's/ / -d/g')"
414 COMPREPLY=($(compgen -W "${gpu_devices_var}" -- ${cur}))
419 # Complete options/switches (not the arguments)
421 if [[ "${cur}" == -* ]]; then
423 COMPREPLY=($(compgen -W "${SHORT_OPTS} ${LONG_OPTS}" -- ${cur}))
428 # additional parameter, no switch nor option but maybe hash file, dictionary, mask, directory
430 # check if first option out of (hash.txt and dictionary|mask|directory)
431 # is first option iff: here
432 # is second option iff: COMP_CWORD > 2 and no switch before (-*) if no option afterwards (for mask -a 3, -a 6, -a 7 - but possible for dicts!)
436 local attack_mode
=0 # also default of oclHashcat
437 local has_charset_1
=0
438 local has_charset_2
=0
439 local has_charset_3
=0
440 local has_charset_4
=0
442 while [ ${h} -le ${COMP_CWORD} ]; do
444 if [[ "${COMP_WORDS[h]}" == "-a" ]]; then
446 attack_mode
=${COMP_WORDS[$((h + 1))]}
448 elif [[ "${COMP_WORDS[h]}" == -a* ]]; then
450 attack_mode
=${COMP_WORDS[h]:2}
452 elif [[ "${COMP_WORDS[h]}" == "--attack-mode" ]]; then
454 attack_mode
=${COMP_WORDS[$((h + 1))]}
456 elif [[ "${COMP_WORDS[h]}" == "-1" ]]; then
460 elif [[ "${COMP_WORDS[h]}" == "--custom-charset1" ]]; then
464 elif [[ "${COMP_WORDS[h]}" == "-2" ]]; then
468 elif [[ "${COMP_WORDS[h]}" == "--custom-charset2" ]]; then
472 elif [[ "${COMP_WORDS[h]}" == "-3" ]]; then
476 elif [[ "${COMP_WORDS[h]}" == "--custom-charset3" ]]; then
480 elif [[ "${COMP_WORDS[h]}" == "-4" ]]; then
484 elif [[ "${COMP_WORDS[h]}" == "--custom-charset4" ]]; then
490 if _oclHashcat_contains
"${OPTIONS}" "${COMP_WORDS[h]}"; then
496 if ! _oclHashcat_contains
"${LONG_OPTS}${SHORT_OPTS}" "${COMP_WORDS[h]}"; then
497 local variants
="-m -a -w -n -u -o -r -d"
500 for v
in ${variants}; do
502 if [[ "${COMP_WORDS[h]:0:2}" == "${v}" ]]; then
508 if [ "${skip}" -eq 0 ]; then
510 no_opts
=$
((no_opts
+ 1))
528 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
529 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
534 case "${attack_mode}" in
537 # dict/directory are files here
538 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
539 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
544 if [ "${no_opts}" -gt 4 ]; then
548 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
549 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
554 if [ "${no_opts}" -eq 2 ]; then
555 local mask
=${BUILD_IN_CHARSETS}
557 if [ "${has_charset_1}" -eq 1 ]; then
563 if [ "${has_charset_2}" -eq 1 ]; then
569 if [ "${has_charset_3}" -eq 1 ]; then
575 if [ "${has_charset_4}" -eq 1 ]; then
581 if [ -e "${cur}" ]; then # should be hcmask file (but not enforced)
583 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
588 if [ -n "${cur}" ]; then
590 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
592 mask
="${mask} ${cur_var}"
597 mask
="${mask} ${cur_var}${h}"
602 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
604 mask
="${mask} ${files}"
606 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
612 if [ "${no_opts}" -eq 2 ]; then
614 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
615 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
617 elif [ "${no_opts}" -eq 3 ]; then
618 local mask
=${BUILD_IN_CHARSETS}
620 if [ "${has_charset_1}" -eq 1 ]; then
626 if [ "${has_charset_2}" -eq 1 ]; then
632 if [ "${has_charset_3}" -eq 1 ]; then
638 if [ "${has_charset_4}" -eq 1 ]; then
644 if [ -e "${cur}" ]; then # should be hcmask file (but not enforced)
646 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
651 if [ -n "${cur}" ]; then
653 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
655 mask
="${mask} ${cur_var}"
660 mask
="${mask} ${cur_var}${h}"
665 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
667 mask
="${mask} ${files}"
669 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
676 if [ "${no_opts}" -eq 2 ]; then
677 local mask
=${BUILD_IN_CHARSETS}
679 if [ "${has_charset_1}" -eq 1 ]; then
685 if [ "${has_charset_2}" -eq 1 ]; then
691 if [ "${has_charset_3}" -eq 1 ]; then
697 if [ "${has_charset_4}" -eq 1 ]; then
703 if [ -e "${cur}" ]; then # should be hcmask file (but not enforced)
705 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
710 if [ -n "${cur}" ]; then
712 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
714 mask
="${mask} ${cur_var}"
719 mask
="${mask} ${cur_var}${h}"
724 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
726 mask
="${mask} ${files}"
728 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
731 elif [ "${no_opts}" -eq 3 ]; then
733 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
734 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
745 complete
-F _oclHashcat
-o filenames
${OCLHASHCAT_ROOT}/oclHashcat64.bin "${OCLHASHCAT_ROOT}"/oclHashcat32.bin "${OCLHASHCAT_ROOT}"/cudaHashcat64.bin "${OCLHASHCAT_ROOT}"/cudaHashcat32.bin