1 ## Authors.....: Jens Steube <jens.steube@gmail.com>
2 ## magnum <john.magnum@hushmail.com>
10 _hashcat_get_permutations
()
12 local num_devices
=${1}
13 hashcat_devices_permutation
=""
15 # Formula: Sum (k=1...num_devices) (num_devices! / (k! * (num_devices - k)!))
16 # or ofc (2 ^ num_devices) - 1
17 if [ "${num_devices}" -gt 0 ]; then
19 hashcat_devices_permutation
=$
(seq 1 $num_devices)
23 for k
in $
(seq 2 $num_devices); do
25 if [ "${k}" -eq ${num_devices} ];then
27 hashcat_devices_permutation
="${hashcat_devices_permutation} $(seq 1 $num_devices | tr '\n' ',' | sed 's/, *$//')"
32 local max_pos
=$
((num_devices
- ${k} + 1))
34 for j
in $
(seq 1 ${max_pos}); do
36 local max_value
=$
((j
+ ${k} - 1))
42 for l
in $
(seq ${j} ${max_value}); do
44 if [ ${l} -gt ${j} ]; then
48 out_str
=${out_str}${l}
54 local max_device
=$
((num_devices
+ 1))
57 while [ "${chg_len}" -lt ${last} ]; do
59 local had_pos_changed
=${pos_changed}
60 local old_chg_len
=${chg_len}
62 local idx
=$
(((k
- chg_len
)))
63 local cur_num
=$
(echo ${out_str} | cut
-d, -f ${idx})
64 local next_num
=$
((cur_num
+ 1))
66 if [ "${pos_changed}" -eq 0 ]; then
68 hashcat_devices_permutation
="${hashcat_devices_permutation} ${out_str}"
76 if [ "${next_num}" -lt ${max_device} -a "${next_num}" -le "${num_devices}" ]; then
78 out_str
=$
(echo ${out_str} | sed "s/,${cur_num},/,${next_num},/;s/,${cur_num}\$/,${next_num}/")
84 chg_len=$((chg_len + 1))
88 if [ "${had_pos_changed}" -eq 1 ];then
93 for m in $(seq 1 ${old_chg_len}); do
95 local reset_idx=$((k - ${old_chg_len} + ${m}))
96 local last_num=$(echo ${out_str} | cut -d, -f ${reset_idx})
97 next_num=$((next_num + 1))
99 if [ "${next_num}" -lt ${max_device} -a "${next_num}" -le "${num_devices}" ]; then
101 out_str=$(echo ${out_str} | sed "s/,${last_num},/,${next_num},/;s/,${last_num}\$/,${next_num}/")
102 max_device
=$
((next_num
+ 2))
103 changed
=$
((changed
+ 1))
111 if [ "${changed}" -gt 0 ]; then
113 max_device
=$
((num_devices
+ 1))
130 _hashcat_opencl_devices
()
134 if which clinfo
&> /dev
/null
; then
136 num_devices
=$
(clinfo
2>/dev
/null
2> /dev
/null
)
138 elif which nvidia-smi
&> /dev
/null
; then
140 num_devices
=$
(nvidia-smi
--list-gpus |
wc -l)
144 return ${num_devices}
147 _hashcat_cpu_devices
()
151 if [ -f "/proc/cpuinfo" ]; then
153 num_devices
=$
(cat /proc
/cpuinfo |
grep -c processor
2> /dev
/null
)
157 return ${num_devices}
165 if echo "${haystack}" |
grep -q " ${needle} " 2> /dev
/null
; then
167 elif echo "${haystack}" |
grep -q "^${needle} " 2> /dev
/null
; then
169 elif echo "${haystack}" |
grep -q " ${needle}\$" 2> /dev
/null
; then
180 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 6212 6213 6221 6222 6223 6231 6232 6233 6241 6242 6243 6300 6400 6500 6600 6700 6800 6900 7100 7200 7300 7400 7500 7600 7700 7800 7900 8000 8100 8200 8300 8400 8500 8600 8700 8800 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 12700 12800 12900 13000"
181 local ATTACK_MODES
="0 1 3 6 7"
182 local OUTFILE_FORMATS
="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15"
183 local OPENCL_DEVICE_TYPES
="1 2 3"
184 local OPENCL_VECTOR_WIDTH
="1 2 4 8 16"
185 local DEBUG_MODE
="1 2 3 4"
186 local WORKLOAD_PROFILE
="1 2 3"
187 local HIDDEN_FILES
="exe|bin|pot|hcstat|dictstat|accepted|sh|cmd|bat|restore"
188 local HIDDEN_FILES_AGGRESIVE
="exe|bin|pot|hcstat|dictstat|hcmask|hcchr|accepted|sh|cmd|restore"
189 local BUILD_IN_CHARSETS
='?l ?u ?d ?a ?b ?s'
191 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"
192 local LONG_OPTS
="--hash-type --attack-mode --version --help --eula --quiet --benchmark --benchmark-repeats --hex-salt --hex-wordlist --hex-charset --force --status --status-timer --machine-readable --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 --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-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"
193 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-repeats --status-timer --weak-hash-threshold --markov-hcstat --markov-threshold --runtime --session --timer --outfile --outfile-format --outfile-check-timer --outfile-check-dir --separator --remove-timer --potfile-path --debug-mode --debug-file --induction-dir --segment-size --bitmap-min --bitmap-max --cpu-affinity --opencl-devices --opencl-platforms --opencl-device-types --opencl-vector-width --workload-profile --kernel-accel --kernel-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"
196 local cur
="${COMP_WORDS[COMP_CWORD]}"
197 local prev
="${COMP_WORDS[COMP_CWORD-1]}"
199 # if cur is just '=', ignore the '=' and treat it as only the prev was provided
200 if [[ "${cur}" == '=' ]]; then
204 elif [[ "${prev}" == '=' ]]; then
206 if [ "${COMP_CWORD}" -gt 2 ]; then
208 prev
="${COMP_WORDS[COMP_CWORD-2]}"
217 COMPREPLY
=($
(compgen
-W "${HASH_MODES}" -- ${cur}))
222 COMPREPLY
=($
(compgen
-W "${ATTACK_MODES}" -- ${cur}))
227 COMPREPLY
=($
(compgen
-W "${OUTFILE_FORMATS}" -- ${cur}))
231 -w|
--workload-profile)
232 COMPREPLY
=($
(compgen
-W "${WORKLOAD_PROFILE}" -- ${cur}))
236 -o|
--outfile|
-r|
--rules-file|
--debug-file|
--potfile-path)
237 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
238 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur})) # or $(compgen -f -X '*.+('${HIDDEN_FILES_AGGRESIVE}')' -- ${cur})
243 local files=$(ls -d ${cur}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev/null)
244 COMPREPLY=($(compgen -W "${files}" -- ${cur})) # or $(compgen -f -X '*.+('${HIDDEN_FILES_AGGRESIVE}')' -- ${cur})
249 _hashcat_opencl_devices
250 local num_devices
=${?}
252 _hashcat_get_permutations
${num_devices}
254 COMPREPLY
=($
(compgen
-W "${hashcat_devices_permutation}" -- ${cur}))
258 --opencl-device-types)
259 COMPREPLY
=($
(compgen
-W "${OPENCL_DEVICE_TYPES}" -- ${cur}))
263 --opencl-vector-width)
264 COMPREPLY
=($
(compgen
-W "${OPENCL_VECTOR_WIDTH}" -- ${cur}))
269 local icd_list
=$
(ls -1 /etc
/OpenCL
/vendors
/*.icd
2> /dev
/null
)
271 local architecture
=$
(getconf LONG_BIT
2> /dev
/null
)
273 if [ -z "${architecture}" ]; then
277 # filter the icd_list (do not show 32 bit on 64bit systems and vice versa)
279 if [ "${architecture}" -eq 64 ]; then
281 icd_list
=$
(echo "${icd_list}" |
grep -v "32.icd")
285 icd_list
=$
(echo "${icd_list}" |
grep -v "64.icd")
289 local number_icds
=$
(seq 1 $
(echo "${icd_list}" |
wc -l))
291 COMPREPLY
=($
(compgen
-W "${number_icds}" -- ${cur}))
298 local num_devices
=${?}
300 _hashcat_get_permutations
${num_devices}
302 COMPREPLY
=($
(compgen
-W "${hashcat_devices_permutation}" -- ${cur}))
306 -1|
-2|
-3|
-4|
--custom-charset1|
--custom-charset2|
--custom-charset3|
--custom-charset4)
307 local mask
=${BUILD_IN_CHARSETS}
309 if [ -e "${cur}" ]; then # should be hcchr file (but not enforced)
311 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
316 if [ -n "${cur}" ]; then
318 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
320 mask
="${mask} ${cur_var}"
324 if ! echo ${cur} |
grep -q ${h} 2> /dev
/null
; then
326 if echo ${cur} |
grep -q '?a' 2> /dev
/null
; then
328 if [[ "${h}" == "?l" ]] ; then
330 elif [[ "${h}" == "?u" ]] ; then
332 elif [[ "${h}" == "?d" ]] ; then
334 elif [[ "${h}" == "?s" ]] ; then
336 elif [[ "${h}" == "?b" ]] ; then
342 mask
="${mask} ${cur_var}${h}"
349 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
351 mask
="${mask} ${files}"
353 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
358 --status-timer|
--markov-threshold|
--runtime|
--session|
--separator|
--segment-size|
--rule-left|
--rule-right| \
359 --gpu-temp-abort|
--gpu-temp-retain|
--generate-rules|
--generate-rules-func-min|
--generate-rules-func-max| \
360 --increment-min|
--increment-max|
--remove-timer|
--bitmap-min|
--bitmap-max|
--skip|
--limit|
--generate-rules-seed| \
361 --weak-hash-threshold|
--outfile-check-timer|
--outfile-check-dir|
--induction-dir|
--scrypt-tmto)
366 COMPREPLY
=($
(compgen
-W "${DEBUG_MODE}" -- ${cur}))
370 --truecrypt-keyfiles)
371 # first: remove the quotes such that file matching is possible
373 local cur_part0
=$
(echo "${cur}" |
grep -Eo '^("|'"'"')')
375 local cur_mod
=$
(echo "${cur}" |
sed 's/^["'"'"']//')
376 local cur_part1
=$
(echo "${cur_mod}" |
grep ',' 2> /dev
/null |
sed 's/^\(.*, *\)[^,]*$/\1/')
377 local cur_part2
=$
(echo "${cur_mod}" |
sed 's/^.*, *\([^,]*\)$/\1/')
379 # generate lines with the file name and a duplicate of it with a comma at the end
381 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}/")
382 COMPREPLY=($(compgen -W "${files}" -- ${cur}))
387 # allow also the VARIANTS w/o spaces
388 # we could use compgen -P prefix, but for some reason it doesn't seem to work always
393 local hash_modes_var="$
(echo -n "-m ${HASH_MODES}" |
sed 's/ / -m/g')"
394 COMPREPLY=($(compgen -W "${hash_modes_var}" -- ${cur}))
399 local attack_modes_var="$
(echo -n "-a ${ATTACK_MODES}" |
sed 's/ / -a/g')"
400 COMPREPLY=($(compgen -W "${attack_modes_var}" -- ${cur}))
405 local workload_profile_var="$
(echo -n "-w ${WORKLOAD_PROFILE}" |
sed 's/ / -w/g')"
406 COMPREPLY=($(compgen -W "${workload_profile_var}" -- ${cur}))
411 local outfile_var=$(ls -d ${cur:2}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev/null)
412 outfile_var="$
(echo -e "\n${outfile_var}" |
sed 's/^/-o/g')"
413 COMPREPLY=($(compgen -W "${outfile_var}" -- ${cur}))
418 local outfile_var=$(ls -d ${cur:2}* 2> /dev/null | grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev/null)
419 outfile_var="$
(echo -e "\n${outfile_var}" |
sed 's/^/-r/g')"
420 COMPREPLY=($(compgen -W "${outfile_var}" -- ${cur}))
425 _hashcat_opencl_devices
426 local num_devices=${?}
428 _hashcat_get_permutations ${num_devices}
430 local opencl_devices_var="$
(echo " "${hashcat_devices_permutation} |
sed 's/ / -d/g')"
431 COMPREPLY=($(compgen -W "${opencl_devices_var}" -- ${cur}))
436 # Complete options/switches (not the arguments)
438 if [[ "${cur}" == -* ]]; then
440 COMPREPLY=($(compgen -W "${SHORT_OPTS} ${LONG_OPTS}" -- ${cur}))
445 # additional parameter, no switch nor option but maybe hash file, dictionary, mask, directory
447 # check if first option out of (hash.txt and dictionary|mask|directory)
448 # is first option iff: here
449 # 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!)
453 local attack_mode
=0 # also default of hashcat
454 local has_charset_1
=0
455 local has_charset_2
=0
456 local has_charset_3
=0
457 local has_charset_4
=0
459 while [ ${h} -le ${COMP_CWORD} ]; do
461 if [[ "${COMP_WORDS[h]}" == "-a" ]]; then
463 attack_mode
=${COMP_WORDS[$((h + 1))]}
465 elif [[ "${COMP_WORDS[h]}" == -a* ]]; then
467 attack_mode
=${COMP_WORDS[h]:2}
469 elif [[ "${COMP_WORDS[h]}" == "--attack-mode" ]]; then
471 attack_mode
=${COMP_WORDS[$((h + 1))]}
473 elif [[ "${COMP_WORDS[h]}" == "-1" ]]; then
477 elif [[ "${COMP_WORDS[h]}" == "--custom-charset1" ]]; then
481 elif [[ "${COMP_WORDS[h]}" == "-2" ]]; then
485 elif [[ "${COMP_WORDS[h]}" == "--custom-charset2" ]]; then
489 elif [[ "${COMP_WORDS[h]}" == "-3" ]]; then
493 elif [[ "${COMP_WORDS[h]}" == "--custom-charset3" ]]; then
497 elif [[ "${COMP_WORDS[h]}" == "-4" ]]; then
501 elif [[ "${COMP_WORDS[h]}" == "--custom-charset4" ]]; then
507 if _hashcat_contains
"${OPTIONS}" "${COMP_WORDS[h]}"; then
513 if ! _hashcat_contains
"${LONG_OPTS}${SHORT_OPTS}" "${COMP_WORDS[h]}"; then
514 local variants
="-m -a -w -n -u -o -r -d"
517 for v
in ${variants}; do
519 if [[ "${COMP_WORDS[h]:0:2}" == "${v}" ]]; then
525 if [ "${skip}" -eq 0 ]; then
527 no_opts
=$
((no_opts
+ 1))
545 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
546 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
551 case "${attack_mode}" in
554 # dict/directory are files here
555 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
556 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
561 if [ "${no_opts}" -gt 4 ]; then
565 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
566 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
571 if [ "${no_opts}" -eq 2 ]; then
572 local mask
=${BUILD_IN_CHARSETS}
574 if [ "${has_charset_1}" -eq 1 ]; then
580 if [ "${has_charset_2}" -eq 1 ]; then
586 if [ "${has_charset_3}" -eq 1 ]; then
592 if [ "${has_charset_4}" -eq 1 ]; then
598 if [ -e "${cur}" ]; then # should be hcmask file (but not enforced)
600 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
605 if [ -n "${cur}" ]; then
607 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
609 mask
="${mask} ${cur_var}"
614 mask
="${mask} ${cur_var}${h}"
619 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
621 mask
="${mask} ${files}"
623 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
629 if [ "${no_opts}" -eq 2 ]; then
631 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
632 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
634 elif [ "${no_opts}" -eq 3 ]; then
635 local mask
=${BUILD_IN_CHARSETS}
637 if [ "${has_charset_1}" -eq 1 ]; then
643 if [ "${has_charset_2}" -eq 1 ]; then
649 if [ "${has_charset_3}" -eq 1 ]; then
655 if [ "${has_charset_4}" -eq 1 ]; then
661 if [ -e "${cur}" ]; then # should be hcmask file (but not enforced)
663 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
668 if [ -n "${cur}" ]; then
670 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
672 mask
="${mask} ${cur_var}"
677 mask
="${mask} ${cur_var}${h}"
682 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
684 mask
="${mask} ${files}"
686 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
693 if [ "${no_opts}" -eq 2 ]; then
694 local mask
=${BUILD_IN_CHARSETS}
696 if [ "${has_charset_1}" -eq 1 ]; then
702 if [ "${has_charset_2}" -eq 1 ]; then
708 if [ "${has_charset_3}" -eq 1 ]; then
714 if [ "${has_charset_4}" -eq 1 ]; then
720 if [ -e "${cur}" ]; then # should be hcmask file (but not enforced)
722 COMPREPLY
=($
(compgen
-W "${cur}" -- ${cur}))
727 if [ -n "${cur}" ]; then
729 local cur_var
=$
(echo "${cur}" |
sed 's/\?$//')
731 mask
="${mask} ${cur_var}"
736 mask
="${mask} ${cur_var}${h}"
741 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES}')' 2> /dev
/null
)
743 mask
="${mask} ${files}"
745 COMPREPLY
=($
(compgen
-W "${mask}" -- ${cur}))
748 elif [ "${no_opts}" -eq 3 ]; then
750 local files
=$
(ls -d ${cur}* 2> /dev
/null |
grep -Eiv '*\.('${HIDDEN_FILES_AGGRESIVE}')' 2> /dev
/null
)
751 COMPREPLY
=($
(compgen
-W "${files}" -- ${cur}))
762 complete
-F _hashcat
-o filenames
"${HASHCAT_ROOT}"/hashcat64.bin "${HASHCAT_ROOT}"/hashcat32.bin "${HASHCAT_ROOT}"/hashcat hashcat