mirror of
https://github.com/hashcat/hashcat.git
synced 2024-12-24 23:48:39 +00:00
249 lines
8.8 KiB
C
249 lines
8.8 KiB
C
/**
|
|
* Authors.....: Jens Steube <jens.steube@gmail.com>
|
|
* Gabriele Gristina <matrix@hashcat.net>
|
|
* magnum <john.magnum@hushmail.com>
|
|
*
|
|
* License.....: MIT
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <errno.h>
|
|
#include <dirent.h>
|
|
#include <time.h>
|
|
#include <unistd.h>
|
|
#include <signal.h>
|
|
#include <fcntl.h>
|
|
|
|
/**
|
|
* OS specific includes
|
|
*/
|
|
|
|
#ifdef _POSIX
|
|
#include <pthread.h>
|
|
#include <dlfcn.h>
|
|
#include <pwd.h>
|
|
#include <limits.h>
|
|
#include <sys/ioctl.h>
|
|
#include <sys/sysctl.h>
|
|
#endif // _POSIX
|
|
|
|
#ifdef __APPLE__
|
|
#include <mach-o/dyld.h>
|
|
#include <mach/mach.h>
|
|
#endif // __APPLE__
|
|
|
|
#ifdef _WIN
|
|
#include <windows.h>
|
|
#include <psapi.h>
|
|
#include <io.h>
|
|
#endif // _WIN
|
|
|
|
/**
|
|
* unsorted
|
|
*/
|
|
|
|
#ifdef __APPLE__
|
|
typedef struct cpu_set
|
|
{
|
|
uint32_t count;
|
|
|
|
} cpu_set_t;
|
|
|
|
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)); }
|
|
#endif
|
|
|
|
|
|
#ifdef _WIN
|
|
#define hc_sleep(x) Sleep ((x) * 1000);
|
|
#elif _POSIX
|
|
#define hc_sleep(x) sleep ((x));
|
|
#endif
|
|
|
|
#define ETC_MAX (60 * 60 * 24 * 365 * 10)
|
|
|
|
|
|
#define INFOSZ CHARSIZ
|
|
|
|
#define TUNING_DB_FILE "hashcat.hctune"
|
|
|
|
#define INDUCT_DIR "induct"
|
|
#define OUTFILES_DIR "outfiles"
|
|
|
|
#define LOOPBACK_FILE "hashcat.loopback"
|
|
#define DICTSTAT_FILENAME "hashcat.dictstat"
|
|
#define POTFILE_FILENAME "hashcat.pot"
|
|
|
|
/**
|
|
* valid project specific global stuff
|
|
*/
|
|
|
|
extern const uint VERSION_BIN;
|
|
extern const uint RESTORE_MIN;
|
|
|
|
extern const char *PROMPT;
|
|
|
|
extern hc_thread_mutex_t mux_display;
|
|
|
|
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";
|
|
|
|
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";
|
|
|
|
|
|
/*
|
|
* functions
|
|
*/
|
|
|
|
char *get_exec_path (void);
|
|
char *get_install_dir (const char *progname);
|
|
char *get_profile_dir (const char *homedir);
|
|
char *get_session_dir (const char *profile_dir);
|
|
|
|
uint count_lines (FILE *fd);
|
|
|
|
void *rulefind (const void *key, void *base, int nmemb, size_t size, int (*compar) (const void *, const void *));
|
|
|
|
int sort_by_u32 (const void *p1, const void *p2);
|
|
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);
|
|
|
|
// 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);
|
|
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);
|
|
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);
|
|
|
|
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);
|
|
|
|
u32 get_random_num (const u32 min, const u32 max);
|
|
|
|
u32 mydivc32 (const u32 dividend, const u32 divisor);
|
|
u64 mydivc64 (const u64 dividend, const u64 divisor);
|
|
|
|
void format_speed_display (double val, char *buf, size_t len);
|
|
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);
|
|
|
|
char *stroptitype (const uint opti_type);
|
|
char *strstatus (const uint threads_status);
|
|
void status ();
|
|
|
|
#ifdef F_SETLKW
|
|
void lock_file (FILE *fp);
|
|
void unlock_file (FILE *fp);
|
|
#else
|
|
#define lock_file(dummy) {}
|
|
#define unlock_file(dummy) {}
|
|
#endif
|
|
|
|
#ifdef _WIN
|
|
void fsync (int fd);
|
|
#endif
|
|
|
|
void myabort (void);
|
|
void myquit (void);
|
|
|
|
void set_cpu_affinity (char *cpu_affinity);
|
|
|
|
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);
|
|
tuning_db_entry_t *tuning_db_search (tuning_db_t *tuning_db, hc_device_param_t *device_param, int attack_mode, int hash_type);
|
|
|
|
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);
|
|
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);
|
|
|
|
u64 get_lowest_words_done (void);
|
|
|
|
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);
|
|
void cycle_restore (void);
|
|
void check_checkpoint (void);
|
|
|
|
#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
|
|
|
|
void *thread_device_watch (void *p);
|
|
void *thread_keypress (void *p);
|
|
void *thread_runtime (void *p);
|
|
|
|
void status_display (void);
|
|
void status_display_machine_readable (void);
|