2016-09-08 14:01:24 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-08 14:01:24 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-09-08 14:01:24 +00:00
|
|
|
#include "locking.h"
|
2019-03-25 11:24:04 +00:00
|
|
|
#include "emu_inc_rp.h"
|
|
|
|
#include "emu_inc_rp_optimized.h"
|
2016-09-08 14:01:24 +00:00
|
|
|
#include "mpsp.h"
|
2019-04-25 12:45:17 +00:00
|
|
|
#include "backend.h"
|
2017-07-06 08:35:25 +00:00
|
|
|
#include "shared.h"
|
2016-09-08 14:01:24 +00:00
|
|
|
#include "stdout.h"
|
|
|
|
|
|
|
|
static void out_flush (out_t *out)
|
|
|
|
{
|
2016-11-20 21:15:39 +00:00
|
|
|
if (out->len == 0) return;
|
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fwrite (out->buf, 1, out->len, &out->fp);
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
out->len = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void out_push (out_t *out, const u8 *pw_buf, const int pw_len)
|
|
|
|
{
|
|
|
|
char *ptr = out->buf + out->len;
|
|
|
|
|
|
|
|
memcpy (ptr, pw_buf, pw_len);
|
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
#if defined (_WIN)
|
2016-10-25 10:40:47 +00:00
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
ptr[pw_len + 0] = '\r';
|
|
|
|
ptr[pw_len + 1] = '\n';
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
out->len += pw_len + 2;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-10-25 10:40:47 +00:00
|
|
|
#else
|
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
ptr[pw_len] = '\n';
|
2016-10-25 10:40:47 +00:00
|
|
|
|
2017-02-23 23:55:06 +00:00
|
|
|
out->len += pw_len + 1;
|
2016-10-25 10:40:47 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-04-08 15:36:26 +00:00
|
|
|
if (out->len >= HCBUFSIZ_SMALL - 300)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
out_flush (out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
int process_stdout (hashcat_ctx_t *hashcat_ctx, hc_device_param_t *device_param, const u64 pws_cnt)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2016-10-06 13:16:30 +00:00
|
|
|
combinator_ctx_t *combinator_ctx = hashcat_ctx->combinator_ctx;
|
|
|
|
hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
mask_ctx_t *mask_ctx = hashcat_ctx->mask_ctx;
|
|
|
|
outfile_ctx_t *outfile_ctx = hashcat_ctx->outfile_ctx;
|
|
|
|
straight_ctx_t *straight_ctx = hashcat_ctx->straight_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2016-09-28 11:51:00 +00:00
|
|
|
char *filename = outfile_ctx->filename;
|
2016-09-10 15:35:58 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
out_t out;
|
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (filename)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
if (hc_fopen (&out.fp, filename, "ab") == false)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno));
|
2016-10-09 20:41:55 +00:00
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
return -1;
|
2016-09-08 14:01:24 +00:00
|
|
|
}
|
2016-11-20 22:15:54 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (hc_lockfile (&out.fp) == -1)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fclose (&out.fp);
|
2016-11-20 22:15:54 +00:00
|
|
|
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", filename, strerror (errno));
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
return -1;
|
2016-09-08 14:01:24 +00:00
|
|
|
}
|
2019-07-02 19:30:35 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
out.fp.is_gzip = false;
|
|
|
|
out.fp.pfp = stdout;
|
|
|
|
out.fp.fd = fileno (stdout);
|
2016-09-08 14:01:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out.len = 0;
|
|
|
|
|
2017-06-17 15:57:30 +00:00
|
|
|
u32 plain_buf[64] = { 0 };
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
u8 *plain_ptr = (u8 *) plain_buf;
|
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
u32 plain_len = 0;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
const u32 il_cnt = device_param->kernel_params_buf32[30]; // ugly, i know
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-09-22 13:41:59 +00:00
|
|
|
if (user_options->attack_mode == ATTACK_MODE_STRAIGHT)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
pw_t pw;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2016-10-15 17:30:57 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (rc == -1)
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
if (filename) hc_fclose (&out.fp);
|
2016-11-20 22:15:54 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2017-08-12 10:11:48 +00:00
|
|
|
const u32 off = device_param->innerloop_pos + il_pos;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2017-08-12 10:11:48 +00:00
|
|
|
if (hashconfig->opti_type & OPTI_TYPE_OPTIMIZED_KERNEL)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2017-08-12 10:11:48 +00:00
|
|
|
plain_len = apply_rules_optimized (straight_ctx->kernel_rules_buf[off].cmds, &plain_buf[0], &plain_buf[4], pw.pw_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-08-12 11:04:52 +00:00
|
|
|
for (int i = 0; i < 64; i++)
|
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
|
|
|
|
2017-11-05 08:52:29 +00:00
|
|
|
plain_len = apply_rules (straight_ctx->kernel_rules_buf[off].cmds, plain_buf, pw.pw_len);
|
2017-08-12 10:11:48 +00:00
|
|
|
}
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-09-28 11:51:00 +00:00
|
|
|
if (plain_len > hashconfig->pw_max) plain_len = hashconfig->pw_max;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
out_push (&out, plain_ptr, plain_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 13:41:59 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_COMBI)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
pw_t pw;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2016-10-15 17:30:57 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (rc == -1)
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
if (filename) hc_fclose (&out.fp);
|
2016-11-20 22:15:54 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2017-06-17 15:57:30 +00:00
|
|
|
for (int i = 0; i < 64; i++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
plain_len = pw.pw_len;
|
|
|
|
|
|
|
|
char *comb_buf = (char *) device_param->combs_buf[il_pos].i;
|
2016-10-31 15:11:52 +00:00
|
|
|
u32 comb_len = device_param->combs_buf[il_pos].pw_len;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-09-27 16:32:09 +00:00
|
|
|
if (combinator_ctx->combs_mode == COMBINATOR_MODE_BASE_LEFT)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
memcpy (plain_ptr + plain_len, comb_buf, comb_len);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
memmove (plain_ptr + comb_len, plain_ptr, plain_len);
|
|
|
|
|
|
|
|
memcpy (plain_ptr, comb_buf, comb_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
plain_len += comb_len;
|
|
|
|
|
2016-10-31 15:11:52 +00:00
|
|
|
if (plain_len > hashconfig->pw_max) plain_len = hashconfig->pw_max;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
out_push (&out, plain_ptr, plain_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 13:41:59 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_BF)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2016-10-04 04:35:49 +00:00
|
|
|
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
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 04:35:49 +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-09-08 14:01:24 +00:00
|
|
|
|
2016-10-04 04:35:49 +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-09-08 14:01:24 +00:00
|
|
|
|
2016-09-25 23:18:00 +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-09-08 14:01:24 +00:00
|
|
|
|
2016-09-25 23:18:00 +00:00
|
|
|
plain_len = mask_ctx->css_cnt;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
out_push (&out, plain_ptr, plain_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 13:41:59 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID1)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
pw_t pw;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2016-10-15 17:30:57 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (rc == -1)
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
if (filename) hc_fclose (&out.fp);
|
2016-11-20 22:15:54 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2017-06-17 15:57:30 +00:00
|
|
|
for (int i = 0; i < 64; i++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
plain_buf[i] = pw.i[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
plain_len = pw.pw_len;
|
|
|
|
|
|
|
|
u64 off = device_param->kernel_params_mp_buf64[3] + il_pos;
|
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
u32 start = 0;
|
|
|
|
u32 stop = device_param->kernel_params_mp_buf32[4];
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-09-25 23:18:00 +00:00
|
|
|
sp_exec (off, (char *) plain_ptr + plain_len, mask_ctx->root_css_buf, mask_ctx->markov_css_buf, start, start + stop);
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
plain_len += start + stop;
|
|
|
|
|
|
|
|
out_push (&out, plain_ptr, plain_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 13:41:59 +00:00
|
|
|
else if (user_options->attack_mode == ATTACK_MODE_HYBRID2)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
|
|
|
pw_t pw;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (u64 gidvid = 0; gidvid < pws_cnt; gidvid++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2016-10-15 17:30:57 +00:00
|
|
|
const int rc = gidd_to_pw_t (hashcat_ctx, device_param, gidvid, &pw);
|
|
|
|
|
2016-11-20 22:15:54 +00:00
|
|
|
if (rc == -1)
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
if (filename) hc_fclose (&out.fp);
|
2016-11-20 22:15:54 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
for (u32 il_pos = 0; il_pos < il_cnt; il_pos++)
|
2016-09-08 14:01:24 +00:00
|
|
|
{
|
2018-08-15 11:32:08 +00:00
|
|
|
u64 off = device_param->kernel_params_mp_buf64[3] + gidvid;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2018-08-15 11:32:08 +00:00
|
|
|
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;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2017-09-16 09:37:59 +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-09-08 14:01:24 +00:00
|
|
|
|
2017-09-16 09:37:59 +00:00
|
|
|
memcpy (plain_ptr + plain_len, comb_buf, comb_len);
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2017-09-16 09:37:59 +00:00
|
|
|
plain_len += comb_len;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
2017-09-16 09:37:59 +00:00
|
|
|
if (plain_len > hashconfig->pw_max) plain_len = hashconfig->pw_max;
|
2016-09-08 14:01:24 +00:00
|
|
|
|
|
|
|
out_push (&out, plain_ptr, plain_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out_flush (&out);
|
|
|
|
|
2020-02-29 09:40:47 +00:00
|
|
|
if (filename)
|
|
|
|
{
|
|
|
|
hc_unlockfile (&out.fp);
|
|
|
|
|
|
|
|
hc_fclose (&out.fp);
|
|
|
|
}
|
2016-10-09 20:41:55 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-08 14:01:24 +00:00
|
|
|
}
|