From 1cb24b0a3cc34a3afd950848063289be466b586c Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Sun, 9 Jan 2022 04:50:28 +0100 Subject: [PATCH 1/5] Fix the build for NetBSD --- include/sort_r.h | 9 ++++++-- src/Makefile | 14 +++++++---- src/affinity.c | 60 ++++++++++++++++++++++++++++++++++++++++++++---- src/folder.c | 20 ++++++++++++++-- src/terminal.c | 2 +- 5 files changed, 92 insertions(+), 13 deletions(-) diff --git a/include/sort_r.h b/include/sort_r.h index 061aed7aa..ebc344fe4 100644 --- a/include/sort_r.h +++ b/include/sort_r.h @@ -25,7 +25,7 @@ Slightly modified to work with hashcat to no falsly detect _SORT_R_LINUX with mi */ #if (defined __APPLE__ || defined __MACH__ || defined __DARWIN__ || \ - defined __FreeBSD__ || defined __DragonFly__) + defined __FreeBSD__ || defined __DragonFly__ || defined __NetBSD__) # define _SORT_R_BSD # define _SORT_R_INLINE inline #elif (defined __linux__) || defined (__CYGWIN__) @@ -202,7 +202,12 @@ static _SORT_R_INLINE void sort_r_simple(void *base, size_t nel, size_t w, struct sort_r_data tmp; tmp.arg = arg; tmp.compar = compar; - qsort_r(base, nel, width, &tmp, sort_r_arg_swap); + + #if defined __NetBSD__ + sort_r_simple(base, nel, width, compar, arg); + #else + qsort_r(base, nel, width, &tmp, sort_r_arg_swap); + #endif #elif defined _SORT_R_WINDOWS diff --git a/src/Makefile b/src/Makefile index 1443d4d5c..9941e671e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -31,7 +31,7 @@ UNAME := $(patsubst MSYS_NT-%,MSYS2,$(UNAME)) UNAME := $(patsubst MINGW32_NT-%,MSYS2,$(UNAME)) UNAME := $(patsubst MINGW64_NT-%,MSYS2,$(UNAME)) -ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin CYGWIN MSYS2)) +ifeq (,$(filter $(UNAME),Linux FreeBSD NetBSD Darwin CYGWIN MSYS2)) $(error "! Your Operating System ($(UNAME)) is not supported by this Makefile") endif @@ -78,7 +78,7 @@ SED_IN_PLACE := -i "" DARWIN_VERSION := $(shell uname -r | cut -d. -f1) endif -ifeq ($(UNAME),FreeBSD) +ifeq (,$(filter $(UNAME),FreeBSD NetBSD)) CC := cc CXX := c++ SED := gsed @@ -314,6 +314,12 @@ LFLAGS_NATIVE += -liconv endif endif # FreeBSD +ifeq ($(UNAME),NetBSD) +CFLAGS_NATIVE := $(CFLAGS) +LFLAGS_NATIVE := $(LFLAGS) +LFLAGS_NATIVE += -lpthread +endif # NetBSD + ifeq ($(UNAME),Darwin) export MACOSX_DEPLOYMENT_TARGET=10.9 CFLAGS_NATIVE := $(CFLAGS) @@ -458,10 +464,10 @@ distclean: clean # allow (whitelist) "make install" only on unix-based systems (also disallow cygwin/msys) ifneq ($(findstring install,$(MAKECMDGOALS)),) - ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin)) + ifeq (,$(filter $(UNAME),Linux FreeBSD Darwin NetBSD)) define ERROR_INSTALL_DISALLOWED ! The 'install' target is not allowed on this operating system ($(UNAME)). \ -Only Linux, FreeBSD and Darwin can use the 'install' target +Only Linux, FreeBSD, NetBSD and Darwin can use the 'install' target endef $(error $(ERROR_INSTALL_DISALLOWED)) diff --git a/src/affinity.c b/src/affinity.c index 3faa46638..920f24f87 100644 --- a/src/affinity.c +++ b/src/affinity.c @@ -45,6 +45,12 @@ static int pthread_setaffinity_np (pthread_t thread, size_t cpu_size, cpu_set_t typedef cpuset_t cpu_set_t; #endif +#if defined(__NetBSD__) +#include +#include +typedef cpuset_t cpu_set_t; +#endif + int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) { #if defined (__CYGWIN__) @@ -54,19 +60,31 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) if (user_options->cpu_affinity == NULL) return 0; + char *devices = hcstrdup (user_options->cpu_affinity); + + if (devices == NULL) return -1; + #if defined (_WIN) DWORD_PTR aff_mask = 0; const int cpu_id_max = 8 * sizeof (aff_mask); + #elif defined(__NetBSD__) + cpuset_t * cpuset; + const int cpu_id_max = 8 * cpuset_size (cpuset); + cpuset = cpuset_create(); + if (cpuset == NULL) + { + event_log_error (hashcat_ctx, "cpuset_create() failed with error: %d", errno); + + hcfree (devices); + + return -1; + } #else cpu_set_t cpuset; const int cpu_id_max = 8 * sizeof (cpuset); CPU_ZERO (&cpuset); #endif - char *devices = hcstrdup (user_options->cpu_affinity); - - if (devices == NULL) return -1; - char *saveptr = NULL; char *next = strtok_r (devices, ",", &saveptr); @@ -79,6 +97,17 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) { #if defined (_WIN) aff_mask = 0; + #elif defined (__NetBSD__) + cpuset_destroy (cpuset); + cpuset = cpuset_create (); + if (cpuset == NULL) + { + event_log_error (hashcat_ctx, "cpuset_create() failed with error: %d", errno); + + hcfree (devices); + + return -1; + } #else CPU_ZERO (&cpuset); #endif @@ -90,6 +119,10 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) { event_log_error (hashcat_ctx, "Invalid cpu_id %d specified.", cpu_id); + #if defined (__NetBSD__) + cpuset_destroy (cpuset); + #endif + hcfree (devices); return -1; @@ -97,12 +130,18 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) #if defined (_WIN) aff_mask |= ((DWORD_PTR) 1) << (cpu_id - 1); + #elif defined (__NetBSD__) + cpuset_set (cpu_id - 1, cpuset); #else CPU_SET ((cpu_id - 1), &cpuset); #endif } while ((next = strtok_r ((char *) NULL, ",", &saveptr)) != NULL); + #if defined (__NetBSD__) + cpuset_destroy (cpuset); + #endif + hcfree (devices); #if defined (_WIN) @@ -114,6 +153,19 @@ int set_cpu_affinity (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx) return -1; } + #elif defined (__NetBSD__) + + pthread_t thread = pthread_self (); + + const int rc = pthread_setaffinity_np (thread, cpuset_size(cpuset), cpuset); + + if (rc != 0) + { + event_log_error (hashcat_ctx, "pthread_setaffinity_np() failed with error: %d", rc); + + return -1; + } + #else pthread_t thread = pthread_self (); diff --git a/src/folder.c b/src/folder.c index eb5914dbe..8a50eeb9c 100644 --- a/src/folder.c +++ b/src/folder.c @@ -13,6 +13,9 @@ #if defined (__APPLE__) #include "event.h" +#elif defined (__FreeBSD__) || defined (__NetBSD__) +#include +#include #endif static int get_exec_path (char *exec_path, const size_t exec_path_sz) @@ -45,8 +48,6 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz) #elif defined (__FreeBSD__) - #include - int mib[4]; mib[0] = CTL_KERN; @@ -60,6 +61,21 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz) const size_t len = strlen (exec_path); + #elif defined (__NetBSD__) + + int mib[4]; + + mib[0] = CTL_KERN; + mib[1] = KERN_PROC_ARGS; + mib[2] = getpid(); + mib[3] = KERN_PROC_PATHNAME; + + size_t size = exec_path_sz; + + sysctl (mib, 4, exec_path, &size, NULL, 0); + + const size_t len = strlen (exec_path); + #else #error Your Operating System is not supported or detected #endif diff --git a/src/terminal.c b/src/terminal.c index 81381b2dc..e56e311c1 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -439,7 +439,7 @@ void SetConsoleWindowSize (const int x) } #endif -#if defined (__linux__) || defined (__CYGWIN__) +#if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__linux__) || defined (__CYGWIN__) static struct termios savemodes; static int havemodes = 0; From 5708b4cf6f5111e5e75eca38bd698781fac50021 Mon Sep 17 00:00:00 2001 From: Chick3nman Date: Tue, 11 Jan 2022 15:05:02 -0600 Subject: [PATCH 2/5] Fix logic flaw Line 81 contains inverted logic introduced by PR#3117, this should fix that logic to detect BSD and correctly select `gsed` on BSD and not on linux --- src/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index 369eb7dc0..fc0afc4fb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -78,7 +78,7 @@ SED_IN_PLACE := -i "" DARWIN_VERSION := $(shell uname -r | cut -d. -f1) endif -ifeq (,$(filter $(UNAME),FreeBSD NetBSD)) +ifneq (,$(filter $(UNAME),FreeBSD NetBSD)) CC := cc CXX := c++ SED := gsed From 516f7588f1a08e034ea618a7620e7e065d8a0e55 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Wed, 12 Jan 2022 09:19:52 +0100 Subject: [PATCH 3/5] Updated Unit Test --- docs/changes.txt | 3 + docs/credits.txt | 2 +- tools/test.sh | 651 +++++++++++++++++++++++++++++------------------ 3 files changed, 412 insertions(+), 244 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)) + ;; + 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=$? - 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 @@ -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=$? + + if [ "${newRet}" -eq 2 ]; then - ret=10 + # 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 + 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 3, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Key-Size ${keySize} ] > $msg : ${e_nf}/${cnt} not found" - - status ${ret} + 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 + 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 3, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, tcMode ${tcMode} ] > $msg : ${e_nf}/${cnt} not found" - - status ${ret} + 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 + 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 0, Mode single, Device-Type ${DEVICE_TYPE}, Kernel-Type ${KERNEL_TYPE}, Vector-Width ${VECTOR}, Cipher ${cipher_cascade} ] > $msg : ${e_nf}/${cnt} not found" - - status ${ret} + 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 4/5] 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 From 50a4d6b58d124a8e337f5cbeb841a2a33bfee7f1 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 14 Jan 2022 18:28:08 +0100 Subject: [PATCH 5/5] Fixed Unit Test early exit on luks test file download/extract failure --- docs/changes.txt | 1 + tools/test.sh | 63 ++++++++++++++++++++++++++++++------------------ 2 files changed, 40 insertions(+), 24 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 0d2fc5fb1..4bc515c4a 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -27,6 +27,7 @@ - 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 +- Fixed Unit Test early exit on luks test file download/extract failure ## ## Technical diff --git a/tools/test.sh b/tools/test.sh index 26ec545ac..c17d20cf7 100755 --- a/tools/test.sh +++ b/tools/test.sh @@ -183,6 +183,11 @@ function init() fi if [ "${hash_type}" -eq ${LUKS_MODE} ]; then + which 7z &>/dev/null + if [ $? -eq 1 ]; then + echo "ATTENTION: 7z is missing. Skipping download and extract luks test files." + return 0 + fi luks_tests_folder="${TDIR}/luks_tests/" @@ -219,12 +224,12 @@ function init() 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 + return 0 fi # extract: - ${EXTRACT_CMD} "${luks_tests}" >/dev/null 2>/dev/null + ${EXTRACT_CMD} "${luks_tests}" &>/dev/null # cleanup: @@ -235,7 +240,7 @@ function init() if [ ! -f "${luks_first_test_file}" ]; then echo "ERROR: downloading and extracting ${luks_tests} into ${luks_tests_folder} did not complete successfully" - exit 1 + return 0 fi fi @@ -469,6 +474,12 @@ function status() e_nm=$((e_nm + 1)) ;; + 30) + echo "luks test files are missing, cmdline : ${CMD}" >> "${OUTD}/logfull.txt" 2>> "${OUTD}/logfull.txt" + + e_rs=$((e_rs + 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." @@ -561,7 +572,7 @@ function attack_0() search="${hash}:${pass}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -670,7 +681,7 @@ function attack_0() search="${hash}:${pass}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -844,7 +855,7 @@ function attack_1() search="${hash}:${line_dict1}${line_dict2}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -986,7 +997,7 @@ function attack_1() search="${hash}:${line_dict1}${line_dict2}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -1150,7 +1161,7 @@ function attack_3() search="${hash}:${line_dict}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -1590,7 +1601,7 @@ function attack_3() search="${hash}:${pass}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -1813,7 +1824,7 @@ function attack_6() search="${hash}:${line_dict1}${line_dict2}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -1968,7 +1979,7 @@ function attack_6() search="${hash}:${line_dict1}${line_dict2}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -2243,7 +2254,7 @@ function attack_7() search="${hash}:${line_dict1}${line_dict2}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -2435,7 +2446,7 @@ function attack_7() search="${hash}:${line_dict1}${line_dict2}" fi - echo "${output}" | grep -F "${search}" >/dev/null 2>/dev/null + echo "${output}" | grep -F "${search}" &>/dev/null newRet=$? @@ -2959,7 +2970,7 @@ function luks_test() LUKS_MODES="cbc-essiv cbc-plain64 xts-plain64" LUKS_KEYSIZES="128 256 512" - LUKS_PASSWORD=$(cat "${TDIR}/luks_tests/pw") + LUKS_PASSWORD=$(cat "${TDIR}/luks_tests/pw" 2>/dev/null) for luks_h in ${LUKS_HASHES}; do for luks_c in ${LUKS_CIPHERS}; do @@ -3017,15 +3028,15 @@ function luks_test() luks_pass_part1_len=$((${#LUKS_PASSWORD} / 2)) luks_pass_part2_start=$((luks_pass_part1_len + 1)) - echo "${LUKS_PASSWORD}" | cut -c-${luks_pass_part1_len} > "${luks_pass_part_file1}" - echo "${LUKS_PASSWORD}" | cut -c${luks_pass_part2_start}- > "${luks_pass_part_file2}" + echo "${LUKS_PASSWORD}" | cut -c-${luks_pass_part1_len} > "${luks_pass_part_file1}" 2>/dev/null + echo "${LUKS_PASSWORD}" | cut -c${luks_pass_part2_start}- > "${luks_pass_part_file2}" 2>/dev/null CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} ${luks_file} ${luks_pass_part_file1} ${luks_pass_part_file2}" ;; 3) luks_mask_fixed_len=$((${#LUKS_PASSWORD} - 1)) - luks_mask="$(echo "${LUKS_PASSWORD}" | cut -c-${luks_mask_fixed_len})" + luks_mask="$(echo "${LUKS_PASSWORD}" | cut -c-${luks_mask_fixed_len} 2>/dev/null)" luks_mask="${luks_mask}${luks_main_mask}" CMD="./${BIN} ${OPTS} -a 3 -m ${hashType} ${luks_file} ${luks_mask}" @@ -3033,12 +3044,12 @@ function luks_test() 6) luks_pass_part1_len=$((${#LUKS_PASSWORD} - 1)) - echo "${LUKS_PASSWORD}" | cut -c-${luks_pass_part1_len} > "${luks_pass_part_file1}" + echo "${LUKS_PASSWORD}" | cut -c-${luks_pass_part1_len} > "${luks_pass_part_file1}" 2>/dev/null CMD="./${BIN} ${OPTS} -a 6 -m ${hashType} ${luks_file} ${luks_pass_part_file1} ${luks_mask}" ;; 7) - echo "${LUKS_PASSWORD}" | cut -c2- > "${luks_pass_part_file1}" + echo "${LUKS_PASSWORD}" | cut -c2- > "${luks_pass_part_file1}" 2>/dev/null CMD="./${BIN} ${OPTS} -a 7 -m ${hashType} ${luks_file} ${luks_mask} ${luks_pass_part_file1}" ;; @@ -3047,10 +3058,14 @@ function luks_test() if [ -n "${CMD}" ]; then 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" - output=$(${CMD} 2>&1) - ret=${?} + if [ -f "${luks_first_test_file}" ]; then + output=$(${CMD} 2>&1) + ret=${?} - echo "${output}" >> "${OUTD}/logfull.txt" + echo "${output}" >> "${OUTD}/logfull.txt" + else + ret=30 + fi e_ce=0 e_rs=0 @@ -3701,7 +3716,7 @@ if [ "${PACKAGE}" -eq 1 ]; then MODE=2 - ls "${PACKAGE_FOLDER}"/*multi* >/dev/null 2>/dev/null + ls "${PACKAGE_FOLDER}"/*multi* &>/dev/null if [ "${?}" -ne 0 ]; then MODE=0 @@ -3752,5 +3767,5 @@ if [ "${PACKAGE}" -eq 1 ]; then -e "s/^\(ATTACK\)=0/\1=${ATTACK}/" \ "${OUTD}/test.sh" - ${PACKAGE_CMD} "${OUTD}/${OUTD}.7z" "${OUTD}/" >/dev/null 2>/dev/null + ${PACKAGE_CMD} "${OUTD}/${OUTD}.7z" "${OUTD}/" &>/dev/null fi