1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-30 03:48:17 +00:00

Merge pull request #1676 from philsmd/master

outfile check: performance improvement by using binary instead of linear search
This commit is contained in:
Jens Steube 2018-08-31 15:46:21 +02:00 committed by GitHub
commit 0339b3bca0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 238 additions and 201 deletions

View File

@ -11,6 +11,7 @@
- Add option --markov-hcstat2 to make it clear that the new hcstat2 format (compressed hcstat2gen output) must be used - Add option --markov-hcstat2 to make it clear that the new hcstat2 format (compressed hcstat2gen output) must be used
- Do not allocate memory segments for bitmap tables if we dont need it, for example in benchmark mode - Do not allocate memory segments for bitmap tables if we dont need it, for example in benchmark mode
- Removed duplicate words in the dictionary file example.dict - Removed duplicate words in the dictionary file example.dict
- Improved the speed of the outfile folder scan when using lots of hashes/salts
## ##
## Bugs ## Bugs

View File

@ -8,6 +8,7 @@
int sort_by_digest_p0p1 (const void *v1, const void *v2, void *v3); int sort_by_digest_p0p1 (const void *v1, const void *v2, void *v3);
int sort_by_salt (const void *v1, const void *v2); int sort_by_salt (const void *v1, const void *v2);
int sort_by_salt_buf (const void *v1, const void *v2, MAYBE_UNUSED void * v3);
int sort_by_hash (const void *v1, const void *v2, void *v3); int sort_by_hash (const void *v1, const void *v2, void *v3);
int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3); int sort_by_hash_no_salt (const void *v1, const void *v2, void *v3);

View File

