Move hlfmt specific functions into their own source file

pull/496/head
jsteube 8 years ago
parent 515f22626a
commit da8e9d50d9

@ -0,0 +1,18 @@
/**
* Author......: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#ifndef _HLFMT_H
#define _HLFMT_H
#include <stdio.h>
char *strhlfmt (const uint hashfile_format);
void hlfmt_hash (uint hashfile_format, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len);
void hlfmt_user (uint hashfile_format, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len);
uint hlfmt_detect (FILE *fp, uint max_check);
#endif // _HLFMT_H

@ -166,7 +166,7 @@ LFLAGS_CROSS_WIN := -lpsapi
## Objects
##
NATIVE_OBJS := obj/status.NATIVE.o obj/restore.NATIVE.o obj/bitmap.NATIVE.o obj/opencl.NATIVE.o obj/affinity.NATIVE.o obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
NATIVE_OBJS := obj/hlfmt.NATIVE.o obj/status.NATIVE.o obj/restore.NATIVE.o obj/bitmap.NATIVE.o obj/opencl.NATIVE.o obj/affinity.NATIVE.o obj/filehandling.NATIVE.o obj/tuningdb.NATIVE.o obj/locking.NATIVE.o obj/folder.NATIVE.o obj/bitops.NATIVE.o obj/convert.NATIVE.o obj/cpu_aes.NATIVE.o obj/cpu_crc32.NATIVE.o obj/cpu_des.NATIVE.o obj/cpu_md5.NATIVE.o obj/cpu_sha1.NATIVE.o obj/cpu_sha256.NATIVE.o obj/data.NATIVE.o obj/ext_OpenCL.NATIVE.o obj/hwmon.NATIVE.o obj/interface.NATIVE.o obj/logfile.NATIVE.o obj/logging.NATIVE.o obj/memory.NATIVE.o obj/mpsp.NATIVE.o obj/rp_cpu.NATIVE.o obj/rp_kernel_on_cpu.NATIVE.o obj/shared.NATIVE.o obj/terminal.NATIVE.o obj/usage.NATIVE.o
ifeq ($(UNAME),Linux)
NATIVE_OBJS += obj/ext_ADL.NATIVE.o
@ -175,8 +175,8 @@ NATIVE_OBJS += obj/ext_nvml.NATIVE.o
NATIVE_OBJS += obj/ext_xnvctrl.NATIVE.o
endif
LINUX_32_OBJS := obj/status.LINUX.32.o obj/restore.LINUX.32.o obj/bitmap.LINUX.32.o obj/opencl.LINUX.32.o obj/affinity.LINUX.32.o obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
LINUX_64_OBJS := obj/status.LINUX.64.o obj/restore.LINUX.64.o obj/bitmap.LINUX.64.o obj/opencl.LINUX.64.o obj/affinity.LINUX.64.o obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
LINUX_32_OBJS := obj/hlfmt.LINUX.32.o obj/status.LINUX.32.o obj/restore.LINUX.32.o obj/bitmap.LINUX.32.o obj/opencl.LINUX.32.o obj/affinity.LINUX.32.o obj/filehandling.LINUX.32.o obj/tuningdb.LINUX.32.o obj/locking.LINUX.32.o obj/folder.LINUX.32.o obj/bitops.LINUX.32.o obj/convert.LINUX.32.o obj/cpu_aes.LINUX.32.o obj/cpu_crc32.LINUX.32.o obj/cpu_des.LINUX.32.o obj/cpu_md5.LINUX.32.o obj/cpu_sha1.LINUX.32.o obj/cpu_sha256.LINUX.32.o obj/data.LINUX.32.o obj/ext_ADL.LINUX.32.o obj/ext_nvapi.LINUX.32.o obj/ext_nvml.LINUX.32.o obj/ext_OpenCL.LINUX.32.o obj/ext_xnvctrl.LINUX.32.o obj/hwmon.LINUX.32.o obj/interface.LINUX.32.o obj/logfile.LINUX.32.o obj/logging.LINUX.32.o obj/memory.LINUX.32.o obj/mpsp.LINUX.32.o obj/rp_cpu.LINUX.32.o obj/rp_kernel_on_cpu.LINUX.32.o obj/shared.LINUX.32.o obj/terminal.LINUX.32.o obj/usage.LINUX.32.o
LINUX_64_OBJS := obj/hlfmt.LINUX.64.o obj/status.LINUX.64.o obj/restore.LINUX.64.o obj/bitmap.LINUX.64.o obj/opencl.LINUX.64.o obj/affinity.LINUX.64.o obj/filehandling.LINUX.64.o obj/tuningdb.LINUX.64.o obj/locking.LINUX.64.o obj/folder.LINUX.64.o obj/bitops.LINUX.64.o obj/convert.LINUX.64.o obj/cpu_aes.LINUX.64.o obj/cpu_crc32.LINUX.64.o obj/cpu_des.LINUX.64.o obj/cpu_md5.LINUX.64.o obj/cpu_sha1.LINUX.64.o obj/cpu_sha256.LINUX.64.o obj/data.LINUX.64.o obj/ext_ADL.LINUX.64.o obj/ext_nvapi.LINUX.64.o obj/ext_nvml.LINUX.64.o obj/ext_OpenCL.LINUX.64.o obj/ext_xnvctrl.LINUX.64.o obj/hwmon.LINUX.64.o obj/interface.LINUX.64.o obj/logfile.LINUX.64.o obj/logging.LINUX.64.o obj/memory.LINUX.64.o obj/mpsp.LINUX.64.o obj/rp_cpu.LINUX.64.o obj/rp_kernel_on_cpu.LINUX.64.o obj/shared.LINUX.64.o obj/terminal.LINUX.64.o obj/usage.LINUX.64.o
# Windows CRT file globbing:
@ -186,8 +186,8 @@ CRT_GLOB_INCLUDE_FOLDER := $(dir $(lastword $(MAKEFILE_LIST)))
include $(CRT_GLOB_INCLUDE_FOLDER)/win_file_globbing.mk
WIN_32_OBJS := obj/status.WIN.32.o obj/restore.WIN.32.o obj/bitmap.WIN.32.o obj/opencl.WIN.32.o obj/affinity.WIN.32.o obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/status.WIN.64.o obj/restore.WIN.64.o obj/bitmap.WIN.64.o obj/opencl.WIN.64.o obj/affinity.WIN.64.o obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
WIN_32_OBJS := obj/hlfmt.WIN.32.o obj/status.WIN.32.o obj/restore.WIN.32.o obj/bitmap.WIN.32.o obj/opencl.WIN.32.o obj/affinity.WIN.32.o obj/filehandling.WIN.32.o obj/tuningdb.WIN.32.o obj/locking.WIN.32.o obj/folder.WIN.32.o obj/bitops.WIN.32.o obj/convert.WIN.32.o obj/cpu_aes.WIN.32.o obj/cpu_crc32.WIN.32.o obj/cpu_des.WIN.32.o obj/cpu_md5.WIN.32.o obj/cpu_sha1.WIN.32.o obj/cpu_sha256.WIN.32.o obj/data.WIN.32.o obj/ext_ADL.WIN.32.o obj/ext_nvapi.WIN.32.o obj/ext_nvml.WIN.32.o obj/ext_OpenCL.WIN.32.o obj/ext_xnvctrl.WIN.32.o obj/hwmon.WIN.32.o obj/interface.WIN.32.o obj/logfile.WIN.32.o obj/logging.WIN.32.o obj/memory.WIN.32.o obj/mpsp.WIN.32.o obj/rp_cpu.WIN.32.o obj/rp_kernel_on_cpu.WIN.32.o obj/shared.WIN.32.o obj/terminal.WIN.32.o obj/usage.WIN.32.o $(CRT_GLOB_32)
WIN_64_OBJS := obj/hlfmt.WIN.64.o obj/status.WIN.64.o obj/restore.WIN.64.o obj/bitmap.WIN.64.o obj/opencl.WIN.64.o obj/affinity.WIN.64.o obj/filehandling.WIN.64.o obj/tuningdb.WIN.64.o obj/locking.WIN.64.o obj/folder.WIN.64.o obj/bitops.WIN.64.o obj/convert.WIN.64.o obj/cpu_aes.WIN.64.o obj/cpu_crc32.WIN.64.o obj/cpu_des.WIN.64.o obj/cpu_md5.WIN.64.o obj/cpu_sha1.WIN.64.o obj/cpu_sha256.WIN.64.o obj/data.WIN.64.o obj/ext_ADL.WIN.64.o obj/ext_nvapi.WIN.64.o obj/ext_nvml.WIN.64.o obj/ext_OpenCL.WIN.64.o obj/ext_xnvctrl.WIN.64.o obj/hwmon.WIN.64.o obj/interface.WIN.64.o obj/logfile.WIN.64.o obj/logging.WIN.64.o obj/memory.WIN.64.o obj/mpsp.WIN.64.o obj/rp_cpu.WIN.64.o obj/rp_kernel_on_cpu.WIN.64.o obj/shared.WIN.64.o obj/terminal.WIN.64.o obj/usage.WIN.64.o $(CRT_GLOB_64)
##
## Targets: Global

@ -65,6 +65,7 @@
#include "bitmap.h"
#include "usage.h"
#include "status.h"
#include "hlfmt.h"
extern hc_global_data_t data;
@ -142,16 +143,7 @@ static double TARGET_MS_PROFILE[4] = { 2, 12, 96, 480 };
#define SCRYPT_TMTO 0
#define OPENCL_VECTOR_WIDTH 0
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";
static const char OPTI_STR_ZERO_BYTE[] = "Zero-Byte";
static const char OPTI_STR_PRECOMPUTE_INIT[] = "Precompute-Init";
@ -5435,357 +5427,6 @@ static void weak_hash_check (hc_device_param_t *device_param, const uint salt_po
data.kernel_rules_buf[0].cmds[0] = cmd0_rule_old;
}
// hlfmt hashcat
static void hlfmt_hash_hashcat (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
if (data.username == 0)
{
*hashbuf_pos = line_buf;
*hashbuf_len = line_len;
}
else
{
char *pos = line_buf;
int len = line_len;
for (int i = 0; i < line_len; i++, pos++, len--)
{
if (line_buf[i] == data.separator)
{
pos++;
len--;
break;
}
}
*hashbuf_pos = pos;
*hashbuf_len = len;
}
}
static void hlfmt_user_hashcat (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
if (line_buf[i] == data.separator)
{
sep_cnt++;
continue;
}
if (sep_cnt == 0)
{
if (pos == NULL) pos = line_buf + i;
len++;
}
}
*userbuf_pos = pos;
*userbuf_len = len;
}
// hlfmt pwdump
static int hlfmt_detect_pwdump (char *line_buf, int line_len)
{
int sep_cnt = 0;
int sep2_len = 0;
int sep3_len = 0;
for (int i = 0; i < line_len; i++)
{
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;
}
static void hlfmt_hash_pwdump (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
if (line_buf[i] == ':')
{
sep_cnt++;
continue;
}
if (data.hash_mode == 1000)
{
if (sep_cnt == 3)
{
if (pos == NULL) pos = line_buf + i;
len++;
}
}
else if (data.hash_mode == 3000)
{
if (sep_cnt == 2)
{
if (pos == NULL) pos = line_buf + i;
len++;
}
}
}
*hashbuf_pos = pos;
*hashbuf_len = len;
}
static void hlfmt_user_pwdump (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
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
static int hlfmt_detect_passwd (char *line_buf, int line_len)
{
int sep_cnt = 0;
char sep5_first = 0;
char sep6_first = 0;
for (int i = 0; i < line_len; i++)
{
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;
}
static void hlfmt_hash_passwd (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
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;
}
static void hlfmt_user_passwd (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
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
static int hlfmt_detect_shadow (char *line_buf, int line_len)
{
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
if (line_buf[i] == ':') sep_cnt++;
}
if (sep_cnt == 8) return 1;
return 0;
}
static void hlfmt_hash_shadow (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
hlfmt_hash_passwd (line_buf, line_len, hashbuf_pos, hashbuf_len);
}
static void hlfmt_user_shadow (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
hlfmt_user_passwd (line_buf, line_len, userbuf_pos, userbuf_len);
}
// hlfmt main
static void hlfmt_hash (uint hashfile_format, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
switch (hashfile_format)
{
case HLFMT_HASHCAT: hlfmt_hash_hashcat (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
case HLFMT_PWDUMP: hlfmt_hash_pwdump (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
case HLFMT_PASSWD: hlfmt_hash_passwd (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
case HLFMT_SHADOW: hlfmt_hash_shadow (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
}
}
static void hlfmt_user (uint hashfile_format, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
switch (hashfile_format)
{
case HLFMT_HASHCAT: hlfmt_user_hashcat (line_buf, line_len, userbuf_pos, userbuf_len); break;
case HLFMT_PWDUMP: hlfmt_user_pwdump (line_buf, line_len, userbuf_pos, userbuf_len); break;
case HLFMT_PASSWD: hlfmt_user_passwd (line_buf, line_len, userbuf_pos, userbuf_len); break;
case HLFMT_SHADOW: hlfmt_user_shadow (line_buf, line_len, userbuf_pos, userbuf_len); break;
}
}
static char *strhlfmt (const uint hashfile_format)
{
switch (hashfile_format)
{
case HLFMT_HASHCAT: return ((char *) HLFMT_TEXT_HASHCAT);
case HLFMT_PWDUMP: return ((char *) HLFMT_TEXT_PWDUMP);
case HLFMT_PASSWD: return ((char *) HLFMT_TEXT_PASSWD);
case HLFMT_SHADOW: return ((char *) HLFMT_TEXT_SHADOW);
case HLFMT_DCC: return ((char *) HLFMT_TEXT_DCC);
case HLFMT_DCC2: return ((char *) HLFMT_TEXT_DCC2);
case HLFMT_NETNTLM1: return ((char *) HLFMT_TEXT_NETNTLM1);
case HLFMT_NETNTLM2: return ((char *) HLFMT_TEXT_NETNTLM2);
case HLFMT_NSLDAP: return ((char *) HLFMT_TEXT_NSLDAP);
case HLFMT_NSLDAPS: return ((char *) HLFMT_TEXT_NSLDAPS);
}
return ((char *) "Unknown");
}
static uint hlfmt_detect (FILE *fp, uint max_check)
{
// Exception: those formats are wrongly detected as HLFMT_SHADOW, prevent it
if (data.hash_mode == 5300) return HLFMT_HASHCAT;
if (data.hash_mode == 5400) return HLFMT_HASHCAT;
uint *formats_cnt = (uint *) mycalloc (HLFMTS_CNT, sizeof (uint));
uint num_check = 0;
char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE);
while (!feof (fp))
{
int line_len = fgetl (fp, line_buf);
if (line_len == 0) continue;
if (hlfmt_detect_pwdump (line_buf, line_len)) formats_cnt[HLFMT_PWDUMP]++;
if (hlfmt_detect_passwd (line_buf, line_len)) formats_cnt[HLFMT_PASSWD]++;
if (hlfmt_detect_shadow (line_buf, line_len)) formats_cnt[HLFMT_SHADOW]++;
if (num_check == max_check) break;
num_check++;
}
myfree (line_buf);
uint hashlist_format = HLFMT_HASHCAT;
for (int i = 1; i < HLFMTS_CNT; i++)
{
if (formats_cnt[i - 1] >= formats_cnt[i]) continue;
hashlist_format = i;
}
free (formats_cnt);
return hashlist_format;
}
int main (int argc, char **argv)
{

@ -0,0 +1,395 @@
/**
* Authors.....: Jens Steube <jens.steube@gmail.com>
* License.....: MIT
*/
#include "common.h"
#include "types_int.h"
#include "types.h"
#include "timer.h"
#include "bitops.h"
#include "memory.h"
#include "folder.h"
#include "convert.h"
#include "logging.h"
#include "logfile.h"
#include "ext_OpenCL.h"
#include "ext_ADL.h"
#include "ext_nvapi.h"
#include "ext_nvml.h"
#include "ext_xnvctrl.h"
#include "opencl.h"
#include "thread.h"
#include "filehandling.h"
#include "rp_cpu.h"
#include "inc_hash_constants.h"
#include "interface.h"
#include "shared.h"
#include "hwmon.h"
#include "mpsp.h"
#include "restore.h"
#include "data.h"
#include "hlfmt.h"
extern hc_global_data_t data;
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";
// hlfmt hashcat
static void hlfmt_hash_hashcat (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
if (data.username == 0)
{
*hashbuf_pos = line_buf;
*hashbuf_len = line_len;
}
else
{
char *pos = line_buf;
int len = line_len;
for (int i = 0; i < line_len; i++, pos++, len--)
{
if (line_buf[i] == data.separator)
{
pos++;
len--;
break;
}
}
*hashbuf_pos = pos;
*hashbuf_len = len;
}
}
static void hlfmt_user_hashcat (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
if (line_buf[i] == data.separator)
{
sep_cnt++;
continue;
}
if (sep_cnt == 0)
{
if (pos == NULL) pos = line_buf + i;
len++;
}
}
*userbuf_pos = pos;
*userbuf_len = len;
}
// hlfmt pwdump
static int hlfmt_detect_pwdump (char *line_buf, int line_len)
{
int sep_cnt = 0;
int sep2_len = 0;
int sep3_len = 0;
for (int i = 0; i < line_len; i++)
{
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;
}
static void hlfmt_hash_pwdump (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
if (line_buf[i] == ':')
{
sep_cnt++;
continue;
}
if (data.hash_mode == 1000)
{
if (sep_cnt == 3)
{
if (pos == NULL) pos = line_buf + i;
len++;
}
}
else if (data.hash_mode == 3000)
{
if (sep_cnt == 2)
{
if (pos == NULL) pos = line_buf + i;
len++;
}
}
}
*hashbuf_pos = pos;
*hashbuf_len = len;
}
static void hlfmt_user_pwdump (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
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
static int hlfmt_detect_passwd (char *line_buf, int line_len)
{
int sep_cnt = 0;
char sep5_first = 0;
char sep6_first = 0;
for (int i = 0; i < line_len; i++)
{
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;
}
static void hlfmt_hash_passwd (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
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;
}
static void hlfmt_user_passwd (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
char *pos = NULL;
int len = 0;
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
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
static int hlfmt_detect_shadow (char *line_buf, int line_len)
{
int sep_cnt = 0;
for (int i = 0; i < line_len; i++)
{
if (line_buf[i] == ':') sep_cnt++;
}
if (sep_cnt == 8) return 1;
return 0;
}
static void hlfmt_hash_shadow (char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
hlfmt_hash_passwd (line_buf, line_len, hashbuf_pos, hashbuf_len);
}
static void hlfmt_user_shadow (char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
hlfmt_user_passwd (line_buf, line_len, userbuf_pos, userbuf_len);
}
// hlfmt main
char *strhlfmt (const uint hashfile_format)
{
switch (hashfile_format)
{
case HLFMT_HASHCAT: return ((char *) HLFMT_TEXT_HASHCAT);
case HLFMT_PWDUMP: return ((char *) HLFMT_TEXT_PWDUMP);
case HLFMT_PASSWD: return ((char *) HLFMT_TEXT_PASSWD);
case HLFMT_SHADOW: return ((char *) HLFMT_TEXT_SHADOW);
case HLFMT_DCC: return ((char *) HLFMT_TEXT_DCC);
case HLFMT_DCC2: return ((char *) HLFMT_TEXT_DCC2);
case HLFMT_NETNTLM1: return ((char *) HLFMT_TEXT_NETNTLM1);
case HLFMT_NETNTLM2: return ((char *) HLFMT_TEXT_NETNTLM2);
case HLFMT_NSLDAP: return ((char *) HLFMT_TEXT_NSLDAP);
case HLFMT_NSLDAPS: return ((char *) HLFMT_TEXT_NSLDAPS);
}
return ((char *) "Unknown");
}
void hlfmt_hash (uint hashfile_format, char *line_buf, int line_len, char **hashbuf_pos, int *hashbuf_len)
{
switch (hashfile_format)
{
case HLFMT_HASHCAT: hlfmt_hash_hashcat (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
case HLFMT_PWDUMP: hlfmt_hash_pwdump (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
case HLFMT_PASSWD: hlfmt_hash_passwd (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
case HLFMT_SHADOW: hlfmt_hash_shadow (line_buf, line_len, hashbuf_pos, hashbuf_len); break;
}
}
void hlfmt_user (uint hashfile_format, char *line_buf, int line_len, char **userbuf_pos, int *userbuf_len)
{
switch (hashfile_format)
{
case HLFMT_HASHCAT: hlfmt_user_hashcat (line_buf, line_len, userbuf_pos, userbuf_len); break;
case HLFMT_PWDUMP: hlfmt_user_pwdump (line_buf, line_len, userbuf_pos, userbuf_len); break;
case HLFMT_PASSWD: hlfmt_user_passwd (line_buf, line_len, userbuf_pos, userbuf_len); break;
case HLFMT_SHADOW: hlfmt_user_shadow (line_buf, line_len, userbuf_pos, userbuf_len); break;
}
}
uint hlfmt_detect (FILE *fp, uint max_check)
{
// Exception: those formats are wrongly detected as HLFMT_SHADOW, prevent it
if (data.hash_mode == 5300) return HLFMT_HASHCAT;
if (data.hash_mode == 5400) return HLFMT_HASHCAT;
uint *formats_cnt = (uint *) mycalloc (HLFMTS_CNT, sizeof (uint));
uint num_check = 0;
char *line_buf = (char *) mymalloc (HCBUFSIZ_LARGE);
while (!feof (fp))
{
int line_len = fgetl (fp, line_buf);
if (line_len == 0) continue;
if (hlfmt_detect_pwdump (line_buf, line_len)) formats_cnt[HLFMT_PWDUMP]++;
if (hlfmt_detect_passwd (line_buf, line_len)) formats_cnt[HLFMT_PASSWD]++;
if (hlfmt_detect_shadow (line_buf, line_len)) formats_cnt[HLFMT_SHADOW]++;
if (num_check == max_check) break;
num_check++;
}
myfree (line_buf);
uint hashlist_format = HLFMT_HASHCAT;
for (int i = 1; i < HLFMTS_CNT; i++)
{
if (formats_cnt[i - 1] >= formats_cnt[i]) continue;
hashlist_format = i;
}
free (formats_cnt);
return hashlist_format;
}
Loading…
Cancel
Save