Use $HEX[...] in case the password includes the separater character, increases potfile reading performance

pull/918/head
jsteube 8 years ago
parent 1be98add82
commit 1342cf2ce3

@ -1,5 +1,11 @@
* changes v3.20 -> v3.21: * changes v3.20 -> v3.21:
##
## Features
##
- Use $HEX[...] in case the password includes the separater character. This makes the MAX_CUT_TRIES logic no longer required which then increase potfile reading
## ##
## Bugs ## Bugs
## ##

@ -79,7 +79,6 @@ but this is nededed for VS compiler which doesn't have inline keyword but has __
#define SPEED_MAXAGE 4096 #define SPEED_MAXAGE 4096
#define BLOCK_SIZE 64 #define BLOCK_SIZE 64
#define EXPECTED_ITERATIONS 10000 #define EXPECTED_ITERATIONS 10000
#define MAX_CUT_TRIES 4
#if defined (_WIN) #if defined (_WIN)
#define EOL "\r\n" #define EOL "\r\n"

@ -8,7 +8,7 @@
#include <ctype.h> #include <ctype.h>
bool need_hexify (const u8 *buf, const int len, bool always_ascii); bool need_hexify (const u8 *buf, const int len, const char separator, bool always_ascii);
void exec_hexify (const u8 *buf, const int len, u8 *out); void exec_hexify (const u8 *buf, const int len, u8 *out);
bool is_valid_hex_char (const u8 c); bool is_valid_hex_char (const u8 c);

@ -75,32 +75,46 @@ static bool printable_ascii (const u8 *buf, const int len)
return true; return true;
} }
bool need_hexify (const u8 *buf, const int len, bool always_ascii) static bool matches_separator (const u8 *buf, const int len, const char separator)
{ {
for (int i = 0; i < len; i++)
{
const char c = (char) buf[i];
if (c == separator) return true;
}
return false;
}
bool need_hexify (const u8 *buf, const int len, const char separator, bool always_ascii)
{
bool rc = false;
if (always_ascii == true) if (always_ascii == true)
{ {
if (printable_ascii (buf, len) == true) if (printable_ascii (buf, len) == false)
{ {
return false; rc = true;
}
else
{
return true;
} }
} }
else else
{ {
if (printable_utf8 (buf, len) == true) if (printable_utf8 (buf, len) == false)
{ {
return false; rc = true;
} }
else }
if (rc == false)
{
if (matches_separator (buf, len, separator) == true)
{ {
return true; rc = true;
} }
} }
return false; return rc;
} }
void exec_hexify (const u8 *buf, const int len, u8 *out) void exec_hexify (const u8 *buf, const int len, u8 *out)

