From 8804c62d49860f842a80973dab5ba6c75114e78f Mon Sep 17 00:00:00 2001 From: b0lek <95943440+b0lek@users.noreply.github.com> Date: Sat, 11 Dec 2021 19:38:30 +0100 Subject: [PATCH 1/5] Fixing HEX wordlist support in -m 3000 see #3050 --- src/wordlist.c | 62 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 8 deletions(-) diff --git a/src/wordlist.c b/src/wordlist.c index 176974e8c..f8bfb2d53 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -97,7 +97,7 @@ int load_segment (hashcat_ctx_t *hashcat_ctx, HCFILE *fp) return 0; } -void get_next_word_lm (char *buf, u64 sz, u64 *len, u64 *off) +void get_next_word_lm_gen (char *buf, u64 sz, u64 *len, u64 *off, u64 cutlen) { char *ptr = buf; @@ -105,12 +105,11 @@ void get_next_word_lm (char *buf, u64 sz, u64 *len, u64 *off) { if (*ptr >= 'a' && *ptr <= 'z') *ptr -= 0x20; - if (i == 7) + if (i == cutlen) { - *off = i; + if (cutlen == 20) buf[i-1]=']'; // add ] in $HEX[] format *len = i; - - return; + // but continue a loop to skip rest of the line } if (*ptr != '\n') continue; @@ -119,13 +118,54 @@ void get_next_word_lm (char *buf, u64 sz, u64 *len, u64 *off) if ((i > 0) && (buf[i - 1] == '\r')) i--; - *len = i; + if (i < cutlen + 1) *len = i; return; } *off = sz; - *len = sz; + if (szopts_type & OPTS_TYPE_PT_LM) { - wl_data->func = get_next_word_lm; + if (hashconfig->opts_type & OPTS_TYPE_PT_HEX){ + wl_data->func = get_next_word_lm_hex; + } + else + { + wl_data->func = get_next_word_lm_text; + } } /** From 2a3a840146638e6433b8daa5f667451172173c57 Mon Sep 17 00:00:00 2001 From: b0lek <95943440+b0lek@users.noreply.github.com> Date: Sat, 11 Dec 2021 21:14:45 +0100 Subject: [PATCH 2/5] Solved --wordlist-autohex-disable not working correcly. --- src/wordlist.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/wordlist.c b/src/wordlist.c index f8bfb2d53..099537c74 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -134,7 +134,7 @@ void get_next_word_lm_hex (char *buf, u64 sz, u64 *len, u64 *off) get_next_word_lm_gen(buf, sz, len, off, 14); } -void get_next_word_lm_text (char *buf, u64 sz, u64 *len, u64 *off) +void get_next_word_lm_hex_or_text (char *buf, u64 sz, u64 *len, u64 *off) { // check if not $HEX[..] format bool hex = true; @@ -168,6 +168,11 @@ void get_next_word_lm_text (char *buf, u64 sz, u64 *len, u64 *off) } } +void get_next_word_lm_text (char *buf, u64 sz, u64 *len, u64 *off) +{ + get_next_word_lm_gen(buf, sz, len, off, 7); +} + void get_next_word_uc (char *buf, u64 sz, u64 *len, u64 *off) { char *ptr = buf; @@ -656,11 +661,16 @@ int wl_data_init (hashcat_ctx_t *hashcat_ctx) if (hashconfig->opts_type & OPTS_TYPE_PT_LM) { if (hashconfig->opts_type & OPTS_TYPE_PT_HEX){ - wl_data->func = get_next_word_lm_hex; + wl_data->func = get_next_word_lm_hex; // all hex in file } else { - wl_data->func = get_next_word_lm_text; + if (user_options->wordlist_autohex_disable == false) + { + wl_data->func = get_next_word_lm_hex_or_text; // might be $HEX[] notation + }else{ + wl_data->func = get_next_word_lm_text; // treat as nromal text + } } } From b6e5c7427bd3ff86c0ae74ecdaf2ec6db92d0881 Mon Sep 17 00:00:00 2001 From: b0lek <95943440+b0lek@users.noreply.github.com> Date: Sun, 12 Dec 2021 14:27:10 +0100 Subject: [PATCH 3/5] Added missing convertion to upper case --- src/wordlist.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/wordlist.c b/src/wordlist.c index 099537c74..45ac0aefc 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -119,7 +119,7 @@ void get_next_word_lm_gen (char *buf, u64 sz, u64 *len, u64 *off, u64 cutlen) if ((i > 0) && (buf[i - 1] == '\r')) i--; if (i < cutlen + 1) *len = i; - + return; } @@ -145,14 +145,33 @@ void get_next_word_lm_hex_or_text (char *buf, u64 sz, u64 *len, u64 *off) if (hex && (buf[3] != 'X')) hex = false; if (hex && (buf[4] != '[')) hex = false; if (hex){ - char *ptr = buf; - for (u64 i = 0; i < sz; i++, ptr++) + char *ptr = buf+5; + for (u64 i = 5; i < sz; i++, ptr++) { if (*ptr == ']') { if ((i & 1) == 0) hex=false; // not even number of characters - else + break; + } + else + { + if (is_valid_hex_char(*ptr) == false) + { + hex = false; break; + } + // upcase character if it is as letter + if ((i & 1) == 1) // if first hex-char + { + if (is_valid_hex_char(buf[i+1])){ + if (buf[i] == '6') + if (buf[i+1] > '0') + buf[i] = '4'; + if (buf[i] == '7') + if (buf[i+1] < 'B') + buf[i] = '5'; + } + } } } } From 33db7a06e0a2f4e2194108e9ab42ba0a3b4ddba5 Mon Sep 17 00:00:00 2001 From: b0lek <95943440+b0lek@users.noreply.github.com> Date: Sun, 12 Dec 2021 14:43:16 +0100 Subject: [PATCH 4/5] Fixed typo and some comments --- src/wordlist.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wordlist.c b/src/wordlist.c index 45ac0aefc..fabf61f9e 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -119,7 +119,7 @@ void get_next_word_lm_gen (char *buf, u64 sz, u64 *len, u64 *off, u64 cutlen) if ((i > 0) && (buf[i - 1] == '\r')) i--; if (i < cutlen + 1) *len = i; - + return; } @@ -145,7 +145,7 @@ void get_next_word_lm_hex_or_text (char *buf, u64 sz, u64 *len, u64 *off) if (hex && (buf[3] != 'X')) hex = false; if (hex && (buf[4] != '[')) hex = false; if (hex){ - char *ptr = buf+5; + char *ptr = buf+5; // starting after '[' for (u64 i = 5; i < sz; i++, ptr++) { if (*ptr == ']') @@ -160,7 +160,7 @@ void get_next_word_lm_hex_or_text (char *buf, u64 sz, u64 *len, u64 *off) hex = false; break; } - // upcase character if it is as letter + // upcase character if it is a letter 'a-z' if ((i & 1) == 1) // if first hex-char { if (is_valid_hex_char(buf[i+1])){ From 3c493877ab0cada1600d191d146d6785b0013fcb Mon Sep 17 00:00:00 2001 From: b0lek <95943440+b0lek@users.noreply.github.com> Date: Sun, 12 Dec 2021 15:11:46 +0100 Subject: [PATCH 5/5] Adding upcase conversion for --hex-wordlist mode --- src/wordlist.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/wordlist.c b/src/wordlist.c index fabf61f9e..1e0d82b74 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -131,6 +131,25 @@ void get_next_word_lm_hex (char *buf, u64 sz, u64 *len, u64 *off) { // this one is called if --hex-wordlist is uesed // we need 14 hex-digits to get 7 characters + // but first convert 7 chars to upper case if thay are a-z + for (u64 i = 5; i < sz; i++) + { + if ((i & 1) == 0) + { + if (is_valid_hex_char(buf[i])) + if (is_valid_hex_char(buf[i+1])) + { + if (buf[i] == '6') + if (buf[i+1] > '0') + buf[i] = '4'; + if (buf[i] == '7') + if (buf[i+1] < 'B') + buf[i] = '5'; + } + } + if (i == 12) break; // stop when 7 chars are converted + } + // call generic next_word get_next_word_lm_gen(buf, sz, len, off, 14); } @@ -163,7 +182,8 @@ void get_next_word_lm_hex_or_text (char *buf, u64 sz, u64 *len, u64 *off) // upcase character if it is a letter 'a-z' if ((i & 1) == 1) // if first hex-char { - if (is_valid_hex_char(buf[i+1])){ + if (is_valid_hex_char(buf[i+1])) + { if (buf[i] == '6') if (buf[i+1] > '0') buf[i] = '4';