You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hashcat/src/shared.c

927 lines
19 KiB

9 years ago
/**
* Authors.....: Jens Steube <jens.steube@gmail.com>
* Gabriele Gristina <matrix@hashcat.net>
* magnum <john.magnum@hushmail.com>
*
9 years ago
* License.....: MIT
*/
#if defined (__APPLE__)
#include <stdio.h>
#endif
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "memory.h"
#include "logging.h"
#include "ext_OpenCL.h"
#include "ext_ADL.h"
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "convert.h"
#include "locking.h"
#include "thread.h"
#include "rp_cpu.h"
#include "hwmon.h"
#include "mpsp.h"
#include "rp_cpu.h"
#include "opencl.h"
#include "restore.h"
#include "data.h"
#include "status.h"
#include "shared.h"
9 years ago
extern hc_global_data_t data;
u32 get_random_num (const u32 min, const u32 max)
{
if (min == max) return (min);
return ((rand () % (max - min)) + min);
}
u32 mydivc32 (const u32 dividend, const u32 divisor)
{
u32 quotient = dividend / divisor;
if (dividend % divisor) quotient++;
return quotient;
}
u64 mydivc64 (const u64 dividend, const u64 divisor)
{
u64 quotient = dividend / divisor;
if (dividend % divisor) quotient++;
return quotient;
}
void naive_replace (char *s, const u8 key_char, const u8 replace_char)
{
const size_t len = strlen (s);
for (size_t in = 0; in < len; in++)
{
const u8 c = s[in];
if (c == key_char)
{
s[in] = replace_char;
}
}
}
void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char)
{
char s_escaped[1024] = { 0 };
size_t s_escaped_max = sizeof (s_escaped);
const size_t len = strlen (s);
for (size_t in = 0, out = 0; in < len; in++, out++)
{
const u8 c = s[in];
if (c == key_char)
{
s_escaped[out] = escape_char;
9 years ago
out++;
}
9 years ago
if (out == s_escaped_max - 2) break;
9 years ago
s_escaped[out] = c;
}
strncpy (s, s_escaped, s_max - 1);
}
9 years ago
// need to sort out from here
int sort_by_u32 (const void *v1, const void *v2)
{
const u32 *s1 = (const u32 *) v1;
const u32 *s2 = (const u32 *) v2;
return *s1 - *s2;
9 years ago
}
int sort_by_salt (const void *v1, const void *v2)
9 years ago
{
const salt_t *s1 = (const salt_t *) v1;
const salt_t *s2 = (const salt_t *) v2;
const int res1 = s1->salt_len - s2->salt_len;
9 years ago
if (res1 != 0) return (res1);
const int res2 = s1->salt_iter - s2->salt_iter;
9 years ago
if (res2 != 0) return (res2);
9 years ago
uint n;
9 years ago
n = 16;
9 years ago
while (n--)
{
if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1);
if (s1->salt_buf[n] < s2->salt_buf[n]) return -1;
}
9 years ago
n = 8;
9 years ago
while (n--)
{
if (s1->salt_buf_pc[n] > s2->salt_buf_pc[n]) return ( 1);
if (s1->salt_buf_pc[n] < s2->salt_buf_pc[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_salt_buf (const void *v1, const void *v2)
{
const pot_t *p1 = (const pot_t *) v1;
const pot_t *p2 = (const pot_t *) v2;
9 years ago
const hash_t *h1 = &p1->hash;
const hash_t *h2 = &p2->hash;
9 years ago
const salt_t *s1 = h1->salt;
const salt_t *s2 = h2->salt;
9 years ago
uint n = 16;
9 years ago
while (n--)
{
if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1);
if (s1->salt_buf[n] < s2->salt_buf[n]) return -1;
}
9 years ago
return 0;
9 years ago
}
int sort_by_hash_t_salt (const void *v1, const void *v2)
9 years ago
{
const hash_t *h1 = (const hash_t *) v1;
const hash_t *h2 = (const hash_t *) v2;
9 years ago
const salt_t *s1 = h1->salt;
const salt_t *s2 = h2->salt;
9 years ago
// testphase: this should work
uint n = 16;
9 years ago
while (n--)
{
if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1);
if (s1->salt_buf[n] < s2->salt_buf[n]) return -1;
}
9 years ago
/* original code, seems buggy since salt_len can be very big (had a case with 131 len)
also it thinks salt_buf[x] is a char but its a uint so salt_len should be / 4
if (s1->salt_len > s2->salt_len) return ( 1);
if (s1->salt_len < s2->salt_len) return -1;
9 years ago
uint n = s1->salt_len;
9 years ago
while (n--)
{
if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1);
if (s1->salt_buf[n] < s2->salt_buf[n]) return -1;
}
*/
9 years ago
return 0;
}
9 years ago
int sort_by_hash_t_salt_hccap (const void *v1, const void *v2)
{
const hash_t *h1 = (const hash_t *) v1;
const hash_t *h2 = (const hash_t *) v2;
9 years ago
const salt_t *s1 = h1->salt;
const salt_t *s2 = h2->salt;
9 years ago
// last 2: salt_buf[10] and salt_buf[11] contain the digest (skip them)
9 years ago
uint n = 9; // 9 * 4 = 36 bytes (max length of ESSID)
9 years ago
while (n--)
{
if (s1->salt_buf[n] > s2->salt_buf[n]) return ( 1);
if (s1->salt_buf[n] < s2->salt_buf[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_hash_no_salt (const void *v1, const void *v2)
{
const hash_t *h1 = (const hash_t *) v1;
const hash_t *h2 = (const hash_t *) v2;
9 years ago
const void *d1 = h1->digest;
const void *d2 = h2->digest;
9 years ago
return data.sort_by_digest (d1, d2);
}
9 years ago
int sort_by_hash (const void *v1, const void *v2)
{
const hash_t *h1 = (const hash_t *) v1;
const hash_t *h2 = (const hash_t *) v2;
9 years ago
if (data.isSalted)
{
const salt_t *s1 = h1->salt;
const salt_t *s2 = h2->salt;
9 years ago
int res = sort_by_salt (s1, s2);
9 years ago
if (res != 0) return (res);
}
9 years ago
const void *d1 = h1->digest;
const void *d2 = h2->digest;
9 years ago
return data.sort_by_digest (d1, d2);
}
9 years ago
int sort_by_pot (const void *v1, const void *v2)
{
const pot_t *p1 = (const pot_t *) v1;
const pot_t *p2 = (const pot_t *) v2;
9 years ago
const hash_t *h1 = &p1->hash;
const hash_t *h2 = &p2->hash;
9 years ago
return sort_by_hash (h1, h2);
}
9 years ago
int sort_by_mtime (const void *p1, const void *p2)
{
const char **f1 = (const char **) p1;
const char **f2 = (const char **) p2;
9 years ago
struct stat s1; stat (*f1, &s1);
struct stat s2; stat (*f2, &s2);
9 years ago
return s2.st_mtime - s1.st_mtime;
}
9 years ago
int sort_by_cpu_rule (const void *p1, const void *p2)
{
const cpu_rule_t *r1 = (const cpu_rule_t *) p1;
const cpu_rule_t *r2 = (const cpu_rule_t *) p2;
9 years ago
return memcmp (r1, r2, sizeof (cpu_rule_t));
}
9 years ago
int sort_by_kernel_rule (const void *p1, const void *p2)
{
const kernel_rule_t *r1 = (const kernel_rule_t *) p1;
const kernel_rule_t *r2 = (const kernel_rule_t *) p2;
9 years ago
return memcmp (r1, r2, sizeof (kernel_rule_t));
}
9 years ago
int sort_by_stringptr (const void *p1, const void *p2)
{
const char **s1 = (const char **) p1;
const char **s2 = (const char **) p2;
9 years ago
return strcmp (*s1, *s2);
}
9 years ago
int sort_by_dictstat (const void *s1, const void *s2)
{
dictstat_t *d1 = (dictstat_t *) s1;
dictstat_t *d2 = (dictstat_t *) s2;
9 years ago
#if defined (__linux__)
d2->stat.st_atim = d1->stat.st_atim;
#else
d2->stat.st_atime = d1->stat.st_atime;
#endif
9 years ago
return memcmp (&d1->stat, &d2->stat, sizeof (struct stat));
}
9 years ago
int sort_by_digest_4_2 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 2;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_4_4 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 4;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_4_5 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 5;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_4_6 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 6;
9 years ago
while (n--)
9 years ago
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
9 years ago
}
return 0;
}
9 years ago
int sort_by_digest_4_8 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 8;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_4_16 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 16;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
9 years ago
}
int sort_by_digest_4_32 (const void *v1, const void *v2)
9 years ago
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 32;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_4_64 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
uint n = 64;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_8_8 (const void *v1, const void *v2)
{
const u64 *d1 = (const u64 *) v1;
const u64 *d2 = (const u64 *) v2;
9 years ago
uint n = 8;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_8_16 (const void *v1, const void *v2)
{
const u64 *d1 = (const u64 *) v1;
const u64 *d2 = (const u64 *) v2;
9 years ago
uint n = 16;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_8_25 (const void *v1, const void *v2)
{
const u64 *d1 = (const u64 *) v1;
const u64 *d2 = (const u64 *) v2;
9 years ago
uint n = 25;
9 years ago
while (n--)
{
if (d1[n] > d2[n]) return ( 1);
if (d1[n] < d2[n]) return -1;
}
9 years ago
return 0;
}
9 years ago
int sort_by_digest_p0p1 (const void *v1, const void *v2)
{
const u32 *d1 = (const u32 *) v1;
const u32 *d2 = (const u32 *) v2;
9 years ago
const uint dgst_pos0 = data.dgst_pos0;
const uint dgst_pos1 = data.dgst_pos1;
const uint dgst_pos2 = data.dgst_pos2;
const uint dgst_pos3 = data.dgst_pos3;
9 years ago
if (d1[dgst_pos3] > d2[dgst_pos3]) return ( 1);
if (d1[dgst_pos3] < d2[dgst_pos3]) return -1;
if (d1[dgst_pos2] > d2[dgst_pos2]) return ( 1);
if (d1[dgst_pos2] < d2[dgst_pos2]) return -1;
if (d1[dgst_pos1] > d2[dgst_pos1]) return ( 1);
if (d1[dgst_pos1] < d2[dgst_pos1]) return -1;
if (d1[dgst_pos0] > d2[dgst_pos0]) return ( 1);
if (d1[dgst_pos0] < d2[dgst_pos0]) return -1;
9 years ago
return 0;
}
9 years ago
void format_debug (char *debug_file, uint debug_mode, unsigned char *orig_plain_ptr, uint orig_plain_len, unsigned char *mod_plain_ptr, uint mod_plain_len, char *rule_buf, int rule_len)
9 years ago
{
uint outfile_autohex = data.outfile_autohex;
9 years ago
unsigned char *rule_ptr = (unsigned char *) rule_buf;
9 years ago
FILE *debug_fp = NULL;
9 years ago
if (debug_file != NULL)
{
debug_fp = fopen (debug_file, "ab");
9 years ago
lock_file (debug_fp);
}
else
{
debug_fp = stderr;
}
9 years ago
if (debug_fp == NULL)
{
log_info ("WARNING: Could not open debug-file for writing");
}
else
{
if ((debug_mode == 2) || (debug_mode == 3) || (debug_mode == 4))
{
format_plain (debug_fp, orig_plain_ptr, orig_plain_len, outfile_autohex);
9 years ago
if ((debug_mode == 3) || (debug_mode == 4)) fputc (':', debug_fp);
}
9 years ago
fwrite (rule_ptr, rule_len, 1, debug_fp);
9 years ago
if (debug_mode == 4)
{
fputc (':', debug_fp);
9 years ago
format_plain (debug_fp, mod_plain_ptr, mod_plain_len, outfile_autohex);
}
9 years ago
fputc ('\n', debug_fp);
9 years ago
if (debug_file != NULL) fclose (debug_fp);
}
}
9 years ago
void format_plain (FILE *fp, unsigned char *plain_ptr, uint plain_len, uint outfile_autohex)
{
int needs_hexify = 0;
9 years ago
if (outfile_autohex == 1)
{
for (uint i = 0; i < plain_len; i++)
{
if (plain_ptr[i] < 0x20)
{
needs_hexify = 1;
9 years ago
break;
}
9 years ago
if (plain_ptr[i] > 0x7f)
{
needs_hexify = 1;
9 years ago
break;
}
}
}
9 years ago
if (needs_hexify == 1)
{
fprintf (fp, "$HEX[");
9 years ago
for (uint i = 0; i < plain_len; i++)
{
fprintf (fp, "%02x", plain_ptr[i]);
}
9 years ago
fprintf (fp, "]");
}
else
{
fwrite (plain_ptr, plain_len, 1, fp);
}
}
9 years ago
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)
{
uint outfile_format = data.outfile_format;
9 years ago
char separator = data.separator;
9 years ago
if (outfile_format & OUTFILE_FMT_HASH)
{
fprintf (out_fp, "%s", out_buf);
9 years ago
if (outfile_format & (OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
{
fputc (separator, out_fp);
}
}
else if (data.username)
{
if (username != NULL)
{
for (uint i = 0; i < user_len; i++)
{
fprintf (out_fp, "%c", username[i]);
}
9 years ago
if (outfile_format & (OUTFILE_FMT_PLAIN | OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
{
fputc (separator, out_fp);
}
}
}
9 years ago
if (outfile_format & OUTFILE_FMT_PLAIN)
{
format_plain (out_fp, plain_ptr, plain_len, data.outfile_autohex);
9 years ago
if (outfile_format & (OUTFILE_FMT_HEXPLAIN | OUTFILE_FMT_CRACKPOS))
{
fputc (separator, out_fp);
}
}
9 years ago
if (outfile_format & OUTFILE_FMT_HEXPLAIN)
{
for (uint i = 0; i < plain_len; i++)
{
fprintf (out_fp, "%02x", plain_ptr[i]);
}
9 years ago
if (outfile_format & (OUTFILE_FMT_CRACKPOS))
{
fputc (separator, out_fp);
}
}
9 years ago
if (outfile_format & OUTFILE_FMT_CRACKPOS)
{
fprintf (out_fp, "%" PRIu64, crackpos);
}
9 years ago
fputs (EOL, out_fp);
9 years ago
}
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)
9 years ago
{
pot_t pot_key;
9 years ago
pot_key.hash.salt = hashes_buf->salt;
pot_key.hash.digest = hashes_buf->digest;
9 years ago
pot_t *pot_ptr = (pot_t *) bsearch (&pot_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
9 years ago
if (pot_ptr)
{
log_info_nn ("");
9 years ago
input_buf[input_len] = 0;
9 years ago
// user
unsigned char *username = NULL;
uint user_len = 0;
9 years ago
if (data.username)
{
user_t *user = hashes_buf->hash_info->user;
9 years ago
if (user)
{
username = (unsigned char *) (user->user_name);
9 years ago
user_len = user->user_len;
}
}
9 years ago
// do output the line
format_output (out_fp, input_buf, (unsigned char *) pot_ptr->plain_buf, pot_ptr->plain_len, 0, username, user_len);
}
}
9 years ago
#define LM_WEAK_HASH "\x4e\xcf\x0d\x0c\x0a\xe2\xfb\xc1"
#define LM_MASKED_PLAIN "[notfound]"
9 years ago
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)
{
// left
9 years ago
pot_t pot_left_key;
9 years ago
pot_left_key.hash.salt = hash_left->salt;
pot_left_key.hash.digest = hash_left->digest;
9 years ago
pot_t *pot_left_ptr = (pot_t *) bsearch (&pot_left_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
9 years ago
// right
9 years ago
uint weak_hash_found = 0;
9 years ago
pot_t pot_right_key;
9 years ago
pot_right_key.hash.salt = hash_right->salt;
pot_right_key.hash.digest = hash_right->digest;
9 years ago
pot_t *pot_right_ptr = (pot_t *) bsearch (&pot_right_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
9 years ago
if (pot_right_ptr == NULL)
{
// special case, if "weak hash"
9 years ago
if (memcmp (hash_right->digest, LM_WEAK_HASH, 8) == 0)
{
weak_hash_found = 1;
9 years ago
pot_right_ptr = (pot_t *) mycalloc (1, sizeof (pot_t));
9 years ago
// in theory this is not needed, but we are paranoia:
9 years ago
memset (pot_right_ptr->plain_buf, 0, sizeof (pot_right_ptr->plain_buf));
pot_right_ptr->plain_len = 0;
}
}
9 years ago
if ((pot_left_ptr == NULL) && (pot_right_ptr == NULL))
{
if (weak_hash_found == 1) myfree (pot_right_ptr); // this shouldn't happen at all: if weak_hash_found == 1, than pot_right_ptr is not NULL for sure
9 years ago
return;
}
9 years ago
// at least one half was found:
9 years ago
log_info_nn ("");
9 years ago
input_buf[input_len] = 0;
9 years ago
// user
9 years ago
unsigned char *username = NULL;
uint user_len = 0;
9 years ago
if (data.username)
{
user_t *user = hash_left->hash_info->user;
9 years ago
if (user)
{
username = (unsigned char *) (user->user_name);
9 years ago
user_len = user->user_len;
}
}
9 years ago
// mask the part which was not found
9 years ago
uint left_part_masked = 0;
uint right_part_masked = 0;
9 years ago
uint mask_plain_len = strlen (LM_MASKED_PLAIN);
9 years ago
if (pot_left_ptr == NULL)
{
left_part_masked = 1;
9 years ago
pot_left_ptr = (pot_t *) mycalloc (1, sizeof (pot_t));
9 years ago
memset (pot_left_ptr->plain_buf, 0, sizeof (pot_left_ptr->plain_buf));
9 years ago
memcpy (pot_left_ptr->plain_buf, LM_MASKED_PLAIN, mask_plain_len);
pot_left_ptr->plain_len = mask_plain_len;
}
9 years ago
if (pot_right_ptr == NULL)
{
right_part_masked = 1;
9 years ago
pot_right_ptr = (pot_t *) mycalloc (1, sizeof (pot_t));
9 years ago
memset (pot_right_ptr->plain_buf, 0, sizeof (pot_right_ptr->plain_buf));
9 years ago
memcpy (pot_right_ptr->plain_buf, LM_MASKED_PLAIN, mask_plain_len);
pot_right_ptr->plain_len = mask_plain_len;
}
9 years ago
// create the pot_ptr out of pot_left_ptr and pot_right_ptr
9 years ago
pot_t pot_ptr;
9 years ago
pot_ptr.plain_len = pot_left_ptr->plain_len + pot_right_ptr->plain_len;
9 years ago
memcpy (pot_ptr.plain_buf, pot_left_ptr->plain_buf, pot_left_ptr->plain_len);
9 years ago
memcpy (pot_ptr.plain_buf + pot_left_ptr->plain_len, pot_right_ptr->plain_buf, pot_right_ptr->plain_len);
9 years ago
// do output the line
9 years ago
format_output (out_fp, input_buf, (unsigned char *) pot_ptr.plain_buf, pot_ptr.plain_len, 0, username, user_len);
9 years ago
if (weak_hash_found == 1) myfree (pot_right_ptr);
9 years ago
if (left_part_masked == 1) myfree (pot_left_ptr);
if (right_part_masked == 1) myfree (pot_right_ptr);
9 years ago
}
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)
9 years ago
{
pot_t pot_key;
9 years ago
memcpy (&pot_key.hash, hashes_buf, sizeof (hash_t));
9 years ago
pot_t *pot_ptr = (pot_t *) bsearch (&pot_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
9 years ago
if (pot_ptr == NULL)
{
log_info_nn ("");
9 years ago
input_buf[input_len] = 0;
9 years ago
format_output (out_fp, input_buf, NULL, 0, 0, NULL, 0);
}
}
9 years ago
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)
{
// left
9 years ago
pot_t pot_left_key;
9 years ago
memcpy (&pot_left_key.hash, hash_left, sizeof (hash_t));
9 years ago
pot_t *pot_left_ptr = (pot_t *) bsearch (&pot_left_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
9 years ago
// right
9 years ago
pot_t pot_right_key;
9 years ago
memcpy (&pot_right_key.hash, hash_right, sizeof (hash_t));
9 years ago
pot_t *pot_right_ptr = (pot_t *) bsearch (&pot_right_key, pot, pot_cnt, sizeof (pot_t), sort_by_pot);
9 years ago
uint weak_hash_found = 0;
9 years ago
if (pot_right_ptr == NULL)
{
// special case, if "weak hash"
9 years ago
if (memcmp (hash_right->digest, LM_WEAK_HASH, 8) == 0)
{
weak_hash_found = 1;
9 years ago
// we just need that pot_right_ptr is not a NULL pointer
9 years ago
pot_right_ptr = (pot_t *) mycalloc (1, sizeof (pot_t));
}
}
9 years ago
if ((pot_left_ptr != NULL) && (pot_right_ptr != NULL))
{
if (weak_hash_found == 1) myfree (pot_right_ptr);
9 years ago
return;
}
9 years ago
// ... at least one part was not cracked
9 years ago
log_info_nn ("");
9 years ago
input_buf[input_len] = 0;
9 years ago
// only show the hash part which is still not cracked
9 years ago
uint user_len = (uint)input_len - 32u;
9 years ago
char *hash_output = (char *) mymalloc (33);
9 years ago
memcpy (hash_output, input_buf, input_len);
9 years ago
if (pot_left_ptr != NULL)
{
// only show right part (because left part was already found)
9 years ago
memcpy (hash_output + user_len, input_buf + user_len + 16, 16);
9 years ago
hash_output[user_len + 16] = 0;
}
9 years ago
if (pot_right_ptr != NULL)
{
// only show left part (because right part was already found)
9 years ago
memcpy (hash_output + user_len, input_buf + user_len, 16);
9 years ago
hash_output[user_len + 16] = 0;
}
9 years ago
format_output (out_fp, hash_output, NULL, 0, 0, NULL, 0);
9 years ago
myfree (hash_output);
9 years ago
if (weak_hash_found == 1) myfree (pot_right_ptr);
}