@ -383,7 +383,7 @@ int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const unsign
{ {
const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false; const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false;
if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, always_ascii) == true)) if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, hashconfig->separator, always_ascii) == true))
{ {
tmp_buf[tmp_len++] = '$'; tmp_buf[tmp_len++] = '$';
tmp_buf[tmp_len++] = 'H'; tmp_buf[tmp_len++] = 'H';

@ -152,7 +152,7 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
if (line_len == 0) continue; if (line_len == 0) continue;
size_t iter = MAX_CUT_TRIES; size_t iter = 1;
for (size_t i = line_len - 1; i && iter; i--, line_len--) for (size_t i = line_len - 1; i && iter; i--, line_len--)
{ {

@ -218,7 +218,7 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *
tmp_len += out_len; tmp_len += out_len;
tmp_buf[tmp_len] = ':'; tmp_buf[tmp_len] = hashconfig->separator;
tmp_len += 1; tmp_len += 1;
} }
@ -227,7 +227,7 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *
{ {
const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false; const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false;
if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, always_ascii) == true)) if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, hashconfig->separator, always_ascii) == true))
{ {
tmp_buf[tmp_len++] = '$'; tmp_buf[tmp_len++] = '$';
tmp_buf[tmp_len++] = 'H'; tmp_buf[tmp_len++] = 'H';
@ -262,9 +262,9 @@ void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, u8 *
int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx) int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
{ {
hashconfig_t *hashconfig = hashcat_ctx->hashconfig; const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
hashes_t *hashes = hashcat_ctx->hashes; const hashes_t *hashes = hashcat_ctx->hashes;
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx; const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
if (potfile_ctx->enabled == false) return 0; if (potfile_ctx->enabled == false) return 0;
@ -325,162 +325,148 @@ int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE); char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
// to be safe work with a copy (because of line_len loop, i etc)
// moved up here because it's easier to handle continue case
// it's just 64kb
char *line_buf_cpy = (char *) hcmalloc (HCBUFSIZ_LARGE);
while (!feof (potfile_ctx->fp)) while (!feof (potfile_ctx->fp))
{ {
int line_len = fgetl (potfile_ctx->fp, line_buf); int line_len = fgetl (potfile_ctx->fp, line_buf);
if (line_len == 0) continue; if (line_len == 0) continue;
const int line_len_orig = line_len; char *last_separator = strrchr (line_buf, hashconfig->separator);
int iter = MAX_CUT_TRIES; if (last_separator == NULL) continue; // ??
for (int i = line_len - 1; i && iter; i--, line_len--) char *line_pw_buf = last_separator + 1;
{
if (line_buf[i] != ':') continue;
iter--; int line_pw_len = line_buf + line_len - line_pw_buf;
if (hashconfig->is_salted) char *line_hash_buf = line_buf;
{
memset (hash_buf.salt, 0, sizeof (salt_t));
}
if (hashconfig->esalt_size) int line_hash_len = last_separator - line_buf;
{
memset (hash_buf.esalt, 0, hashconfig->esalt_size); line_hash_buf[line_hash_len] = 0;
}
if (line_hash_len == 0) continue;
if (line_pw_len == 0) continue;
hash_t *found = NULL; if (hashconfig->is_salted)
{
memset (hash_buf.salt, 0, sizeof (salt_t));
}
if (hashconfig->esalt_size)
{
memset (hash_buf.esalt, 0, hashconfig->esalt_size);
}
hash_t *found = NULL;
if (hashconfig->hash_mode == 6800) if (hashconfig->hash_mode == 6800)
{
if (line_hash_len < 64) // 64 = 16 * u32 in salt_buf[]
{ {
if (i < 64) // 64 = 16 * u32 in salt_buf[] // manipulate salt_buf
{ memcpy (hash_buf.salt->salt_buf, line_hash_buf, line_hash_len);
// manipulate salt_buf
memcpy (hash_buf.salt->salt_buf, line_buf, i);
hash_buf.salt->salt_len = i; hash_buf.salt->salt_len = line_hash_len;
found = (hash_t *) bsearch (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_t_salt); found = (hash_t *) bsearch (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_t_salt);
}
} }
else if (hashconfig->hash_mode == 2500) }
else if (hashconfig->hash_mode == 2500)
{
if (line_hash_len < 64) // 64 = 16 * u32 in salt_buf[]
{ {
if (i < 64) // 64 = 16 * u32 in salt_buf[] // here we have in line_hash_buf: ESSID:MAC1:MAC2 (without the plain)
{
// here we have in line_buf: ESSID:MAC1:MAC2 (without the plain)
// manipulate salt_buf
memcpy (line_buf_cpy, line_buf, i); char *mac2_pos = strrchr (line_hash_buf, ':');
line_buf_cpy[i] = 0; if (mac2_pos == NULL) continue;
char *mac2_pos = strrchr (line_buf_cpy, ':'); mac2_pos[0] = 0;
mac2_pos++;
if (mac2_pos == NULL) continue; if (strlen (mac2_pos) != 12) continue;
mac2_pos[0] = 0; char *mac1_pos = strrchr (line_hash_buf, ':');
mac2_pos++;
if (strlen (mac2_pos) != 12) continue; if (mac1_pos == NULL) continue;
char *mac1_pos = strrchr (line_buf_cpy, ':'); mac1_pos[0] = 0;
mac1_pos++;
if (mac1_pos == NULL) continue; if (strlen (mac1_pos) != 12) continue;
mac1_pos[0] = 0; u32 essid_length = mac1_pos - line_hash_buf - 1;
mac1_pos++;
if (strlen (mac1_pos) != 12) continue; if (hashconfig->is_salted)
{
// this should be always true, but we need it to make scan-build happy
u32 essid_length = mac1_pos - line_buf_cpy - 1; memcpy (hash_buf.salt->salt_buf, line_hash_buf, essid_length);
if (hashconfig->is_salted) hash_buf.salt->salt_len = essid_length;
{ }
// this should be always true, but we need it to make scan-build happy
memcpy (hash_buf.salt->salt_buf, line_buf_cpy, essid_length); found = (hash_t *) bsearch (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_t_salt_hccap);
hash_buf.salt->salt_len = essid_length; if (found)
} {
wpa_t *wpa = (wpa_t *) found->esalt;
found = (hash_t *) bsearch (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_t_salt_hccap); // compare hex string(s) vs binary MAC address(es)
if (found) for (u32 mac_idx = 0, orig_mac_idx = 0; mac_idx < 6; mac_idx += 1, orig_mac_idx += 2)
{ {
wpa_t *wpa = (wpa_t *) found->esalt; if (wpa->orig_mac1[mac_idx] != hex_to_u8 ((const u8 *) &mac1_pos[orig_mac_idx]))
// compare hex string(s) vs binary MAC address(es)
for (u32 mac_idx = 0, orig_mac_idx = 0; mac_idx < 6; mac_idx += 1, orig_mac_idx += 2)
{ {
if (wpa->orig_mac1[mac_idx] != hex_to_u8 ((const u8 *) &mac1_pos[orig_mac_idx])) found = NULL;
{
found = NULL;
break; break;
}
} }
// early skip ;) if (wpa->orig_mac2[mac_idx] != hex_to_u8 ((const u8 *) &mac2_pos[orig_mac_idx]))
if (!found) continue;
for (u32 mac_idx = 0, orig_mac_idx = 0; mac_idx < 6; mac_idx += 1, orig_mac_idx += 2)
{ {
if (wpa->orig_mac2[mac_idx] != hex_to_u8 ((const u8 *) &mac2_pos[orig_mac_idx])) found = NULL;
{
found = NULL;
break; break;
}
} }
} }
} }
} }
else }
{ else
int parser_status = hashconfig->parse_func ((u8 *) line_buf, line_len - 1, &hash_buf, hashconfig); {
int parser_status = hashconfig->parse_func ((u8 *) line_hash_buf, line_hash_len, &hash_buf, hashconfig);
if (parser_status == PARSER_OK) if (parser_status == PARSER_OK)
{
if (hashconfig->is_salted)
{ {
if (hashconfig->is_salted) found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig);
{ }
found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig); else
} {
else found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash_no_salt, (void *) hashconfig);
{
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; if (found == NULL) continue;
char *pw_buf = line_buf + line_len;
int pw_len = line_len_orig - line_len;
found->pw_buf = (char *) hcmalloc (pw_len + 1); char *pw_buf = line_pw_buf;
found->pw_len = pw_len; int pw_len = line_pw_len;
memcpy (found->pw_buf, pw_buf, pw_len); found->pw_buf = (char *) hcmalloc (pw_len + 1);
found->pw_len = pw_len;
found->pw_buf[found->pw_len] = 0; memcpy (found->pw_buf, pw_buf, pw_len);
found->cracked = 1; found->pw_buf[found->pw_len] = 0;
break; found->cracked = 1;
}
} }
hcfree (line_buf_cpy);
hcfree (line_buf); hcfree (line_buf);
potfile_read_close (hashcat_ctx); potfile_read_close (hashcat_ctx);

@ -737,8 +737,8 @@ char *status_get_input_candidates_dev (const hashcat_ctx_t *hashcat_ctx, const i
const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false; const bool always_ascii = (hashconfig->hash_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false;
const bool need_hex1 = need_hexify (plain_ptr1, plain_len1, always_ascii); const bool need_hex1 = need_hexify (plain_ptr1, plain_len1, 0, always_ascii);
const bool need_hex2 = need_hexify (plain_ptr2, plain_len2, always_ascii); const bool need_hex2 = need_hexify (plain_ptr2, plain_len2, 0, always_ascii);
if ((need_hex1 == true) || (need_hex2 == true)) if ((need_hex1 == true) || (need_hex2 == true))
{ {

Loading…
Cancel
Save