From d706f90a75d472a1dc2fe53083525d937ece472f Mon Sep 17 00:00:00 2001 From: Jens Steube Date: Tue, 10 Mar 2020 15:42:55 +0100 Subject: [PATCH] Dictstat: On Windows, the st_ino attribute in the stat struct is not set which can lead to invalid cache hits. Added the filename to the database entry. --- docs/changes.txt | 1 + include/dictstat.h | 2 +- include/types.h | 2 ++ src/dictstat.c | 4 ++++ src/wordlist.c | 16 +++++++++++++++- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index 34f830347..160004738 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -108,6 +108,7 @@ - Building: Fix for library compilation failure due to multiple defenition of sbob_xx64() - Building: Updated BUILD.md - Cracking bcrypt and Password Safe v2: Use a feedback from the compute API backend to dynamically find out optimal thread count +- Dictstat: On Windows, the st_ino attribute in the stat struct is not set which can lead to invalid cache hits. Added the filename to the database entry. - Documents: Added README on how to build hashcat on MSYS2 - File handling: Print a truncation warning when an oversized line is detected - My Wallet: Added additional plaintext pattern used in newer versions diff --git a/include/dictstat.h b/include/dictstat.h index 4e79169b1..bfe8fe7b0 100644 --- a/include/dictstat.h +++ b/include/dictstat.h @@ -18,7 +18,7 @@ #define MAX_DICTSTAT 100000 #define DICTSTAT_FILENAME "hashcat.dictstat2" -#define DICTSTAT_VERSION (0x6863646963743200 | 0x01) +#define DICTSTAT_VERSION (0x6863646963743200 | 0x02) int sort_by_dictstat (const void *s1, const void *s2); diff --git a/include/types.h b/include/types.h index a17f9d10f..5ae4f2b0e 100644 --- a/include/types.h +++ b/include/types.h @@ -1656,6 +1656,8 @@ typedef struct dictstat char encoding_from[64]; char encoding_to[64]; + u8 hash_filename[16]; + } dictstat_t; typedef struct hashdump diff --git a/src/dictstat.c b/src/dictstat.c index 15830c68b..03736e74b 100644 --- a/src/dictstat.c +++ b/src/dictstat.c @@ -17,6 +17,10 @@ int sort_by_dictstat (const void *s1, const void *s2) const dictstat_t *d1 = (const dictstat_t *) s1; const dictstat_t *d2 = (const dictstat_t *) s2; + const int rc_hash = memcmp (d1->hash_filename, d2->hash_filename, 16); + + if (rc_hash != 0) return rc_hash; + const int rc_from = strcmp (d1->encoding_from, d2->encoding_from); if (rc_from != 0) return rc_from; diff --git a/src/wordlist.c b/src/wordlist.c index 380dfcf4d..651ff4d80 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -13,6 +13,7 @@ #include "rp_cpu.h" #include "shared.h" #include "wordlist.h" +#include "emu_inc_hash_sha1.h" size_t convert_from_hex (hashcat_ctx_t *hashcat_ctx, char *line_buf, const size_t line_len) { @@ -340,7 +341,7 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u dictstat_t d; - d.cnt = 0; + memset (&d, 0, sizeof (d)); if (fstat (hc_fileno (fp), &d.stat)) { @@ -378,6 +379,19 @@ int count_words (hashcat_ctx_t *hashcat_ctx, HCFILE *fp, const char *dictfile, u return 0; } + const size_t dictfile_len = strlen (dictfile); + + u32 *dictfile_padded = (u32 *) hcmalloc (dictfile_len + 64); // padding required for sha1_update() + + sha1_ctx_t sha1_ctx; + sha1_init (&sha1_ctx); + sha1_update (&sha1_ctx, dictfile_padded, dictfile_len); + sha1_final (&sha1_ctx); + + hcfree (dictfile_padded); + + memcpy (d.hash_filename, sha1_ctx.h, 16); + const u64 cached_cnt = dictstat_find (hashcat_ctx, &d); if (run_rule_engine (user_options_extra->rule_len_l, user_options->rule_buf_l) == 0)