@ -79,6 +79,11 @@ int sort_by_salt (const void *v1, const void *v2)
return 0; return 0;
} }
int sort_by_salt_buf (const void *v1, const void *v2, MAYBE_UNUSED void * v3)
{
return sort_by_salt (v1, v2);
}
int sort_by_hash (const void *v1, const void *v2, void *v3) int sort_by_hash (const void *v1, const void *v2, void *v3)
{ {
const hash_t *h1 = (const hash_t *) v1; const hash_t *h1 = (const hash_t *) v1;

View File

@ -15,6 +15,7 @@
#include "interface.h" #include "interface.h"
#include "shared.h" #include "shared.h"
#include "thread.h" #include "thread.h"
#include "bitops.h"
static int outfile_remove (hashcat_ctx_t *hashcat_ctx) static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
{ {
@ -33,6 +34,11 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
u32 hash_mode = hashconfig->hash_mode; u32 hash_mode = hashconfig->hash_mode;
char separator = hashconfig->separator; char separator = hashconfig->separator;
salt_t *salts_buf = hashes->salts_buf;
const u32 salts_cnt = hashes->salts_cnt;
char *digests_buf = hashes->digests_buf;
char *root_directory = outcheck_ctx->root_directory; char *root_directory = outcheck_ctx->root_directory;
u32 outfile_check_timer = user_options->outfile_check_timer; u32 outfile_check_timer = user_options->outfile_check_timer;
@ -45,8 +51,6 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
if (esalt_size > 0) hash_buf.esalt = hcmalloc (esalt_size); if (esalt_size > 0) hash_buf.esalt = hcmalloc (esalt_size);
if (hook_salt_size > 0) hash_buf.hook_salt = hcmalloc (hook_salt_size); if (hook_salt_size > 0) hash_buf.hook_salt = hcmalloc (hook_salt_size);
u32 digest_buf[64] = { 0 };
outfile_data_t *out_info = NULL; outfile_data_t *out_info = NULL;
char **out_files = NULL; char **out_files = NULL;
@ -65,14 +69,16 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
check_left--; check_left--;
if (check_left == 0) if (check_left != 0) continue;
{
if (hc_path_exist (root_directory) == true) check_left = outfile_check_timer;
{
if (hc_path_exist (root_directory) == false) continue;
const bool is_dir = hc_path_is_directory (root_directory); const bool is_dir = hc_path_is_directory (root_directory);
if (is_dir == true) if (is_dir == false) continue;
{
struct stat outfile_check_stat; struct stat outfile_check_stat;
if (stat (root_directory, &outfile_check_stat) == -1) if (stat (root_directory, &outfile_check_stat) == -1)
@ -105,22 +111,19 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
for (int j = 0; j < out_cnt; j++) for (int j = 0; j < out_cnt; j++)
{ {
if (strcmp (out_info[j].file_name, out_info_new[i].file_name) == 0) if (strcmp (out_info[j].file_name, out_info_new[i].file_name) != 0) continue;
{
struct stat outfile_stat; struct stat outfile_stat;
if (stat (out_info_new[i].file_name, &outfile_stat) == 0) if (stat (out_info_new[i].file_name, &outfile_stat) != 0) continue;
{
if (outfile_stat.st_ctime == out_info[j].ctime) if (outfile_stat.st_ctime != out_info[j].ctime) continue;
{
out_info_new[i].ctime = out_info[j].ctime; out_info_new[i].ctime = out_info[j].ctime;
out_info_new[i].seek = out_info[j].seek; out_info_new[i].seek = out_info[j].seek;
} }
} }
} }
}
}
}
hcfree (out_info); hcfree (out_info);
hcfree (out_files); hcfree (out_files);
@ -136,8 +139,8 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
{ {
FILE *fp = fopen (out_info[j].file_name, "rb"); FILE *fp = fopen (out_info[j].file_name, "rb");
if (fp != NULL) if (fp == NULL) continue;
{
//hc_thread_mutex_lock (status_ctx->mux_display); //hc_thread_mutex_lock (status_ctx->mux_display);
struct stat outfile_stat; struct stat outfile_stat;
@ -169,70 +172,109 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
if (line_len == 0) continue; if (line_len == 0) continue;
size_t iter = 1; size_t cut_tries = 5;
for (size_t i = line_len - 1; i && iter; i--, line_len--) for (size_t i = line_len - 1; i && cut_tries; i--, line_len--)
{ {
if (line_buf[i] != separator) continue; if (line_buf[i] != separator) continue;
iter--; cut_tries--;
int parser_status = PARSER_OK; if (is_salted == true) memset (hash_buf.salt, 0, sizeof (salt_t)); // needed ? (let's play it safe!)
if ((hash_mode != 2500) && (hash_mode != 2501) && (hash_mode != 6800)) int parser_status = PARSER_HASH_LENGTH;
if ((hash_mode == 2500) || (hash_mode == 2501)) // special case WPA/WPA2
{
// fake the parsing of the salt
u32 identifier_len = 32 + 1 + 12 + 1 + 12 + 1; // format is [ID_MD5]:[MAC1]:[MAC2]:$salt:$pass
if ((line_len - 1) < identifier_len) continue;
hash_buf.salt->salt_len = line_len - 1 - identifier_len;
memcpy (hash_buf.salt->salt_buf, line_buf + identifier_len, hash_buf.salt->salt_len);
// fake the parsing of the digest
if (is_valid_hex_string ((u8 *) line_buf, 32) == false) break;
u32 *digest = (u32 *) hash_buf.digest;
digest[0] = hex_to_u32 ((u8 *) line_buf + 0);
digest[1] = hex_to_u32 ((u8 *) line_buf + 8);
digest[2] = hex_to_u32 ((u8 *) line_buf + 16);
digest[3] = hex_to_u32 ((u8 *) line_buf + 24);
digest[0] = byte_swap_32 (digest[0]);
digest[1] = byte_swap_32 (digest[1]);
digest[2] = byte_swap_32 (digest[2]);
digest[3] = byte_swap_32 (digest[3]);
parser_status = PARSER_OK;
}
else if (hash_mode == 6800) // special case LastPass (only email address in outfile/potfile)
{
// fake the parsing of the hash/salt
hash_buf.salt->salt_len = line_len - 1;
memcpy (hash_buf.salt->salt_buf, line_buf, line_len - 1);
parser_status = PARSER_OK;
}
else // "normal" case: hash in the outfile is the same as the hash in the original hash file
{ {
parser_status = hashconfig->parse_func ((u8 *) line_buf, (u32) line_len - 1, &hash_buf, hashconfig); parser_status = hashconfig->parse_func ((u8 *) line_buf, (u32) line_len - 1, &hash_buf, hashconfig);
} }
u32 found = 0; if (parser_status != PARSER_OK) continue;
if (parser_status == PARSER_OK)
salt_t *salt_buf = salts_buf;
if (is_salted == true)
{ {
for (u32 salt_pos = 0; (found == 0) && (salt_pos < hashes->salts_cnt); salt_pos++) salt_buf = (salt_t *) hc_bsearch_r (hash_buf.salt, salts_buf, salts_cnt, sizeof (salt_t), sort_by_salt_buf, (void *) hashconfig);
{ }
if (hashes->salts_shown[salt_pos] == 1) continue;
salt_t *salt_buf = &hashes->salts_buf[salt_pos]; if (salt_buf == NULL) continue;
for (u32 digest_pos = 0; (found == 0) && (digest_pos < salt_buf->digests_cnt); digest_pos++) u32 salt_pos = salt_buf - salts_buf; // the offset from the start of the array (unit: sizeof (salt_t))
{
u32 idx = salt_buf->digests_offset + digest_pos;
if (hashes->digests_shown[idx] == 1) continue; if (hashes->salts_shown[salt_pos] == 1) break; // already marked as cracked (no action needed)
u32 cracked = 0; u32 idx = salt_buf->digests_offset;
bool cracked = false;
if (hash_mode == 6800) if (hash_mode == 6800)
{ {
if (i == salt_buf->salt_len) // the comparison with only matching salt is a bit inaccurate
{
cracked = (memcmp (line_buf, salt_buf->salt_buf, salt_buf->salt_len) == 0);
}
}
else if ((hash_mode == 2500) || (hash_mode == 2501))
{
// this comparison is a bit inaccurate as we compare only ESSID
// call it a bug, but it's good enough for a special case used in a special case // call it a bug, but it's good enough for a special case used in a special case
// in this case all essid will be marked as cracked that match the essid
if (i == salt_buf->salt_len) cracked = true;
{
cracked = (memcmp (line_buf, salt_buf->salt_buf, salt_buf->salt_len) == 0);
}
} }
else else
{ {
char *digests_buf_ptr = (char *) hashes->digests_buf; char *digests_buf_ptr = digests_buf + (salt_buf->digests_offset * dgst_size);
u32 digests_buf_cnt = salt_buf->digests_cnt;
memcpy (digest_buf, digests_buf_ptr + (hashes->salts_buf[salt_pos].digests_offset * dgst_size) + (digest_pos * dgst_size), dgst_size); char *digest_buf = (char *) hc_bsearch_r (hash_buf.digest, digests_buf_ptr, digests_buf_cnt, dgst_size, sort_by_digest_p0p1, (void *) hashconfig);
cracked = (sort_by_digest_p0p1 (digest_buf, hash_buf.digest, hashconfig) == 0); if (digest_buf != NULL)
{
idx += (digest_buf - digests_buf_ptr) / dgst_size;
if (hashes->digests_shown[idx] == 1) break;
cracked = true;
}
} }
if (cracked == 1) if (cracked == true)
{ {
found = 1;
hashes->digests_shown[idx] = 1; hashes->digests_shown[idx] = 1;
hashes->digests_done++; hashes->digests_done++;
@ -245,21 +287,14 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
hashes->salts_done++; hashes->salts_done++;
if (hashes->salts_done == hashes->salts_cnt) mycracked (hashcat_ctx); if (hashes->salts_done == salts_cnt) mycracked (hashcat_ctx);
}
} }
if (status_ctx->shutdown_inner == true) break; break;
} }
if (status_ctx->shutdown_inner == true) break; if (status_ctx->shutdown_inner == true) break;
} }
}
if (found) break;
if (status_ctx->shutdown_inner == true) break;
}
if (status_ctx->shutdown_inner == true) break; if (status_ctx->shutdown_inner == true) break;
} }
@ -271,16 +306,10 @@ static int outfile_remove (hashcat_ctx_t *hashcat_ctx)
//hc_thread_mutex_unlock (status_ctx->mux_display); //hc_thread_mutex_unlock (status_ctx->mux_display);
fclose (fp); fclose (fp);
}
if (status_ctx->shutdown_inner == true) break; if (status_ctx->shutdown_inner == true) break;
} }
} }
}
check_left = outfile_check_timer;
}
}
hcfree (hash_buf.esalt); hcfree (hash_buf.esalt);
hcfree (hash_buf.hook_salt); hcfree (hash_buf.hook_salt);
@ -326,8 +355,9 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx)
if ((user_options->hash_mode == 5200) || if ((user_options->hash_mode == 5200) ||
((user_options->hash_mode >= 6200) && (user_options->hash_mode <= 6299)) || ((user_options->hash_mode >= 6200) && (user_options->hash_mode <= 6299)) ||
(user_options->hash_mode == 9000) ||
((user_options->hash_mode >= 13700) && (user_options->hash_mode <= 13799)) || ((user_options->hash_mode >= 13700) && (user_options->hash_mode <= 13799)) ||
(user_options->hash_mode == 9000)) return 0; (user_options->hash_mode == 14600)) return 0;
if (user_options->outfile_check_dir == NULL) if (user_options->outfile_check_dir == NULL)
{ {