1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-13 19:28:56 +00:00

fixes #963: show all user's hashes if --show/--left was specified

This commit is contained in:
philsmd 2017-02-01 09:00:16 +01:00
parent 934cc6fcec
commit dfd4084b3b
No known key found for this signature in database
GPG Key ID: 4F25D016D9D6A8AF
5 changed files with 88 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -1244,6 +1244,8 @@ typedef struct potfile_ctx
{
bool enabled;
bool keep_all_usernames;
FILE *fp;
char *filename;

View File

@ -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)
{

View File

@ -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);