The hashcat brain
This commit is contained in:
+242
@@ -0,0 +1,242 @@
|
||||
/**
|
||||
* Author......: See docs/credits.txt
|
||||
* License.....: MIT
|
||||
*/
|
||||
|
||||
#ifndef _BRAIN_H
|
||||
#define _BRAIN_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <inttypes.h>
|
||||
#include <errno.h>
|
||||
#include <dirent.h>
|
||||
#include <search.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#if defined (_WIN)
|
||||
#define _WINNT_WIN32 0x0601
|
||||
#include <ws2tcpip.h>
|
||||
#include <winsock2.h>
|
||||
#include <wincrypt.h>
|
||||
#define SEND_FLAGS 0
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <signal.h>
|
||||
#define SEND_FLAGS MSG_NOSIGNAL
|
||||
#endif
|
||||
|
||||
#include "xxhash.h"
|
||||
|
||||
static const int BRAIN_CLIENT_CONNECT_TIMEOUT = 5;
|
||||
static const int BRAIN_SERVER_DUMP_EVERY = 5 * 60;
|
||||
static const int BRAIN_SERVER_SESSIONS_MAX = 64;
|
||||
static const int BRAIN_SERVER_ATTACKS_MAX = 64 * 1024;
|
||||
static const int BRAIN_SERVER_CLIENTS_MAX = 256;
|
||||
static const int BRAIN_SERVER_REALLOC_HASH_SIZE = 1024 * 1024;
|
||||
static const int BRAIN_SERVER_REALLOC_ATTACK_SIZE = 1024;
|
||||
static const int BRAIN_HASH_SIZE = 2 * sizeof (u32);
|
||||
static const int BRAIN_LINK_VERSION_CUR = 1;
|
||||
static const int BRAIN_LINK_VERSION_MIN = 1;
|
||||
static const int BRAIN_LINK_CHUNK_SIZE = 4 * 1024;
|
||||
static const int BRAIN_LINK_CANDIDATES_MAX = 128 * 1024 * 256; // units * threads * accel
|
||||
|
||||
typedef enum brain_operation
|
||||
{
|
||||
BRAIN_OPERATION_COMMIT = 1,
|
||||
BRAIN_OPERATION_HASH_LOOKUP = 2,
|
||||
BRAIN_OPERATION_ATTACK_RESERVE = 3,
|
||||
|
||||
} brain_operation_t;
|
||||
|
||||
typedef enum brain_client_feature
|
||||
{
|
||||
BRAIN_CLIENT_FEATURE_HASHES = 1,
|
||||
BRAIN_CLIENT_FEATURE_ATTACKS = 2,
|
||||
|
||||
} brain_client_feature_t;
|
||||
|
||||
typedef struct brain_server_attack_long
|
||||
{
|
||||
u64 offset;
|
||||
u64 length;
|
||||
|
||||
} brain_server_attack_long_t;
|
||||
|
||||
typedef struct brain_server_attack_short
|
||||
{
|
||||
u64 offset;
|
||||
u64 length;
|
||||
|
||||
int client_fd;
|
||||
|
||||
} brain_server_attack_short_t;
|
||||
|
||||
typedef struct brain_server_hash_long
|
||||
{
|
||||
u32 hash[2];
|
||||
|
||||
} brain_server_hash_long_t;
|
||||
|
||||
typedef struct brain_server_hash_short
|
||||
{
|
||||
u32 hash[2];
|
||||
|
||||
} brain_server_hash_short_t;
|
||||
|
||||
typedef struct brain_server_hash_unique
|
||||
{
|
||||
u32 hash[2];
|
||||
|
||||
i64 hash_idx;
|
||||
|
||||
} brain_server_hash_unique_t;
|
||||
|
||||
typedef struct brain_server_db_attack
|
||||
{
|
||||
u32 brain_attack;
|
||||
|
||||
brain_server_attack_short_t *short_buf;
|
||||
|
||||
i64 short_alloc;
|
||||
i64 short_cnt;
|
||||
|
||||
brain_server_attack_long_t *long_buf;
|
||||
|
||||
i64 long_alloc;
|
||||
i64 long_cnt;
|
||||
|
||||
int ab;
|
||||
|
||||
hc_thread_mutex_t mux_ar;
|
||||
hc_thread_mutex_t mux_ag;
|
||||
|
||||
bool write_attacks;
|
||||
|
||||
} brain_server_db_attack_t;
|
||||
|
||||
typedef struct brain_server_db_hash
|
||||
{
|
||||
u32 brain_session;
|
||||
|
||||
brain_server_hash_long_t *long_buf;
|
||||
|
||||
i64 long_alloc;
|
||||
i64 long_cnt;
|
||||
|
||||
int hb;
|
||||
|
||||
hc_thread_mutex_t mux_hr;
|
||||
hc_thread_mutex_t mux_hg;
|
||||
|
||||
bool write_hashes;
|
||||
|
||||
} brain_server_db_hash_t;
|
||||
|
||||
typedef struct brain_server_db_short
|
||||
{
|
||||
brain_server_hash_short_t *short_buf;
|
||||
|
||||
i64 short_cnt;
|
||||
|
||||
} brain_server_db_short_t;
|
||||
|
||||
typedef struct brain_server_dbs
|
||||
{
|
||||
// required for cyclic dump
|
||||
|
||||
hc_thread_mutex_t mux_dbs;
|
||||
|
||||
brain_server_db_hash_t *hash_buf;
|
||||
brain_server_db_attack_t *attack_buf;
|
||||
|
||||
int hash_cnt;
|
||||
int attack_cnt;
|
||||
|
||||
} brain_server_dbs_t;
|
||||
|
||||
typedef struct brain_server_dumper_options
|
||||
{
|
||||
brain_server_dbs_t *brain_server_dbs;
|
||||
|
||||
} brain_server_dumper_options_t;
|
||||
|
||||
typedef struct brain_server_client_options
|
||||
{
|
||||
brain_server_dbs_t *brain_server_dbs;
|
||||
|
||||
int client_fd;
|
||||
|
||||
char *auth_password;
|
||||
|
||||
u32 *session_whitelist_buf;
|
||||
int session_whitelist_cnt;
|
||||
|
||||
} brain_server_client_options_t;
|
||||
|
||||
int brain_logging (FILE *stream, const int client_fd, const char *format, ...);
|
||||
|
||||
u32 brain_compute_session (hashcat_ctx_t *hashcat_ctx);
|
||||
u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx);
|
||||
u64 brain_compute_attack_wordlist (const char *filename);
|
||||
|
||||
u32 brain_auth_challenge (void);
|
||||
u64 brain_auth_hash (const u32 challenge, const char *pw_buf, const int pw_len);
|
||||
|
||||
int brain_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen, const int timeout);
|
||||
bool brain_recv (int sockfd, void *buf, size_t len, int flags, hc_device_param_t *device_param, const status_ctx_t *status_ctx);
|
||||
bool brain_send (int sockfd, void *buf, size_t len, int flags, hc_device_param_t *device_param, const status_ctx_t *status_ctx);
|
||||
bool brain_recv_all (int sockfd, void *buf, size_t len, int flags, hc_device_param_t *device_param, const status_ctx_t *status_ctx);
|
||||
bool brain_send_all (int sockfd, void *buf, size_t len, int flags, hc_device_param_t *device_param, const status_ctx_t *status_ctx);
|
||||
|
||||
bool brain_client_reserve (hc_device_param_t *device_param, const status_ctx_t *status_ctx, u64 words_off, u64 work, u64 *overlap);
|
||||
bool brain_client_commit (hc_device_param_t *device_param, const status_ctx_t *status_ctx);
|
||||
bool brain_client_lookup (hc_device_param_t *device_param, const status_ctx_t *status_ctx);
|
||||
bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *status_ctx, const char *host, const int port, const char *password, u32 brain_session, u32 brain_attack, i64 passwords_max, u64 *highest);
|
||||
void brain_client_disconnect (hc_device_param_t *device_param);
|
||||
void brain_client_generate_hash (u64 *hash, const char *line_buf, const size_t line_len);
|
||||
|
||||
int brain_server (const char *listen_host, const int listen_port, const char *brain_password, const char *brain_session_whitelist);
|
||||
bool brain_server_read_hash_dumps (brain_server_dbs_t *brain_server_dbs, const char *path);
|
||||
bool brain_server_write_hash_dumps (brain_server_dbs_t *brain_server_dbs, const char *path);
|
||||
bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash, const char *file);
|
||||
bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash, const char *file);
|
||||
bool brain_server_read_attack_dumps (brain_server_dbs_t *brain_server_dbs, const char *path);
|
||||
bool brain_server_write_attack_dumps (brain_server_dbs_t *brain_server_dbs, const char *path);
|
||||
bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_attack, const char *file);
|
||||
bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_attack, const char *file);
|
||||
|
||||
u64 brain_server_highest_attack (const brain_server_db_attack_t *buf);
|
||||
u64 brain_server_highest_attack_long (const brain_server_attack_long_t *buf, const i64 cnt, const u64 start);
|
||||
u64 brain_server_highest_attack_short (const brain_server_attack_short_t *buf, const i64 cnt, const u64 start);
|
||||
u64 brain_server_find_attack_long (const brain_server_attack_long_t *buf, const i64 cnt, const u64 offset, const u64 length);
|
||||
u64 brain_server_find_attack_short (const brain_server_attack_short_t *buf, const i64 cnt, const u64 offset, const u64 length);
|
||||
i64 brain_server_find_hash_long (const u32 *search, const brain_server_hash_long_t *buf, const i64 cnt);
|
||||
i64 brain_server_find_hash_short (const u32 *search, const brain_server_hash_short_t *buf, const i64 cnt);
|
||||
int brain_server_sort_db_hash (const void *v1, const void *v2);
|
||||
int brain_server_sort_db_attack (const void *v1, const void *v2);
|
||||
int brain_server_sort_attack_long (const void *v1, const void *v2);
|
||||
int brain_server_sort_attack_short (const void *v1, const void *v2);
|
||||
int brain_server_sort_hash (const void *v1, const void *v2);
|
||||
int brain_server_sort_hash_long (const void *v1, const void *v2);
|
||||
int brain_server_sort_hash_short (const void *v1, const void *v2);
|
||||
int brain_server_sort_hash_unique (const void *v1, const void *v2);
|
||||
void brain_server_handle_signal (int signo);
|
||||
void *brain_server_handle_client (void *p);
|
||||
void *brain_server_handle_dumps (void *p);
|
||||
void brain_server_db_hash_init (brain_server_db_hash_t *brain_server_db_hash, const u32 brain_session);
|
||||
bool brain_server_db_hash_realloc (brain_server_db_hash_t *brain_server_db_hash, const i64 new_long_cnt);
|
||||
void brain_server_db_hash_free (brain_server_db_hash_t *brain_server_db_hash);
|
||||
void brain_server_db_attack_init (brain_server_db_attack_t *brain_server_db_attack, const u32 brain_attack);
|
||||
bool brain_server_db_attack_realloc (brain_server_db_attack_t *brain_server_db_attack, const i64 new_long_cnt, const i64 new_short_cnt);
|
||||
void brain_server_db_attack_free (brain_server_db_attack_t *brain_server_db_attack);
|
||||
|
||||
#endif // _BRAIN_H
|
||||
@@ -6,6 +6,22 @@
|
||||
#ifndef _DISPATCH_H
|
||||
#define _DISPATCH_H
|
||||
|
||||
#ifdef WITH_BRAIN
|
||||
#if defined (_WIN)
|
||||
#include <winsock.h>
|
||||
#define SEND_FLAGS 0
|
||||
#endif
|
||||
|
||||
#if defined (__linux__)
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
#define SEND_FLAGS MSG_NOSIGNAL
|
||||
#endif
|
||||
#endif
|
||||
|
||||
HC_API_CALL void *thread_calc_stdin (void *p);
|
||||
HC_API_CALL void *thread_calc (void *p);
|
||||
|
||||
|
||||
@@ -85,6 +85,16 @@ int status_get_innerloop_pos_dev (const hashcat_ctx_t *hash
|
||||
int status_get_innerloop_left_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
int status_get_iteration_pos_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
int status_get_iteration_left_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
#ifdef WITH_BRAIN
|
||||
int status_get_brain_session (const hashcat_ctx_t *hashcat_ctx);
|
||||
int status_get_brain_attack (const hashcat_ctx_t *hashcat_ctx);
|
||||
int status_get_brain_link_client_id_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
int status_get_brain_link_status_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
char *status_get_brain_link_recv_bytes_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
char *status_get_brain_link_send_bytes_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
char *status_get_brain_link_recv_bytes_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
char *status_get_brain_link_send_bytes_sec_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
#endif
|
||||
char *status_get_hwmon_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
int status_get_corespeed_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
int status_get_memoryspeed_dev (const hashcat_ctx_t *hashcat_ctx, const int device_id);
|
||||
|
||||
@@ -536,6 +536,13 @@ typedef enum user_options_defaults
|
||||
BENCHMARK = false,
|
||||
BITMAP_MAX = 24,
|
||||
BITMAP_MIN = 16,
|
||||
#ifdef WITH_BRAIN
|
||||
BRAIN_CLIENT = false,
|
||||
BRAIN_CLIENT_FEATURES = 3,
|
||||
BRAIN_PORT = 6863,
|
||||
BRAIN_SERVER = false,
|
||||
BRAIN_SESSION = 0,
|
||||
#endif
|
||||
DEBUG_MODE = 0,
|
||||
EXAMPLE_HASHES = false,
|
||||
FORCE = false,
|
||||
@@ -609,6 +616,16 @@ typedef enum user_options_map
|
||||
IDX_BENCHMARK = 'b',
|
||||
IDX_BITMAP_MAX = 0xff02,
|
||||
IDX_BITMAP_MIN = 0xff03,
|
||||
#ifdef WITH_BRAIN
|
||||
IDX_BRAIN_CLIENT = 'z',
|
||||
IDX_BRAIN_CLIENT_FEATURES = 0xff04,
|
||||
IDX_BRAIN_HOST = 0xff05,
|
||||
IDX_BRAIN_PASSWORD = 0xff06,
|
||||
IDX_BRAIN_PORT = 0xff07,
|
||||
IDX_BRAIN_SERVER = 0xff08,
|
||||
IDX_BRAIN_SESSION = 0xff09,
|
||||
IDX_BRAIN_SESSION_WHITELIST = 0xff0a,
|
||||
#endif
|
||||
IDX_CPU_AFFINITY = 0xff0b,
|
||||
IDX_CUSTOM_CHARSET_1 = '1',
|
||||
IDX_CUSTOM_CHARSET_2 = '2',
|
||||
@@ -712,6 +729,16 @@ typedef enum token_attr
|
||||
|
||||
} token_attr_t;
|
||||
|
||||
#ifdef WITH_BRAIN
|
||||
typedef enum brain_link_status
|
||||
{
|
||||
BRAIN_LINK_STATUS_CONNECTED = 1 << 0,
|
||||
BRAIN_LINK_STATUS_RECEIVING = 1 << 1,
|
||||
BRAIN_LINK_STATUS_SENDING = 1 << 2,
|
||||
|
||||
} brain_link_status_t;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* structs
|
||||
*/
|
||||
@@ -950,6 +977,16 @@ typedef struct plain
|
||||
|
||||
} plain_t;
|
||||
|
||||
#define LINK_SPEED_COUNT 10000
|
||||
|
||||
typedef struct link_speed
|
||||
{
|
||||
hc_timer_t timer[LINK_SPEED_COUNT];
|
||||
ssize_t bytes[LINK_SPEED_COUNT];
|
||||
int pos;
|
||||
|
||||
} link_speed_t;
|
||||
|
||||
#include "ext_OpenCL.h"
|
||||
|
||||
typedef struct hc_device_param
|
||||
@@ -1085,6 +1122,21 @@ typedef struct hc_device_param
|
||||
size_t size_st_salts;
|
||||
size_t size_st_esalts;
|
||||
|
||||
#ifdef WITH_BRAIN
|
||||
size_t size_brain_link_in;
|
||||
size_t size_brain_link_out;
|
||||
|
||||
int brain_link_client_fd;
|
||||
link_speed_t brain_link_recv_speed;
|
||||
link_speed_t brain_link_send_speed;
|
||||
bool brain_link_recv_active;
|
||||
bool brain_link_send_active;
|
||||
u64 brain_link_recv_bytes;
|
||||
u64 brain_link_send_bytes;
|
||||
u8 *brain_link_in_buf;
|
||||
u32 *brain_link_out_buf;
|
||||
#endif
|
||||
|
||||
char *scratch_buf;
|
||||
|
||||
FILE *combs_fp;
|
||||
@@ -1618,6 +1670,11 @@ typedef struct user_options
|
||||
char **hc_argv;
|
||||
|
||||
bool attack_mode_chgd;
|
||||
#ifdef WITH_BRAIN
|
||||
bool brain_host_chgd;
|
||||
bool brain_port_chgd;
|
||||
bool brain_password_chgd;
|
||||
#endif
|
||||
bool hash_mode_chgd;
|
||||
bool hccapx_message_pair_chgd;
|
||||
bool increment_max_chgd;
|
||||
@@ -1639,6 +1696,10 @@ typedef struct user_options
|
||||
bool advice_disable;
|
||||
bool benchmark;
|
||||
bool benchmark_all;
|
||||
#ifdef WITH_BRAIN
|
||||
bool brain_client;
|
||||
bool brain_server;
|
||||
#endif
|
||||
bool example_hashes;
|
||||
bool force;
|
||||
bool gpu_temp_disable;
|
||||
@@ -1673,6 +1734,11 @@ typedef struct user_options
|
||||
bool username;
|
||||
bool version;
|
||||
bool wordlist_autohex_disable;
|
||||
#ifdef WITH_BRAIN
|
||||
char *brain_host;
|
||||
char *brain_password;
|
||||
char *brain_session_whitelist;
|
||||
#endif
|
||||
char *cpu_affinity;
|
||||
char *custom_charset_4;
|
||||
char *debug_file;
|
||||
@@ -1700,6 +1766,12 @@ typedef struct user_options
|
||||
u32 attack_mode;
|
||||
u32 bitmap_max;
|
||||
u32 bitmap_min;
|
||||
#ifdef WITH_BRAIN
|
||||
u32 brain_client_features;
|
||||
u32 brain_port;
|
||||
u32 brain_session;
|
||||
u32 brain_attack;
|
||||
#endif
|
||||
u32 debug_mode;
|
||||
u32 gpu_temp_abort;
|
||||
u32 hash_mode;
|
||||
@@ -1893,6 +1965,16 @@ typedef struct device_info
|
||||
int innerloop_left_dev;
|
||||
int iteration_pos_dev;
|
||||
int iteration_left_dev;
|
||||
#ifdef WITH_BRAIN
|
||||
int brain_link_client_id_dev;
|
||||
int brain_link_status_dev;
|
||||
char *brain_link_recv_bytes_dev;
|
||||
char *brain_link_send_bytes_dev;
|
||||
char *brain_link_recv_bytes_sec_dev;
|
||||
char *brain_link_send_bytes_sec_dev;
|
||||
double brain_link_time_recv_dev;
|
||||
double brain_link_time_send_dev;
|
||||
#endif
|
||||
|
||||
} device_info_t;
|
||||
|
||||
@@ -1912,6 +1994,10 @@ typedef struct hashcat_status
|
||||
char *guess_charset;
|
||||
int guess_mask_length;
|
||||
char *session;
|
||||
#ifdef WITH_BRAIN
|
||||
int brain_session;
|
||||
int brain_attack;
|
||||
#endif
|
||||
const char *status_string;
|
||||
int status_number;
|
||||
char *time_estimated_absolute;
|
||||
|
||||
Reference in New Issue
Block a user