2016-09-27 18:07:49 +00:00
|
|
|
/**
|
|
|
|
* Author......: See docs/credits.txt
|
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
2016-10-08 21:45:35 +00:00
|
|
|
#include "event.h"
|
2016-09-27 18:07:49 +00:00
|
|
|
#include "memory.h"
|
|
|
|
#include "combinator.h"
|
2016-10-31 10:28:06 +00:00
|
|
|
#include "shared.h"
|
2016-09-27 18:07:49 +00:00
|
|
|
#include "wordlist.h"
|
|
|
|
|
2016-10-06 08:10:04 +00:00
|
|
|
int combinator_ctx_init (hashcat_ctx_t *hashcat_ctx)
|
2016-09-27 18:07:49 +00:00
|
|
|
{
|
2016-10-06 08:10:04 +00:00
|
|
|
combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2016-09-27 18:07:49 +00:00
|
|
|
combinator_ctx->enabled = false;
|
|
|
|
|
2016-09-30 11:14:11 +00:00
|
|
|
if (user_options->left == true) return 0;
|
|
|
|
if (user_options->opencl_info == true) return 0;
|
|
|
|
if (user_options->show == true) return 0;
|
|
|
|
if (user_options->usage == true) return 0;
|
|
|
|
if (user_options->version == true) return 0;
|
2016-09-30 09:48:14 +00:00
|
|
|
|
2016-09-27 18:07:49 +00:00
|
|
|
if ((user_options->attack_mode != ATTACK_MODE_COMBI)
|
|
|
|
&& (user_options->attack_mode != ATTACK_MODE_HYBRID1)
|
|
|
|
&& (user_options->attack_mode != ATTACK_MODE_HYBRID2)) return 0;
|
|
|
|
|
|
|
|
combinator_ctx->enabled = true;
|
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
combinator_ctx->scratch_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-10-05 13:41:56 +00:00
|
|
|
|
2016-10-03 14:27:34 +00:00
|
|
|
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_COMBI)
|
|
|
|
{
|
|
|
|
// display
|
|
|
|
|
|
|
|
char *dictfile1 = user_options_extra->hc_workv[0];
|
|
|
|
char *dictfile2 = user_options_extra->hc_workv[1];
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
// at this point we know the file actually exist
|
2016-10-03 14:27:34 +00:00
|
|
|
// find the bigger dictionary and use as base
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
if (hc_path_is_file (dictfile1) == false)
|
2016-10-03 14:27:34 +00:00
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: Not a regular file.", dictfile1);
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
if (hc_path_is_file (dictfile2) == false)
|
2016-10-03 14:27:34 +00:00
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: Not a regular file.", dictfile2);
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
FILE *fp1 = NULL;
|
|
|
|
FILE *fp2 = NULL;
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
if ((fp1 = fopen (dictfile1, "rb")) == NULL)
|
2016-10-03 14:27:34 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", dictfile1, strerror (errno));
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2017-01-27 10:46:45 +00:00
|
|
|
if ((fp2 = fopen (dictfile2, "rb")) == NULL)
|
2016-10-03 14:27:34 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", dictfile2, strerror (errno));
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-02-11 00:09:58 +00:00
|
|
|
fclose (fp1);
|
|
|
|
|
2016-10-03 14:27:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
combinator_ctx->combs_cnt = 1;
|
|
|
|
|
2017-02-22 15:33:23 +00:00
|
|
|
u64 words1_cnt = 0;
|
|
|
|
|
|
|
|
const int rc1 = count_words (hashcat_ctx, fp1, dictfile1, &words1_cnt);
|
|
|
|
|
|
|
|
if (rc1 == -1)
|
|
|
|
{
|
|
|
|
event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", dictfile1);
|
|
|
|
|
|
|
|
fclose (fp1);
|
|
|
|
fclose (fp2);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
if (words1_cnt == 0)
|
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: empty file.", dictfile1);
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
fclose (fp1);
|
|
|
|
fclose (fp2);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
combinator_ctx->combs_cnt = 1;
|
|
|
|
|
2017-02-22 15:33:23 +00:00
|
|
|
u64 words2_cnt = 0;
|
|
|
|
|
|
|
|
const int rc2 = count_words (hashcat_ctx, fp2, dictfile2, &words2_cnt);
|
|
|
|
|
|
|
|
if (rc2 == -1)
|
|
|
|
{
|
|
|
|
event_log_error (hashcat_ctx, "Integer overflow detected in keyspace of wordlist: %s", dictfile2);
|
|
|
|
|
|
|
|
fclose (fp1);
|
|
|
|
fclose (fp2);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
if (words2_cnt == 0)
|
|
|
|
{
|
2017-04-02 07:50:06 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: empty file.", dictfile2);
|
2016-10-03 14:27:34 +00:00
|
|
|
|
|
|
|
fclose (fp1);
|
|
|
|
fclose (fp2);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose (fp1);
|
|
|
|
fclose (fp2);
|
|
|
|
|
|
|
|
combinator_ctx->dict1 = dictfile1;
|
|
|
|
combinator_ctx->dict2 = dictfile2;
|
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
if (user_options->length_limit_disable == true)
|
2016-10-03 14:27:34 +00:00
|
|
|
{
|
|
|
|
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT;
|
|
|
|
combinator_ctx->combs_cnt = words2_cnt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-06-29 10:19:05 +00:00
|
|
|
if (words1_cnt >= words2_cnt)
|
|
|
|
{
|
|
|
|
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT;
|
|
|
|
combinator_ctx->combs_cnt = words2_cnt;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_RIGHT;
|
|
|
|
combinator_ctx->combs_cnt = words1_cnt;
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
// we also have to switch wordlist related rules!
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
char *tmpc = user_options->rule_buf_l;
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
user_options->rule_buf_l = user_options->rule_buf_r;
|
|
|
|
user_options->rule_buf_r = tmpc;
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
u32 tmpi = user_options_extra->rule_len_l;
|
2016-10-03 14:27:34 +00:00
|
|
|
|
2017-06-29 10:19:05 +00:00
|
|
|
user_options_extra->rule_len_l = user_options_extra->rule_len_r;
|
|
|
|
user_options_extra->rule_len_r = tmpi;
|
|
|
|
}
|
2016-10-03 14:27:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_BF)
|
|
|
|
{
|
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
|
|
|
|
{
|
|
|
|
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT;
|
|
|
|
}
|
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
|
|
|
|
{
|
2017-06-29 10:19:05 +00:00
|
|
|
if (user_options->length_limit_disable == true)
|
|
|
|
{
|
|
|
|
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_LEFT;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
combinator_ctx->combs_mode = COMBINATOR_MODE_BASE_RIGHT;
|
|
|
|
}
|
2016-10-03 14:27:34 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 18:07:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-06 08:10:04 +00:00
|
|
|
void combinator_ctx_destroy (hashcat_ctx_t *hashcat_ctx)
|
2016-09-27 18:07:49 +00:00
|
|
|
{
|
2016-10-06 08:10:04 +00:00
|
|
|
combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
if (combinator_ctx->enabled == false) return;
|
2016-09-30 11:36:27 +00:00
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (combinator_ctx->scratch_buf);
|
2016-10-05 13:41:56 +00:00
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
memset (combinator_ctx, 0, sizeof (combinator_ctx_t));
|
2016-09-27 18:07:49 +00:00
|
|
|
}
|