From dfd4084b3bf567a4e56ed63f69ba64f559b25e8c Mon Sep 17 00:00:00 2001 From: philsmd Date: Wed, 1 Feb 2017 09:00:16 +0100 Subject: [PATCH 1/2] fixes #963: show all user's hashes if --show/--left was specified --- docs/changes.txt | 1 + include/potfile.h | 3 ++ include/types.h | 2 + src/hashes.c | 7 +++- src/potfile.c | 103 ++++++++++++++++++++++++++++++++++------------ 5 files changed, 88 insertions(+), 28 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 5f09a7aa3..8b314d757 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -6,6 +6,7 @@ - Added support for parsing 7-Zip hashes with LZMA/LZMA2 compression indicator set to a non-zero value - Added support for decompressing LZMA1/LZMA2 data for -m 11600 = 7-Zip to validate the CRC +- Added support for showing all user names with --show and --left if --username was specified ## ## Algorithms diff --git a/include/potfile.h b/include/potfile.h index 01b2180ef..257294ef8 100644 --- a/include/potfile.h +++ b/include/potfile.h @@ -26,4 +26,7 @@ void potfile_destroy (hashcat_ctx_t *hashcat_ctx); int potfile_handle_show (hashcat_ctx_t *hashcat_ctx); int potfile_handle_left (hashcat_ctx_t *hashcat_ctx); +void potfile_update_hash (hashcat_ctx_t *hashcat_ctx, hash_t *found, char *line_pw_buf, int line_pw_len); +void potfile_update_hashes (hashcat_ctx_t *hashcat_ctx, hash_t *found, hash_t *hashes_buf, u32 hashes_cnt, int (*compar) (const void *, const void *, void *), char *line_pw_buf, int line_pw_len); + #endif // _POTFILE_H diff --git a/include/types.h b/include/types.h index ef17789a9..559837419 100644 --- a/include/types.h +++ b/include/types.h @@ -1244,6 +1244,8 @@ typedef struct potfile_ctx { bool enabled; + bool keep_all_usernames; + FILE *fp; char *filename; diff --git a/src/hashes.c b/src/hashes.c index e9769a2f9..dd5f64183 100644 --- a/src/hashes.c +++ b/src/hashes.c @@ -1068,6 +1068,7 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) hashconfig_t *hashconfig = hashcat_ctx->hashconfig; hashes_t *hashes = hashcat_ctx->hashes; user_options_t *user_options = hashcat_ctx->user_options; + potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; hash_t *hashes_buf = hashes->hashes_buf; u32 hashes_cnt = hashes->hashes_cnt; @@ -1082,7 +1083,11 @@ int hashes_init_stage2 (hashcat_ctx_t *hashcat_ctx) for (u32 hashes_pos = 1; hashes_pos < hashes_cnt; hashes_pos++) { - if (hashconfig->is_salted) + if (potfile_ctx->keep_all_usernames == true) + { + // do not sort, because we need to keep all hashes in this particular case + } + else if (hashconfig->is_salted) { if (sort_by_salt (hashes_buf[hashes_pos].salt, hashes_buf[hashes_pos - 1].salt) == 0) { diff --git a/src/potfile.c b/src/potfile.c index 9d4a03575..a4a796d52 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -90,6 +90,18 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx) potfile_ctx->fp = NULL; } + // keep all usernames and hashes if --username was combined with --left or --show + + potfile_ctx->keep_all_usernames = false; + + if (user_options->username == true) + { + if ((user_options->show == true) || (user_options->left == true)) + { + potfile_ctx->keep_all_usernames = true; + } + } + // starting from here, we should allocate some scratch buffer for later use u8 *out_buf = (u8 *) hcmalloc (HCBUFSIZ_LARGE); @@ -255,11 +267,52 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 * unlock_file (potfile_ctx->fp); } +void potfile_update_hash (hashcat_ctx_t *hashcat_ctx, hash_t *found, char *line_pw_buf, int line_pw_len) +{ + const loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; + + if (found == NULL) return; + + char *pw_buf = line_pw_buf; + int pw_len = line_pw_len; + + found->pw_buf = (char *) hcmalloc (pw_len + 1); + found->pw_len = pw_len; + + memcpy (found->pw_buf, pw_buf, pw_len); + + found->pw_buf[found->pw_len] = 0; + + found->cracked = 1; + + // if enabled, update also the loopback file + + if (loopback_ctx->fp != NULL) + { + loopback_write_append (hashcat_ctx, (u8 *) pw_buf, (unsigned int) pw_len); + } +} + +void potfile_update_hashes (hashcat_ctx_t *hashcat_ctx, hash_t *hash_buf, hash_t *hashes_buf, u32 hashes_cnt, int (*compar) (const void *, const void *, void *), char *line_pw_buf, int line_pw_len) +{ + const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; + + // linear search + + for (u32 hash_pos = 0; hash_pos < hashes_cnt; hash_pos++) + { + if (compar ((void *) &hashes_buf[hash_pos], (void *) hash_buf, (void *) hashconfig) == 0) + { + potfile_update_hash (hashcat_ctx, &hashes_buf[hash_pos], line_pw_buf, line_pw_len); + } + } +} + int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashes_t *hashes = hashcat_ctx->hashes; - const loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx; + const user_options_t *user_options = hashcat_ctx->user_options; const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; if (potfile_ctx->enabled == false) return 0; @@ -314,14 +367,15 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) if (parser_status == PARSER_OK) { - hash_t *found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig); - - if (found) + if (potfile_ctx->keep_all_usernames == true) { - found->pw_buf = ""; - found->pw_len = 0; + potfile_update_hashes (hashcat_ctx, &hash_buf, hashes_buf, hashes_cnt, sort_by_hash_no_salt, "", 0); + } + else + { + hash_t *found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig); - found->cracked = 1; + potfile_update_hash (hashcat_ctx, found, "", 0); } } } @@ -456,35 +510,30 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) { if (hashconfig->is_salted) { + if (potfile_ctx->keep_all_usernames == true) + { + potfile_update_hashes (hashcat_ctx, &hash_buf, hashes_buf, hashes_cnt, sort_by_hash, line_pw_buf, line_pw_len); + + continue; + } + found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig); } else { + if (potfile_ctx->keep_all_usernames == true) + { + potfile_update_hashes (hashcat_ctx, &hash_buf, hashes_buf, hashes_cnt, sort_by_hash_no_salt, line_pw_buf, line_pw_len); + + continue; + } + found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig); } } } - if (found == NULL) continue; - - char *pw_buf = line_pw_buf; - int pw_len = line_pw_len; - - found->pw_buf = (char *) hcmalloc (pw_len + 1); - found->pw_len = pw_len; - - memcpy (found->pw_buf, pw_buf, pw_len); - - found->pw_buf[found->pw_len] = 0; - - found->cracked = 1; - - // if enabled, update also the loopback file - - if (loopback_ctx->fp != NULL) - { - loopback_write_append (hashcat_ctx, (u8 *) pw_buf, (unsigned int) pw_len); - } + potfile_update_hash (hashcat_ctx, found, line_pw_buf, line_pw_len); } hcfree (line_buf); From 1c4af583e8d8922050186382fcb68d05555fd6c9 Mon Sep 17 00:00:00 2001 From: philsmd Date: Wed, 1 Feb 2017 09:20:10 +0100 Subject: [PATCH 2/2] minor: removed unused user_options variable --- src/potfile.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/potfile.c b/src/potfile.c index a4a796d52..06bf49bb4 100644 --- a/src/potfile.c +++ b/src/potfile.c @@ -312,7 +312,6 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) { const hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashes_t *hashes = hashcat_ctx->hashes; - const user_options_t *user_options = hashcat_ctx->user_options; const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; if (potfile_ctx->enabled == false) return 0;