2016-09-08 12:36:15 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-08 12:36:15 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "types.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "filehandling.h"
|
|
|
|
#include "hlfmt.h"
|
|
|
|
|
2017-11-13 20:05:40 +00:00
|
|
|
static const char *HLFMT_TEXT_HASHCAT = "native hashcat";
|
|
|
|
static const char *HLFMT_TEXT_PWDUMP = "pwdump";
|
|
|
|
static const char *HLFMT_TEXT_PASSWD = "passwd";
|
|
|
|
static const char *HLFMT_TEXT_SHADOW = "shadow";
|
|
|
|
static const char *HLFMT_TEXT_DCC = "DCC";
|
|
|
|
static const char *HLFMT_TEXT_DCC2 = "DCC 2";
|
|
|
|
static const char *HLFMT_TEXT_NETNTLM1 = "NetNTLMv1";
|
|
|
|
static const char *HLFMT_TEXT_NETNTLM2 = "NetNTLMv2";
|
|
|
|
static const char *HLFMT_TEXT_NSLDAP = "nsldap";
|
|
|
|
static const char *HLFMT_TEXT_NSLDAPS = "nsldaps";
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
// hlfmt hashcat
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_hash_hashcat (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **hashbuf_pos, size_t *hashbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
const user_options_t *user_options = hashcat_ctx->user_options;
|
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
|
2016-09-22 09:56:06 +00:00
|
|
|
if (user_options->username == 0)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
*hashbuf_pos = line_buf;
|
|
|
|
*hashbuf_len = line_len;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
char *pos = line_buf;
|
|
|
|
size_t len = line_len;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++, pos++, len--)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-09-09 14:54:48 +00:00
|
|
|
if (line_buf[i] == hashconfig->separator)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
pos++;
|
|
|
|
|
|
|
|
len--;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*hashbuf_pos = pos;
|
|
|
|
*hashbuf_len = len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_user_hashcat (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **userbuf_pos, size_t *userbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
char *pos = NULL;
|
|
|
|
size_t len = 0;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-09-09 14:54:48 +00:00
|
|
|
if (line_buf[i] == hashconfig->separator)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 0)
|
|
|
|
{
|
|
|
|
if (pos == NULL) pos = line_buf + i;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*userbuf_pos = pos;
|
|
|
|
*userbuf_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hlfmt pwdump
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static int hlfmt_detect_pwdump (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, const char *line_buf, size_t line_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
|
|
|
int sep2_len = 0;
|
|
|
|
int sep3_len = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 2) sep2_len++;
|
|
|
|
if (sep_cnt == 3) sep3_len++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sep_cnt == 6) && ((sep2_len == 32) || (sep3_len == 32))) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_hash_pwdump (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **hashbuf_pos, size_t *hashbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
char *pos = NULL;
|
|
|
|
size_t len = 0;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-09-09 14:54:48 +00:00
|
|
|
if (hashconfig->hash_mode == 1000)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (sep_cnt == 3)
|
|
|
|
{
|
|
|
|
if (pos == NULL) pos = line_buf + i;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
2016-09-09 14:54:48 +00:00
|
|
|
else if (hashconfig->hash_mode == 3000)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (sep_cnt == 2)
|
|
|
|
{
|
|
|
|
if (pos == NULL) pos = line_buf + i;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*hashbuf_pos = pos;
|
|
|
|
*hashbuf_len = len;
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_user_pwdump (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **userbuf_pos, size_t *userbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
char *pos = NULL;
|
|
|
|
size_t len = 0;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 0)
|
|
|
|
{
|
|
|
|
if (pos == NULL) pos = line_buf + i;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*userbuf_pos = pos;
|
|
|
|
*userbuf_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hlfmt passwd
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static int hlfmt_detect_passwd (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, const char *line_buf, size_t line_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
|
|
|
char sep5_first = 0;
|
|
|
|
char sep6_first = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 5) if (sep5_first == 0) sep5_first = line_buf[i];
|
|
|
|
if (sep_cnt == 6) if (sep6_first == 0) sep6_first = line_buf[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sep_cnt == 6) && ((sep5_first == '/') || (sep6_first == '/'))) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_hash_passwd (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **hashbuf_pos, size_t *hashbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
char *pos = NULL;
|
|
|
|
size_t len = 0;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 1)
|
|
|
|
{
|
|
|
|
if (pos == NULL) pos = line_buf + i;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*hashbuf_pos = pos;
|
|
|
|
*hashbuf_len = len;
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_user_passwd (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **userbuf_pos, size_t *userbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
char *pos = NULL;
|
|
|
|
size_t len = 0;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':')
|
|
|
|
{
|
|
|
|
sep_cnt++;
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 0)
|
|
|
|
{
|
|
|
|
if (pos == NULL) pos = line_buf + i;
|
|
|
|
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*userbuf_pos = pos;
|
|
|
|
*userbuf_len = len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// hlfmt shadow
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static int hlfmt_detect_shadow (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, const char *line_buf, size_t line_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
int sep_cnt = 0;
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
for (size_t i = 0; i < line_len; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (line_buf[i] == ':') sep_cnt++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sep_cnt == 8) return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_hash_shadow (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **hashbuf_pos, size_t *hashbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
hlfmt_hash_passwd (hashcat_ctx, line_buf, line_len, hashbuf_pos, hashbuf_len);
|
2016-09-08 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
static void hlfmt_user_shadow (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, char *line_buf, size_t line_len, char **userbuf_pos, size_t *userbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
hlfmt_user_passwd (hashcat_ctx, line_buf, line_len, userbuf_pos, userbuf_len);
|
2016-09-08 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// hlfmt main
|
|
|
|
|
2017-11-14 04:46:26 +00:00
|
|
|
const char *strhlfmt (const u32 hashfile_format)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
switch (hashfile_format)
|
|
|
|
{
|
2017-11-14 04:46:26 +00:00
|
|
|
case HLFMT_HASHCAT: return HLFMT_TEXT_HASHCAT;
|
|
|
|
case HLFMT_PWDUMP: return HLFMT_TEXT_PWDUMP;
|
|
|
|
case HLFMT_PASSWD: return HLFMT_TEXT_PASSWD;
|
|
|
|
case HLFMT_SHADOW: return HLFMT_TEXT_SHADOW;
|
|
|
|
case HLFMT_DCC: return HLFMT_TEXT_DCC;
|
|
|
|
case HLFMT_DCC2: return HLFMT_TEXT_DCC2;
|
|
|
|
case HLFMT_NETNTLM1: return HLFMT_TEXT_NETNTLM1;
|
|
|
|
case HLFMT_NETNTLM2: return HLFMT_TEXT_NETNTLM2;
|
|
|
|
case HLFMT_NSLDAP: return HLFMT_TEXT_NSLDAP;
|
|
|
|
case HLFMT_NSLDAPS: return HLFMT_TEXT_NSLDAPS;
|
2016-09-08 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-14 04:46:26 +00:00
|
|
|
return "Unknown";
|
2016-09-08 12:36:15 +00:00
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
void hlfmt_hash (hashcat_ctx_t *hashcat_ctx, u32 hashfile_format, char *line_buf, size_t line_len, char **hashbuf_pos, size_t *hashbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
switch (hashfile_format)
|
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
case HLFMT_HASHCAT: hlfmt_hash_hashcat (hashcat_ctx, line_buf, line_len, hashbuf_pos, hashbuf_len); break;
|
|
|
|
case HLFMT_PWDUMP: hlfmt_hash_pwdump (hashcat_ctx, line_buf, line_len, hashbuf_pos, hashbuf_len); break;
|
|
|
|
case HLFMT_PASSWD: hlfmt_hash_passwd (hashcat_ctx, line_buf, line_len, hashbuf_pos, hashbuf_len); break;
|
|
|
|
case HLFMT_SHADOW: hlfmt_hash_shadow (hashcat_ctx, line_buf, line_len, hashbuf_pos, hashbuf_len); break;
|
2016-09-08 12:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-08 18:13:29 +00:00
|
|
|
void hlfmt_user (hashcat_ctx_t *hashcat_ctx, u32 hashfile_format, char *line_buf, size_t line_len, char **userbuf_pos, size_t *userbuf_len)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
switch (hashfile_format)
|
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
case HLFMT_HASHCAT: hlfmt_user_hashcat (hashcat_ctx, line_buf, line_len, userbuf_pos, userbuf_len); break;
|
|
|
|
case HLFMT_PWDUMP: hlfmt_user_pwdump (hashcat_ctx, line_buf, line_len, userbuf_pos, userbuf_len); break;
|
|
|
|
case HLFMT_PASSWD: hlfmt_user_passwd (hashcat_ctx, line_buf, line_len, userbuf_pos, userbuf_len); break;
|
|
|
|
case HLFMT_SHADOW: hlfmt_user_shadow (hashcat_ctx, line_buf, line_len, userbuf_pos, userbuf_len); break;
|
2016-09-08 12:36:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-06 19:12:32 +00:00
|
|
|
u32 hlfmt_detect (hashcat_ctx_t *hashcat_ctx, FILE *fp, u32 max_check)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
2016-10-06 19:12:32 +00:00
|
|
|
const hashconfig_t *hashconfig = hashcat_ctx->hashconfig;
|
|
|
|
|
2016-09-08 12:36:15 +00:00
|
|
|
// Exception: those formats are wrongly detected as HLFMT_SHADOW, prevent it
|
|
|
|
|
2016-09-09 14:54:48 +00:00
|
|
|
if (hashconfig->hash_mode == 5300) return HLFMT_HASHCAT;
|
|
|
|
if (hashconfig->hash_mode == 5400) return HLFMT_HASHCAT;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
u32 *formats_cnt = (u32 *) hccalloc (HLFMTS_CNT, sizeof (u32));
|
2016-09-08 12:36:15 +00:00
|
|
|
|
2016-10-04 04:35:49 +00:00
|
|
|
u32 num_check = 0;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
2016-11-20 21:54:52 +00:00
|
|
|
char *line_buf = (char *) hcmalloc (HCBUFSIZ_LARGE);
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
while (!feof (fp))
|
|
|
|
{
|
2018-02-08 18:13:29 +00:00
|
|
|
const size_t line_len = fgetl (fp, line_buf);
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
if (line_len == 0) continue;
|
|
|
|
|
2016-10-06 19:12:32 +00:00
|
|
|
if (hlfmt_detect_pwdump (hashcat_ctx, line_buf, line_len)) formats_cnt[HLFMT_PWDUMP]++;
|
|
|
|
if (hlfmt_detect_passwd (hashcat_ctx, line_buf, line_len)) formats_cnt[HLFMT_PASSWD]++;
|
|
|
|
if (hlfmt_detect_shadow (hashcat_ctx, line_buf, line_len)) formats_cnt[HLFMT_SHADOW]++;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
|
|
|
if (num_check == max_check) break;
|
|
|
|
|
|
|
|
num_check++;
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
hcfree (line_buf);
|
2016-09-08 12:36:15 +00:00
|
|
|
|
2016-09-30 16:19:42 +00:00
|
|
|
u32 hashlist_format = HLFMT_HASHCAT;
|
2016-09-08 12:36:15 +00:00
|
|
|
|
2016-09-30 16:19:42 +00:00
|
|
|
for (u32 i = 1; i < HLFMTS_CNT; i++)
|
2016-09-08 12:36:15 +00:00
|
|
|
{
|
|
|
|
if (formats_cnt[i - 1] >= formats_cnt[i]) continue;
|
|
|
|
|
|
|
|
hashlist_format = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
free (formats_cnt);
|
|
|
|
|
|
|
|
return hashlist_format;
|
|
|
|
}
|