2015-12-04 14:47:52 +00:00
|
|
|
/**
|
2016-01-24 21:48:01 +00:00
|
|
|
* Authors.....: Jens Steube <jens.steube@gmail.com>
|
|
|
|
* Gabriele Gristina <matrix@hashcat.net>
|
2016-02-16 15:42:08 +00:00
|
|
|
* magnum <john.magnum@hushmail.com>
|
2016-01-24 21:48:01 +00:00
|
|
|
*
|
2015-12-04 14:47:52 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2016-09-05 19:47:26 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <fcntl.h>
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-05 19:47:26 +00:00
|
|
|
* OS specific includes
|
2015-12-04 14:47:52 +00:00
|
|
|
*/
|
|
|
|
|
2016-09-05 19:47:26 +00:00
|
|
|
#ifdef _POSIX
|
|
|
|
#include <pthread.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <limits.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/sysctl.h>
|
|
|
|
#endif // _POSIX
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-09-05 19:47:26 +00:00
|
|
|
#ifdef __APPLE__
|
|
|
|
#include <mach-o/dyld.h>
|
|
|
|
#include <mach/mach.h>
|
|
|
|
#endif // __APPLE__
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-09-05 19:47:26 +00:00
|
|
|
#ifdef _WIN
|
|
|
|
#include <windows.h>
|
|
|
|
#include <psapi.h>
|
|
|
|
#include <io.h>
|
|
|
|
#endif // _WIN
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-09-05 19:47:26 +00:00
|
|
|
/**
|
|
|
|
* unsorted
|
|
|
|
*/
|
2016-02-06 17:00:04 +00:00
|
|
|
|
2016-07-08 21:14:57 +00:00
|
|
|
#ifdef __APPLE__
|
2016-02-06 17:00:04 +00:00
|
|
|
typedef struct cpu_set
|
|
|
|
{
|
|
|
|
uint32_t count;
|
|
|
|
|
|
|
|
} cpu_set_t;
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-02-06 17:00:04 +00:00
|
|
|
static inline void CPU_ZERO (cpu_set_t *cs) { cs->count = 0; }
|
|
|
|
static inline void CPU_SET (int num, cpu_set_t *cs) { cs->count |= (1 << num); }
|
|
|
|
static inline int CPU_ISSET (int num, cpu_set_t *cs) { return (cs->count & (1 << num)); }
|
2015-12-04 14:47:52 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef _WIN
|
|
|
|
#define hc_sleep(x) Sleep ((x) * 1000);
|
|
|
|
#elif _POSIX
|
|
|
|
#define hc_sleep(x) sleep ((x));
|
|
|
|
#endif
|
|
|
|
|
2016-04-26 11:59:14 +00:00
|
|
|
#define ETC_MAX (60 * 60 * 24 * 365 * 10)
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-04-26 11:59:14 +00:00
|
|
|
#define BLOCK_SIZE 64
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-04-26 11:59:14 +00:00
|
|
|
#define INFOSZ CHARSIZ
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-05-10 17:07:07 +00:00
|
|
|
#define TUNING_DB_FILE "hashcat.hctune"
|
2016-02-10 19:40:21 +00:00
|
|
|
|
2016-04-26 11:59:14 +00:00
|
|
|
#define INDUCT_DIR "induct"
|
|
|
|
#define OUTFILES_DIR "outfiles"
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-04-26 11:59:14 +00:00
|
|
|
#define LOOPBACK_FILE "hashcat.loopback"
|
|
|
|
#define DICTSTAT_FILENAME "hashcat.dictstat"
|
|
|
|
#define POTFILE_FILENAME "hashcat.pot"
|
2016-04-03 13:46:05 +00:00
|
|
|
|
2015-12-04 14:47:52 +00:00
|
|
|
/**
|
|
|
|
* valid project specific global stuff
|
|
|
|
*/
|
|
|
|
|
|
|
|
extern const uint VERSION_BIN;
|
|
|
|
extern const uint RESTORE_MIN;
|
|
|
|
|
|
|
|
extern const char *USAGE_MINI[];
|
|
|
|
extern const char *USAGE_BIG[];
|
|
|
|
|
|
|
|
extern const char *PROMPT;
|
|
|
|
|
|
|
|
extern hc_thread_mutex_t mux_display;
|
|
|
|
|
2016-09-05 09:14:31 +00:00
|
|
|
static const char OPTI_STR_ZERO_BYTE[] = "Zero-Byte";
|
|
|
|
static const char OPTI_STR_PRECOMPUTE_INIT[] = "Precompute-Init";
|
|
|
|
static const char OPTI_STR_PRECOMPUTE_MERKLE[] = "Precompute-Merkle-Demgard";
|
|
|
|
static const char OPTI_STR_PRECOMPUTE_PERMUT[] = "Precompute-Final-Permutation";
|
|
|
|
static const char OPTI_STR_MEET_IN_MIDDLE[] = "Meet-In-The-Middle";
|
|
|
|
static const char OPTI_STR_EARLY_SKIP[] = "Early-Skip";
|
|
|
|
static const char OPTI_STR_NOT_SALTED[] = "Not-Salted";
|
|
|
|
static const char OPTI_STR_NOT_ITERATED[] = "Not-Iterated";
|
|
|
|
static const char OPTI_STR_PREPENDED_SALT[] = "Prepended-Salt";
|
|
|
|
static const char OPTI_STR_APPENDED_SALT[] = "Appended-Salt";
|
|
|
|
static const char OPTI_STR_SINGLE_HASH[] = "Single-Hash";
|
|
|
|
static const char OPTI_STR_SINGLE_SALT[] = "Single-Salt";
|
|
|
|
static const char OPTI_STR_BRUTE_FORCE[] = "Brute-Force";
|
|
|
|
static const char OPTI_STR_RAW_HASH[] = "Raw-Hash";
|
|
|
|
static const char OPTI_STR_SLOW_HASH_SIMD[] = "Slow-Hash-SIMD";
|
|
|
|
static const char OPTI_STR_USES_BITS_8[] = "Uses-8-Bit";
|
|
|
|
static const char OPTI_STR_USES_BITS_16[] = "Uses-16-Bit";
|
|
|
|
static const char OPTI_STR_USES_BITS_32[] = "Uses-32-Bit";
|
|
|
|
static const char OPTI_STR_USES_BITS_64[] = "Uses-64-Bit";
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-09-05 09:14:31 +00:00
|
|
|
static const char ST_0000[] = "Initializing";
|
|
|
|
static const char ST_0001[] = "Starting";
|
|
|
|
static const char ST_0002[] = "Running";
|
|
|
|
static const char ST_0003[] = "Paused";
|
|
|
|
static const char ST_0004[] = "Exhausted";
|
|
|
|
static const char ST_0005[] = "Cracked";
|
|
|
|
static const char ST_0006[] = "Aborted";
|
|
|
|
static const char ST_0007[] = "Quit";
|
|
|
|
static const char ST_0008[] = "Bypass";
|
|
|
|
static const char ST_0009[] = "Running (stop at checkpoint)";
|
|
|
|
static const char ST_0010[] = "Autotuning";
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* functions
|
|
|
|
*/
|
|
|
|
|
2016-08-31 01:37:16 +00:00
|
|
|
char *get_exec_path (void);
|
2015-12-04 14:47:52 +00:00
|
|
|
char *get_install_dir (const char *progname);
|
2015-12-13 11:21:36 +00:00
|
|
|
char *get_profile_dir (const char *homedir);
|
2016-01-03 16:11:36 +00:00
|
|
|
char *get_session_dir (const char *profile_dir);
|
2016-02-10 19:40:21 +00:00
|
|
|
uint count_lines (FILE *fd);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *));
|
|
|
|
|
2016-02-19 17:58:03 +00:00
|
|
|
int sort_by_u32 (const void *p1, const void *p2);
|
2016-01-15 16:16:43 +00:00
|
|
|
int sort_by_mtime (const void *p1, const void *p2);
|
|
|
|
int sort_by_cpu_rule (const void *p1, const void *p2);
|
|
|
|
int sort_by_kernel_rule (const void *p1, const void *p2);
|
|
|
|
int sort_by_stringptr (const void *p1, const void *p2);
|
|
|
|
int sort_by_dictstat (const void *s1, const void *s2);
|
|
|
|
int sort_by_bitmap (const void *s1, const void *s2);
|
|
|
|
|
|
|
|
int sort_by_pot (const void *v1, const void *v2);
|
|
|
|
int sort_by_hash (const void *v1, const void *v2);
|
|
|
|
int sort_by_hash_no_salt (const void *v1, const void *v2);
|
|
|
|
int sort_by_salt (const void *v1, const void *v2);
|
|
|
|
int sort_by_salt_buf (const void *v1, const void *v2);
|
|
|
|
int sort_by_hash_t_salt (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_2 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_4 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_5 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_6 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_8 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_16 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_32 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_4_64 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_8_8 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_8_16 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_8_25 (const void *v1, const void *v2);
|
|
|
|
int sort_by_digest_p0p1 (const void *v1, const void *v2);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
// special version for hccap (last 2 uints should be skipped where the digest is located)
|
|
|
|
int sort_by_hash_t_salt_hccap (const void *v1, const void *v2);
|
|
|
|
|
|
|
|
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);
|
|
|
|
void format_plain (FILE *fp, unsigned char *plain_ptr, uint plain_len, uint outfile_autohex);
|
2016-01-15 16:16:43 +00:00
|
|
|
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);
|
2015-12-04 14:47:52 +00:00
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
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);
|
|
|
|
|
2016-01-15 16:23:07 +00:00
|
|
|
u32 setup_opencl_platforms_filter (char *opencl_platforms);
|
|
|
|
u32 setup_devices_filter (char *opencl_devices);
|
|
|
|
cl_device_type setup_device_types_filter (char *opencl_device_types);
|
2016-01-13 16:10:40 +00:00
|
|
|
|
2016-01-15 16:16:43 +00:00
|
|
|
u32 get_random_num (const u32 min, const u32 max);
|
2016-01-13 16:10:40 +00:00
|
|
|
|
2016-01-15 16:16:43 +00:00
|
|
|
u32 mydivc32 (const u32 dividend, const u32 divisor);
|
|
|
|
u64 mydivc64 (const u64 dividend, const u64 divisor);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-08-27 03:38:45 +00:00
|
|
|
void format_speed_display (double val, char *buf, size_t len);
|
2015-12-04 14:47:52 +00:00
|
|
|
void format_timer_display (struct tm *tm, char *buf, size_t len);
|
|
|
|
int fgetl (FILE *fp, char *line_buf);
|
|
|
|
int in_superchop (char *buf);
|
|
|
|
char **scan_directory (const char *path);
|
|
|
|
int count_dictionaries (char **dictionary_files);
|
2016-09-06 09:49:26 +00:00
|
|
|
|
2015-12-04 14:47:52 +00:00
|
|
|
char *stroptitype (const uint opti_type);
|
|
|
|
char *strstatus (const uint threads_status);
|
|
|
|
void status ();
|
|
|
|
|
2016-08-27 04:05:44 +00:00
|
|
|
#ifdef F_SETLKW
|
2016-01-29 10:54:18 +00:00
|
|
|
void lock_file (FILE *fp);
|
|
|
|
void unlock_file (FILE *fp);
|
|
|
|
#else
|
|
|
|
#define lock_file(dummy) {}
|
|
|
|
#define unlock_file(dummy) {}
|
|
|
|
#endif
|
|
|
|
|
2015-12-04 14:47:52 +00:00
|
|
|
#ifdef _WIN
|
|
|
|
void fsync (int fd);
|
|
|
|
#endif
|
|
|
|
|
2016-08-31 01:37:16 +00:00
|
|
|
void myabort (void);
|
|
|
|
void myquit (void);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
void set_cpu_affinity (char *cpu_affinity);
|
|
|
|
|
|
|
|
void usage_mini_print (const char *progname);
|
2016-01-15 16:16:43 +00:00
|
|
|
void usage_big_print (const char *progname);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-02-10 19:40:21 +00:00
|
|
|
void tuning_db_destroy (tuning_db_t *tuning_db);
|
|
|
|
tuning_db_t *tuning_db_alloc (FILE *fp);
|
|
|
|
tuning_db_t *tuning_db_init (const char *tuning_db_file);
|
2016-02-19 23:58:22 +00:00
|
|
|
tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type);
|
2016-02-10 19:40:21 +00:00
|
|
|
|
2016-06-25 08:37:24 +00:00
|
|
|
void naive_replace (char *s, const u8 key_char, const u8 replace_char);
|
|
|
|
void naive_escape (char *s, size_t s_max, const u8 key_char, const u8 escape_char);
|
2016-01-15 16:16:43 +00:00
|
|
|
void load_kernel (const char *kernel_file, int num_devices, size_t *kernel_lengths, const u8 **kernel_sources);
|
|
|
|
void writeProgramBin (char *dst, u8 *binary, size_t binary_size);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-08-31 01:37:16 +00:00
|
|
|
u64 get_lowest_words_done (void);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
restore_data_t *init_restore (int argc, char **argv);
|
|
|
|
void read_restore (const char *eff_restore_file, restore_data_t *rd);
|
|
|
|
void write_restore (const char *new_restore_file, restore_data_t *rd);
|
2016-08-31 01:37:16 +00:00
|
|
|
void cycle_restore (void);
|
|
|
|
void check_checkpoint (void);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
#ifdef WIN
|
|
|
|
|
|
|
|
BOOL WINAPI sigHandler_default (DWORD sig);
|
|
|
|
BOOL WINAPI sigHandler_benchmark (DWORD sig);
|
|
|
|
void hc_signal (BOOL WINAPI (callback) (DWORD sig));
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
void sigHandler_default (int sig);
|
|
|
|
void sigHandler_benchmark (int sig);
|
|
|
|
void hc_signal (void c (int));
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2016-01-15 16:16:43 +00:00
|
|
|
bool class_num (u8 c);
|
|
|
|
bool class_lower (u8 c);
|
|
|
|
bool class_upper (u8 c);
|
|
|
|
bool class_alpha (u8 c);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
|
|
|
int mangle_lrest (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_urest (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_trest (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_reverse (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_double (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_double_times (char arr[BLOCK_SIZE], int arr_len, int times);
|
|
|
|
int mangle_reflect (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_rotate_left (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_rotate_right (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_append (char arr[BLOCK_SIZE], int arr_len, char c);
|
|
|
|
int mangle_prepend (char arr[BLOCK_SIZE], int arr_len, char c);
|
|
|
|
int mangle_delete_at (char arr[BLOCK_SIZE], int arr_len, int upos);
|
|
|
|
int mangle_extract (char arr[BLOCK_SIZE], int arr_len, int upos, int ulen);
|
|
|
|
int mangle_omit (char arr[BLOCK_SIZE], int arr_len, int upos, int ulen);
|
|
|
|
int mangle_insert (char arr[BLOCK_SIZE], int arr_len, int upos, char c);
|
|
|
|
int mangle_overstrike (char arr[BLOCK_SIZE], int arr_len, int upos, char c);
|
|
|
|
int mangle_truncate_at (char arr[BLOCK_SIZE], int arr_len, int upos);
|
|
|
|
int mangle_replace (char arr[BLOCK_SIZE], int arr_len, char oldc, char newc);
|
|
|
|
int mangle_purgechar (char arr[BLOCK_SIZE], int arr_len, char c);
|
|
|
|
int mangle_dupeblock_prepend (char arr[BLOCK_SIZE], int arr_len, int ulen);
|
|
|
|
int mangle_dupeblock_append (char arr[BLOCK_SIZE], int arr_len, int ulen);
|
|
|
|
int mangle_dupechar_at (char arr[BLOCK_SIZE], int arr_len, int upos, int ulen);
|
|
|
|
int mangle_dupechar (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
int mangle_switch_at_check (char arr[BLOCK_SIZE], int arr_len, int upos, int upos2);
|
|
|
|
int mangle_switch_at (char arr[BLOCK_SIZE], int arr_len, int upos, int upos2);
|
2016-01-15 16:16:43 +00:00
|
|
|
int mangle_chr_shiftl (char arr[BLOCK_SIZE], int arr_len, int upos);
|
|
|
|
int mangle_chr_shiftr (char arr[BLOCK_SIZE], int arr_len, int upos);
|
|
|
|
int mangle_chr_incr (char arr[BLOCK_SIZE], int arr_len, int upos);
|
|
|
|
int mangle_chr_decr (char arr[BLOCK_SIZE], int arr_len, int upos);
|
2015-12-04 14:47:52 +00:00
|
|
|
int mangle_title (char arr[BLOCK_SIZE], int arr_len);
|
|
|
|
|
2016-01-15 16:16:43 +00:00
|
|
|
int generate_random_rule (char rule_buf[RP_RULE_BUFSIZ], u32 rp_gen_func_min, u32 rp_gen_func_max);
|
2015-12-04 14:47:52 +00:00
|
|
|
int _old_apply_rule (char *rule, int rule_len, char in[BLOCK_SIZE], int in_len, char out[BLOCK_SIZE]);
|
|
|
|
|
2016-03-26 09:37:59 +00:00
|
|
|
int cpu_rule_to_kernel_rule (char *rule_buf, uint rule_len, kernel_rule_t *rule);
|
|
|
|
int kernel_rule_to_cpu_rule (char *rule_buf, kernel_rule_t *rule);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-01-05 07:26:44 +00:00
|
|
|
void *thread_device_watch (void *p);
|
2016-01-15 16:16:43 +00:00
|
|
|
void *thread_keypress (void *p);
|
|
|
|
void *thread_runtime (void *p);
|
2015-12-04 14:47:52 +00:00
|
|
|
|
2016-08-31 01:37:16 +00:00
|
|
|
void status_display (void);
|
|
|
|
void status_display_machine_readable (void);
|