From 516f7588f1a08e034ea618a7620e7e065d8a0e55 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Wed, 12 Jan 2022 09:19:52 +0100 Subject: [PATCH 1/2] Updated Unit Test --- docs/changes.txt | 3 + docs/credits.txt | 2 +- tools/test.sh | 671 +++++++++++++++++++++++++++++------------------ 3 files changed, 422 insertions(+), 254 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index f99eb33dd..0d2fc5fb1 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -26,6 +26,7 @@ - Fixed undefined function call to hc_byte_perm_S() in hash-mode 17010 on non-CUDA compute devices - Fixed wordlist handling in -m 3000 when candidate passwords use the $HEX[...] syntax - Fixed false negative on Unit Test with hash-type 25400 +- Fixed false negative on Unit Test in case of out-of-memory with grep in single mode ## ## Technical @@ -45,6 +46,8 @@ - HIP Backend: moved functions to ext_hip.c/ext_hiprtc.c and includes to ext_hip.h/ext_hiprtc.h - CUDA Backend: moved functions to ext_cuda.c/ext_nvrtc.c and includes to ext_cuda.h/ext_nvrtc.h - Makefile: updated MACOSX_DEPLOYMENT_TARGET to 10.15 and removed OpenCL framework from LFLAGS_NATIVE on MacOS +- Unit tests: added -r (--runtime) option +- Unit tests: handle negative status code, skip deprecated hash-types, skip hash-types with known perl modules issues, updated output * changes v6.2.4 -> v6.2.5 diff --git a/docs/credits.txt b/docs/credits.txt index 62c5b04e1..1d962206e 100644 --- a/docs/credits.txt +++ b/docs/credits.txt @@ -24,7 +24,7 @@ Gabriele "matrix" Gristina (@gm4tr1x) * Apple macOS port * Apple Silicon support * Hardware monitor initial code base and maintenance -* Test suite initial code base +* Test suite initial code base and maintenance * Makefile initial code base * Multithreading initial code base * MultiGPU initial code base diff --git a/tools/test.sh b/tools/test.sh index 1acbd4cb3..dbc50bb35 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -5,9 +5,10 @@ ## License.....: MIT ## -OPTS="--quiet --potfile-disable --runtime 400 --hwmon-disable" +OPTS="--quiet --potfile-disable --hwmon-disable" FORCE=0 +RUNTIME=400 TDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" @@ -150,11 +151,13 @@ mask_7[31]="?d?d?d?d?d?d?d?d0000000" # $1: value # $2: array # Returns 0 (SUCCESS) if the value is found, 1 otherwise + function is_in_array() { for e in "${@:2}"; do [ "$e" = "$1" ] && return 0 done + return 1 } @@ -211,8 +214,9 @@ function init() echo "" # download: + wget -q "${luks_tests_url}" - if ! wget -q "${luks_tests_url}" >/dev/null 2>/dev/null; then + if [ $? -ne 0 ] || [ ! -f "${luks_tests}" ]; then cd - >/dev/null echo "ERROR: Could not fetch the luks test files from this url: ${luks_tests_url}" exit 1 @@ -296,17 +300,14 @@ function init() # special case (passwords longer than expected) pass_len=${#pass} - if [ "${pass_len}" -gt 1 ] - then + if [ "${pass_len}" -gt 1 ]; then p1=$((p1 + min_offset)) p0=$((p0 + min_offset)) if [ "${p1}" -gt "${pass_len}" ]; then - p1=${pass_len} p0=$((p1 - 1)) - fi # add splitted password to dicts @@ -348,6 +349,7 @@ function init() if [ "${MODE}" -ge 1 ]; then i=2 + while [ "$i" -lt 9 ]; do cmd_file=${OUTD}/${hash_type}_multi_${i}.txt @@ -380,6 +382,7 @@ function init() echo "${pass}" | cut -c ${p1}- >> "${OUTD}/${hash_type}_dict2_multi_${i}" done 9< "${OUTD}/${hash_type}_passwords_multi_${i}.txt" + i=$((i + 1)) done @@ -395,20 +398,56 @@ function status() if [ "${RET}" -ne 0 ]; then case ${RET} in + 248) + echo "skipped by runtime (mixed backend errors detected), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 1)) + ;; + + 249) + echo "skipped by runtime (Invalid module_extra_buffer_size), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 1)) + ;; + + 250) + echo "skipped by runtime (Too many compute units to keep minimum kernel accel limit), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 1)) + ;; + + 251) + echo "skipped by runtime (main kernel build error), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 1)) + ;; + + 252) + echo "skipped by runtime (memory hit limit), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 1)) + ;; + + 253) + echo "skipped by runtime (module_unstable_warning), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 1)) + ;; + 1) if ! is_in_array "${hash_type}" ${NEVER_CRACK_ALGOS}; then - echo "password not found, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" e_nf=$((e_nf + 1)) - fi ;; + 4) echo "timeout reached, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" - e_to=$((e_to + 1)) + e_to=$((e_to + 1)) ;; + 10) if is_in_array "${hash_type}" ${NEVER_CRACK_ALGOS}; then return @@ -419,14 +458,24 @@ function status() else echo "hash:plains not matched in output, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.tx"t fi - e_nm=$((e_nm + 1)) + e_nm=$((e_nm + 1)) ;; + + 20) + echo "grep out-of-memory (cannot check if plains match in output), cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_ce=$((e_ce + 1)) + e_nm=$((e_nm + 1)) + ;; + *) echo "! unhandled return code ${RET}, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" echo "! unhandled return code, see ${OUTD}/logfull.txt or ${OUTD}/test_report.log for details." + e_nf=$((e_nf + 1)) ;; + esac fi } @@ -436,14 +485,14 @@ function attack_0() file_only=0 if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then - file_only=1 - fi # single hash if [ "${MODE}" -ne 1 ]; then + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -454,9 +503,7 @@ function attack_0() max=32 if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then - max=12 - fi i=0 @@ -464,18 +511,14 @@ function attack_0() while read -r -u 9 line; do if [ "${i}" -ge ${max} ]; then - break - fi hash="$(echo "${line}" | cut -d\' -f2)" pass="$(echo "${line}" | cut -d' ' -f2)" if [ -z "${hash}" ]; then - break - fi if [ "${file_only}" -eq 1 ]; then @@ -518,17 +561,33 @@ function attack_0() search="${hash}:${pass}" fi - if [ ${hash_type} -eq 25400 ]; then - tmp=$(echo $output | sed -e 's/ (user password.*//g') - output="${tmp}" - fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? + if [ "${newRet}" -eq 2 ]; then + + # out-of-memory, workaround + + echo "${output}" | head -1 > tmp_file_out + echo "${search}" > tmp_file_search + + out_md5=$(md5sum tmp_file_out | cut -d' ' -f1) + search_md5=$(md5sum tmp_file_search | cut -d' ' -f1) + + rm tmp_file_out tmp_file_search + + if [ "${out_md5}" == "${search_md5}" ]; then + newRet=0 + fi + fi + + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else ret=10 - + fi fi fi @@ -541,23 +600,24 @@ function attack_0() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi # multihash if [ "${MODE}" -ne 0 ]; then + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -612,12 +672,16 @@ function attack_0() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi break - fi i=$((i + 1)) @@ -630,18 +694,17 @@ function attack_0() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi } @@ -650,14 +713,14 @@ function attack_1() file_only=0 if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then - file_only=1 - fi # single hash if [ "${MODE}" -ne 1 ]; then + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -678,6 +741,8 @@ function attack_1() elif [ "${hash_type}" -eq 15400 ]; then min=0 max=5 + elif [ "${hash_type}" -eq 20510 ]; then + min=2 fi 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" @@ -743,7 +808,6 @@ function attack_1() # finally, modify the dicts accordingly: tmp_file="${dict1}_mod" - head -n $((line_nr - 1)) "${dict1}" > "${tmp_file}" echo "${line_dict1}" >> "${tmp_file}" tail -n $((line_num - line_nr - 1)) "${dict1}" >> "${tmp_file}" @@ -782,10 +846,31 @@ function attack_1() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -eq 2 ]; then + # out-of-memory, workaround + + echo "${output}" | head -1 > tmp_file_out + echo "${search}" > tmp_file_search + + out_md5=$(md5sum tmp_file_out | cut -d' ' -f1) + search_md5=$(md5sum tmp_file_search | cut -d' ' -f1) + + rm tmp_file_out tmp_file_search + + if [ "${out_md5}" == "${search_md5}" ]; then + newRet=0 + fi + fi + + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi fi fi @@ -802,18 +887,17 @@ function attack_1() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi # multihash @@ -831,6 +915,8 @@ function attack_1() return fi + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -902,36 +988,38 @@ function attack_1() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi break - fi i=$((i + 1)) done 9< "${OUTD}/${hash_type}_multihash_combi.txt" - fi status ${ret} msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi } @@ -940,14 +1028,14 @@ function attack_3() file_only=0 if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then - file_only=1 - fi # single hash if [ "${MODE}" -ne 1 ]; then + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -980,13 +1068,9 @@ function attack_3() while read -r -u 9 hash; do if [ "${i}" -gt 6 ]; then - if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then - break - fi - fi if [ "${file_only}" -eq 1 ]; then @@ -1000,10 +1084,8 @@ function attack_3() fi hash="${temp_file}" - fi - # construct a meaningful mask from the password itself: dict="${OUTD}/${hash_type}_passwords.txt" @@ -1022,21 +1104,15 @@ function attack_3() mask="" if [ "${hash_type}" -eq 14000 ]; then - mask="${pass}" - elif [ "${hash_type}" -eq 14100 ]; then - mask="${pass}" - else - for i in $(seq 1 ${i}); do mask="${mask}?d" done mask="${mask}${pass_part_2}" - fi if [ "${hash_type}" -eq 20510 ]; then # special case for PKZIP Master Key @@ -1076,10 +1152,31 @@ function attack_3() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -eq 2 ]; then + # out-of-memory, workaround + + echo "${output}" | head -1 > tmp_file_out + echo "${search}" > tmp_file_search + + out_md5=$(md5sum tmp_file_out | cut -d' ' -f1) + search_md5=$(md5sum tmp_file_search | cut -d' ' -f1) + + rm tmp_file_out tmp_file_search + + if [ "${out_md5}" == "${search_md5}" ]; then + newRet=0 + fi + fi + + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi fi fi @@ -1094,18 +1191,17 @@ function attack_3() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi # multihash @@ -1123,6 +1219,8 @@ function attack_3() return fi + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -1131,9 +1229,7 @@ function attack_3() increment_max=8 if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then - increment_max=5 - fi increment_min=1 @@ -1280,27 +1376,19 @@ function attack_3() # just make sure that all custom charset fields are initialized if [ -z "${charset_1}" ]; then - charset_1="1" - fi if [ -z "${charset_2}" ]; then - charset_2="2" - fi if [ -z "${charset_3}" ]; then - charset_3="3" - fi if [ -z "${charset_4}" ]; then - charset_4="4" - fi # unique and remove new lines @@ -1365,27 +1453,19 @@ function attack_3() # just make sure that all custom charset fields are initialized if [ -z "${charset_1}" ]; then - charset_1="1" - fi if [ -z "${charset_2}" ]; then - charset_2="2" - fi if [ -z "${charset_3}" ]; then - charset_3="3" - fi if [ -z "${charset_4}" ]; then - charset_4="4" - fi # unique and remove new lines @@ -1450,27 +1530,19 @@ function attack_3() # just make sure that all custom charset fields are initialized if [ -z "${charset_1}" ]; then - charset_1="1" - fi if [ -z "${charset_2}" ]; then - charset_2="2" - fi if [ -z "${charset_3}" ]; then - charset_3="3" - fi if [ -z "${charset_4}" ]; then - charset_4="4" - fi # unique and remove new lines @@ -1520,12 +1592,16 @@ function attack_3() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi break - fi i=$((i + 1)) @@ -1538,18 +1614,17 @@ function attack_3() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi } @@ -1558,14 +1633,14 @@ function attack_6() file_only=0 if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then - file_only=1 - fi # single hash if [ "${MODE}" -ne 1 ]; then + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -1604,7 +1679,6 @@ function attack_6() # special case: we need to split the first line if [ "${min}" -eq 0 ]; then - pass_part_1=$(sed -n 1p "${OUTD}/${hash_type}_dict1") pass_part_2=$(sed -n 1p "${OUTD}/${hash_type}_dict2") @@ -1618,38 +1692,26 @@ function attack_6() for i in $(seq 1 $((${#pass} - mask_offset))); do if [ "${hash_type}" -eq 14000 ]; then - char=$(echo -n "${pass}" | cut -b $((i + mask_offset))) mask_custom="${mask_custom}${char}" - elif [ "${hash_type}" -eq 14100 ]; then - char=$(echo -n "${pass}" | cut -b $((i + mask_offset))) mask_custom="${mask_custom}${char}" - else - mask_custom="${mask_custom}?d" - fi done - fi - i=1 while read -r -u 9 hash; do if [ "${i}" -gt 6 ]; then - if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then - break - fi - fi if [ ${i} -gt ${min} ]; then @@ -1718,7 +1780,6 @@ function attack_6() # end of shuf/sort -R - mask="" for j in $(seq 1 ${i}); do @@ -1754,16 +1815,35 @@ function attack_6() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -eq 2 ]; then + # out-of-memory, workaround + echo "${output}" | head -1 > tmp_file_out + echo "${search}" > tmp_file_search + + out_md5=$(md5sum tmp_file_out | cut -d' ' -f1) + search_md5=$(md5sum tmp_file_search | cut -d' ' -f1) + + rm tmp_file_out tmp_file_search + + if [ "${out_md5}" == "${search_md5}" ]; then + newRet=0 + fi + fi + + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi fi fi status ${ret} - fi if [ "${i}" -eq ${max} ]; then break; fi @@ -1774,21 +1854,20 @@ function attack_6() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" + 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" rm -f "${OUTD}/${hash_type}_dict1_custom" rm -f "${OUTD}/${hash_type}_dict2_custom" - fi # multihash @@ -1806,6 +1885,8 @@ function attack_6() return fi + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -1828,15 +1909,10 @@ function attack_6() fi if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then - max=5 - if [ "${hash_type}" -eq 3200 ]; then - max=3 - fi - fi i=2 @@ -1894,18 +1970,21 @@ function attack_6() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi break - fi j=$((j + 1)) done 9< "${OUTD}/${hash_type}_hashes_multi_${i}.txt" - fi status ${ret} @@ -1915,18 +1994,17 @@ function attack_6() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi } @@ -1935,14 +2013,14 @@ function attack_7() file_only=0 if is_in_array "${hash_type}" ${FILE_BASED_ALGOS}; then - file_only=1 - fi # single hash if [ "${MODE}" -ne 1 ]; then + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -1996,19 +2074,13 @@ function attack_7() for i in $(seq 1 ${mask_offset}); do if [ "${hash_type}" -eq 14000 ]; then - char=$(echo -n "${pass}" | cut -b ${i}) mask_custom="${mask_custom}${char}" - elif [ "${hash_type}" -eq 14100 ]; then - char=$(echo -n "${pass}" | cut -b ${i}) mask_custom="${mask_custom}${char}" - else - mask_custom="${mask_custom}?d" - fi done @@ -2173,16 +2245,37 @@ function attack_7() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -eq 2 ]; then + # out-of-memory, workaround + + echo "${output}" | head -1 > tmp_file_out + echo "${search}" > tmp_file_search + + out_md5=$(md5sum tmp_file_out | cut -d' ' -f1) + search_md5=$(md5sum tmp_file_search | cut -d' ' -f1) + + rm tmp_file_out tmp_file_search + + if [ "${out_md5}" == "${search_md5}" ]; then + newRet=0 + fi + fi + + if [ "${newRet}" -ne 0 ]; then + + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi fi fi status ${ret} - fi if [ $i -eq ${max} ]; then break; fi @@ -2193,21 +2286,20 @@ function attack_7() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" + 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" rm -f "${OUTD}/${hash_type}_dict1_custom" rm -f "${OUTD}/${hash_type}_dict2_custom" - fi # multihash @@ -2225,6 +2317,8 @@ function attack_7() return fi + e_ce=0 + e_rs=0 e_to=0 e_nf=0 e_nm=0 @@ -2255,15 +2349,10 @@ function attack_7() fi if is_in_array "${hash_type}" ${TIMEOUT_ALGOS}; then - max=7 - if [ "${hash_type}" -eq 3200 ]; then - max=4 - fi - fi i=2 @@ -2348,18 +2437,21 @@ function attack_7() echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ]; then + newRet=$? - ret=10 + if [ "${newRet}" -ne 0 ]; then + if [ "${newRet}" -eq 2 ]; then + ret=20 + else + ret=10 + fi break - fi j=$((j + 1)) done 9< "${OUTD}/${hash_type}_hashes_multi_${i}.txt" - fi status ${ret} @@ -2369,18 +2461,17 @@ function attack_7() msg="OK" - if [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then - + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" - elif [ "${e_to}" -ne 0 ]; then - msg="Warning" - fi - 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" - + 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" fi } @@ -2540,18 +2631,30 @@ function cryptoloop_test() echo "${output}" >> "${OUTD}/logfull.txt" - cnt=1 + e_ce=0 + e_rs=0 + e_to=0 e_nf=0 - msg="OK" - - if [ ${ret} -ne 0 ]; then - e_nf=1 - msg="Error" - fi - - 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=0 + cnt=0 status ${ret} + + cnt=1 + + msg="OK" + + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then + msg="Error" + elif [ "${e_to}" -ne 0 ]; then + msg="Warning" + fi + + 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" fi } @@ -2723,18 +2826,30 @@ function truecrypt_test() echo "${output}" >> "${OUTD}/logfull.txt" - cnt=1 + e_ce=0 + e_rs=0 + e_to=0 e_nf=0 - msg="OK" - - if [ ${ret} -ne 0 ]; then - e_nf=1 - msg="Error" - fi - - 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=0 + cnt=0 status ${ret} + + cnt=1 + + msg="OK" + + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then + msg="Error" + elif [ "${e_to}" -ne 0 ]; then + msg="Warning" + fi + + 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" fi } @@ -2800,18 +2915,30 @@ function veracrypt_test() echo "${output}" >> "${OUTD}/logfull.txt" - cnt=1 + e_ce=0 + e_rs=0 + e_to=0 e_nf=0 - msg="OK" - - if [ ${ret} -ne 0 ]; then - e_nf=1 - msg="Error" - fi - - 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=0 + cnt=0 status ${ret} + + cnt=1 + + msg="OK" + + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then + msg="Error" + elif [ "${e_to}" -ne 0 ]; then + msg="Warning" + fi + + 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" } function luks_test() @@ -2925,16 +3052,30 @@ function luks_test() echo "${output}" >> "${OUTD}/logfull.txt" - cnt=1 + e_ce=0 + e_rs=0 + e_to=0 e_nf=0 + e_nm=0 + cnt=0 + + status ${ret} + + cnt=1 + msg="OK" - if [ ${ret} -ne 0 ]; then - e_nf=1 + if [ "${e_ce}" -ne 0 ]; then + msg="Compare Error" + elif [ "${e_rs}" -ne 0 ]; then + msg="Skip" + elif [ "${e_nf}" -ne 0 ] || [ "${e_nm}" -ne 0 ]; then msg="Error" + elif [ "${e_to}" -ne 0 ]; then + msg="Warning" fi - 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" + 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" status ${ret} fi @@ -3000,6 +3141,8 @@ OPTIONS: -f Use --force to ignore hashcat warnings (default : disabled) + -r Setup max runtime limit (default: 400) + -p Package the tests into a .7z file -F Use this folder as test folder instead of the default one @@ -3026,7 +3169,7 @@ HT=0 PACKAGE=0 OPTIMIZED=1 -while getopts "V:t:m:a:b:hcpd:x:o:d:D:F:POI:s:f" opt; do +while getopts "V:t:m:a:b:hcpd:x:o:d:D:F:POI:s:fr:" opt; do case ${opt} in "V") @@ -3158,6 +3301,10 @@ while getopts "V:t:m:a:b:hcpd:x:o:d:D:F:POI:s:f" opt; do FORCE=1 ;; + "r") + RUNTIME=${OPTARG} + ;; + \?) usage ;; @@ -3190,6 +3337,10 @@ if [ "${OPTIMIZED}" -eq 1 ]; then OPTS="${OPTS} -O" fi +# set max-runtime + +OPTS="${OPTS} --runtime ${RUNTIME}" + # set default device-type to CPU with Apple Intel, else GPU if [ "${DEVICE_TYPE}" = "null" ]; then @@ -3207,24 +3358,18 @@ if [ ${FORCE} -eq 1 ]; then fi if [ -n "${ARCHITECTURE}" ]; then - BIN="${BIN}${ARCHITECTURE}" - fi if [ -n "${EXTENSION}" ]; then - BIN="${BIN}.${EXTENSION}" - fi if [ -n "${PACKAGE_FOLDER}" ]; then - if [ ! -e "${PACKAGE_FOLDER}" ]; then echo "! folder '${PACKAGE_FOLDER}' does not exist" exit 1 fi - fi if [ "${PACKAGE}" -eq 0 ] || [ -z "${PACKAGE_FOLDER}" ]; then @@ -3242,7 +3387,6 @@ if [ "${PACKAGE}" -eq 0 ] || [ -z "${PACKAGE_FOLDER}" ]; then HT_MIN=${HT} HT_MAX=${HT} elif echo -n "${HT}" | grep -q '^[0-9]\+-[1-9][0-9]*$'; then - HT_MIN=$(echo -n ${HT} | sed "s/-.*//") HT_MAX=$(echo -n ${HT} | sed "s/.*-//") @@ -3330,7 +3474,6 @@ if [ "${PACKAGE}" -eq 0 ] || [ -z "${PACKAGE_FOLDER}" ]; then for hash_type in $HASH_TYPES; do if [ "${HT}" -ne 65535 ]; then - # check if the loop variable "hash_type" is between HT_MIN and HT_MAX (both included) if [ "${hash_type}" -lt "${HT_MIN}" ]; then @@ -3353,15 +3496,45 @@ if [ "${PACKAGE}" -eq 0 ] || [ -z "${PACKAGE_FOLDER}" ]; then fi fi - if [ -z "${PACKAGE_FOLDER}" ]; then + # skip deprecated hash-types + if [ "${hash_type}" -eq 2500 ] || [ "${hash_type}" -eq 2501 ] || [ "${hash_type}" -eq 16800 ] || [ "${hash_type}" -eq 16801 ] ; then + continue + fi + # test.pl produce wrong hashes with Apple + # would be necessary to investigate to understand why + if [ "${hash_type}" -eq 1800 ]; then + if [[ "$OSTYPE" == "darwin"* ]]; then + continue + fi + fi + + # Digest::BLAKE2 is broken on Apple Silicon + if [ "${hash_type}" -eq 600 ]; then + if [ "${IS_APPLE_SILICON}" -eq 1 ]; then + continue + fi + fi + + # Digest::GOST is broken on Apple Silicon + if [ "${hash_type}" -eq 6900 ]; then + if [ "${IS_APPLE_SILICON}" -eq 1 ]; then + continue + fi + fi + + # Crypt::GCrypt is broken on Apple and Linux + if [ "${hash_type}" -eq 18600 ]; then + if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then + continue + fi + fi + + if [ -z "${PACKAGE_FOLDER}" ]; then # init test data init - else - echo "[ ${OUTD} ] > Run packaged test for hash type $hash_type." - fi if [ "${PACKAGE}" -eq 0 ]; then @@ -3530,25 +3703,18 @@ if [ "${PACKAGE}" -eq 1 ]; then ls "${PACKAGE_FOLDER}"/*multi* >/dev/null 2>/dev/null - if [ "${?}" -ne 0 ] - then - + if [ "${?}" -ne 0 ]; then MODE=0 - fi HT=$(grep -o -- "-m *[0-9]*" "${PACKAGE_FOLDER}/all.sh" | sort -u | sed 's/-m //' 2> /dev/null) if [ -n "${HT}" ]; then - HT_COUNT=$(echo "${HT}" | wc -l) if [ "${HT_COUNT}" -gt 1 ]; then - HT=65535 - fi - fi #ATTACK=65535 # more appropriate ? @@ -3587,5 +3753,4 @@ if [ "${PACKAGE}" -eq 1 ]; then "${OUTD}/test.sh" ${PACKAGE_CMD} "${OUTD}/${OUTD}.7z" "${OUTD}/" >/dev/null 2>/dev/null - fi From e0e8ce81652a267473aafae69b2a7f268e937d8a Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 13 Jan 2022 13:24:23 +0100 Subject: [PATCH 2/2] Removed limitation with hash-type 18600 on linux --- tools/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/test.sh b/tools/test.sh index dbc50bb35..26ec545ac 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -3523,9 +3523,9 @@ if [ "${PACKAGE}" -eq 0 ] || [ -z "${PACKAGE_FOLDER}" ]; then fi fi - # Crypt::GCrypt is broken on Apple and Linux + # Crypt::GCrypt is broken on Apple if [ "${hash_type}" -eq 18600 ]; then - if [[ "$OSTYPE" == "linux-gnu"* ]] || [[ "$OSTYPE" == "darwin"* ]]; then + if [[ "$OSTYPE" == "darwin"* ]]; then continue fi fi