mirror of
https://github.com/hashcat/hashcat
synced 2024-12-23 14:13:43 +01:00
Fixed missing call to WSAStartup() and client indexing in order to start the brain server on windows
This commit is contained in:
parent
81a4604964
commit
61ded2bd54
@ -23,7 +23,8 @@
|
||||
## Bugs
|
||||
##
|
||||
|
||||
- Fix endianness and invalid separator character in outfile format of hash-mode 16801 (WPA-PMKID-PMK)
|
||||
- Fixed missing call to WSAStartup() and client indexing in order to start the brain server on windows
|
||||
- Fixed endianness and invalid separator character in outfile format of hash-mode 16801 (WPA-PMKID-PMK)
|
||||
|
||||
* changes v4.2.1 -> v5.0.0
|
||||
|
||||
|
@ -80,7 +80,7 @@ typedef struct brain_server_attack_short
|
||||
u64 offset;
|
||||
u64 length;
|
||||
|
||||
int client_fd;
|
||||
int client_idx;
|
||||
|
||||
} brain_server_attack_short_t;
|
||||
|
||||
@ -165,6 +165,8 @@ typedef struct brain_server_dbs
|
||||
int hash_cnt;
|
||||
int attack_cnt;
|
||||
|
||||
int *client_slots;
|
||||
|
||||
} brain_server_dbs_t;
|
||||
|
||||
typedef struct brain_server_dumper_options
|
||||
@ -177,6 +179,7 @@ typedef struct brain_server_client_options
|
||||
{
|
||||
brain_server_dbs_t *brain_server_dbs;
|
||||
|
||||
int client_idx;
|
||||
int client_fd;
|
||||
|
||||
char *auth_password;
|
||||
@ -186,7 +189,7 @@ typedef struct brain_server_client_options
|
||||
|
||||
} brain_server_client_options_t;
|
||||
|
||||
int brain_logging (FILE *stream, const int client_fd, const char *format, ...);
|
||||
int brain_logging (FILE *stream, const int client_idx, const char *format, ...);
|
||||
|
||||
u32 brain_compute_session (hashcat_ctx_t *hashcat_ctx);
|
||||
u32 brain_compute_attack (hashcat_ctx_t *hashcat_ctx);
|
||||
@ -217,6 +220,7 @@ bool brain_server_read_attack_dumps (brain_server_dbs_t *brain_server_dbs, c
|
||||
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);
|
||||
int brain_server_get_client_idx (brain_server_dbs_t *brain_server_dbs);
|
||||
|
||||
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);
|
||||
|
333
src/brain.c
333
src/brain.c
@ -22,7 +22,7 @@ static hc_timer_t timer_logging;
|
||||
|
||||
static hc_thread_mutex_t mux_display;
|
||||
|
||||
int brain_logging (FILE *stream, const int client_fd, const char *format, ...)
|
||||
int brain_logging (FILE *stream, const int client_idx, const char *format, ...)
|
||||
{
|
||||
const double ms = hc_timer_get (timer_logging);
|
||||
|
||||
@ -34,7 +34,7 @@ int brain_logging (FILE *stream, const int client_fd, const char *format, ...)
|
||||
|
||||
gettimeofday (&v, NULL);
|
||||
|
||||
fprintf (stream, "%d.%06d | %6.2fs | %3d | ", (u32) v.tv_sec, (u32) v.tv_usec, ms / 1000, client_fd);
|
||||
fprintf (stream, "%d.%06d | %6.2fs | %3d | ", (u32) v.tv_sec, (u32) v.tv_usec, ms / 1000, client_idx);
|
||||
|
||||
va_list ap;
|
||||
|
||||
@ -590,7 +590,7 @@ u32 brain_auth_challenge (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, 0, "CryptGenRandom: %d\n", (int) GetLastError ());
|
||||
brain_logging (stderr, -1, "CryptGenRandom: %d\n", (int) GetLastError ());
|
||||
|
||||
return val;
|
||||
}
|
||||
@ -599,7 +599,7 @@ u32 brain_auth_challenge (void)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, 0, "CryptAcquireContext: %d\n", (int) GetLastError ());
|
||||
brain_logging (stderr, -1, "CryptAcquireContext: %d\n", (int) GetLastError ());
|
||||
|
||||
return val;
|
||||
}
|
||||
@ -612,14 +612,14 @@ u32 brain_auth_challenge (void)
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", urandom, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", urandom, strerror (errno));
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
if (fread (&val, sizeof (val), 1, fd) != 1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", urandom, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", urandom, strerror (errno));
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -658,7 +658,7 @@ int brain_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen, c
|
||||
sizeof (msg), // size of msgbuf, bytes
|
||||
NULL); // va_list of arguments
|
||||
|
||||
brain_logging (stderr, 0, "connect: %s\n", msg);
|
||||
brain_logging (stderr, -1, "connect: %s\n", msg);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -669,7 +669,7 @@ int brain_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen, c
|
||||
|
||||
if (fcntl (sockfd, F_SETFL, old_mode | O_NONBLOCK) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "fcntl: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "fcntl: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -682,7 +682,7 @@ int brain_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen, c
|
||||
|
||||
if (rc_select == 0)
|
||||
{
|
||||
brain_logging (stderr, 0, "connect: timeout\n");
|
||||
brain_logging (stderr, -1, "connect: timeout\n");
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -693,21 +693,21 @@ int brain_connect (int sockfd, const struct sockaddr *addr, socklen_t addrlen, c
|
||||
|
||||
if (getsockopt (sockfd, SOL_SOCKET, SO_ERROR, &so_error, &len) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "getsockopt: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "getsockopt: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (fcntl (sockfd, F_SETFL, old_mode) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "fcntl: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "fcntl: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (so_error != 0)
|
||||
{
|
||||
brain_logging (stderr, 0, "connect: %s\n", strerror (so_error));
|
||||
brain_logging (stderr, -1, "connect: %s\n", strerror (so_error));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -892,11 +892,26 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
memset (&device_param->brain_link_recv_speed, 0, sizeof (link_speed_t));
|
||||
memset (&device_param->brain_link_send_speed, 0, sizeof (link_speed_t));
|
||||
|
||||
#if defined (_WIN)
|
||||
WSADATA wsaData;
|
||||
|
||||
WORD wVersionRequested = MAKEWORD (2,2);
|
||||
|
||||
const int iResult = WSAStartup (wVersionRequested, &wsaData);
|
||||
|
||||
if (iResult != NO_ERROR)
|
||||
{
|
||||
fprintf (stderr, "WSAStartup: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
const int brain_link_client_fd = socket (AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
if (brain_link_client_fd == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "socket: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "socket: %s\n", strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -906,7 +921,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (setsockopt (brain_link_client_fd, SOL_TCP, TCP_NODELAY, &one, sizeof (one)) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "setsockopt: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "setsockopt: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -953,7 +968,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", host_real, gai_strerror (rc_getaddrinfo));
|
||||
brain_logging (stderr, -1, "%s: %s\n", host_real, gai_strerror (rc_getaddrinfo));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -973,7 +988,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_send (brain_link_client_fd, &brain_link_version, sizeof (brain_link_version), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -984,7 +999,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_recv (brain_link_client_fd, &brain_link_version_ok, sizeof (brain_link_version_ok), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -993,7 +1008,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_link_version_ok == 0)
|
||||
{
|
||||
brain_logging (stderr, 0, "Invalid brain server version\n");
|
||||
brain_logging (stderr, -1, "Invalid brain server version\n");
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1004,7 +1019,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_recv (brain_link_client_fd, &challenge, sizeof (challenge), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1015,7 +1030,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_send (brain_link_client_fd, &response, sizeof (response), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1026,7 +1041,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_recv (brain_link_client_fd, &password_ok, sizeof (password_ok), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1035,7 +1050,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (password_ok == 0)
|
||||
{
|
||||
brain_logging (stderr, 0, "Invalid brain server password\n");
|
||||
brain_logging (stderr, -1, "Invalid brain server password\n");
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1044,7 +1059,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_send (brain_link_client_fd, &brain_session, sizeof (brain_session), SEND_FLAGS, device_param, status_ctx) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1053,7 +1068,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_send (brain_link_client_fd, &brain_attack, sizeof (brain_attack), SEND_FLAGS, device_param, status_ctx) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1062,7 +1077,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_send (brain_link_client_fd, &passwords_max, sizeof (passwords_max), SEND_FLAGS, device_param, status_ctx) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1071,7 +1086,7 @@ bool brain_client_connect (hc_device_param_t *device_param, const status_ctx_t *
|
||||
|
||||
if (brain_recv (brain_link_client_fd, highest, sizeof (u64), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
close (brain_link_client_fd);
|
||||
|
||||
@ -1501,7 +1516,7 @@ bool brain_server_read_hash_dumps (brain_server_dbs_t *brain_server_dbs, const c
|
||||
|
||||
if (chdir (path) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", path, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", path, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1510,7 +1525,7 @@ bool brain_server_read_hash_dumps (brain_server_dbs_t *brain_server_dbs, const c
|
||||
|
||||
if (dirp == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", path, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", path, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1589,7 +1604,7 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (stat (file, &sb) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1598,7 +1613,7 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1608,7 +1623,7 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (brain_server_db_hash_realloc (brain_server_db_hash, temp_cnt) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -1619,7 +1634,7 @@ bool brain_server_read_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (nread != (size_t) temp_cnt)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_hash_long_t));
|
||||
brain_logging (stderr, -1, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_hash_long_t));
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -1654,7 +1669,7 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1664,7 +1679,7 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (nwrite != (size_t) brain_server_db_hash->long_cnt)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_hash_long_t));
|
||||
brain_logging (stderr, -1, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_hash_long_t));
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -1684,7 +1699,7 @@ bool brain_server_write_hash_dump (brain_server_db_hash_t *brain_server_db_hash,
|
||||
|
||||
if (stat (file, &sb) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1700,7 +1715,7 @@ bool brain_server_read_attack_dumps (brain_server_dbs_t *brain_server_dbs, const
|
||||
|
||||
if (chdir (path) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", path, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", path, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1709,7 +1724,7 @@ bool brain_server_read_attack_dumps (brain_server_dbs_t *brain_server_dbs, const
|
||||
|
||||
if (dirp == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", path, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", path, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1788,7 +1803,7 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at
|
||||
|
||||
if (stat (file, &sb) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1797,7 +1812,7 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1807,7 +1822,7 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at
|
||||
|
||||
if (brain_server_db_attack_realloc (brain_server_db_attack, temp_cnt, 0) == false)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -1818,7 +1833,7 @@ bool brain_server_read_attack_dump (brain_server_db_attack_t *brain_server_db_at
|
||||
|
||||
if (nread != (size_t) temp_cnt)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_attack_long_t));
|
||||
brain_logging (stderr, -1, "%s: only %" PRIu64 " bytes read\n", file, (u64) nread * sizeof (brain_server_attack_long_t));
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -1853,7 +1868,7 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a
|
||||
|
||||
if (fd == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1865,7 +1880,7 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a
|
||||
|
||||
if (nwrite != (size_t) brain_server_db_attack->long_cnt)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_attack_long_t));
|
||||
brain_logging (stderr, -1, "%s: only %" PRIu64 " bytes written\n", file, (u64) nwrite * sizeof (brain_server_attack_long_t));
|
||||
|
||||
fclose (fd);
|
||||
|
||||
@ -1885,7 +1900,7 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a
|
||||
|
||||
if (stat (file, &sb) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", file, strerror (errno));
|
||||
brain_logging (stderr, -1, "%s: %s\n", file, strerror (errno));
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -1895,6 +1910,21 @@ bool brain_server_write_attack_dump (brain_server_db_attack_t *brain_server_db_a
|
||||
return true;
|
||||
}
|
||||
|
||||
int brain_server_get_client_idx (brain_server_dbs_t *brain_server_dbs)
|
||||
{
|
||||
for (int i = 0; i < BRAIN_SERVER_CLIENTS_MAX; i++)
|
||||
{
|
||||
if (brain_server_dbs->client_slots[i] == 0)
|
||||
{
|
||||
brain_server_dbs->client_slots[i] = 1;
|
||||
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
i64 brain_server_find_hash_long (const u32 *search, const brain_server_hash_long_t *buf, const i64 cnt)
|
||||
{
|
||||
for (i64 l = 0, r = cnt; r; r >>= 1)
|
||||
@ -1981,6 +2011,7 @@ void *brain_server_handle_client (void *p)
|
||||
{
|
||||
brain_server_client_options_t *brain_server_client_options = (brain_server_client_options_t *) p;
|
||||
|
||||
const int client_idx = brain_server_client_options->client_idx;
|
||||
const int client_fd = brain_server_client_options->client_fd;
|
||||
const char *auth_password = brain_server_client_options->auth_password;
|
||||
const u32 *session_whitelist_buf = brain_server_client_options->session_whitelist_buf;
|
||||
@ -1995,7 +2026,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (setsockopt (client_fd, SOL_TCP, TCP_NODELAY, &one, sizeof (one)) == -1)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "setsockopt: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "setsockopt: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2009,7 +2042,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_recv (client_fd, &brain_link_version, sizeof (brain_link_version), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2020,7 +2055,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_send (client_fd, &brain_link_version_ok, sizeof (brain_link_version_ok), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2029,7 +2066,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_link_version_ok == 0)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Invalid version\n");
|
||||
brain_logging (stderr, client_idx, "Invalid version\n");
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2040,7 +2079,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_send (client_fd, &challenge, sizeof (challenge), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2051,7 +2092,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_recv (client_fd, &response, sizeof (response), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2064,7 +2107,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_send (client_fd, &password_ok, sizeof (password_ok), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2073,7 +2118,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (password_ok == 0)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Invalid password\n");
|
||||
brain_logging (stderr, client_idx, "Invalid password\n");
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2084,7 +2131,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_recv (client_fd, &brain_session, sizeof (brain_session), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2107,7 +2156,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (found == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Invalid brain session: 0x%08x\n", brain_session);
|
||||
brain_logging (stderr, client_idx, "Invalid brain session: 0x%08x\n", brain_session);
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2119,7 +2170,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_recv (client_fd, &brain_attack, sizeof (brain_attack), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2130,7 +2183,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_recv (client_fd, &passwords_max, sizeof (passwords_max), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_recv: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_recv: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2139,14 +2194,16 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (passwords_max >= BRAIN_LINK_CANDIDATES_MAX)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Too large candidate allocation buffer size\n");
|
||||
brain_logging (stderr, client_idx, "Too large candidate allocation buffer size\n");
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
brain_logging (stdout, client_fd, "Session: 0x%08x, Attack: 0x%08x, Kernel-power: %" PRIu64 "\n", brain_session, brain_attack, passwords_max);
|
||||
brain_logging (stdout, client_idx, "Session: 0x%08x, Attack: 0x%08x, Kernel-power: %" PRIu64 "\n", brain_session, brain_attack, passwords_max);
|
||||
|
||||
// so far so good
|
||||
|
||||
@ -2170,7 +2227,9 @@ void *brain_server_handle_client (void *p)
|
||||
{
|
||||
if (brain_server_dbs->hash_cnt >= BRAIN_SERVER_SESSIONS_MAX)
|
||||
{
|
||||
brain_logging (stderr, 0, "too many sessions\n");
|
||||
brain_logging (stderr, -1, "too many sessions\n");
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2202,7 +2261,9 @@ void *brain_server_handle_client (void *p)
|
||||
{
|
||||
if (brain_server_dbs->attack_cnt >= BRAIN_SERVER_ATTACKS_MAX)
|
||||
{
|
||||
brain_logging (stderr, 0, "too many attacks\n");
|
||||
brain_logging (stderr, -1, "too many attacks\n");
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2224,7 +2285,9 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_send (client_fd, &highest, sizeof (highest), 0, NULL, NULL) == false)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "brain_send: %s\n", strerror (errno));
|
||||
brain_logging (stderr, client_idx, "brain_send: %s\n", strerror (errno));
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2239,7 +2302,7 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (recv_buf == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -2252,7 +2315,11 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (send_buf == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -2263,7 +2330,11 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (temp_buf == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -2277,7 +2348,11 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (brain_server_db_short->short_buf == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -2387,9 +2462,9 @@ void *brain_server_handle_client (void *p)
|
||||
{
|
||||
if (brain_server_db_attack_realloc (brain_server_db_attack, 0, 1) == true)
|
||||
{
|
||||
brain_server_db_attack->short_buf[brain_server_db_attack->short_cnt].offset = offset + overlap;
|
||||
brain_server_db_attack->short_buf[brain_server_db_attack->short_cnt].length = length - overlap;
|
||||
brain_server_db_attack->short_buf[brain_server_db_attack->short_cnt].client_fd = client_fd;
|
||||
brain_server_db_attack->short_buf[brain_server_db_attack->short_cnt].offset = offset + overlap;
|
||||
brain_server_db_attack->short_buf[brain_server_db_attack->short_cnt].length = length - overlap;
|
||||
brain_server_db_attack->short_buf[brain_server_db_attack->short_cnt].client_idx = client_idx;
|
||||
|
||||
brain_server_db_attack->short_cnt++;
|
||||
|
||||
@ -2403,7 +2478,7 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
const double ms = hc_timer_get (timer_reserved);
|
||||
|
||||
brain_logging (stdout, client_fd, "R | %8.2f ms | Offset: %" PRIu64 ", Length: %" PRIu64 ", Overlap: %" PRIu64 "\n", ms, offset, length, overlap);
|
||||
brain_logging (stdout, client_idx, "R | %8.2f ms | Offset: %" PRIu64 ", Length: %" PRIu64 ", Overlap: %" PRIu64 "\n", ms, offset, length, overlap);
|
||||
}
|
||||
else if (operation == BRAIN_OPERATION_COMMIT)
|
||||
{
|
||||
@ -2419,7 +2494,7 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
for (i64 idx = 0; idx < brain_server_db_attack->short_cnt; idx++)
|
||||
{
|
||||
if (brain_server_db_attack->short_buf[idx].client_fd == client_fd)
|
||||
if (brain_server_db_attack->short_buf[idx].client_idx == client_idx)
|
||||
{
|
||||
if (brain_server_db_attack_realloc (brain_server_db_attack, 1, 0) == true)
|
||||
{
|
||||
@ -2432,12 +2507,12 @@ void *brain_server_handle_client (void *p)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
}
|
||||
|
||||
brain_server_db_attack->short_buf[idx].offset = 0;
|
||||
brain_server_db_attack->short_buf[idx].length = 0;
|
||||
brain_server_db_attack->short_buf[idx].client_fd = 0;
|
||||
brain_server_db_attack->short_buf[idx].offset = 0;
|
||||
brain_server_db_attack->short_buf[idx].length = 0;
|
||||
brain_server_db_attack->short_buf[idx].client_idx = 0;
|
||||
|
||||
new_attacks++;
|
||||
}
|
||||
@ -2451,7 +2526,7 @@ void *brain_server_handle_client (void *p)
|
||||
{
|
||||
const double ms_attacks = hc_timer_get (timer_commit);
|
||||
|
||||
brain_logging (stdout, client_fd, "C | %8.2f ms | Attacks: %" PRIi64 "\n", ms_attacks, new_attacks);
|
||||
brain_logging (stdout, client_idx, "C | %8.2f ms | Attacks: %" PRIi64 "\n", ms_attacks, new_attacks);
|
||||
}
|
||||
|
||||
// time the lookups for debugging
|
||||
@ -2506,7 +2581,7 @@ void *brain_server_handle_client (void *p)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, client_fd, "unexpected remaining buffers in compare: %" PRIi64 " - %" PRIi64 "\n", long_left, short_left);
|
||||
brain_logging (stderr, client_idx, "unexpected remaining buffers in compare: %" PRIi64 " - %" PRIi64 "\n", long_left, short_left);
|
||||
}
|
||||
|
||||
brain_server_hash_long_t *next = &brain_server_db_hash->long_buf[idx];
|
||||
@ -2539,7 +2614,7 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if ((long_left != -1) || (short_left != -1))
|
||||
{
|
||||
brain_logging (stderr, client_fd, "unexpected remaining buffers in commit: %" PRIi64 " - %" PRIi64 "\n", long_left, short_left);
|
||||
brain_logging (stderr, client_idx, "unexpected remaining buffers in commit: %" PRIi64 " - %" PRIi64 "\n", long_left, short_left);
|
||||
}
|
||||
|
||||
brain_server_db_hash->long_cnt = cnt_total - long_dupes;
|
||||
@ -2556,7 +2631,7 @@ void *brain_server_handle_client (void *p)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
}
|
||||
|
||||
brain_server_db_hash->write_hashes = true;
|
||||
@ -2568,7 +2643,7 @@ void *brain_server_handle_client (void *p)
|
||||
{
|
||||
const double ms_hashes = hc_timer_get (timer_commit);
|
||||
|
||||
brain_logging (stdout, client_fd, "C | %8.2f ms | Hashes: %" PRIi64 "\n", ms_hashes, brain_server_db_short->short_cnt);
|
||||
brain_logging (stdout, client_idx, "C | %8.2f ms | Hashes: %" PRIi64 "\n", ms_hashes, brain_server_db_short->short_cnt);
|
||||
}
|
||||
|
||||
brain_server_db_short->short_cnt = 0;
|
||||
@ -2581,7 +2656,7 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (in_size == 0)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Zero in_size value\n");
|
||||
brain_logging (stderr, client_idx, "Zero in_size value\n");
|
||||
|
||||
break;
|
||||
}
|
||||
@ -2594,14 +2669,14 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
if (hashes_cnt == 0)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Zero passwords\n");
|
||||
brain_logging (stderr, client_idx, "Zero passwords\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (hashes_cnt > passwords_max)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Too many passwords\n");
|
||||
brain_logging (stderr, client_idx, "Too many passwords\n");
|
||||
|
||||
break;
|
||||
}
|
||||
@ -2783,7 +2858,7 @@ void *brain_server_handle_client (void *p)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, client_fd, "unexpected remaining buffers in compare: %" PRIi64 " - %" PRIi64 "\n", short_left, unique_left);
|
||||
brain_logging (stderr, client_idx, "unexpected remaining buffers in compare: %" PRIi64 " - %" PRIi64 "\n", short_left, unique_left);
|
||||
}
|
||||
|
||||
brain_server_hash_short_t *next = brain_server_db_short->short_buf + idx;
|
||||
@ -2804,13 +2879,13 @@ void *brain_server_handle_client (void *p)
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, client_fd, "unexpected zero comparison in commit\n");
|
||||
brain_logging (stderr, client_idx, "unexpected zero comparison in commit\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ((short_left != -1) || (unique_left != -1))
|
||||
{
|
||||
brain_logging (stderr, client_fd, "unexpected remaining buffers in commit: %" PRIi64 " - %" PRIi64 "\n", short_left, unique_left);
|
||||
brain_logging (stderr, client_idx, "unexpected remaining buffers in commit: %" PRIi64 " - %" PRIi64 "\n", short_left, unique_left);
|
||||
}
|
||||
|
||||
brain_server_db_short->short_cnt = cnt_total;
|
||||
@ -2833,7 +2908,7 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
const double ms = hc_timer_get (timer_lookup);
|
||||
|
||||
brain_logging (stdout, client_fd, "L | %8.2f ms | Long: %" PRIi64 ", Inc: %d, New: %d\n", ms, brain_server_db_hash->long_cnt, hashes_cnt, local_lookup_new);
|
||||
brain_logging (stdout, client_idx, "L | %8.2f ms | Long: %" PRIi64 ", Inc: %d, New: %d\n", ms, brain_server_db_hash->long_cnt, hashes_cnt, local_lookup_new);
|
||||
|
||||
// send
|
||||
|
||||
@ -2855,11 +2930,11 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
for (i64 idx = 0; idx < brain_server_db_attack->short_cnt; idx++)
|
||||
{
|
||||
if (brain_server_db_attack->short_buf[idx].client_fd == client_fd)
|
||||
if (brain_server_db_attack->short_buf[idx].client_idx == client_idx)
|
||||
{
|
||||
brain_server_db_attack->short_buf[idx].offset = 0;
|
||||
brain_server_db_attack->short_buf[idx].length = 0;
|
||||
brain_server_db_attack->short_buf[idx].client_fd = 0;
|
||||
brain_server_db_attack->short_buf[idx].offset = 0;
|
||||
brain_server_db_attack->short_buf[idx].length = 0;
|
||||
brain_server_db_attack->short_buf[idx].client_idx = -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2876,7 +2951,9 @@ void *brain_server_handle_client (void *p)
|
||||
hcfree (temp_buf);
|
||||
hcfree (recv_buf);
|
||||
|
||||
brain_logging (stdout, client_fd, "Disconnected\n");
|
||||
brain_logging (stdout, client_idx, "Disconnected\n");
|
||||
|
||||
brain_server_dbs->client_slots[client_idx] = 0;
|
||||
|
||||
close (client_fd);
|
||||
|
||||
@ -2885,6 +2962,21 @@ void *brain_server_handle_client (void *p)
|
||||
|
||||
int brain_server (const char *listen_host, const int listen_port, const char *brain_password, const char *brain_session_whitelist)
|
||||
{
|
||||
#if defined (_WIN)
|
||||
WSADATA wsaData;
|
||||
|
||||
WORD wVersionRequested = MAKEWORD (2,2);
|
||||
|
||||
const int iResult = WSAStartup (wVersionRequested, &wsaData);
|
||||
|
||||
if (iResult != NO_ERROR)
|
||||
{
|
||||
fprintf (stderr, "WSAStartup: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
hc_timer_set (&timer_logging);
|
||||
|
||||
hc_thread_mutex_init (mux_display);
|
||||
@ -2914,7 +3006,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (server_fd == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "socket: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "socket: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -2924,14 +3016,14 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (setsockopt (server_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof (one)) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "setsockopt: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "setsockopt: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (setsockopt (server_fd, SOL_TCP, TCP_NODELAY, &one, sizeof (one)) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "setsockopt: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "setsockopt: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -2972,7 +3064,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
}
|
||||
else
|
||||
{
|
||||
brain_logging (stderr, 0, "%s: %s\n", listen_host, gai_strerror (rc_getaddrinfo));
|
||||
brain_logging (stderr, -1, "%s: %s\n", listen_host, gai_strerror (rc_getaddrinfo));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -2980,14 +3072,14 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (bind (server_fd, (struct sockaddr *) &sa, salen) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "bind: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "bind: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (listen (server_fd, 5) == -1)
|
||||
{
|
||||
brain_logging (stderr, 0, "listen: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "listen: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -2996,7 +3088,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (brain_server_dbs == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -3008,7 +3100,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (brain_server_dbs->hash_buf == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -3023,7 +3115,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (brain_server_dbs->attack_buf == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -3033,6 +3125,15 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
return -1;
|
||||
}
|
||||
|
||||
brain_server_dbs->client_slots = (int *) hccalloc (BRAIN_SERVER_CLIENTS_MAX, sizeof (int));
|
||||
|
||||
if (brain_server_dbs->client_slots == NULL)
|
||||
{
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// session whitelists
|
||||
|
||||
u32 *session_whitelist_buf = (u32 *) hccalloc (BRAIN_SERVER_SESSIONS_MAX, sizeof (u32));
|
||||
@ -3044,7 +3145,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (sessions == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -3072,7 +3173,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (brain_server_client_options == NULL)
|
||||
{
|
||||
brain_logging (stderr, 0, "%s\n", MSG_ENOMEM);
|
||||
brain_logging (stderr, -1, "%s\n", MSG_ENOMEM);
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -3082,8 +3183,9 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
// none of these value change
|
||||
|
||||
brain_server_client_options[client_idx].brain_server_dbs = brain_server_dbs;
|
||||
brain_server_client_options[client_idx].client_fd = client_idx;
|
||||
brain_server_client_options[client_idx].auth_password = auth_password;
|
||||
brain_server_client_options[client_idx].client_idx = client_idx;
|
||||
brain_server_client_options[client_idx].client_fd = -1;
|
||||
brain_server_client_options[client_idx].session_whitelist_buf = session_whitelist_buf;
|
||||
brain_server_client_options[client_idx].session_whitelist_cnt = session_whitelist_cnt;
|
||||
}
|
||||
@ -3094,7 +3196,7 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
if (signal (SIGINT, brain_server_handle_signal) == SIG_ERR)
|
||||
{
|
||||
brain_logging (stderr, 0, "signal: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "signal: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
@ -3132,33 +3234,28 @@ int brain_server (const char *listen_host, const int listen_port, const char *br
|
||||
|
||||
const int client_fd = accept (server_fd, (struct sockaddr *) &ca, (socklen_t *) &calen);
|
||||
|
||||
brain_logging (stdout, client_fd, "Connection from %s:%d\n", inet_ntoa (ca.sin_addr), ntohs (ca.sin_port));
|
||||
brain_logging (stdout, -1, "Connection from %s:%d\n", inet_ntoa (ca.sin_addr), ntohs (ca.sin_port));
|
||||
|
||||
if (client_fd <= 2)
|
||||
const int client_idx = brain_server_get_client_idx (brain_server_dbs);
|
||||
|
||||
if (client_idx == -1)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Invalid client_fd\n");
|
||||
|
||||
keep_running = false;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (client_fd >= BRAIN_SERVER_CLIENTS_MAX)
|
||||
{
|
||||
brain_logging (stderr, client_fd, "Too many clients\n");
|
||||
brain_logging (stderr, client_idx, "Too many clients\n");
|
||||
|
||||
close (client_fd);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
brain_server_client_options[client_idx].client_fd = client_fd;
|
||||
|
||||
hc_thread_t client_thr;
|
||||
|
||||
hc_thread_create (client_thr, brain_server_handle_client, &brain_server_client_options[client_fd]);
|
||||
hc_thread_create (client_thr, brain_server_handle_client, &brain_server_client_options[client_idx]);
|
||||
|
||||
if (client_thr == 0)
|
||||
{
|
||||
brain_logging (stderr, 0, "pthread_create: %s\n", strerror (errno));
|
||||
brain_logging (stderr, -1, "pthread_create: %s\n", strerror (errno));
|
||||
|
||||
close (client_fd);
|
||||
|
||||
|
@ -1871,24 +1871,6 @@ int user_options_check_files (hashcat_ctx_t *hashcat_ctx)
|
||||
// brain
|
||||
|
||||
#ifdef WITH_BRAIN
|
||||
#if defined (_WIN)
|
||||
if ((user_options->brain_client == true) || (user_options->brain_server == true))
|
||||
{
|
||||
WSADATA wsaData;
|
||||
|
||||
WORD wVersionRequested = MAKEWORD (2,2);
|
||||
|
||||
const int iResult = WSAStartup (wVersionRequested, &wsaData);
|
||||
|
||||
if (iResult != NO_ERROR)
|
||||
{
|
||||
fprintf (stderr, "WSAStartup: %s\n", strerror (errno));
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (user_options->brain_host)
|
||||
{
|
||||
struct addrinfo hints;
|
||||
|
Loading…
Reference in New Issue
Block a user