1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-28 02:49:18 +00:00
hashcat/src/induct.c

139 lines
3.6 KiB
C
Raw Normal View History

2016-09-11 09:42:19 +00:00
/**
* Author......: See docs/credits.txt
2016-09-11 09:42:19 +00:00
* License.....: MIT
*/
#include "common.h"
#include "types.h"
#include "memory.h"
#include "event.h"
#include "folder.h"
#include "shared.h"
2016-09-11 09:42:19 +00:00
#include "induct.h"
static int sort_by_mtime (const void *p1, const void *p2)
{
const char **f1 = (const char **) p1;
const char **f2 = (const char **) p2;
hc_stat_t s1; hc_stat (*f1, &s1);
hc_stat_t s2; hc_stat (*f2, &s2);
return s2.st_mtime - s1.st_mtime;
}
2016-10-06 14:46:08 +00:00
int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
{
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;
induct_ctx->enabled = false;
if (user_options->benchmark == true) return 0;
2016-09-30 09:59:24 +00:00
if (user_options->keyspace == true) return 0;
if (user_options->left == true) return 0;
if (user_options->opencl_info == true) return 0;
2016-09-30 09:59:24 +00:00
if (user_options->show == 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-09-30 09:59:24 +00:00
if (user_options->usage == true) return 0;
if (user_options->version == true) return 0;
if (user_options->attack_mode == ATTACK_MODE_BF) return 0;
if (user_options->attack_mode == ATTACK_MODE_COMBI) return 0;
induct_ctx->enabled = true;
if (user_options->induction_dir == NULL)
{
char *root_directory = (char *) hcmalloc (HCBUFSIZ_TINY);
snprintf (root_directory, HCBUFSIZ_TINY - 1, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR);
if (rmdir (root_directory) == -1)
{
if (errno == ENOENT)
{
// good, we can ignore
}
else if (errno == ENOTEMPTY)
{
char *root_directory_mv = (char *) hcmalloc (HCBUFSIZ_TINY);
snprintf (root_directory_mv, HCBUFSIZ_TINY - 1, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL));
if (rename (root_directory, root_directory_mv) != 0)
{
2016-10-11 08:55:02 +00:00
event_log_error (hashcat_ctx, "Rename directory %s to %s: %s", root_directory, root_directory_mv, strerror (errno));
return -1;
}
}
else
{
2016-10-11 08:55:02 +00:00
event_log_error (hashcat_ctx, "%s: %s", root_directory, strerror (errno));
return -1;
}
}
2016-10-01 11:51:06 +00:00
if (hc_mkdir (root_directory, 0700) == -1)
{
2016-10-11 08:55:02 +00:00
event_log_error (hashcat_ctx, "%s: %s", root_directory, strerror (errno));
return -1;
}
induct_ctx->root_directory = root_directory;
}
else
{
induct_ctx->root_directory = hcstrdup (user_options->induction_dir);
}
return 0;
}
2016-10-06 14:46:08 +00:00
void induct_ctx_scan (hashcat_ctx_t *hashcat_ctx)
{
2016-10-06 14:46:08 +00:00
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
if (induct_ctx->enabled == false) return;
induct_ctx->induction_dictionaries = scan_directory (induct_ctx->root_directory);
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-10-06 14:46:08 +00:00
void induct_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
{
2016-10-06 14:46:08 +00:00
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
if (induct_ctx->enabled == false) return;
if (rmdir (induct_ctx->root_directory) == -1)
{
if (errno == ENOENT)
{
// good, we can ignore
}
else if (errno == ENOTEMPTY)
{
// good, we can ignore
}
else
{
2016-10-11 08:55:02 +00:00
event_log_error (hashcat_ctx, "%s: %s", induct_ctx->root_directory, strerror (errno));
//return -1;
}
}
hcfree (induct_ctx->root_directory);
memset (induct_ctx, 0, sizeof (induct_ctx_t));
}