From 3c6f4b0e695942cee30d94697ab44837598d6231 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 10 Jun 2021 20:44:21 +0200 Subject: [PATCH 1/3] add identify/autodetect-only option --- include/types.h | 3 +++ src/hashcat.c | 17 ++++++++++++----- src/user_options.c | 3 +++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/include/types.h b/include/types.h index 192c0998b..9760aa931 100644 --- a/include/types.h +++ b/include/types.h @@ -597,6 +597,7 @@ typedef enum user_options_defaults ADVICE_DISABLE = false, ATTACK_MODE = ATTACK_MODE_STRAIGHT, AUTODETECT = false, + AUTODETECT_ONLY = false, BENCHMARK_ALL = false, BENCHMARK = false, BITMAP_MAX = 18, @@ -685,6 +686,7 @@ typedef enum user_options_map { IDX_ADVICE_DISABLE = 0xff00, IDX_ATTACK_MODE = 'a', + IDX_AUTODETECT_ONLY = 0xff4d, IDX_BACKEND_DEVICES = 'd', IDX_BACKEND_IGNORE_CUDA = 0xff01, IDX_BACKEND_IGNORE_OPENCL = 0xff02, @@ -1943,6 +1945,7 @@ typedef struct user_options bool attack_mode_chgd; bool autodetect; + bool autodetect_only; #ifdef WITH_BRAIN bool brain_host_chgd; bool brain_port_chgd; diff --git a/src/hashcat.c b/src/hashcat.c index c7532f61e..d367ef1d2 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1476,13 +1476,18 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) hcfree (usage_sort_buf[i].hash_name); } + hcfree (usage_sort_buf); + event_log_info (hashcat_ctx, NULL); - event_log_error (hashcat_ctx, "Please specify the hash-mode with -m [hash-mode]."); + if (user_options->autodetect_only == false) + { + event_log_error (hashcat_ctx, "Please specify the hash-mode with -m [hash-mode]."); - hcfree (usage_sort_buf); + return -1; + } - return -1; + return 0; } // modes_cnt == 1 @@ -1494,12 +1499,14 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) event_log_warning (hashcat_ctx, "Do NOT report auto-detect issues unless you are certain of the hash type."); event_log_warning (hashcat_ctx, NULL); - user_options->autodetect = false; - user_options->hash_mode = usage_sort_buf[0].hash_mode; hcfree (usage_sort_buf[0].hash_name); hcfree (usage_sort_buf); + + if (user_options->autodetect_only == true) return 0; + + user_options->autodetect = false; } /** diff --git a/src/user_options.c b/src/user_options.c index bc4465c5c..2ab1c632f 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -63,6 +63,7 @@ static const struct option long_options[] = {"hex-salt", no_argument, NULL, IDX_HEX_SALT}, {"hex-wordlist", no_argument, NULL, IDX_HEX_WORDLIST}, {"hook-threads", required_argument, NULL, IDX_HOOK_THREADS}, + {"identify", no_argument, NULL, IDX_AUTODETECT_ONLY}, {"increment-max", required_argument, NULL, IDX_INCREMENT_MAX}, {"increment-min", required_argument, NULL, IDX_INCREMENT_MIN}, {"increment", no_argument, NULL, IDX_INCREMENT}, @@ -158,6 +159,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->advice_disable = ADVICE_DISABLE; user_options->attack_mode = ATTACK_MODE; user_options->autodetect = AUTODETECT; + user_options->autodetect_only = AUTODETECT_ONLY; user_options->backend_devices = NULL; user_options->backend_ignore_cuda = BACKEND_IGNORE_CUDA; user_options->backend_ignore_opencl = BACKEND_IGNORE_OPENCL; @@ -396,6 +398,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_STDOUT_FLAG: user_options->stdout_flag = true; break; case IDX_STDIN_TIMEOUT_ABORT: user_options->stdin_timeout_abort = hc_strtoul (optarg, NULL, 10); user_options->stdin_timeout_abort_chgd = true; break; + case IDX_AUTODETECT_ONLY: user_options->autodetect_only = true; break; case IDX_SPEED_ONLY: user_options->speed_only = true; break; case IDX_PROGRESS_ONLY: user_options->progress_only = true; break; case IDX_RESTORE_DISABLE: user_options->restore_disable = true; break; From 340e8d1033a55ace1832aa3d641e045b54951d49 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 11 Jun 2021 19:25:39 +0200 Subject: [PATCH 2/3] fix identify functionality --- include/types.h | 102 ++++++++++++++++++++++----------------------- src/hashcat.c | 4 +- src/usage.c | 1 + src/user_options.c | 6 +-- 4 files changed, 57 insertions(+), 56 deletions(-) diff --git a/include/types.h b/include/types.h index 9760aa931..2b240ba59 100644 --- a/include/types.h +++ b/include/types.h @@ -597,7 +597,6 @@ typedef enum user_options_defaults ADVICE_DISABLE = false, ATTACK_MODE = ATTACK_MODE_STRAIGHT, AUTODETECT = false, - AUTODETECT_ONLY = false, BENCHMARK_ALL = false, BENCHMARK = false, BITMAP_MAX = 18, @@ -620,6 +619,7 @@ typedef enum user_options_defaults HEX_SALT = false, HEX_WORDLIST = false, HOOK_THREADS = 0, + IDENTIFY = false, INCREMENT = false, INCREMENT_MAX = PW_MAX, INCREMENT_MIN = 1, @@ -686,7 +686,6 @@ typedef enum user_options_map { IDX_ADVICE_DISABLE = 0xff00, IDX_ATTACK_MODE = 'a', - IDX_AUTODETECT_ONLY = 0xff4d, IDX_BACKEND_DEVICES = 'd', IDX_BACKEND_IGNORE_CUDA = 0xff01, IDX_BACKEND_IGNORE_OPENCL = 0xff02, @@ -727,73 +726,74 @@ typedef enum user_options_map IDX_HEX_SALT = 0xff1a, IDX_HEX_WORDLIST = 0xff1b, IDX_HOOK_THREADS = 0xff1c, + IDX_IDENTIFY = 0xff1d, IDX_INCREMENT = 'i', - IDX_INCREMENT_MAX = 0xff1d, - IDX_INCREMENT_MIN = 0xff1e, - IDX_INDUCTION_DIR = 0xff1f, - IDX_KEEP_GUESSING = 0xff20, + IDX_INCREMENT_MAX = 0xff1e, + IDX_INCREMENT_MIN = 0xff1f, + IDX_INDUCTION_DIR = 0xff20, + IDX_KEEP_GUESSING = 0xff21, IDX_KERNEL_ACCEL = 'n', IDX_KERNEL_LOOPS = 'u', IDX_KERNEL_THREADS = 'T', - IDX_KEYBOARD_LAYOUT_MAPPING = 0xff21, - IDX_KEYSPACE = 0xff22, - IDX_LEFT = 0xff23, + IDX_KEYBOARD_LAYOUT_MAPPING = 0xff22, + IDX_KEYSPACE = 0xff23, + IDX_LEFT = 0xff24, IDX_LIMIT = 'l', - IDX_LOGFILE_DISABLE = 0xff24, - IDX_LOOPBACK = 0xff25, - IDX_MACHINE_READABLE = 0xff26, - IDX_MARKOV_CLASSIC = 0xff27, - IDX_MARKOV_DISABLE = 0xff28, - IDX_MARKOV_HCSTAT2 = 0xff29, + IDX_LOGFILE_DISABLE = 0xff25, + IDX_LOOPBACK = 0xff26, + IDX_MACHINE_READABLE = 0xff27, + IDX_MARKOV_CLASSIC = 0xff28, + IDX_MARKOV_DISABLE = 0xff29, + IDX_MARKOV_HCSTAT2 = 0xff2a, IDX_MARKOV_THRESHOLD = 't', - IDX_NONCE_ERROR_CORRECTIONS = 0xff2a, + IDX_NONCE_ERROR_CORRECTIONS = 0xff2b, IDX_OPENCL_DEVICE_TYPES = 'D', IDX_OPTIMIZED_KERNEL_ENABLE = 'O', - IDX_OUTFILE_AUTOHEX_DISABLE = 0xff2b, - IDX_OUTFILE_CHECK_DIR = 0xff2c, - IDX_OUTFILE_CHECK_TIMER = 0xff2d, - IDX_OUTFILE_FORMAT = 0xff2e, + IDX_OUTFILE_AUTOHEX_DISABLE = 0xff2c, + IDX_OUTFILE_CHECK_DIR = 0xff2d, + IDX_OUTFILE_CHECK_TIMER = 0xff2e, + IDX_OUTFILE_FORMAT = 0xff2f, IDX_OUTFILE = 'o', - IDX_POTFILE_DISABLE = 0xff2f, - IDX_POTFILE_PATH = 0xff30, - IDX_PROGRESS_ONLY = 0xff31, - IDX_QUIET = 0xff32, - IDX_REMOVE = 0xff33, - IDX_REMOVE_TIMER = 0xff34, - IDX_RESTORE = 0xff35, - IDX_RESTORE_DISABLE = 0xff36, - IDX_RESTORE_FILE_PATH = 0xff37, + IDX_POTFILE_DISABLE = 0xff30, + IDX_POTFILE_PATH = 0xff31, + IDX_PROGRESS_ONLY = 0xff32, + IDX_QUIET = 0xff33, + IDX_REMOVE = 0xff34, + IDX_REMOVE_TIMER = 0xff35, + IDX_RESTORE = 0xff36, + IDX_RESTORE_DISABLE = 0xff37, + IDX_RESTORE_FILE_PATH = 0xff38, IDX_RP_FILE = 'r', - IDX_RP_GEN_FUNC_MAX = 0xff38, - IDX_RP_GEN_FUNC_MIN = 0xff39, + IDX_RP_GEN_FUNC_MAX = 0xff39, + IDX_RP_GEN_FUNC_MIN = 0xff3a, IDX_RP_GEN = 'g', - IDX_RP_GEN_SEED = 0xff3a, + IDX_RP_GEN_SEED = 0xff3b, IDX_RULE_BUF_L = 'j', IDX_RULE_BUF_R = 'k', - IDX_RUNTIME = 0xff3b, - IDX_SCRYPT_TMTO = 0xff3c, + IDX_RUNTIME = 0xff3c, + IDX_SCRYPT_TMTO = 0xff3d, IDX_SEGMENT_SIZE = 'c', - IDX_SELF_TEST_DISABLE = 0xff3d, + IDX_SELF_TEST_DISABLE = 0xff3e, IDX_SEPARATOR = 'p', - IDX_SESSION = 0xff3e, - IDX_SHOW = 0xff3f, + IDX_SESSION = 0xff3f, + IDX_SHOW = 0xff40, IDX_SKIP = 's', IDX_SLOW_CANDIDATES = 'S', - IDX_SPEED_ONLY = 0xff40, - IDX_SPIN_DAMP = 0xff41, - IDX_STATUS = 0xff42, - IDX_STATUS_JSON = 0xff43, - IDX_STATUS_TIMER = 0xff44, - IDX_STDOUT_FLAG = 0xff45, - IDX_STDIN_TIMEOUT_ABORT = 0xff46, - IDX_TRUECRYPT_KEYFILES = 0xff47, - IDX_USERNAME = 0xff48, - IDX_VERACRYPT_KEYFILES = 0xff49, - IDX_VERACRYPT_PIM_START = 0xff4a, - IDX_VERACRYPT_PIM_STOP = 0xff4b, + IDX_SPEED_ONLY = 0xff41, + IDX_SPIN_DAMP = 0xff42, + IDX_STATUS = 0xff43, + IDX_STATUS_JSON = 0xff44, + IDX_STATUS_TIMER = 0xff45, + IDX_STDOUT_FLAG = 0xff46, + IDX_STDIN_TIMEOUT_ABORT = 0xff47, + IDX_TRUECRYPT_KEYFILES = 0xff48, + IDX_USERNAME = 0xff49, + IDX_VERACRYPT_KEYFILES = 0xff4a, + IDX_VERACRYPT_PIM_START = 0xff4b, + IDX_VERACRYPT_PIM_STOP = 0xff4c, IDX_VERSION_LOWER = 'v', IDX_VERSION = 'V', - IDX_WORDLIST_AUTOHEX_DISABLE = 0xff4c, + IDX_WORDLIST_AUTOHEX_DISABLE = 0xff4d, IDX_WORKLOAD_PROFILE = 'w', } user_options_map_t; @@ -1945,7 +1945,6 @@ typedef struct user_options bool attack_mode_chgd; bool autodetect; - bool autodetect_only; #ifdef WITH_BRAIN bool brain_host_chgd; bool brain_port_chgd; @@ -1954,6 +1953,7 @@ typedef struct user_options #endif bool hash_mode_chgd; bool hccapx_message_pair_chgd; + bool identify; bool increment_max_chgd; bool increment_min_chgd; bool kernel_accel_chgd; diff --git a/src/hashcat.c b/src/hashcat.c index d367ef1d2..7d309dff8 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1480,7 +1480,7 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) event_log_info (hashcat_ctx, NULL); - if (user_options->autodetect_only == false) + if (user_options->identify == false) { event_log_error (hashcat_ctx, "Please specify the hash-mode with -m [hash-mode]."); @@ -1504,7 +1504,7 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) hcfree (usage_sort_buf[0].hash_name); hcfree (usage_sort_buf); - if (user_options->autodetect_only == true) return 0; + if (user_options->identify == true) return 0; user_options->autodetect = false; } diff --git a/src/usage.c b/src/usage.c index b63e417c2..3ea1397ba 100644 --- a/src/usage.c +++ b/src/usage.c @@ -120,6 +120,7 @@ static const char *const USAGE_BIG_PRE_HASHMODES[] = " -2, --custom-charset2 | CS | User-defined charset ?2 | -2 ?l?d?s", " -3, --custom-charset3 | CS | User-defined charset ?3 |", " -4, --custom-charset4 | CS | User-defined charset ?4 |", + " --identify | | Shows all supported algorithms for input hashes | --identify my.hash", " -i, --increment | | Enable mask increment mode |", " --increment-min | Num | Start mask incrementing at X | --increment-min=4", " --increment-max | Num | Stop mask incrementing at X | --increment-max=8", diff --git a/src/user_options.c b/src/user_options.c index 2ab1c632f..cb2c73379 100644 --- a/src/user_options.c +++ b/src/user_options.c @@ -63,7 +63,7 @@ static const struct option long_options[] = {"hex-salt", no_argument, NULL, IDX_HEX_SALT}, {"hex-wordlist", no_argument, NULL, IDX_HEX_WORDLIST}, {"hook-threads", required_argument, NULL, IDX_HOOK_THREADS}, - {"identify", no_argument, NULL, IDX_AUTODETECT_ONLY}, + {"identify", no_argument, NULL, IDX_IDENTIFY}, {"increment-max", required_argument, NULL, IDX_INCREMENT_MAX}, {"increment-min", required_argument, NULL, IDX_INCREMENT_MIN}, {"increment", no_argument, NULL, IDX_INCREMENT}, @@ -159,7 +159,6 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->advice_disable = ADVICE_DISABLE; user_options->attack_mode = ATTACK_MODE; user_options->autodetect = AUTODETECT; - user_options->autodetect_only = AUTODETECT_ONLY; user_options->backend_devices = NULL; user_options->backend_ignore_cuda = BACKEND_IGNORE_CUDA; user_options->backend_ignore_opencl = BACKEND_IGNORE_OPENCL; @@ -198,6 +197,7 @@ int user_options_init (hashcat_ctx_t *hashcat_ctx) user_options->hex_salt = HEX_SALT; user_options->hex_wordlist = HEX_WORDLIST; user_options->hook_threads = HOOK_THREADS; + user_options->identify = IDENTIFY; user_options->increment = INCREMENT; user_options->increment_max = INCREMENT_MAX; user_options->increment_min = INCREMENT_MIN; @@ -398,7 +398,7 @@ int user_options_getopt (hashcat_ctx_t *hashcat_ctx, int argc, char **argv) case IDX_STDOUT_FLAG: user_options->stdout_flag = true; break; case IDX_STDIN_TIMEOUT_ABORT: user_options->stdin_timeout_abort = hc_strtoul (optarg, NULL, 10); user_options->stdin_timeout_abort_chgd = true; break; - case IDX_AUTODETECT_ONLY: user_options->autodetect_only = true; break; + case IDX_IDENTIFY: user_options->identify = true; break; case IDX_SPEED_ONLY: user_options->speed_only = true; break; case IDX_PROGRESS_ONLY: user_options->progress_only = true; break; case IDX_RESTORE_DISABLE: user_options->restore_disable = true; break; From a25db47215b40356edb334cf0e953b84c95c68ef Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Fri, 11 Jun 2021 20:12:59 +0200 Subject: [PATCH 3/3] updated output messages for identify functionality --- src/hashcat.c | 61 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/src/hashcat.c b/src/hashcat.c index 7d309dff8..61b6cb68f 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -1464,21 +1464,31 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) if (modes_cnt > 1) { - event_log_info (hashcat_ctx, "The following %d hash-modes match the structure of your input hash:", modes_cnt); - event_log_info (hashcat_ctx, NULL); - event_log_info (hashcat_ctx, " # | Name | Category"); - event_log_info (hashcat_ctx, " ======+=====================================================+======================================"); + if (user_options->quiet == false) + { + event_log_info (hashcat_ctx, "The following %d hash-modes match the structure of your input hash:", modes_cnt); + event_log_info (hashcat_ctx, NULL); + event_log_info (hashcat_ctx, " # | Name | Category"); + event_log_info (hashcat_ctx, " ======+=====================================================+======================================"); + } for (int i = 0; i < modes_cnt; i++) { - event_log_info (hashcat_ctx, "%7u | %-51s | %s", usage_sort_buf[i].hash_mode, usage_sort_buf[i].hash_name, strhashcategory (usage_sort_buf[i].hash_category)); + if (user_options->quiet == false) + { + event_log_info (hashcat_ctx, "%7u | %-51s | %s", usage_sort_buf[i].hash_mode, usage_sort_buf[i].hash_name, strhashcategory (usage_sort_buf[i].hash_category)); + } + else + { + event_log_info (hashcat_ctx, "%u", usage_sort_buf[i].hash_mode); + } hcfree (usage_sort_buf[i].hash_name); } hcfree (usage_sort_buf); - event_log_info (hashcat_ctx, NULL); + if (user_options->quiet == false) event_log_info (hashcat_ctx, NULL); if (user_options->identify == false) { @@ -1492,12 +1502,39 @@ int hashcat_session_execute (hashcat_ctx_t *hashcat_ctx) // modes_cnt == 1 - event_log_warning (hashcat_ctx, "Hash-mode was not specified with -m. Attempting to auto-detect hash mode."); - event_log_warning (hashcat_ctx, "The following mode was auto-detected as the only one matching your input hash:"); - event_log_warning (hashcat_ctx, "\n%u | %s | %s\n", usage_sort_buf[0].hash_mode, usage_sort_buf[0].hash_name, strhashcategory (usage_sort_buf[0].hash_category)); - event_log_warning (hashcat_ctx, "NOTE: Auto-detect is best effort. The correct hash-mode is NOT guaranteed!"); - event_log_warning (hashcat_ctx, "Do NOT report auto-detect issues unless you are certain of the hash type."); - event_log_warning (hashcat_ctx, NULL); + if (user_options->identify == false) + { + event_log_warning (hashcat_ctx, "Hash-mode was not specified with -m. Attempting to auto-detect hash mode."); + event_log_warning (hashcat_ctx, "The following mode was auto-detected as the only one matching your input hash:"); + } + + if (user_options->identify == true) + { + if (user_options->quiet == true) + { + event_log_info (hashcat_ctx, "%u", usage_sort_buf[0].hash_mode); + } + else + { + event_log_info (hashcat_ctx, "The following hash-mode match the structure of your input hash:"); + event_log_info (hashcat_ctx, NULL); + event_log_info (hashcat_ctx, " # | Name | Category"); + event_log_info (hashcat_ctx, " ======+=====================================================+======================================"); + event_log_info (hashcat_ctx, "%7u | %-51s | %s", usage_sort_buf[0].hash_mode, usage_sort_buf[0].hash_name, strhashcategory (usage_sort_buf[0].hash_category)); + event_log_info (hashcat_ctx, NULL); + } + } + else + { + event_log_info (hashcat_ctx, "\n%u | %s | %s\n", usage_sort_buf[0].hash_mode, usage_sort_buf[0].hash_name, strhashcategory (usage_sort_buf[0].hash_category)); + } + + if (user_options->identify == false) + { + event_log_warning (hashcat_ctx, "NOTE: Auto-detect is best effort. The correct hash-mode is NOT guaranteed!"); + event_log_warning (hashcat_ctx, "Do NOT report auto-detect issues unless you are certain of the hash type."); + event_log_warning (hashcat_ctx, NULL); + } user_options->hash_mode = usage_sort_buf[0].hash_mode;