|
|
|
@ -17,7 +17,7 @@
|
|
|
|
|
int sort_by_hash (const void *v1, const void *v2);
|
|
|
|
|
int sort_by_hash_no_salt (const void *v1, const void *v2);
|
|
|
|
|
void format_plain (FILE *fp, unsigned char *plain_ptr, uint plain_len, uint outfile_autohex);
|
|
|
|
|
void format_output (FILE *out_fp, char *out_buf, unsigned char *plain_ptr, const uint plain_len, const u64 crackpos, unsigned char *username, const uint user_len, hashconfig_t *hashconfig);
|
|
|
|
|
void format_output (FILE *out_fp, char *out_buf, unsigned char *plain_ptr, const uint plain_len, const u64 crackpos, unsigned char *username, const uint user_len, const hashconfig_t *hashconfig);
|
|
|
|
|
// get rid of this later
|
|
|
|
|
|
|
|
|
|
int sort_by_pot (const void *v1, const void *v2)
|
|
|
|
@ -108,14 +108,239 @@ int sort_by_hash_t_salt_hccap (const void *v1, const void *v2)
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_show_request (pot_t *pot, uint pot_cnt, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *), FILE *out_fp, hashconfig_t *hashconfig)
|
|
|
|
|
void potfile_init (potfile_ctx_t *potfile_ctx, const char *profile_dir, const char *potfile_path)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->fp = NULL;
|
|
|
|
|
|
|
|
|
|
potfile_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY);
|
|
|
|
|
|
|
|
|
|
if (potfile_path == NULL)
|
|
|
|
|
{
|
|
|
|
|
snprintf (potfile_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.potfile", profile_dir);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strncpy (potfile_ctx->filename, potfile_path, HCBUFSIZ_TINY - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot = NULL;
|
|
|
|
|
potfile_ctx->pot_cnt = 0;
|
|
|
|
|
potfile_ctx->pot_avail = 0;
|
|
|
|
|
potfile_ctx->pot_hashes_avail = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int potfile_read_open (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->fp = fopen (potfile_ctx->filename, "rb");
|
|
|
|
|
|
|
|
|
|
if (potfile_ctx->fp == NULL)
|
|
|
|
|
{
|
|
|
|
|
//log_error ("ERROR: %s: %s", potfile_ctx->filename, strerror (errno));
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_read_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->pot_avail = count_lines (potfile_ctx->fp);
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot = (pot_t *) mycalloc (potfile_ctx->pot_avail, sizeof (pot_t));
|
|
|
|
|
|
|
|
|
|
rewind (potfile_ctx->fp);
|
|
|
|
|
|
|
|
|
|
char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE);
|
|
|
|
|
|
|
|
|
|
for (uint line_num = 0; line_num < potfile_ctx->pot_avail; line_num++)
|
|
|
|
|
{
|
|
|
|
|
int line_len = fgetl (potfile_ctx->fp, line_buf);
|
|
|
|
|
|
|
|
|
|
if (line_len == 0) continue;
|
|
|
|
|
|
|
|
|
|
pot_t *pot_ptr = &potfile_ctx->pot[potfile_ctx->pot_cnt];
|
|
|
|
|
|
|
|
|
|
// we do not initialize all hashes_buf->digest etc at the beginning, since many lines may not be
|
|
|
|
|
// valid lines of this specific hash type (otherwise it would be more waste of memory than gain)
|
|
|
|
|
|
|
|
|
|
if (potfile_ctx->pot_cnt == potfile_ctx->pot_hashes_avail)
|
|
|
|
|
{
|
|
|
|
|
potfile_hash_alloc (potfile_ctx, hashconfig, INCR_POT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int parser_status;
|
|
|
|
|
|
|
|
|
|
int iter = MAX_CUT_TRIES;
|
|
|
|
|
|
|
|
|
|
hash_t *hashes_buf = &pot_ptr->hash;
|
|
|
|
|
|
|
|
|
|
char *plain_buf = line_buf + line_len;
|
|
|
|
|
|
|
|
|
|
int plain_len = 0;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
for (int i = line_len - 1; i; i--, plain_len++, plain_buf--, line_len--)
|
|
|
|
|
{
|
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
|
{
|
|
|
|
|
line_len--;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashconfig->hash_mode != 2500)
|
|
|
|
|
{
|
|
|
|
|
parser_status = hashconfig->parse_func (line_buf, line_len, hashes_buf, hashconfig);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int max_salt_size = sizeof (hashes_buf->salt->salt_buf);
|
|
|
|
|
|
|
|
|
|
if (line_len > max_salt_size)
|
|
|
|
|
{
|
|
|
|
|
parser_status = PARSER_GLOBAL_LENGTH;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memset (&hashes_buf->salt->salt_buf, 0, max_salt_size);
|
|
|
|
|
|
|
|
|
|
memcpy (&hashes_buf->salt->salt_buf, line_buf, line_len);
|
|
|
|
|
|
|
|
|
|
hashes_buf->salt->salt_len = line_len;
|
|
|
|
|
|
|
|
|
|
parser_status = PARSER_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if NOT parsed without error, we add the ":" to the plain
|
|
|
|
|
|
|
|
|
|
if (parser_status == PARSER_GLOBAL_LENGTH || parser_status == PARSER_HASH_LENGTH || parser_status == PARSER_SALT_LENGTH)
|
|
|
|
|
{
|
|
|
|
|
plain_len++;
|
|
|
|
|
plain_buf--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while ((parser_status == PARSER_GLOBAL_LENGTH || parser_status == PARSER_HASH_LENGTH || parser_status == PARSER_SALT_LENGTH) && --iter);
|
|
|
|
|
|
|
|
|
|
if (parser_status < PARSER_GLOBAL_ZERO)
|
|
|
|
|
{
|
|
|
|
|
// log_info ("WARNING: Potfile '%s' in line %u (%s): %s", potfile, line_num, line_buf, strparser (parser_status));
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plain_len >= HCBUFSIZ_TINY) continue;
|
|
|
|
|
|
|
|
|
|
memcpy (pot_ptr->plain_buf, plain_buf, plain_len);
|
|
|
|
|
|
|
|
|
|
pot_ptr->plain_len = plain_len;
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot_cnt++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
myfree (line_buf);
|
|
|
|
|
|
|
|
|
|
qsort (potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_read_close (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
fclose (potfile_ctx->fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int potfile_write_open (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->fp = fopen (potfile_ctx->filename, "ab");
|
|
|
|
|
|
|
|
|
|
if (potfile_ctx->fp == NULL)
|
|
|
|
|
{
|
|
|
|
|
log_error ("ERROR: %s: %s", potfile_ctx->filename, strerror (errno));
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_write_close (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
fclose (potfile_ctx->fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_write_append (potfile_ctx_t *potfile_ctx, const char *out_buf, u8 *plain_ptr, unsigned int plain_len)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = potfile_ctx->fp;
|
|
|
|
|
|
|
|
|
|
fprintf (fp, "%s:", out_buf);
|
|
|
|
|
|
|
|
|
|
format_plain (fp, plain_ptr, plain_len, 1);
|
|
|
|
|
|
|
|
|
|
fputc ('\n', fp);
|
|
|
|
|
|
|
|
|
|
fflush (fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_hash_alloc (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, const uint num)
|
|
|
|
|
{
|
|
|
|
|
uint pos = 0;
|
|
|
|
|
|
|
|
|
|
for (pos = 0; pos < num; pos++)
|
|
|
|
|
{
|
|
|
|
|
if ((potfile_ctx->pot_cnt + pos) >= potfile_ctx->pot_avail) break;
|
|
|
|
|
|
|
|
|
|
pot_t *tmp_pot = &potfile_ctx->pot[potfile_ctx->pot_cnt + pos];
|
|
|
|
|
|
|
|
|
|
hash_t *tmp_hash = &tmp_pot->hash;
|
|
|
|
|
|
|
|
|
|
tmp_hash->digest = mymalloc (hashconfig->dgst_size);
|
|
|
|
|
|
|
|
|
|
if (hashconfig->is_salted)
|
|
|
|
|
{
|
|
|
|
|
tmp_hash->salt = (salt_t *) mymalloc (sizeof (salt_t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashconfig->esalt_size)
|
|
|
|
|
{
|
|
|
|
|
tmp_hash->esalt = mymalloc (hashconfig->esalt_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot_hashes_avail++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_hash_free (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig)
|
|
|
|
|
{
|
|
|
|
|
for (uint i = 0; i < potfile_ctx->pot_cnt; i++)
|
|
|
|
|
{
|
|
|
|
|
pot_t *pot_ptr = &potfile_ctx->pot[i];
|
|
|
|
|
|
|
|
|
|
hash_t *hashes_buf = &pot_ptr->hash;
|
|
|
|
|
|
|
|
|
|
myfree (hashes_buf->digest);
|
|
|
|
|
|
|
|
|
|
if (hashconfig->is_salted)
|
|
|
|
|
{
|
|
|
|
|
myfree (hashes_buf->salt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashconfig->esalt_size)
|
|
|
|
|
{
|
|
|
|
|
myfree (hashes_buf->esalt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_show_request (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *), FILE *out_fp)
|
|
|
|
|
{
|
|
|
|
|
pot_t pot_key;
|
|
|
|
|
|
|
|
|
|
pot_key.hash.salt = hashes_buf->salt;
|
|
|
|
|
pot_key.hash.digest = hashes_buf->digest;
|
|
|
|
|
|
|
|
|
|
pot_t *pot_ptr = (pot_t *) bsearch (&pot_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
pot_t *pot_ptr = (pot_t *) bsearch (&pot_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
|
|
|
|
|
if (pot_ptr)
|
|
|
|
|
{
|
|
|
|
@ -144,13 +369,13 @@ void handle_show_request (pot_t *pot, uint pot_cnt, char *input_buf, int input_l
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_left_request (pot_t *pot, uint pot_cnt, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *), FILE *out_fp, hashconfig_t *hashconfig)
|
|
|
|
|
void potfile_left_request (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, char *input_buf, int input_len, hash_t *hashes_buf, int (*sort_by_pot) (const void *, const void *), FILE *out_fp)
|
|
|
|
|
{
|
|
|
|
|
pot_t pot_key;
|
|
|
|
|
|
|
|
|
|
memcpy (&pot_key.hash, hashes_buf, sizeof (hash_t));
|
|
|
|
|
|
|
|
|
|
pot_t *pot_ptr = (pot_t *) bsearch (&pot_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
pot_t *pot_ptr = (pot_t *) bsearch (&pot_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
|
|
|
|
|
if (pot_ptr == NULL)
|
|
|
|
|
{
|
|
|
|
@ -162,7 +387,7 @@ void handle_left_request (pot_t *pot, uint pot_cnt, char *input_buf, int input_l
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_show_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *), FILE *out_fp, hashconfig_t *hashconfig)
|
|
|
|
|
void potfile_show_request_lm (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *), FILE *out_fp)
|
|
|
|
|
{
|
|
|
|
|
// left
|
|
|
|
|
|
|
|
|
@ -171,7 +396,7 @@ void handle_show_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int inpu
|
|
|
|
|
pot_left_key.hash.salt = hash_left->salt;
|
|
|
|
|
pot_left_key.hash.digest = hash_left->digest;
|
|
|
|
|
|
|
|
|
|
pot_t *pot_left_ptr = (pot_t *) bsearch (&pot_left_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
pot_t *pot_left_ptr = (pot_t *) bsearch (&pot_left_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
|
|
|
|
|
// right
|
|
|
|
|
|
|
|
|
@ -182,7 +407,7 @@ void handle_show_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int inpu
|
|
|
|
|
pot_right_key.hash.salt = hash_right->salt;
|
|
|
|
|
pot_right_key.hash.digest = hash_right->digest;
|
|
|
|
|
|
|
|
|
|
pot_t *pot_right_ptr = (pot_t *) bsearch (&pot_right_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
pot_t *pot_right_ptr = (pot_t *) bsearch (&pot_right_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
|
|
|
|
|
if (pot_right_ptr == NULL)
|
|
|
|
|
{
|
|
|
|
@ -282,7 +507,7 @@ void handle_show_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int inpu
|
|
|
|
|
if (right_part_masked == 1) myfree (pot_right_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handle_left_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *), FILE *out_fp, hashconfig_t *hashconfig)
|
|
|
|
|
void potfile_left_request_lm (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, char *input_buf, int input_len, hash_t *hash_left, hash_t *hash_right, int (*sort_by_pot) (const void *, const void *), FILE *out_fp)
|
|
|
|
|
{
|
|
|
|
|
// left
|
|
|
|
|
|
|
|
|
@ -290,7 +515,7 @@ void handle_left_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int inpu
|
|
|
|
|
|
|
|
|
|
memcpy (&pot_left_key.hash, hash_left, sizeof (hash_t));
|
|
|
|
|
|
|
|
|
|
pot_t *pot_left_ptr = (pot_t *) bsearch (&pot_left_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
pot_t *pot_left_ptr = (pot_t *) bsearch (&pot_left_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
|
|
|
|
|
// right
|
|
|
|
|
|
|
|
|
@ -298,7 +523,7 @@ void handle_left_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int inpu
|
|
|
|
|
|
|
|
|
|
memcpy (&pot_right_key.hash, hash_right, sizeof (hash_t));
|
|
|
|
|
|
|
|
|
|
pot_t *pot_right_ptr = (pot_t *) bsearch (&pot_right_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
pot_t *pot_right_ptr = (pot_t *) bsearch (&pot_right_key, potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
|
|
|
|
|
uint weak_hash_found = 0;
|
|
|
|
|
|
|
|
|
@ -362,231 +587,6 @@ void handle_left_request_lm (pot_t *pot, uint pot_cnt, char *input_buf, int inpu
|
|
|
|
|
if (weak_hash_found == 1) myfree (pot_right_ptr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_init (potfile_ctx_t *potfile_ctx, const char *profile_dir, const char *potfile_path)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->fp = NULL;
|
|
|
|
|
|
|
|
|
|
potfile_ctx->filename = (char *) mymalloc (HCBUFSIZ_TINY);
|
|
|
|
|
|
|
|
|
|
if (potfile_path == NULL)
|
|
|
|
|
{
|
|
|
|
|
snprintf (potfile_ctx->filename, HCBUFSIZ_TINY - 1, "%s/hashcat.potfile", profile_dir);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
strncpy (potfile_ctx->filename, potfile_path, HCBUFSIZ_TINY - 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot = NULL;
|
|
|
|
|
potfile_ctx->pot_cnt = 0;
|
|
|
|
|
potfile_ctx->pot_avail = 0;
|
|
|
|
|
potfile_ctx->pot_hashes_avail = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int potfile_read_open (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->fp = fopen (potfile_ctx->filename, "rb");
|
|
|
|
|
|
|
|
|
|
if (potfile_ctx->fp == NULL)
|
|
|
|
|
{
|
|
|
|
|
//log_error ("ERROR: %s: %s", potfile_ctx->filename, strerror (errno));
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_read_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->pot_avail = count_lines (potfile_ctx->fp);
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot = (pot_t *) mycalloc (potfile_ctx->pot_avail, sizeof (pot_t));
|
|
|
|
|
|
|
|
|
|
rewind (potfile_ctx->fp);
|
|
|
|
|
|
|
|
|
|
char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE);
|
|
|
|
|
|
|
|
|
|
for (uint line_num = 0; line_num < potfile_ctx->pot_avail; line_num++)
|
|
|
|
|
{
|
|
|
|
|
int line_len = fgetl (potfile_ctx->fp, line_buf);
|
|
|
|
|
|
|
|
|
|
if (line_len == 0) continue;
|
|
|
|
|
|
|
|
|
|
pot_t *pot_ptr = &potfile_ctx->pot[potfile_ctx->pot_cnt];
|
|
|
|
|
|
|
|
|
|
// we do not initialize all hashes_buf->digest etc at the beginning, since many lines may not be
|
|
|
|
|
// valid lines of this specific hash type (otherwise it would be more waste of memory than gain)
|
|
|
|
|
|
|
|
|
|
if (potfile_ctx->pot_cnt == potfile_ctx->pot_hashes_avail)
|
|
|
|
|
{
|
|
|
|
|
potfile_hash_alloc (potfile_ctx, hashconfig, INCR_POT);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int parser_status;
|
|
|
|
|
|
|
|
|
|
int iter = MAX_CUT_TRIES;
|
|
|
|
|
|
|
|
|
|
hash_t *hashes_buf = &pot_ptr->hash;
|
|
|
|
|
|
|
|
|
|
char *plain_buf = line_buf + line_len;
|
|
|
|
|
|
|
|
|
|
int plain_len = 0;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
for (int i = line_len - 1; i; i--, plain_len++, plain_buf--, line_len--)
|
|
|
|
|
{
|
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
|
{
|
|
|
|
|
line_len--;
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashconfig->hash_mode != 2500)
|
|
|
|
|
{
|
|
|
|
|
parser_status = hashconfig->parse_func (line_buf, line_len, hashes_buf, hashconfig);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int max_salt_size = sizeof (hashes_buf->salt->salt_buf);
|
|
|
|
|
|
|
|
|
|
if (line_len > max_salt_size)
|
|
|
|
|
{
|
|
|
|
|
parser_status = PARSER_GLOBAL_LENGTH;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
memset (&hashes_buf->salt->salt_buf, 0, max_salt_size);
|
|
|
|
|
|
|
|
|
|
memcpy (&hashes_buf->salt->salt_buf, line_buf, line_len);
|
|
|
|
|
|
|
|
|
|
hashes_buf->salt->salt_len = line_len;
|
|
|
|
|
|
|
|
|
|
parser_status = PARSER_OK;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if NOT parsed without error, we add the ":" to the plain
|
|
|
|
|
|
|
|
|
|
if (parser_status == PARSER_GLOBAL_LENGTH || parser_status == PARSER_HASH_LENGTH || parser_status == PARSER_SALT_LENGTH)
|
|
|
|
|
{
|
|
|
|
|
plain_len++;
|
|
|
|
|
plain_buf--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} while ((parser_status == PARSER_GLOBAL_LENGTH || parser_status == PARSER_HASH_LENGTH || parser_status == PARSER_SALT_LENGTH) && --iter);
|
|
|
|
|
|
|
|
|
|
if (parser_status < PARSER_GLOBAL_ZERO)
|
|
|
|
|
{
|
|
|
|
|
// log_info ("WARNING: Potfile '%s' in line %u (%s): %s", potfile, line_num, line_buf, strparser (parser_status));
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (plain_len >= HCBUFSIZ_TINY) continue;
|
|
|
|
|
|
|
|
|
|
memcpy (pot_ptr->plain_buf, plain_buf, plain_len);
|
|
|
|
|
|
|
|
|
|
pot_ptr->plain_len = plain_len;
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot_cnt++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
myfree (line_buf);
|
|
|
|
|
|
|
|
|
|
qsort (potfile_ctx->pot, potfile_ctx->pot_cnt, sizeof (pot_t), sort_by_pot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_read_close (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
fclose (potfile_ctx->fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int potfile_write_open (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
potfile_ctx->fp = fopen (potfile_ctx->filename, "ab");
|
|
|
|
|
|
|
|
|
|
if (potfile_ctx->fp == NULL)
|
|
|
|
|
{
|
|
|
|
|
log_error ("ERROR: %s: %s", potfile_ctx->filename, strerror (errno));
|
|
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_write_close (potfile_ctx_t *potfile_ctx)
|
|
|
|
|
{
|
|
|
|
|
fclose (potfile_ctx->fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_write_append (potfile_ctx_t *potfile_ctx, const char *out_buf, u8 *plain_ptr, unsigned int plain_len)
|
|
|
|
|
{
|
|
|
|
|
FILE *fp = potfile_ctx->fp;
|
|
|
|
|
|
|
|
|
|
fprintf (fp, "%s:", out_buf);
|
|
|
|
|
|
|
|
|
|
format_plain (fp, plain_ptr, plain_len, 1);
|
|
|
|
|
|
|
|
|
|
fputc ('\n', fp);
|
|
|
|
|
|
|
|
|
|
fflush (fp);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_hash_alloc (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, const uint num)
|
|
|
|
|
{
|
|
|
|
|
uint pos = 0;
|
|
|
|
|
|
|
|
|
|
for (pos = 0; pos < num; pos++)
|
|
|
|
|
{
|
|
|
|
|
if ((potfile_ctx->pot_cnt + pos) >= potfile_ctx->pot_avail) break;
|
|
|
|
|
|
|
|
|
|
pot_t *tmp_pot = &potfile_ctx->pot[potfile_ctx->pot_cnt + pos];
|
|
|
|
|
|
|
|
|
|
hash_t *tmp_hash = &tmp_pot->hash;
|
|
|
|
|
|
|
|
|
|
tmp_hash->digest = mymalloc (hashconfig->dgst_size);
|
|
|
|
|
|
|
|
|
|
if (hashconfig->is_salted)
|
|
|
|
|
{
|
|
|
|
|
tmp_hash->salt = (salt_t *) mymalloc (sizeof (salt_t));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashconfig->esalt_size)
|
|
|
|
|
{
|
|
|
|
|
tmp_hash->esalt = mymalloc (hashconfig->esalt_size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
potfile_ctx->pot_hashes_avail++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void potfile_hash_free (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig)
|
|
|
|
|
{
|
|
|
|
|
for (uint i = 0; i < potfile_ctx->pot_cnt; i++)
|
|
|
|
|
{
|
|
|
|
|
pot_t *pot_ptr = &potfile_ctx->pot[i];
|
|
|
|
|
|
|
|
|
|
hash_t *hashes_buf = &pot_ptr->hash;
|
|
|
|
|
|
|
|
|
|
myfree (hashes_buf->digest);
|
|
|
|
|
|
|
|
|
|
if (hashconfig->is_salted)
|
|
|
|
|
{
|
|
|
|
|
myfree (hashes_buf->salt);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (hashconfig->esalt_size)
|
|
|
|
|
{
|
|
|
|
|
myfree (hashes_buf->esalt);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int potfile_remove_parse (potfile_ctx_t *potfile_ctx, const hashconfig_t *hashconfig, const hash_t *hashes_buf, const uint hashes_cnt)
|
|
|
|
|
{
|
|
|
|
|
// no solution for these special hash types (for instane because they use hashfile in output etc)
|
|
|
|
|