2016-09-11 09:42:19 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-11 09:42:19 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-09-22 15:06:53 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "memory.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-09-22 15:06:53 +00:00
|
|
|
#include "folder.h"
|
2016-10-31 10:28:06 +00:00
|
|
|
#include "shared.h"
|
2016-09-11 09:42:19 +00:00
|
|
|
#include "induct.h"
|
2016-09-14 13:08:22 +00:00
|
|
|
|
2016-09-22 15:06:53 +00:00
|
|
|
static int sort_by_mtime (const void *p1, const void *p2)
|
2016-09-14 13:08:22 +00:00
|
|
|
{
|
2017-11-24 19:05:54 +00:00
|
|
|
const char* const *f1 = (const char* const *) p1;
|
|
|
|
const char* const *f2 = (const char* const *) p2;
|
2016-09-14 13:08:22 +00:00
|
|
|
|
2017-12-10 00:40:45 +00:00
|
|
|
struct stat s1;
|
|
|
|
struct stat s2;
|
2017-02-15 12:27:33 +00:00
|
|
|
|
2017-12-10 00:40:45 +00:00
|
|
|
const int rc1 = stat (*f1, &s1);
|
|
|
|
const int rc2 = stat (*f2, &s2);
|
2017-02-15 12:27:33 +00:00
|
|
|
|
|
|
|
if (rc1 < rc2) return 1;
|
|
|
|
if (rc1 > rc2) return -1;
|
2016-09-14 13:08:22 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
if (s1.st_mtime < s2.st_mtime) return 1;
|
|
|
|
if (s1.st_mtime > s2.st_mtime) return -1;
|
|
|
|
|
|
|
|
return 0;
|
2016-09-14 13:08:22 +00:00
|
|
|
}
|
2016-09-22 15:06:53 +00:00
|
|
|
|
2016-10-06 14:46:08 +00:00
|
|
|
int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
|
2016-09-22 15:06:53 +00:00
|
|
|
{
|
2016-10-06 14:46:08 +00:00
|
|
|
folder_config_t *folder_config = hashcat_ctx->folder_config;
|
|
|
|
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2016-09-22 15:06:53 +00:00
|
|
|
induct_ctx->enabled = false;
|
|
|
|
|
2017-08-22 09:09:46 +00:00
|
|
|
if (user_options->benchmark == true) return 0;
|
|
|
|
if (user_options->example_hashes == true) return 0;
|
|
|
|
if (user_options->keyspace == true) return 0;
|
|
|
|
if (user_options->left == true) return 0;
|
2019-05-01 13:52:56 +00:00
|
|
|
if (user_options->backend_info == true) return 0;
|
2017-08-22 09:09:46 +00:00
|
|
|
if (user_options->show == true) return 0;
|
|
|
|
if (user_options->stdout_flag == true) return 0;
|
|
|
|
if (user_options->speed_only == true) return 0;
|
|
|
|
if (user_options->progress_only == true) return 0;
|
|
|
|
if (user_options->usage == true) return 0;
|
|
|
|
if (user_options->version == true) return 0;
|
2016-09-30 09:59:24 +00:00
|
|
|
|
2020-09-29 13:56:32 +00:00
|
|
|
if ((user_options->attack_mode != ATTACK_MODE_STRAIGHT)
|
|
|
|
&& (user_options->attack_mode != ATTACK_MODE_ASSOCIATION)) return 0;
|
2016-09-30 09:59:24 +00:00
|
|
|
|
|
|
|
induct_ctx->enabled = true;
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
if (user_options->induction_dir == NULL)
|
|
|
|
{
|
2016-12-20 00:46:30 +00:00
|
|
|
char *root_directory;
|
2016-09-22 15:06:53 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR);
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
if (rmdir (root_directory) == -1)
|
|
|
|
{
|
|
|
|
if (errno == ENOENT)
|
|
|
|
{
|
|
|
|
// good, we can ignore
|
|
|
|
}
|
|
|
|
else if (errno == ENOTEMPTY)
|
|
|
|
{
|
2016-12-20 00:46:30 +00:00
|
|
|
char *root_directory_mv;
|
2016-09-22 15:06:53 +00:00
|
|
|
|
2017-12-10 00:40:45 +00:00
|
|
|
hc_asprintf (&root_directory_mv, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL));
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
if (rename (root_directory, root_directory_mv) != 0)
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "Rename directory %s to %s: %s", root_directory, root_directory_mv, strerror (errno));
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-12-20 00:46:30 +00:00
|
|
|
|
|
|
|
hcfree (root_directory_mv);
|
2016-09-22 15:06:53 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", root_directory, strerror (errno));
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-01 11:51:06 +00:00
|
|
|
if (hc_mkdir (root_directory, 0700) == -1)
|
2016-09-22 15:06:53 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", root_directory, strerror (errno));
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
induct_ctx->root_directory = root_directory;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-11-20 21:54:52 +00:00
|
|
|
induct_ctx->root_directory = hcstrdup (user_options->induction_dir);
|
2016-09-22 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-06 14:46:08 +00:00
|
|
|
void induct_ctx_scan (hashcat_ctx_t *hashcat_ctx)
|
2016-09-22 15:06:53 +00:00
|
|
|
{
|
2016-10-06 14:46:08 +00:00
|
|
|
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
|
|
|
|
|
2016-09-22 15:06:53 +00:00
|
|
|
if (induct_ctx->enabled == false) return;
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
induct_ctx->induction_dictionaries = scan_directory (induct_ctx->root_directory);
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
induct_ctx->induction_dictionaries_cnt = count_dictionaries (induct_ctx->induction_dictionaries);
|
|
|
|
|
2016-09-30 16:39:31 +00:00
|
|
|
qsort (induct_ctx->induction_dictionaries, (size_t) induct_ctx->induction_dictionaries_cnt, sizeof (char *), sort_by_mtime);
|
2016-09-22 15:06:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 14:46:08 +00:00
|
|
|
void induct_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
|
2016-09-22 15:06:53 +00:00
|
|
|
{
|
2016-10-06 14:46:08 +00:00
|
|
|
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
|
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
if (induct_ctx->enabled == false) return;
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
if (rmdir (induct_ctx->root_directory) == -1)
|
|
|
|
{
|
|
|
|
if (errno == ENOENT)
|
|
|
|
{
|
|
|
|
// good, we can ignore
|
|
|
|
}
|
|
|
|
else if (errno == ENOTEMPTY)
|
|
|
|
{
|
|
|
|
// good, we can ignore
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", induct_ctx->root_directory, strerror (errno));
|
2016-09-22 15:06:53 +00:00
|
|
|
|
|
|
|
//return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (induct_ctx->root_directory);
|
2016-09-22 15:06:53 +00:00
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
memset (induct_ctx, 0, sizeof (induct_ctx_t));
|
2016-09-22 15:06:53 +00:00
|
|
|
}
|