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-16 15:01:18 +00:00
|
|
|
#include "types.h"
|
2016-09-12 12:58:25 +00:00
|
|
|
#include "memory.h"
|
2016-10-09 20:41:55 +00:00
|
|
|
#include "event.h"
|
2016-09-12 12:58:25 +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 "loopback.h"
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
static void loopback_format_plain (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const unsigned int plain_len)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2016-10-06 15:01:29 +00:00
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
|
|
|
|
if (loopback_ctx->enabled == false) return;
|
|
|
|
|
|
|
|
int needs_hexify = 0;
|
|
|
|
|
|
|
|
for (u32 i = 0; i < plain_len; i++)
|
|
|
|
{
|
|
|
|
if (plain_ptr[i] < 0x20)
|
|
|
|
{
|
|
|
|
needs_hexify = 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (plain_ptr[i] > 0x7f)
|
|
|
|
{
|
|
|
|
needs_hexify = 1;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needs_hexify == 1)
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fprintf (&loopback_ctx->fp, "$HEX[");
|
2016-10-06 15:01:29 +00:00
|
|
|
|
|
|
|
for (u32 i = 0; i < plain_len; i++)
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fprintf (&loopback_ctx->fp, "%02x", plain_ptr[i]);
|
2016-10-06 15:01:29 +00:00
|
|
|
}
|
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fprintf (&loopback_ctx->fp, "]");
|
2016-10-06 15:01:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fwrite ((void *)plain_ptr, plain_len, 1, &loopback_ctx->fp);
|
2016-10-06 15:01:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:26:15 +00:00
|
|
|
int loopback_init (hashcat_ctx_t *hashcat_ctx)
|
2016-10-06 15:01:29 +00:00
|
|
|
{
|
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
|
2016-09-30 10:07:49 +00:00
|
|
|
loopback_ctx->enabled = false;
|
|
|
|
|
2017-08-22 09:09:46 +00:00
|
|
|
if (user_options->benchmark == true) return 0;
|
2020-12-29 03:58:58 +00:00
|
|
|
if (user_options->hash_info == true) return 0;
|
2017-08-22 09:09:46 +00:00
|
|
|
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-10-06 15:26:15 +00:00
|
|
|
|
|
|
|
loopback_ctx->enabled = true;
|
2019-07-02 19:30:35 +00:00
|
|
|
loopback_ctx->fp.pfp = NULL;
|
2016-11-20 21:54:52 +00:00
|
|
|
loopback_ctx->filename = (char *) hcmalloc (HCBUFSIZ_TINY);
|
2016-10-06 15:26:15 +00:00
|
|
|
|
|
|
|
return 0;
|
2016-09-12 12:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
void loopback_destroy (hashcat_ctx_t *hashcat_ctx)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2016-10-06 15:01:29 +00:00
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
if (loopback_ctx->enabled == false) return;
|
2016-09-30 10:07:49 +00:00
|
|
|
|
2016-10-01 22:00:21 +00:00
|
|
|
memset (loopback_ctx, 0, sizeof (loopback_ctx_t));
|
2016-09-12 12:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
int loopback_write_open (hashcat_ctx_t *hashcat_ctx)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2016-10-06 15:01:29 +00:00
|
|
|
induct_ctx_t *induct_ctx = hashcat_ctx->induct_ctx;
|
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
|
2016-09-30 10:07:49 +00:00
|
|
|
if (loopback_ctx->enabled == false) return 0;
|
|
|
|
|
|
|
|
if (induct_ctx->enabled == false) return 0;
|
|
|
|
|
2017-12-10 00:40:45 +00:00
|
|
|
time_t now;
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2017-12-10 00:40:45 +00:00
|
|
|
time (&now);
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2016-10-04 09:22:08 +00:00
|
|
|
const u32 random_num = get_random_num (0, 9999);
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2016-12-23 23:40:40 +00:00
|
|
|
hc_asprintf (&loopback_ctx->filename, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num);
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (hc_fopen (&loopback_ctx->fp, loopback_ctx->filename, "ab") == false)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2017-02-04 01:53:50 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s: %s", loopback_ctx->filename, strerror (errno));
|
2016-09-12 12:58:25 +00:00
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
2016-11-05 10:33:29 +00:00
|
|
|
|
2016-10-26 13:10:59 +00:00
|
|
|
loopback_ctx->unused = true;
|
|
|
|
|
2016-09-12 12:58:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
void loopback_write_unlink (hashcat_ctx_t *hashcat_ctx)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2016-10-06 15:01:29 +00:00
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
|
2016-09-30 10:07:49 +00:00
|
|
|
if (loopback_ctx->enabled == false) return;
|
|
|
|
|
2016-09-12 12:58:25 +00:00
|
|
|
if (loopback_ctx->filename == NULL) return;
|
|
|
|
|
|
|
|
unlink (loopback_ctx->filename);
|
|
|
|
}
|
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
void loopback_write_close (hashcat_ctx_t *hashcat_ctx)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2016-10-06 15:01:29 +00:00
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
|
|
|
|
2016-09-30 10:07:49 +00:00
|
|
|
if (loopback_ctx->enabled == false) return;
|
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
if (loopback_ctx->fp.pfp == NULL) return;
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fclose (&loopback_ctx->fp);
|
2016-10-26 13:10:59 +00:00
|
|
|
|
|
|
|
if (loopback_ctx->unused == true)
|
|
|
|
{
|
|
|
|
loopback_write_unlink (hashcat_ctx);
|
|
|
|
}
|
2016-09-12 12:58:25 +00:00
|
|
|
}
|
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
void loopback_write_append (hashcat_ctx_t *hashcat_ctx, const u8 *plain_ptr, const unsigned int plain_len)
|
2016-09-12 12:58:25 +00:00
|
|
|
{
|
2016-10-06 15:01:29 +00:00
|
|
|
loopback_ctx_t *loopback_ctx = hashcat_ctx->loopback_ctx;
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2016-09-30 10:07:49 +00:00
|
|
|
if (loopback_ctx->enabled == false) return;
|
|
|
|
|
2016-10-06 15:01:29 +00:00
|
|
|
loopback_format_plain (hashcat_ctx, plain_ptr, plain_len);
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_lockfile (&loopback_ctx->fp);
|
2016-12-02 10:18:55 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fwrite (EOL, strlen (EOL), 1, &loopback_ctx->fp);
|
2016-09-12 12:58:25 +00:00
|
|
|
|
2019-07-02 19:30:35 +00:00
|
|
|
hc_fflush (&loopback_ctx->fp);
|
2016-10-26 13:10:59 +00:00
|
|
|
|
2020-02-29 09:40:47 +00:00
|
|
|
hc_unlockfile (&loopback_ctx->fp);
|
2016-12-02 10:18:55 +00:00
|
|
|
|
2016-10-26 13:10:59 +00:00
|
|
|
loopback_ctx->unused = false;
|
2016-09-12 12:58:25 +00:00
|
|
|
}
|