2016-09-10 15:35:58 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-10 15:35:58 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
2020-01-23 08:03:22 +00:00
|
|
|
#include "memory.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-10-10 11:10:50 +00:00
|
|
|
#include "convert.h"
|
2016-10-04 16:30:00 +00:00
|
|
|
#include "mpsp.h"
|
|
|
|
#include "rp.h"
|
2019-03-25 11:24:04 +00:00
|
|
|
#include "emu_inc_rp.h"
|
|
|
|
#include "emu_inc_rp_optimized.h"
|
2019-04-25 12:45:17 +00:00
|
|
|
#include "backend.h"
|
2016-10-31 10:28:06 +00:00
|
|
|
#include "shared.h"
|
2016-11-05 10:33:29 +00:00
|
|
|
#include "locking.h"
|
2019-03-31 15:39:00 +00:00
|
|
|
#include "outfile.h"
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2020-01-23 08:03:22 +00:00
|
|
|
u32 outfile_format_parse (const char *format_string)
|
|
|
|
{
|
2020-01-24 17:43:13 +00:00
|
|
|
if (format_string == NULL) return 0;
|
2020-01-23 08:03:22 +00:00
|
|
|
|
|
|
|
char *format = hcstrdup (format_string);
|
|
|
|
|
|
|
|
if (format == NULL) return 0;
|
|
|
|
|
|
|
|
char *saveptr = NULL;
|
|
|
|
|
|
|
|
char *next = strtok_r (format, ",", &saveptr);
|
|
|
|
|
2020-01-24 17:43:13 +00:00
|
|
|
if (next == NULL)
|
|
|
|
{
|
|
|
|
hcfree (format);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-01-24 08:42:44 +00:00
|
|
|
|
2020-01-23 08:03:22 +00:00
|
|
|
u32 outfile_format = 0;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
const int tok_len = strlen (next);
|
|
|
|
|
|
|
|
// reject non-numbers:
|
|
|
|
|
|
|
|
if (is_valid_digit_string ((const u8 *) next, tok_len) == false)
|
|
|
|
{
|
|
|
|
outfile_format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// string to number conversion:
|
|
|
|
|
|
|
|
const u32 num = hc_strtoul (next, NULL, 10);
|
|
|
|
|
|
|
|
if (num == 0)
|
|
|
|
{
|
|
|
|
outfile_format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (num > 31)
|
|
|
|
{
|
|
|
|
outfile_format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// to bitmask:
|
|
|
|
|
|
|
|
const u32 bit = 1 << (num - 1);
|
|
|
|
|
|
|
|
bool accepted = false;
|
|
|
|
|
|
|
|
switch (bit)
|
|
|
|
{
|
|
|
|
// allowed formats:
|
|
|
|
case OUTFILE_FMT_HASH:
|
|
|
|
case OUTFILE_FMT_PLAIN:
|
|
|
|
case OUTFILE_FMT_HEXPLAIN:
|
|
|
|
case OUTFILE_FMT_CRACKPOS:
|
|
|
|
case OUTFILE_FMT_TIME_ABS:
|
|
|
|
case OUTFILE_FMT_TIME_REL:
|
|
|
|
accepted = true;
|
|
|
|
break;
|
|
|
|
// NOT acceptable formats:
|
|
|
|
default:
|
|
|
|
accepted = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (accepted == false)
|
|
|
|
{
|
|
|
|
outfile_format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// the user should specify any format at most once:
|
|
|
|
|
|
|
|
if (outfile_format & bit)
|
|
|
|
{
|
|
|
|
outfile_format = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
outfile_format |= bit;
|
|
|
|
|
|
|
|
} while ((next = strtok_r ((char *) NULL, ",", &saveptr)) != NULL);
|
|
|
|
|
|
|
|
hcfree (format);
|
|
|
|
|
|
|
|
return outfile_format;
|
|
|
|
}
|
|
|
|
|
2016-10-15 17:30:57 +00:00
|
|
|
int build_plain (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u32 *plain_buf, int *out_len)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2019-07-29 14:11:50 +00:00
|
|
|
const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
const hashes_t *hashes = hashcat_ctx->hashes;
|
|
|
|
const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
|
|
|
|
const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const u64 gidvid = plain->gidvid;
|
2016-10-29 20:19:00 +00:00
|
|
|
const u32 il_pos = plain->il_pos;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
|
|
|
int plain_len = 0;
|
|
|
|
|
|
|
|
u8 *plain_ptr = (u8 *) plain_buf;
|
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (user_options->slow_candidates == true)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
|
|
|
pw_t pw;
|
|
|
|
|
2016-10-15 17:30:57 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
|
|
|
|
|
|
|
if (rc == -1) return -1;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
memcpy (plain_buf, pw.i, pw.pw_len);
|
2017-08-12 11:04:52 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = pw.pw_len;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
else
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
|
|
|
|
{
|
|
|
|
pw_t pw;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
2016-10-15 17:30:57 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (rc == -1) return -1;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
const u64 off = device_param->innerloop_pos + il_pos;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = apply_rules_optimized (straight_ctx->kernel_rules_buf[off].cmds, &plain_buf[0], &plain_buf[4], pw.pw_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = apply_rules (straight_ctx->kernel_rules_buf[off].cmds, plain_buf, pw.pw_len);
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_COMBI)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
pw_t pw;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (rc == -1) return -1;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = (int) pw.pw_len;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
char *comb_buf = (char *) device_param->combs_buf[il_pos].i;
|
|
|
|
u32 comb_len = device_param->combs_buf[il_pos].pw_len;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
|
|
|
|
{
|
|
|
|
memcpy (plain_ptr + plain_len, comb_buf, (size_t) comb_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memmove (plain_ptr + comb_len, plain_ptr, (size_t) plain_len);
|
2016-10-15 17:30:57 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
memcpy (plain_ptr, comb_buf, comb_len);
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len += comb_len;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_BF)
|
|
|
|
{
|
|
|
|
u64 l_off = device_param->kernel_params_mp_l_buf64[3] + gidvid;
|
|
|
|
u64 r_off = device_param->kernel_params_mp_r_buf64[3] + il_pos;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
u32 l_start = device_param->kernel_params_mp_l_buf32[5];
|
|
|
|
u32 r_start = device_param->kernel_params_mp_r_buf32[5];
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
u32 l_stop = device_param->kernel_params_mp_l_buf32[4];
|
|
|
|
u32 r_stop = device_param->kernel_params_mp_r_buf32[4];
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
sp_exec (l_off, (char *) plain_ptr + l_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, l_start, l_start + l_stop);
|
|
|
|
sp_exec (r_off, (char *) plain_ptr + r_start, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, r_start, r_start + r_stop);
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = (int) mask_ctx->css_cnt;
|
|
|
|
}
|
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
|
2017-06-30 14:51:57 +00:00
|
|
|
{
|
|
|
|
pw_t pw;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2017-06-30 14:51:57 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
2016-10-15 17:30:57 +00:00
|
|
|
|
2017-06-30 14:51:57 +00:00
|
|
|
if (rc == -1) return -1;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
2017-06-30 14:51:57 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
plain_len = (int) pw.pw_len;
|
2017-06-30 14:51:57 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u64 off = device_param->kernel_params_mp_buf64[3] + il_pos;
|
2017-06-30 14:51:57 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
u32 start = 0;
|
|
|
|
u32 stop = device_param->kernel_params_mp_buf32[4];
|
2017-06-30 14:51:57 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
sp_exec (off, (char *) plain_ptr + plain_len, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);
|
2017-06-30 14:51:57 +00:00
|
|
|
|
2017-07-18 11:23:42 +00:00
|
|
|
plain_len += start + stop;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
|
2017-06-30 14:51:57 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
|
|
|
{
|
|
|
|
pw_t pw;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (rc == -1) return -1;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = (int) pw.pw_len;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
u64 off = device_param->kernel_params_mp_buf64[3] + il_pos;
|
2017-06-30 14:51:57 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
u32 start = 0;
|
|
|
|
u32 stop = device_param->kernel_params_mp_buf32[4];
|
2017-07-18 11:23:42 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
memmove (plain_ptr + stop, plain_ptr, plain_len);
|
2017-07-18 11:23:42 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
sp_exec (off, (char *) plain_ptr, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);
|
2017-07-18 11:23:42 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len += start + stop;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pw_t pw;
|
|
|
|
|
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
|
|
|
|
|
|
|
if (rc == -1) return -1;
|
|
|
|
|
|
|
|
u64 off = device_param->kernel_params_mp_buf64[3] + gidvid;
|
|
|
|
|
|
|
|
u32 start = 0;
|
|
|
|
u32 stop = device_param->kernel_params_mp_buf32[4];
|
|
|
|
|
|
|
|
sp_exec (off, (char *) plain_ptr, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);
|
|
|
|
|
|
|
|
plain_len = stop;
|
|
|
|
|
|
|
|
char *comb_buf = (char *) device_param->combs_buf[il_pos].i;
|
|
|
|
u32 comb_len = device_param->combs_buf[il_pos].pw_len;
|
|
|
|
|
|
|
|
memcpy (plain_ptr + plain_len, comb_buf, comb_len);
|
|
|
|
|
|
|
|
plain_len += comb_len;
|
|
|
|
}
|
2017-06-30 14:51:57 +00:00
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (user_options->attack_mode == ATTACK_MODE_BF)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_BRUTE_FORCE) // lots of optimizations can happen here
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_SINGLE_HASH)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_APPENDED_SALT)
|
|
|
|
{
|
|
|
|
plain_len = plain_len - hashes->salts_buf[0].salt_len;
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16LE)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
for (int i = 0, j = 0; i < plain_len; i += 2, j += 1)
|
|
|
|
{
|
|
|
|
plain_ptr[j] = plain_ptr[i];
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = plain_len / 2;
|
2017-06-04 20:46:05 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
else if (hashconfig->opts_type & OPTS_TYPE_PT_UTF16BE)
|
|
|
|
{
|
|
|
|
for (int i = 1, j = 0; i < plain_len; i += 2, j += 1)
|
|
|
|
{
|
|
|
|
plain_ptr[j] = plain_ptr[i];
|
|
|
|
}
|
2017-06-04 20:46:05 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
plain_len = plain_len / 2;
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-29 14:11:50 +00:00
|
|
|
int pw_max = (const int) hashconfig->pw_max;
|
|
|
|
|
|
|
|
// pw_max is per pw_t element but in combinator we have two pw_t elements.
|
|
|
|
// therefore we can support up to 64 in combinator in optimized mode (but limited by general hash limit 55)
|
|
|
|
// or full 512 in pure mode (but limited by hashcat buffer size limit 256).
|
|
|
|
// some algorithms do not support general default pw_max = 31,
|
|
|
|
// therefore we need to use pw_max as a base and not hardcode it.
|
|
|
|
|
|
|
|
if (plain_len > pw_max)
|
|
|
|
{
|
|
|
|
if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
|
|
|
|
{
|
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
|
|
|
{
|
|
|
|
pw_max = MIN ((pw_max * 2), 55);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pw_max = MIN ((pw_max * 2), 256);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-22 17:59:46 +00:00
|
|
|
|
2018-12-15 18:46:55 +00:00
|
|
|
if (plain_len > pw_max) plain_len = MIN (plain_len, pw_max);
|
2018-01-22 17:59:46 +00:00
|
|
|
|
2016-10-29 21:11:38 +00:00
|
|
|
plain_ptr[plain_len] = 0;
|
|
|
|
|
2016-10-04 16:30:00 +00:00
|
|
|
*out_len = plain_len;
|
2016-10-15 17:30:57 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 17:30:57 +00:00
|
|
|
int build_crackpos (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u64 *out_pos)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2016-10-29 21:11:38 +00:00
|
|
|
const combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
const mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
|
|
|
|
const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
2018-09-01 10:31:17 +00:00
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
2016-10-29 21:11:38 +00:00
|
|
|
const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const u64 gidvid = plain->gidvid;
|
2016-10-29 21:11:38 +00:00
|
|
|
const u32 il_pos = plain->il_pos;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
|
|
|
u64 crackpos = device_param->words_off;
|
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (user_options->slow_candidates == true)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
crackpos = gidvid;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
2018-09-01 10:31:17 +00:00
|
|
|
else
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
if (user_options_extra->attack_kern == ATTACK_KERN_STRAIGHT)
|
|
|
|
{
|
|
|
|
crackpos += gidvid;
|
|
|
|
crackpos *= straight_ctx->kernel_rules_cnt;
|
|
|
|
crackpos += device_param->innerloop_pos + il_pos;
|
|
|
|
}
|
|
|
|
else if (user_options_extra->attack_kern == ATTACK_KERN_COMBI)
|
|
|
|
{
|
|
|
|
crackpos += gidvid;
|
|
|
|
crackpos *= combinator_ctx->combs_cnt;
|
|
|
|
crackpos += device_param->innerloop_pos + il_pos;
|
|
|
|
}
|
|
|
|
else if (user_options_extra->attack_kern == ATTACK_MODE_BF)
|
|
|
|
{
|
|
|
|
crackpos += gidvid;
|
|
|
|
crackpos *= mask_ctx->bfs_cnt;
|
|
|
|
crackpos += device_param->innerloop_pos + il_pos;
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*out_pos = crackpos;
|
2016-10-15 17:30:57 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-15 17:30:57 +00:00
|
|
|
int build_debugdata (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, plain_t *plain, u8 *debug_rule_buf, int *debug_rule_len, u8 *debug_plain_ptr, int *debug_plain_len)
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2016-10-29 21:11:38 +00:00
|
|
|
const debugfile_ctx_t *debugfile_ctx = hashcat_ctx->debugfile_ctx;
|
|
|
|
const straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
const u64 gidvid = plain->gidvid;
|
2016-10-29 21:11:38 +00:00
|
|
|
const u32 il_pos = plain->il_pos;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2016-10-15 17:30:57 +00:00
|
|
|
if (user_options->attack_mode != ATTACK_MODE_STRAIGHT) return 0;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
|
|
|
const u32 debug_mode = debugfile_ctx->mode;
|
|
|
|
|
2016-10-15 17:30:57 +00:00
|
|
|
if (debug_mode == 0) return 0;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (user_options->slow_candidates == true)
|
|
|
|
{
|
|
|
|
pw_pre_t *pw_base = device_param->pws_base_buf + gidvid;
|
|
|
|
|
|
|
|
// save rule
|
|
|
|
if ((debug_mode == 1) || (debug_mode == 3) || (debug_mode == 4))
|
|
|
|
{
|
|
|
|
const int len = kernel_rule_to_cpu_rule ((char *) debug_rule_buf, &straight_ctx->kernel_rules_buf[pw_base->rule_idx]);
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
debug_rule_buf[len] = 0;
|
2016-10-15 17:30:57 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
*debug_rule_len = len;
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
// save plain
|
|
|
|
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
|
|
|
|
{
|
|
|
|
memcpy (debug_plain_ptr, pw_base->base_buf, pw_base->base_len);
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
debug_plain_ptr[pw_base->base_len] = 0;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
*debug_plain_len = pw_base->base_len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2016-10-04 16:30:00 +00:00
|
|
|
{
|
2018-09-01 10:31:17 +00:00
|
|
|
pw_t pw;
|
2016-10-29 21:11:38 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
2016-10-29 21:11:38 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
if (rc == -1) return -1;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
int plain_len = (int) pw.pw_len;
|
|
|
|
|
|
|
|
const u64 off = device_param->innerloop_pos + il_pos;
|
2016-10-04 16:30:00 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
// save rule
|
|
|
|
if ((debug_mode == 1) || (debug_mode == 3) || (debug_mode == 4))
|
|
|
|
{
|
|
|
|
const int len = kernel_rule_to_cpu_rule ((char *) debug_rule_buf, &straight_ctx->kernel_rules_buf[off]);
|
2016-10-29 21:11:38 +00:00
|
|
|
|
2018-09-01 10:31:17 +00:00
|
|
|
debug_rule_buf[len] = 0;
|
|
|
|
|
|
|
|
*debug_rule_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// save plain
|
|
|
|
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
|
|
|
|
{
|
|
|
|
memcpy (debug_plain_ptr, (char *) pw.i, (size_t) plain_len);
|
|
|
|
|
|
|
|
debug_plain_ptr[plain_len] = 0;
|
|
|
|
|
|
|
|
*debug_plain_len = plain_len;
|
|
|
|
}
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
2016-10-15 17:30:57 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-10-04 16:30:00 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
int outfile_init (hashcat_ctx_t *hashcat_ctx)
|
2016-10-06 13:40:27 +00:00
|
|
|
{
|
|
|
|
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2020-01-23 08:03:22 +00:00
|
|
|
outfile_ctx->fp.pfp = NULL;
|
|
|
|
outfile_ctx->filename = user_options->outfile;
|
2020-01-24 17:43:13 +00:00
|
|
|
outfile_ctx->outfile_format = user_options->outfile_format;
|
2020-01-23 08:03:22 +00:00
|
|
|
outfile_ctx->outfile_autohex = user_options->outfile_autohex;
|
2016-10-06 15:26:15 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-10-06 13:40:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void outfile_destroy (hashcat_ctx_t *hashcat_ctx)
|
|
|
|
{
|
|
|
|
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
|
|
|
|
|
|
|
memset (outfile_ctx, 0, sizeof (outfile_ctx_t));
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
int outfile_write_open (hashcat_ctx_t *hashcat_ctx)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-10-06 13:40:27 +00:00
|
|
|
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
if (outfile_ctx->filename == NULL) return 0;
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (hc_fopen (&outfile_ctx->fp, outfile_ctx->filename, "ab") == false)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno));
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
return -1;
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
2016-10-06 15:26:15 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (hc_lockfile (&outfile_ctx->fp) == -1)
|
2016-11-05 10:33:29 +00:00
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fclose (&outfile_ctx->fp);
|
2016-11-20 22:15:54 +00:00
|
|
|
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", outfile_ctx->filename, strerror (errno));
|
2016-11-05 10:33:29 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
return 0;
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 13:40:27 +00:00
|
|
|
void outfile_write_close (hashcat_ctx_t *hashcat_ctx)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-10-06 13:40:27 +00:00
|
|
|
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (outfile_ctx->fp.pfp == NULL) return;
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2020-02-29 09:40:47 +00:00
|
|
|
hc_unlockfile (&outfile_ctx->fp);
|
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fclose (&outfile_ctx->fp);
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-15 13:43:49 +00:00
|
|
|
int outfile_write (hashcat_ctx_t *hashcat_ctx, const char *out_buf, const int out_len, const unsigned char *plain_ptr, const u32 plain_len, const u64 crackpos, const unsigned char *username, const u32 user_len, const bool print_eol, char tmp_buf[HCBUFSIZ_LARGE])
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-11-04 21:12:25 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
2019-07-02 19:30:35 +00:00
|
|
|
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
2020-01-23 08:03:22 +00:00
|
|
|
status_ctx_t *status_ctx = hashcat_ctx->status_ctx;
|
2016-10-06 13:40:27 +00:00
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
const u32 outfile_format = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_HEXIFY) ? 5 : outfile_ctx->outfile_format;
|
|
|
|
|
2016-10-12 09:27:10 +00:00
|
|
|
int tmp_len = 0;
|
2016-10-10 11:10:50 +00:00
|
|
|
|
2016-10-19 10:42:41 +00:00
|
|
|
if (user_len > 0)
|
|
|
|
{
|
|
|
|
if (username != NULL)
|
|
|
|
{
|
|
|
|
memcpy (tmp_buf + tmp_len, username, user_len);
|
|
|
|
|
|
|
|
tmp_len += user_len;
|
|
|
|
|
2020-01-23 08:03:22 +00:00
|
|
|
if (outfile_format & (OUTFILE_FMT_TIME_ABS | OUTFILE_FMT_TIME_REL | OUTFILE_FMT_HASH | OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
|
2016-10-19 10:42:41 +00:00
|
|
|
{
|
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
|
|
|
|
|
|
|
tmp_len += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-23 08:03:22 +00:00
|
|
|
if (outfile_format & OUTFILE_FMT_TIME_ABS)
|
|
|
|
{
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
time (&now);
|
|
|
|
|
|
|
|
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "%" PRIu64, (u64) now);
|
|
|
|
|
|
|
|
if (outfile_format & (OUTFILE_FMT_TIME_REL | OUTFILE_FMT_HASH | OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
|
|
|
|
{
|
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
|
|
|
|
|
|
|
tmp_len += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (outfile_format & OUTFILE_FMT_TIME_REL)
|
|
|
|
{
|
|
|
|
time_t time_now;
|
|
|
|
|
|
|
|
time (&time_now);
|
|
|
|
|
|
|
|
time_t time_started = status_ctx->runtime_start;
|
|
|
|
|
|
|
|
u64 diff = 0;
|
|
|
|
|
|
|
|
if (time_now > time_started) // should always be true, but you never know
|
|
|
|
{
|
|
|
|
diff = (u64) time_now - (u64) time_started;
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "%" PRIu64, diff);
|
|
|
|
|
|
|
|
if (outfile_format & (OUTFILE_FMT_HASH | OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
|
|
|
|
{
|
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
|
|
|
|
|
|
|
tmp_len += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & OUTFILE_FMT_HASH)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-10-10 11:10:50 +00:00
|
|
|
memcpy (tmp_buf + tmp_len, out_buf, out_len);
|
|
|
|
|
|
|
|
tmp_len += out_len;
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & (OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-10-10 11:10:50 +00:00
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
|
|
|
|
|
|
|
tmp_len += 1;
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & OUTFILE_FMT_PLAIN)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2017-11-17 09:13:04 +00:00
|
|
|
bool convert_to_hex = false;
|
2016-11-05 12:27:08 +00:00
|
|
|
|
2017-11-17 09:13:04 +00:00
|
|
|
if (user_options->show == false)
|
|
|
|
{
|
|
|
|
if (user_options->outfile_autohex == true)
|
|
|
|
{
|
2019-02-12 14:30:42 +00:00
|
|
|
const bool always_ascii = (hashconfig->opts_type & OPTS_TYPE_PT_ALWAYS_ASCII) ? true : false;
|
2017-11-17 09:13:04 +00:00
|
|
|
|
|
|
|
convert_to_hex = need_hexify (plain_ptr, plain_len, hashconfig->separator, always_ascii);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (convert_to_hex)
|
2016-10-10 11:10:50 +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 20:33:41 +00:00
|
|
|
exec_hexify (plain_ptr, plain_len, (u8 *) tmp_buf + tmp_len);
|
2016-10-10 11:10:50 +00:00
|
|
|
|
|
|
|
tmp_len += plain_len * 2;
|
|
|
|
|
|
|
|
tmp_buf[tmp_len++] = ']';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memcpy (tmp_buf + tmp_len, plain_ptr, plain_len);
|
|
|
|
|
|
|
|
tmp_len += plain_len;
|
|
|
|
}
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & (OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-10-10 11:10:50 +00:00
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
|
|
|
|
|
|
|
tmp_len += 1;
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & OUTFILE_FMT_HEXPLAIN)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2017-11-05 20:33:41 +00:00
|
|
|
exec_hexify (plain_ptr, plain_len, (u8 *) tmp_buf + tmp_len);
|
2016-10-10 11:10:50 +00:00
|
|
|
|
2016-12-18 12:11:54 +00:00
|
|
|
tmp_len += plain_len * 2;
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & (OUTFILE_FMT_CRACKPOS))
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2016-10-10 11:10:50 +00:00
|
|
|
tmp_buf[tmp_len] = hashconfig->separator;
|
|
|
|
|
|
|
|
tmp_len += 1;
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 15:12:29 +00:00
|
|
|
if (outfile_format & OUTFILE_FMT_CRACKPOS)
|
2016-09-10 15:35:58 +00:00
|
|
|
{
|
2017-10-20 10:19:33 +00:00
|
|
|
tmp_len += snprintf (tmp_buf + tmp_len, HCBUFSIZ_LARGE - tmp_len, "%" PRIu64, crackpos);
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 11:10:50 +00:00
|
|
|
tmp_buf[tmp_len] = 0;
|
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (outfile_ctx->fp.pfp != NULL)
|
2016-10-12 09:27:10 +00:00
|
|
|
{
|
2020-06-15 13:43:49 +00:00
|
|
|
hc_fwrite (tmp_buf, tmp_len, 1, &outfile_ctx->fp);
|
|
|
|
|
|
|
|
if (print_eol == true)
|
|
|
|
{
|
|
|
|
hc_fwrite (EOL, strlen (EOL), 1, &outfile_ctx->fp);
|
|
|
|
}
|
2016-10-12 09:27:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return tmp_len;
|
2016-09-10 15:35:58 +00:00
|
|
|
}
|