2016-09-09 21:17:43 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-09 21:17:43 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
2016-09-10 10:16:16 +00:00
|
|
|
#include "convert.h"
|
2016-09-09 21:17:43 +00:00
|
|
|
#include "memory.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2019-03-31 15:39:00 +00:00
|
|
|
#include "hashes.h"
|
2016-09-10 09:32:26 +00:00
|
|
|
#include "filehandling.h"
|
2017-01-03 18:21:27 +00:00
|
|
|
#include "loopback.h"
|
2016-09-10 15:35:58 +00:00
|
|
|
#include "outfile.h"
|
2016-11-05 10:33:29 +00:00
|
|
|
#include "locking.h"
|
2016-11-16 09:22:57 +00:00
|
|
|
#include "shared.h"
|
2019-03-31 15:39:00 +00:00
|
|
|
#include "potfile.h"
|
2016-10-01 08:47:03 +00:00
|
|
|
|
2019-01-08 14:55:11 +00:00
|
|
|
static const char MASKED_PLAIN[] = "[notfound]";
|
|
|
|
|
2016-09-10 09:32:26 +00:00
|
|
|
// get rid of this later
|
2016-09-30 20:52:44 +00:00
|
|
|
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);
|
2016-09-10 09:32:26 +00:00
|
|
|
// get rid of this later
|
2016-09-09 21:17:43 +00:00
|
|
|
|
2017-02-01 11:25:21 +00:00
|
|
|
// this function is for potfile comparison where the potfile does not contain all the
|
|
|
|
// information requires to do a true sort_by_hash() bsearch
|
2019-04-03 19:53:34 +00:00
|
|
|
/*
|
2017-03-07 13:41:58 +00:00
|
|
|
static int sort_by_hash_t_salt (const void *v1, const void *v2)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
|
|
|
const hash_t *h1 = (const hash_t *) v1;
|
|
|
|
const hash_t *h2 = (const hash_t *) v2;
|
|
|
|
|
|
|
|
const salt_t *s1 = h1->salt;
|
|
|
|
const salt_t *s2 = h2->salt;
|
|
|
|
|
2017-02-01 11:25:21 +00:00
|
|
|
const int res1 = (int) s1->salt_len - (int) s2->salt_len;
|
|
|
|
|
|
|
|
if (res1 != 0) return (res1);
|
|
|
|
|
|
|
|
//const int res2 = (int) s1->salt_iter - (int) s2->salt_iter;
|
|
|
|
//
|
|
|
|
//if (res2 != 0) return (res2);
|
|
|
|
|
2017-01-23 16:54:56 +00:00
|
|
|
for (int n = 0; n < 16; n++)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2017-01-23 16:54:56 +00:00
|
|
|
if (s1->salt_buf[n] > s2->salt_buf[n]) return 1;
|
2016-09-10 10:16:16 +00:00
|
|
|
if (s1->salt_buf[n] < s2->salt_buf[n]) return -1;
|
|
|
|
}
|
|
|
|
|
2017-02-01 11:25:21 +00:00
|
|
|
for (int n = 0; n < 8; n++)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2017-02-01 11:25:21 +00:00
|
|
|
if (s1->salt_buf_pc[n] > s2->salt_buf_pc[n]) return 1;
|
|
|
|
if (s1->salt_buf_pc[n] < s2->salt_buf_pc[n]) return -1;
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-03 19:53:34 +00:00
|
|
|
*/
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
// this function is special and only used whenever --username and --show are used together:
|
|
|
|
// it will sort all tree entries according to the settings stored in hashconfig
|
|
|
|
|
|
|
|
int sort_pot_tree_by_hash (const void *v1, const void *v2)
|
|
|
|
{
|
|
|
|
const pot_tree_entry_t *t1 = (const pot_tree_entry_t *) v1;
|
|
|
|
const pot_tree_entry_t *t2 = (const pot_tree_entry_t *) v2;
|
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
const hash_t *h1 = (const hash_t *) t1->nodes->hash_buf;
|
|
|
|
const hash_t *h2 = (const hash_t *) t2->nodes->hash_buf;
|
2017-10-17 10:08:17 +00:00
|
|
|
|
|
|
|
hashconfig_t *hc = (hashconfig_t *) t1->hashconfig; // is same as t2->hashconfig
|
|
|
|
|
|
|
|
return sort_by_hash (h1, h2, hc);
|
|
|
|
}
|
|
|
|
|
|
|
|
// the problem with the GNU tdestroy () function is that it doesn't work with mingw etc
|
|
|
|
// there are 2 alternatives:
|
|
|
|
// 1. recursively delete the entries with entry->left and entry->right
|
|
|
|
// 2. use tdelete () <- this is what we currently use, but this could be slower!
|
|
|
|
|
|
|
|
void pot_tree_destroy (pot_tree_entry_t *tree)
|
|
|
|
{
|
|
|
|
pot_tree_entry_t *entry = tree;
|
|
|
|
|
|
|
|
while (tree != NULL)
|
|
|
|
{
|
|
|
|
entry = *(pot_tree_entry_t **) tree;
|
|
|
|
|
|
|
|
tdelete (entry, (void **) &tree, sort_pot_tree_by_hash);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
int potfile_init (hashcat_ctx_t *hashcat_ctx)
|
2016-10-06 13:40:27 +00:00
|
|
|
{
|
2018-12-20 10:04:37 +00:00
|
|
|
const folder_config_t *folder_config = hashcat_ctx->folder_config;
|
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
2016-10-06 13:40:27 +00:00
|
|
|
|
|
|
|
potfile_ctx->enabled = false;
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
if (user_options->benchmark == true) return 0;
|
2017-08-22 09:09:46 +00:00
|
|
|
if (user_options->example_hashes == true) return 0;
|
2016-10-06 15:26:15 +00:00
|
|
|
if (user_options->keyspace == true) return 0;
|
|
|
|
if (user_options->opencl_info == true) return 0;
|
|
|
|
if (user_options->stdout_flag == true) return 0;
|
2016-10-14 19:38:52 +00:00
|
|
|
if (user_options->speed_only == true) return 0;
|
2016-12-09 22:44:43 +00:00
|
|
|
if (user_options->progress_only == true) return 0;
|
2016-10-06 15:26:15 +00:00
|
|
|
if (user_options->usage == true) return 0;
|
|
|
|
if (user_options->version == true) return 0;
|
|
|
|
if (user_options->potfile_disable == true) return 0;
|
2016-10-06 13:40:27 +00:00
|
|
|
|
2018-12-20 10:04:37 +00:00
|
|
|
if (hashconfig->potfile_disable == true) return 0;
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
potfile_ctx->enabled = true;
|
|
|
|
|
|
|
|
if (user_options->potfile_path == NULL)
|
|
|
|
{
|
|
|
|
potfile_ctx->fp = NULL;
|
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir);
|
2016-10-06 13:40:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
potfile_ctx->filename = hcstrdup (user_options->potfile_path);
|
2016-10-06 13:40:27 +00:00
|
|
|
potfile_ctx->fp = NULL;
|
|
|
|
}
|
|
|
|
|
2016-10-30 21:47:48 +00:00
|
|
|
// starting from here, we should allocate some scratch buffer for later use
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
u8 *out_buf = (u8 *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-10-30 21:47:48 +00:00
|
|
|
|
|
|
|
potfile_ctx->out_buf = out_buf;
|
|
|
|
|
|
|
|
// we need two buffers in parallel
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
u8 *tmp_buf = (u8 *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-10-30 21:47:48 +00:00
|
|
|
|
|
|
|
potfile_ctx->tmp_buf = tmp_buf;
|
|
|
|
|
2016-12-31 12:52:35 +00:00
|
|
|
// old potfile detection
|
|
|
|
|
|
|
|
if (user_options->potfile_path == NULL)
|
|
|
|
{
|
|
|
|
char *potfile_old;
|
|
|
|
|
|
|
|
hc_asprintf (&potfile_old, "%s/hashcat.pot", folder_config->profile_dir);
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
if (hc_path_exist (potfile_old) == true)
|
2016-12-31 12:52:35 +00:00
|
|
|
{
|
|
|
|
event_log_warning (hashcat_ctx, "Old potfile detected: %s", potfile_old);
|
|
|
|
event_log_warning (hashcat_ctx, "New potfile is: %s ", potfile_ctx->filename);
|
2017-02-10 18:46:52 +00:00
|
|
|
event_log_warning (hashcat_ctx, NULL);
|
2016-12-31 12:52:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hcfree (potfile_old);
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
return 0;
|
2016-10-06 13:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void potfile_destroy (hashcat_ctx_t *hashcat_ctx)
|
2016-09-10 13:17:23 +00:00
|
|
|
{
|
2018-12-20 10:04:37 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2016-10-06 13:40:27 +00:00
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
|
|
|
|
if (potfile_ctx->enabled == false) return;
|
|
|
|
|
2018-12-20 10:04:37 +00:00
|
|
|
if (hashconfig->potfile_disable == true) return;
|
|
|
|
|
2016-10-30 21:47:48 +00:00
|
|
|
hcfree (potfile_ctx->out_buf);
|
|
|
|
hcfree (potfile_ctx->tmp_buf);
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
memset (potfile_ctx, 0, sizeof (potfile_ctx_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
int potfile_read_open (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
|
2016-09-30 10:37:29 +00:00
|
|
|
if (potfile_ctx->enabled == false) return 0;
|
2016-09-14 17:46:31 +00:00
|
|
|
|
2016-09-10 13:17:23 +00:00
|
|
|
potfile_ctx->fp = fopen (potfile_ctx->filename, "rb");
|
|
|
|
|
|
|
|
if (potfile_ctx->fp == NULL)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
|
2016-09-10 13:17:23 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-18 18:42:34 +00:00
|
|
|
void potfile_read_close (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
2018-12-20 10:04:37 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2016-10-18 18:42:34 +00:00
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
|
|
|
|
if (potfile_ctx->enabled == false) return;
|
|
|
|
|
2018-12-20 10:04:37 +00:00
|
|
|
if (hashconfig->potfile_disable == true) return;
|
|
|
|
|
2016-10-18 18:42:34 +00:00
|
|
|
if (potfile_ctx->fp == NULL) return;
|
|
|
|
|
|
|
|
fclose (potfile_ctx->fp);
|
|
|
|
}
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
int potfile_write_open (hashcat_ctx_t *hashcat_ctx)
|
2016-09-10 13:17:23 +00:00
|
|
|
{
|
2016-10-06 13:40:27 +00:00
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
|
2016-09-30 10:37:29 +00:00
|
|
|
if (potfile_ctx->enabled == false) return 0;
|
2016-09-14 17:46:31 +00:00
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
FILE *fp = fopen (potfile_ctx->filename, "ab");
|
2016-09-10 13:17:23 +00:00
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (fp == NULL)
|
2016-09-10 13:17:23 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", potfile_ctx->filename, strerror (errno));
|
2016-09-10 13:17:23 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
potfile_ctx->fp = fp;
|
|
|
|
|
2016-09-10 13:17:23 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
void potfile_write_close (hashcat_ctx_t *hashcat_ctx)
|
2016-09-10 13:17:23 +00:00
|
|
|
{
|
2018-12-20 10:04:37 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2016-10-06 13:40:27 +00:00
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
|
2016-09-30 10:37:29 +00:00
|
|
|
if (potfile_ctx->enabled == false) return;
|
2016-09-14 17:46:31 +00:00
|
|
|
|
2018-12-20 10:04:37 +00:00
|
|
|
if (hashconfig->potfile_disable == true) return;
|
|
|
|
|
2016-09-10 13:17:23 +00:00
|
|
|
fclose (potfile_ctx->fp);
|
|
|
|
}
|
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
void potfile_write_append (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, u8 *plain_ptr, unsigned int plain_len)
|
2016-09-10 13:17:23 +00:00
|
|
|
{
|
2016-11-05 13:46:00 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2016-11-04 21:12:25 +00:00
|
|
|
const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
2016-10-06 13:40:27 +00:00
|
|
|
|
2016-09-30 10:37:29 +00:00
|
|
|
if (potfile_ctx->enabled == false) return;
|
2016-09-14 17:46:31 +00:00
|
|
|
|
2018-12-20 10:04:37 +00:00
|
|
|
if (hashconfig->potfile_disable == true) return;
|
|
|
|
|
2016-10-30 21:47:48 +00:00
|
|
|
u8 *tmp_buf = potfile_ctx->tmp_buf;
|
2016-10-12 12:38:33 +00:00
|
|
|
|
|
|
|
int tmp_len = 0;
|
|
|
|
|
|
|
|
if (1)
|
|
|
|
{
|
|
|
|
memcpy (tmp_buf + tmp_len, out_buf, out_len);
|
|
|
|
|
|
|
|
tmp_len += out_len;
|
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
2016-10-12 12:38:33 +00:00
|
|
|
|
|
|
|
tmp_len += 1;
|
|
|
|
}
|
|
|
|
|
2019-04-02 09:24:22 +00:00
|
|
|
if ((hashconfig->opts_type & OPTS_TYPE_POTFILE_NOPASS) == 0)
|
2016-10-12 12:38:33 +00:00
|
|
|
{
|
2019-02-12 14:30:42 +00:00
|
|
|
const bool always_ascii = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false;
|
2016-11-05 12:27:08 +00:00
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
if ((user_options->outfile_autohex == true) && (need_hexify (plain_ptr, plain_len, hashconfig->separator, always_ascii) == true))
|
2016-10-12 12:38:33 +00:00
|
|
|
{
|
|
|
|
tmp_buf[tmp_len++] = '$';
|
|
|
|
tmp_buf[tmp_len++] = 'H';
|
|
|
|
tmp_buf[tmp_len++] = 'E';
|
|
|
|
tmp_buf[tmp_len++] = 'X';
|
|
|
|
tmp_buf[tmp_len++] = '[';
|
|
|
|
|
2017-11-05 08:52:29 +00:00
|
|
|
exec_hexify ((const u8 *) plain_ptr, plain_len, tmp_buf + tmp_len);
|
2016-10-12 12:38:33 +00:00
|
|
|
|
|
|
|
tmp_len += plain_len * 2;
|
2016-09-10 13:17:23 +00:00
|
|
|
|
2016-10-12 12:38:33 +00:00
|
|
|
tmp_buf[tmp_len++] = ']';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy (tmp_buf + tmp_len, plain_ptr, plain_len);
|
|
|
|
|
|
|
|
tmp_len += plain_len;
|
|
|
|
}
|
|
|
|
}
|
2016-09-10 13:17:23 +00:00
|
|
|
|
2016-10-12 12:38:33 +00:00
|
|
|
tmp_buf[tmp_len] = 0;
|
2016-09-10 13:17:23 +00:00
|
|
|
|
2016-12-02 10:18:55 +00:00
|
|
|
lock_file (potfile_ctx->fp);
|
|
|
|
|
2016-10-25 10:40:47 +00:00
|
|
|
fprintf (potfile_ctx->fp, "%s" EOL, tmp_buf);
|
2016-11-05 10:33:29 +00:00
|
|
|
|
2016-11-19 14:13:54 +00:00
|
|
|
fflush (potfile_ctx->fp);
|
2016-12-02 10:18:55 +00:00
|
|
|
|
2017-02-14 14:15:50 +00:00
|
|
|
if (unlock_file (potfile_ctx->fp))
|
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: Failed to unlock file.", potfile_ctx->filename);
|
2017-02-14 14:15:50 +00:00
|
|
|
}
|
2016-09-10 13:17:23 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 08:00:16 +00:00
|
|
|
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;
|
|
|
|
|
2019-04-05 11:46:29 +00:00
|
|
|
if (pw_buf)
|
|
|
|
{
|
|
|
|
memcpy (found->pw_buf, pw_buf, pw_len);
|
2017-02-01 08:00:16 +00:00
|
|
|
|
2019-04-05 11:46:29 +00:00
|
|
|
found->pw_buf[found->pw_len] = 0;
|
|
|
|
}
|
2017-02-01 08:00:16 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
void potfile_update_hashes (hashcat_ctx_t *hashcat_ctx, hash_t *hash_buf, char *line_pw_buf, int line_pw_len, pot_tree_entry_t *tree)
|
2017-02-01 08:00:16 +00:00
|
|
|
{
|
2017-10-17 10:08:17 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
// the linked list node:
|
|
|
|
|
|
|
|
pot_hash_node_t search_node;
|
|
|
|
|
|
|
|
search_node.hash_buf = hash_buf;
|
|
|
|
search_node.next = NULL;
|
|
|
|
|
|
|
|
// the search entry:
|
|
|
|
|
|
|
|
pot_tree_entry_t search_entry;
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
search_entry.nodes = &search_node;
|
|
|
|
search_entry.hashconfig = hashconfig;
|
2017-02-01 08:00:16 +00:00
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
|
|
|
|
// the main search function is this:
|
|
|
|
|
|
|
|
void **found = tfind (&search_entry, (void **) &tree, sort_pot_tree_by_hash);
|
2017-02-01 08:00:16 +00:00
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
if (found)
|
2017-02-01 08:00:16 +00:00
|
|
|
{
|
2017-10-17 10:08:17 +00:00
|
|
|
pot_tree_entry_t *found_entry = (pot_tree_entry_t *) *found;
|
|
|
|
|
|
|
|
pot_hash_node_t *node = found_entry->nodes;
|
|
|
|
|
|
|
|
while (node)
|
2017-02-01 08:00:16 +00:00
|
|
|
{
|
2017-10-17 10:08:17 +00:00
|
|
|
potfile_update_hash (hashcat_ctx, node->hash_buf, line_pw_buf, line_pw_len);
|
|
|
|
|
|
|
|
node = node->next;
|
2017-02-01 08:00:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
int potfile_remove_parse (hashcat_ctx_t *hashcat_ctx)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2018-12-14 11:22:13 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2017-01-03 18:21:27 +00:00
|
|
|
const hashes_t *hashes = hashcat_ctx->hashes;
|
2018-12-14 11:22:13 +00:00
|
|
|
const module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
|
2017-01-03 18:21:27 +00:00
|
|
|
const potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
2016-10-06 13:40:27 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
if (potfile_ctx->enabled == false) return 0;
|
2016-09-14 17:46:31 +00:00
|
|
|
|
2018-12-20 10:04:37 +00:00
|
|
|
if (hashconfig->potfile_disable == true) return 0;
|
2019-03-31 15:39:00 +00:00
|
|
|
|
2019-03-13 14:17:02 +00:00
|
|
|
if (hashconfig->opts_type & OPTS_TYPE_PT_NEVERCRACK) return 0;
|
2018-12-20 10:04:37 +00:00
|
|
|
|
2017-01-27 13:50:39 +00:00
|
|
|
// if no potfile exists yet we don't need to do anything here
|
|
|
|
|
|
|
|
if (hc_path_exist (potfile_ctx->filename) == false) return 0;
|
|
|
|
|
2016-09-16 15:01:18 +00:00
|
|
|
hash_t *hashes_buf = hashes->hashes_buf;
|
2016-10-07 19:47:11 +00:00
|
|
|
u32 hashes_cnt = hashes->hashes_cnt;
|
2016-09-16 15:01:18 +00:00
|
|
|
|
2016-09-10 10:16:16 +00:00
|
|
|
// no solution for these special hash types (for instane because they use hashfile in output etc)
|
|
|
|
|
|
|
|
hash_t hash_buf;
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
hash_buf.digest = hcmalloc (hashconfig->dgst_size);
|
2016-09-10 10:16:16 +00:00
|
|
|
hash_buf.salt = NULL;
|
|
|
|
hash_buf.esalt = NULL;
|
2017-01-24 14:23:48 +00:00
|
|
|
hash_buf.hook_salt = NULL;
|
2016-09-10 10:16:16 +00:00
|
|
|
hash_buf.cracked = 0;
|
2019-01-20 09:28:54 +00:00
|
|
|
hash_buf.hash_info = NULL;
|
|
|
|
hash_buf.pw_buf = NULL;
|
|
|
|
hash_buf.pw_len = 0;
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2017-09-16 20:33:04 +00:00
|
|
|
if (hashconfig->is_salted == true)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
hash_buf.salt = (salt_t *) hcmalloc (sizeof (salt_t));
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 20:33:04 +00:00
|
|
|
if (hashconfig->esalt_size > 0)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
hash_buf.esalt = hcmalloc (hashconfig->esalt_size);
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 20:33:04 +00:00
|
|
|
if (hashconfig->hook_salt_size > 0)
|
2017-01-24 14:23:48 +00:00
|
|
|
{
|
|
|
|
hash_buf.hook_salt = hcmalloc (hashconfig->hook_salt_size);
|
|
|
|
}
|
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
// we only need this variable in a very specific situation:
|
|
|
|
// whenever we use --username and --show together we want to keep all hashes sorted within a nice structure
|
|
|
|
|
|
|
|
pot_tree_entry_t *all_hashes_tree = NULL;
|
|
|
|
pot_tree_entry_t *tree_entry_cache = NULL;
|
2017-10-18 10:09:32 +00:00
|
|
|
pot_hash_node_t *tree_nodes_cache = NULL;
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2018-12-20 11:59:56 +00:00
|
|
|
if (hashconfig->potfile_keep_all_hashes == true)
|
2017-10-17 10:08:17 +00:00
|
|
|
{
|
2017-10-18 10:09:32 +00:00
|
|
|
// we need *at most* one entry for every hash
|
|
|
|
// (if there are no hashes with the same keys (hash + salt), a counter example would be: same hash but different user name)
|
2017-10-18 13:42:43 +00:00
|
|
|
tree_entry_cache = (pot_tree_entry_t *) hccalloc (hashes_cnt, sizeof (pot_tree_entry_t));
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
// we need *always exactly* one linked list for every hash
|
2017-10-18 13:42:43 +00:00
|
|
|
tree_nodes_cache = (pot_hash_node_t *) hccalloc (hashes_cnt, sizeof (pot_hash_node_t));
|
2017-10-18 10:09:32 +00:00
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
for (u32 hash_pos = 0; hash_pos < hashes_cnt; hash_pos++)
|
|
|
|
{
|
2017-10-18 10:09:32 +00:00
|
|
|
// initialize the linked list node:
|
|
|
|
// we always need to create a new one and add it, because we want to keep and later update all hashes:
|
|
|
|
|
|
|
|
pot_hash_node_t *new_node = &tree_nodes_cache[hash_pos];
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
new_node->hash_buf = &hashes_buf[hash_pos];
|
|
|
|
new_node->next = NULL;
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
// initialize the entry:
|
|
|
|
|
|
|
|
pot_tree_entry_t *new_entry = &tree_entry_cache[hash_pos];
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
// note: the "key" (hash + salt) is indirectly accessible via the first nodes "hash_buf"
|
|
|
|
|
|
|
|
new_entry->nodes = new_node;
|
2017-10-17 10:08:17 +00:00
|
|
|
// the hashconfig is needed here because we need to be able to check within the sort function if we also need
|
|
|
|
// to sort by salt and we also need to have the correct order of dgst_pos0...dgst_pos3:
|
|
|
|
new_entry->hashconfig = (hashconfig_t *) hashconfig; // "const hashconfig_t" gives a warning
|
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
|
|
|
|
// the following function searches if the "key" is already present and if not inserts the new entry:
|
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
void **found = tsearch (new_entry, (void **) &all_hashes_tree, sort_pot_tree_by_hash);
|
|
|
|
|
|
|
|
pot_tree_entry_t *found_entry = (pot_tree_entry_t *) *found;
|
|
|
|
|
|
|
|
// we now need to check these cases; tsearch () could return:
|
|
|
|
// 1. NULL : if we have a memory allocation problem (not enough memory for the tree structure)
|
|
|
|
// 2. found_entry == new_entry: if we successfully insert a new key (which was not present yet)
|
|
|
|
// 3. found_entry != new_entry: if the key was already present
|
|
|
|
|
|
|
|
// case 1: memory allocation error
|
|
|
|
|
|
|
|
if (found_entry == NULL)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "Error while allocating memory for the potfile search: %s\n", MSG_ENOMEM);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// case 2: this means it was a new insert (and the insert was successful)
|
|
|
|
|
|
|
|
if (found_entry == new_entry)
|
|
|
|
{
|
2017-10-18 06:54:21 +00:00
|
|
|
// no updates to the linked list required (since it is the first one!)
|
2017-10-17 10:08:17 +00:00
|
|
|
}
|
|
|
|
// case 3: if we have found an already existing entry
|
|
|
|
else
|
|
|
|
{
|
2017-10-18 06:54:21 +00:00
|
|
|
new_node->next = found_entry->nodes;
|
2017-10-17 10:08:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-18 06:54:21 +00:00
|
|
|
// we always insert the new node at the very beginning
|
|
|
|
// (or in other words: the head of the linked list always points to *this* new inserted node)
|
2017-10-17 10:08:17 +00:00
|
|
|
|
2017-10-18 06:54:21 +00:00
|
|
|
found_entry->nodes = new_node;
|
2017-10-17 10:08:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 11:59:56 +00:00
|
|
|
// do not use this unless really needed, for example as in LM
|
2016-11-29 19:37:29 +00:00
|
|
|
|
2019-01-05 19:17:12 +00:00
|
|
|
if (module_ctx->module_hash_decode_zero_hash != MODULE_DEFAULT)
|
2016-11-29 19:37:29 +00:00
|
|
|
{
|
2019-01-25 10:14:04 +00:00
|
|
|
module_ctx->module_hash_decode_zero_hash (hashconfig, hash_buf.digest, hash_buf.salt, hash_buf.esalt, hash_buf.hook_salt, hash_buf.hash_info);
|
2016-11-29 19:37:29 +00:00
|
|
|
|
2018-12-20 11:59:56 +00:00
|
|
|
if (hashconfig->potfile_keep_all_hashes == true)
|
2016-11-29 19:37:29 +00:00
|
|
|
{
|
2018-12-20 11:59:56 +00:00
|
|
|
potfile_update_hashes (hashcat_ctx, &hash_buf, NULL, 0, all_hashes_tree);
|
|
|
|
}
|
|
|
|
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);
|
2016-11-29 19:37:29 +00:00
|
|
|
|
2018-12-20 11:59:56 +00:00
|
|
|
potfile_update_hash (hashcat_ctx, found, NULL, 0);
|
2016-11-29 19:37:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
const int rc = potfile_read_open (hashcat_ctx);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
if (rc == -1) return -1;
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2019-04-02 09:24:22 +00:00
|
|
|
void *tmps = NULL;
|
|
|
|
|
|
|
|
if (hashconfig->tmp_size > 0)
|
|
|
|
{
|
|
|
|
tmps = hcmalloc (hashconfig->tmp_size);
|
|
|
|
}
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
|
|
|
while (!feof (potfile_ctx->fp))
|
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
size_t line_len = fgetl (potfile_ctx->fp, line_buf);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
|
|
|
if (line_len == 0) continue;
|
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
char *last_separator = strrchr (line_buf, hashconfig->separator);
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
if (last_separator == NULL) continue; // ??
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
char *line_pw_buf = last_separator + 1;
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
size_t line_pw_len = line_buf + line_len - line_pw_buf;
|
2016-11-19 14:25:01 +00:00
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
char *line_hash_buf = line_buf;
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2018-12-14 11:22:13 +00:00
|
|
|
int line_hash_len = last_separator - line_buf;
|
2016-12-09 13:54:13 +00:00
|
|
|
|
|
|
|
line_hash_buf[line_hash_len] = 0;
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2016-12-09 13:54:13 +00:00
|
|
|
if (line_hash_len == 0) continue;
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2019-04-05 11:46:29 +00:00
|
|
|
if (hash_buf.salt)
|
2016-12-09 13:54:13 +00:00
|
|
|
{
|
|
|
|
memset (hash_buf.salt, 0, sizeof (salt_t));
|
|
|
|
}
|
|
|
|
|
2019-04-05 11:46:29 +00:00
|
|
|
if (hash_buf.esalt)
|
2016-12-09 13:54:13 +00:00
|
|
|
{
|
|
|
|
memset (hash_buf.esalt, 0, hashconfig->esalt_size);
|
|
|
|
}
|
|
|
|
|
2019-04-05 11:46:29 +00:00
|
|
|
if (hash_buf.hook_salt)
|
2017-01-24 14:23:48 +00:00
|
|
|
{
|
|
|
|
memset (hash_buf.hook_salt, 0, hashconfig->hook_salt_size);
|
|
|
|
}
|
|
|
|
|
2019-04-01 10:32:11 +00:00
|
|
|
if (module_ctx->module_hash_decode_potfile != MODULE_DEFAULT)
|
2016-12-09 13:54:13 +00:00
|
|
|
{
|
2019-04-02 09:24:22 +00:00
|
|
|
if (module_ctx->module_potfile_custom_check != MODULE_DEFAULT)
|
|
|
|
{
|
|
|
|
const int parser_status = module_ctx->module_hash_decode_potfile (hashconfig, hash_buf.digest, hash_buf.salt, hash_buf.esalt, hash_buf.hook_salt, hash_buf.hash_info, line_hash_buf, line_hash_len, tmps);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2019-04-02 09:24:22 +00:00
|
|
|
if (parser_status != PARSER_OK) continue;
|
|
|
|
|
|
|
|
for (u32 hashes_pos = 0; hashes_pos < hashes_cnt; hashes_pos++)
|
|
|
|
{
|
|
|
|
const bool cracked = module_ctx->module_potfile_custom_check (hashconfig, &hashes_buf[hashes_pos], &hash_buf, tmps);
|
|
|
|
|
|
|
|
if (cracked == true)
|
|
|
|
{
|
|
|
|
potfile_update_hash (hashcat_ctx, &hashes_buf[hashes_pos], line_pw_buf, (u32) line_pw_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// should be rejected?
|
|
|
|
//const int parser_status = module_ctx->module_hash_decode_potfile (hashconfig, hash_buf.digest, hash_buf.salt, hash_buf.esalt, hash_buf.hook_salt, hash_buf.hash_info, line_hash_buf, line_hash_len, NULL);
|
|
|
|
//if (parser_status != PARSER_OK) continue;
|
|
|
|
}
|
2016-12-09 13:54:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-25 10:14:04 +00:00
|
|
|
const int parser_status = module_ctx->module_hash_decode (hashconfig, hash_buf.digest, hash_buf.salt, hash_buf.esalt, hash_buf.hook_salt, hash_buf.hash_info, line_hash_buf, line_hash_len);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2017-10-17 10:08:17 +00:00
|
|
|
if (parser_status != PARSER_OK) continue;
|
|
|
|
|
2018-12-20 11:59:56 +00:00
|
|
|
if (hashconfig->potfile_keep_all_hashes == true)
|
2016-12-09 13:54:13 +00:00
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
potfile_update_hashes (hashcat_ctx, &hash_buf, line_pw_buf, (u32) line_pw_len, all_hashes_tree);
|
2017-10-17 10:08:17 +00:00
|
|
|
|
|
|
|
continue;
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
2019-04-02 09:24:22 +00:00
|
|
|
hash_t *found = (hash_t *) hc_bsearch_r (&hash_buf, hashes_buf, hashes_cnt, sizeof (hash_t), sort_by_hash, (void *) hashconfig);
|
2018-12-20 14:46:26 +00:00
|
|
|
|
2019-04-02 09:24:22 +00:00
|
|
|
potfile_update_hash (hashcat_ctx, found, line_pw_buf, (u32) line_pw_len);
|
|
|
|
}
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (line_buf);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2019-04-02 09:24:22 +00:00
|
|
|
if (hashconfig->tmp_size > 0)
|
|
|
|
{
|
|
|
|
hcfree (tmps);
|
|
|
|
}
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
potfile_read_close (hashcat_ctx);
|
2016-09-10 10:16:16 +00:00
|
|
|
|
2018-12-20 11:59:56 +00:00
|
|
|
if (hashconfig->potfile_keep_all_hashes == true)
|
2017-10-17 10:08:17 +00:00
|
|
|
{
|
|
|
|
pot_tree_destroy (all_hashes_tree); // this could be slow (should we just skip it?)
|
|
|
|
|
2017-10-18 10:09:32 +00:00
|
|
|
hcfree (tree_nodes_cache);
|
2017-10-17 10:08:17 +00:00
|
|
|
hcfree (tree_entry_cache);
|
|
|
|
}
|
|
|
|
|
2017-09-16 20:33:04 +00:00
|
|
|
if (hashconfig->esalt_size > 0)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (hash_buf.esalt);
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
2017-09-16 20:33:04 +00:00
|
|
|
if (hashconfig->hook_salt_size > 0)
|
2017-01-24 14:23:48 +00:00
|
|
|
{
|
|
|
|
hcfree (hash_buf.hook_salt);
|
|
|
|
}
|
|
|
|
|
2017-09-16 20:33:04 +00:00
|
|
|
if (hashconfig->is_salted == true)
|
2016-09-10 10:16:16 +00:00
|
|
|
{
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (hash_buf.salt);
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (hash_buf.digest);
|
2016-10-13 08:07:04 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-10 10:16:16 +00:00
|
|
|
}
|
2016-10-18 18:42:34 +00:00
|
|
|
|
|
|
|
int potfile_handle_show (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
2017-02-13 15:46:37 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2016-10-30 21:47:48 +00:00
|
|
|
hashes_t *hashes = hashcat_ctx->hashes;
|
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2016-10-30 21:47:48 +00:00
|
|
|
hash_t *hashes_buf = hashes->hashes_buf;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
|
|
|
u32 salts_cnt = hashes->salts_cnt;
|
|
|
|
salt_t *salts_buf = hashes->salts_buf;
|
|
|
|
|
2019-01-06 11:04:42 +00:00
|
|
|
if (hashconfig->opts_type & OPTS_TYPE_HASH_SPLIT)
|
2016-10-19 09:55:43 +00:00
|
|
|
{
|
2019-01-06 11:04:42 +00:00
|
|
|
// this implementation will work for LM only
|
|
|
|
// however, LM is the only hash support which splits the password into multiple hashes
|
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++)
|
|
|
|
{
|
|
|
|
salt_t *salt_buf = salts_buf + salt_idx;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u32 digests_cnt = salt_buf->digests_cnt;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++)
|
|
|
|
{
|
|
|
|
const u32 hashes_idx = salt_buf->digests_offset + digest_idx;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u32 *digests_shown = hashes->digests_shown;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
hash_t *hash1 = &hashes_buf[hashes_idx];
|
|
|
|
hash_t *hash2 = NULL;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
int split_neighbor = -1;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
// find out if at least one of the parts has been cracked
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
if (hash1->hash_info->split->split_origin == SPLIT_ORIGIN_LEFT)
|
|
|
|
{
|
|
|
|
split_neighbor = hash1->hash_info->split->split_neighbor;
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
hash2 = &hashes_buf[split_neighbor];
|
2016-10-19 09:55:43 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
if ((digests_shown[hashes_idx] == 0) && (digests_shown[split_neighbor] == 0)) continue;
|
|
|
|
}
|
|
|
|
else if (hash1->hash_info->split->split_origin == SPLIT_ORIGIN_NONE)
|
|
|
|
{
|
|
|
|
if (digests_shown[hashes_idx] == 0) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SPLIT_ORIGIN_RIGHT are not handled this way
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u8 *out_buf = potfile_ctx->out_buf;
|
|
|
|
|
2019-03-31 15:39:00 +00:00
|
|
|
int out_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 0, HCBUFSIZ_LARGE - 0, salt_idx, digest_idx);
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
if (hash2)
|
|
|
|
{
|
2019-03-31 15:39:00 +00:00
|
|
|
out_len += hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 16, HCBUFSIZ_LARGE - 16, salt_idx, split_neighbor);
|
2017-02-13 15:46:37 +00:00
|
|
|
}
|
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
out_buf[out_len] = 0;
|
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
// user
|
|
|
|
unsigned char *username = NULL;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u32 user_len = 0;
|
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
user_t *user = hash1->hash_info->user;
|
2017-02-13 15:46:37 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
username = (unsigned char *) (user->user_name);
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
user_len = user->user_len;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
username[user_len] = 0;
|
2016-10-19 10:42:41 +00:00
|
|
|
}
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
u8 *tmp_buf = potfile_ctx->tmp_buf;
|
|
|
|
|
|
|
|
tmp_buf[0] = 0;
|
|
|
|
|
|
|
|
u8 mixed_buf[20] = { 0 };
|
|
|
|
|
|
|
|
u8 mixed_len = 0;
|
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
if (digests_shown[hashes_idx] == 1)
|
2017-02-13 15:46:37 +00:00
|
|
|
{
|
2017-02-14 19:53:42 +00:00
|
|
|
memcpy (mixed_buf + mixed_len, hash1->pw_buf, hash1->pw_len);
|
2017-02-13 15:46:37 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
mixed_len += hash1->pw_len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-08 14:55:11 +00:00
|
|
|
memcpy (mixed_buf + mixed_len, MASKED_PLAIN, strlen (MASKED_PLAIN));
|
2017-02-13 15:46:37 +00:00
|
|
|
|
2019-01-08 14:55:11 +00:00
|
|
|
mixed_len += strlen (MASKED_PLAIN);
|
2017-02-13 15:46:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (hash2)
|
|
|
|
{
|
|
|
|
if (digests_shown[split_neighbor] == 1)
|
|
|
|
{
|
|
|
|
memcpy (mixed_buf + mixed_len, hash2->pw_buf, hash2->pw_len);
|
|
|
|
|
|
|
|
mixed_len += hash2->pw_len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-08 14:55:11 +00:00
|
|
|
memcpy (mixed_buf + mixed_len, MASKED_PLAIN, strlen (MASKED_PLAIN));
|
2017-02-13 15:46:37 +00:00
|
|
|
|
2019-01-08 14:55:11 +00:00
|
|
|
mixed_len += strlen (MASKED_PLAIN);
|
2017-02-13 15:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, (u8 *) mixed_buf, mixed_len, 0, username, user_len, (char *) tmp_buf);
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
EVENT_DATA (EVENT_POTFILE_HASH_SHOW, tmp_buf, tmp_len);
|
2016-10-19 10:42:41 +00:00
|
|
|
}
|
2017-02-13 15:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++)
|
|
|
|
{
|
|
|
|
salt_t *salt_buf = salts_buf + salt_idx;
|
|
|
|
|
|
|
|
u32 digests_cnt = salt_buf->digests_cnt;
|
|
|
|
|
|
|
|
for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++)
|
|
|
|
{
|
|
|
|
const u32 hashes_idx = salt_buf->digests_offset + digest_idx;
|
|
|
|
|
|
|
|
u32 *digests_shown = hashes->digests_shown;
|
|
|
|
|
|
|
|
if (digests_shown[hashes_idx] == 0) continue;
|
|
|
|
|
|
|
|
hash_t *hash = &hashes_buf[hashes_idx];
|
|
|
|
|
|
|
|
u8 *out_buf = potfile_ctx->out_buf;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2019-03-31 15:39:00 +00:00
|
|
|
const int out_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_idx, digest_idx);
|
2016-10-30 21:47:48 +00:00
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
out_buf[out_len] = 0;
|
2016-10-30 21:47:48 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
// user
|
|
|
|
unsigned char *username = NULL;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u32 user_len = 0;
|
|
|
|
|
|
|
|
if (hash->hash_info != NULL)
|
|
|
|
{
|
|
|
|
user_t *user = hash->hash_info->user;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
username = (unsigned char *) (user->user_name);
|
|
|
|
|
|
|
|
user_len = user->user_len;
|
|
|
|
|
|
|
|
username[user_len] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *tmp_buf = potfile_ctx->tmp_buf;
|
|
|
|
|
|
|
|
tmp_buf[0] = 0;
|
|
|
|
|
2017-08-25 07:55:10 +00:00
|
|
|
|
|
|
|
// special case for collider modes: we do not use the $HEX[] format within the hash itself
|
|
|
|
// therefore we need to convert the $HEX[] password into hexadecimal (without "$HEX[" and "]")
|
|
|
|
|
|
|
|
bool is_collider_hex_password = false;
|
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_HEXIFY)
|
2017-08-25 07:55:10 +00:00
|
|
|
{
|
|
|
|
if (is_hexify ((u8 *) hash->pw_buf, hash->pw_len) == true)
|
|
|
|
{
|
|
|
|
is_collider_hex_password = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int tmp_len = 0;
|
|
|
|
|
|
|
|
if (is_collider_hex_password == true)
|
|
|
|
{
|
2019-04-08 15:36:26 +00:00
|
|
|
u8 pass_unhexified[HCBUFSIZ_SMALL] = { 0 };
|
2017-08-25 07:55:10 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const size_t pass_unhexified_len = exec_unhexify ((u8 *) hash->pw_buf, hash->pw_len, pass_unhexified, sizeof (pass_unhexified));
|
2017-08-25 07:55:10 +00:00
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, pass_unhexified, (u32) pass_unhexified_len, 0, username, user_len, (char *) tmp_buf);
|
2017-08-25 07:55:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-11 22:11:56 +00:00
|
|
|
tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, (u8 *) hash->pw_buf, hash->pw_len, 0, username, user_len, (char *) tmp_buf);
|
2017-08-25 07:55:10 +00:00
|
|
|
}
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
EVENT_DATA (EVENT_POTFILE_HASH_SHOW, tmp_buf, tmp_len);
|
|
|
|
}
|
2016-10-19 09:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-18 18:42:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int potfile_handle_left (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
2017-02-13 15:46:37 +00:00
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
2016-10-30 21:47:48 +00:00
|
|
|
hashes_t *hashes = hashcat_ctx->hashes;
|
2019-04-02 19:23:44 +00:00
|
|
|
module_ctx_t *module_ctx = hashcat_ctx->module_ctx;
|
2016-10-30 21:47:48 +00:00
|
|
|
potfile_ctx_t *potfile_ctx = hashcat_ctx->potfile_ctx;
|
2016-10-18 18:42:34 +00:00
|
|
|
|
2016-10-19 10:42:41 +00:00
|
|
|
hash_t *hashes_buf = hashes->hashes_buf;
|
|
|
|
|
2016-10-18 19:03:16 +00:00
|
|
|
u32 salts_cnt = hashes->salts_cnt;
|
|
|
|
salt_t *salts_buf = hashes->salts_buf;
|
|
|
|
|
2019-01-06 11:04:42 +00:00
|
|
|
if (hashconfig->opts_type & OPTS_TYPE_HASH_SPLIT)
|
2016-10-18 19:03:16 +00:00
|
|
|
{
|
2019-01-06 11:04:42 +00:00
|
|
|
// this implementation will work for LM only
|
|
|
|
// however, LM is the only hash support which splits the password into multiple hashes
|
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++)
|
|
|
|
{
|
|
|
|
salt_t *salt_buf = salts_buf + salt_idx;
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u32 digests_cnt = salt_buf->digests_cnt;
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++)
|
|
|
|
{
|
|
|
|
const u32 hashes_idx = salt_buf->digests_offset + digest_idx;
|
|
|
|
|
|
|
|
u32 *digests_shown = hashes->digests_shown;
|
|
|
|
|
|
|
|
hash_t *hash1 = &hashes_buf[hashes_idx];
|
|
|
|
hash_t *hash2 = NULL;
|
|
|
|
|
|
|
|
int split_neighbor = -1;
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
// find out if at least one of the parts has been cracked
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
if (hash1->hash_info->split->split_origin == SPLIT_ORIGIN_LEFT)
|
|
|
|
{
|
|
|
|
split_neighbor = hash1->hash_info->split->split_neighbor;
|
|
|
|
|
|
|
|
hash2 = &hashes_buf[split_neighbor];
|
|
|
|
|
|
|
|
if ((digests_shown[hashes_idx] == 1) && (digests_shown[split_neighbor] == 1)) continue;
|
|
|
|
}
|
|
|
|
else if (hash1->hash_info->split->split_origin == SPLIT_ORIGIN_NONE)
|
|
|
|
{
|
|
|
|
if (digests_shown[hashes_idx] == 1) continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// SPLIT_ORIGIN_RIGHT are not handled this way
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u8 *out_buf = potfile_ctx->out_buf;
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2019-03-31 15:39:00 +00:00
|
|
|
int out_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 0, HCBUFSIZ_LARGE - 0, salt_idx, digest_idx);
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
if (hash2)
|
|
|
|
{
|
2019-03-31 15:39:00 +00:00
|
|
|
out_len += hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf + 16, HCBUFSIZ_LARGE - 16, salt_idx, split_neighbor);
|
2017-02-13 15:46:37 +00:00
|
|
|
}
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
out_buf[out_len] = 0;
|
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
// user
|
|
|
|
unsigned char *username = NULL;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u32 user_len = 0;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
user_t *user = hash1->hash_info->user;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
username = (unsigned char *) (user->user_name);
|
2017-02-13 15:46:37 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
user_len = user->user_len;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-14 19:53:42 +00:00
|
|
|
username[user_len] = 0;
|
2016-10-19 10:42:41 +00:00
|
|
|
}
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
u8 *tmp_buf = potfile_ctx->tmp_buf;
|
|
|
|
|
|
|
|
tmp_buf[0] = 0;
|
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, NULL, 0, 0, username, user_len, (char *) tmp_buf);
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
EVENT_DATA (EVENT_POTFILE_HASH_LEFT, tmp_buf, tmp_len);
|
2016-10-19 10:42:41 +00:00
|
|
|
}
|
2017-02-13 15:46:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (u32 salt_idx = 0; salt_idx < salts_cnt; salt_idx++)
|
|
|
|
{
|
|
|
|
salt_t *salt_buf = salts_buf + salt_idx;
|
|
|
|
|
|
|
|
u32 digests_cnt = salt_buf->digests_cnt;
|
|
|
|
|
|
|
|
for (u32 digest_idx = 0; digest_idx < digests_cnt; digest_idx++)
|
|
|
|
{
|
|
|
|
const u32 hashes_idx = salt_buf->digests_offset + digest_idx;
|
|
|
|
|
|
|
|
u32 *digests_shown = hashes->digests_shown;
|
2016-10-19 10:42:41 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
if (digests_shown[hashes_idx] == 1) continue;
|
2016-10-30 21:47:48 +00:00
|
|
|
|
2017-02-13 15:46:37 +00:00
|
|
|
u8 *out_buf = potfile_ctx->out_buf;
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2019-04-02 19:23:44 +00:00
|
|
|
int out_len;
|
|
|
|
|
|
|
|
if (module_ctx->module_hash_binary_save != MODULE_DEFAULT)
|
|
|
|
{
|
|
|
|
char *binary_buf = NULL;
|
|
|
|
|
|
|
|
int binary_len = module_ctx->module_hash_binary_save (hashes, salt_idx, digest_idx, &binary_buf);
|
|
|
|
|
|
|
|
if ((hashconfig->opts_type & OPTS_TYPE_BINARY_HASHFILE) == 0)
|
|
|
|
{
|
2019-04-02 19:30:33 +00:00
|
|
|
binary_len--; // no need for the newline
|
2019-04-02 19:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (out_buf, binary_buf, binary_len);
|
|
|
|
|
|
|
|
out_len = binary_len;
|
|
|
|
|
|
|
|
hcfree (binary_buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out_len = hash_encode (hashcat_ctx->hashconfig, hashcat_ctx->hashes, hashcat_ctx->module_ctx, (char *) out_buf, HCBUFSIZ_LARGE, salt_idx, digest_idx);
|
|
|
|
}
|
2016-10-18 19:03:16 +00:00
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
out_buf[out_len] = 0;
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
hash_t *hash = &hashes_buf[hashes_idx];
|
|
|
|
|
|
|
|
// user
|
|
|
|
unsigned char *username = NULL;
|
|
|
|
|
|
|
|
u32 user_len = 0;
|
|
|
|
|
|
|
|
if (hash->hash_info != NULL)
|
|
|
|
{
|
|
|
|
user_t *user = hash->hash_info->user;
|
|
|
|
|
|
|
|
if (user)
|
|
|
|
{
|
|
|
|
username = (unsigned char *) (user->user_name);
|
|
|
|
|
|
|
|
user_len = user->user_len;
|
|
|
|
|
|
|
|
username[user_len] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
u8 *tmp_buf = potfile_ctx->tmp_buf;
|
|
|
|
|
|
|
|
tmp_buf[0] = 0;
|
|
|
|
|
2019-01-11 22:11:56 +00:00
|
|
|
const int tmp_len = outfile_write (hashcat_ctx, (char *) out_buf, out_len, NULL, 0, 0, username, user_len, (char *) tmp_buf);
|
2017-02-13 15:46:37 +00:00
|
|
|
|
|
|
|
EVENT_DATA (EVENT_POTFILE_HASH_LEFT, tmp_buf, tmp_len);
|
|
|
|
}
|
2016-10-18 19:03:16 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-18 18:42:34 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|