Cosmetic changes

This commit is contained in:
wiire-a 2017-12-20 19:15:07 +01:00
parent 0eb8050d6c
commit 8807357127
5 changed files with 37 additions and 47 deletions

View File

@ -252,7 +252,7 @@ static void init_crack_jobs(struct global *wps, int mode)
job_control.nonce_seed = 0; job_control.nonce_seed = 0;
memset(job_control.randr_enonce, 0, sizeof(job_control.randr_enonce)); memset(job_control.randr_enonce, 0, sizeof(job_control.randr_enonce));
/* Converting enrollee nonce to the sequence may be generated by current random function */ /* Convert Enrollee nonce to the sequence may be generated by current random function */
int i, j = 0; int i, j = 0;
if (mode == -RTL819x) ; /* nuffin' */ if (mode == -RTL819x) ; /* nuffin' */
else if (mode == RTL819x) else if (mode == RTL819x)
@ -362,7 +362,7 @@ static int find_rtl_es(struct global *wps)
init_crack_jobs(wps, -RTL819x); init_crack_jobs(wps, -RTL819x);
/* Checking distance 0 in the main thread, as it is the most likely */ /* Check distance 0 in the main thread, as it is the most likely */
uint8_t nonce_buf[WPS_SECRET_NONCE_LEN]; uint8_t nonce_buf[WPS_SECRET_NONCE_LEN];
char pin[WPS_PIN_LEN + 1]; char pin[WPS_PIN_LEN + 1];
@ -961,7 +961,7 @@ usage_err:
if (!wps->authkey) { if (!wps->authkey) {
if (wps->e_nonce) { if (wps->e_nonce) {
if (wps->r_nonce) { if (wps->r_nonce) {
if (wps->e_bssid) { /* Computing AuthKey */ if (wps->e_bssid) { /* Compute AuthKey */
wps->dhkey = malloc(WPS_HASH_LEN); wps->dhkey = malloc(WPS_HASH_LEN);
if (!wps->dhkey) if (!wps->dhkey)
goto memory_err; goto memory_err;
@ -1033,11 +1033,11 @@ usage_err:
} }
} }
/* Allocating memory for E-S1 and E-S2 */ /* Allocate memory for E-S1 and E-S2 */
wps->e_s1 = malloc(WPS_SECRET_NONCE_LEN); if (!wps->e_s1) goto memory_err; wps->e_s1 = malloc(WPS_SECRET_NONCE_LEN); if (!wps->e_s1) goto memory_err;
wps->e_s2 = malloc(WPS_SECRET_NONCE_LEN); if (!wps->e_s2) goto memory_err; wps->e_s2 = malloc(WPS_SECRET_NONCE_LEN); if (!wps->e_s2) goto memory_err;
/* Allocating memory for digests */ /* Allocate memory for digests */
wps->psk1 = malloc(WPS_HASH_LEN); if (!wps->psk1) goto memory_err; wps->psk1 = malloc(WPS_HASH_LEN); if (!wps->psk1) goto memory_err;
wps->psk2 = malloc(WPS_HASH_LEN); if (!wps->psk2) goto memory_err; wps->psk2 = malloc(WPS_HASH_LEN); if (!wps->psk2) goto memory_err;
wps->empty_psk = malloc(WPS_HASH_LEN); if (!wps->empty_psk) goto memory_err; wps->empty_psk = malloc(WPS_HASH_LEN); if (!wps->empty_psk) goto memory_err;
@ -1133,7 +1133,7 @@ usage_err:
DEBUG_PRINT(" * Mode: %d (%s)", ECOS_SIMPLE, p_mode_name[ECOS_SIMPLE]); DEBUG_PRINT(" * Mode: %d (%s)", ECOS_SIMPLE, p_mode_name[ECOS_SIMPLE]);
uint32_t known = wps->e_nonce[0] << 25; /* Reducing entropy from 32 to 25 bits */ uint32_t known = wps->e_nonce[0] << 25; /* Reduce entropy from 32 to 25 bits */
uint32_t seed, counter = 0; uint32_t seed, counter = 0;
while (counter < 0x02000000) { while (counter < 0x02000000) {
int i; int i;
@ -1194,7 +1194,7 @@ usage_err:
} }
else { else {
/* Checks if the sequence may actually be generated by current random function */ /* Check if the sequence may actually be generated by current random function */
if (!(wps->e_nonce[0] & 0x80) && !(wps->e_nonce[4] & 0x80) && if (!(wps->e_nonce[0] & 0x80) && !(wps->e_nonce[4] & 0x80) &&
!(wps->e_nonce[8] & 0x80) && !(wps->e_nonce[12] & 0x80)) { !(wps->e_nonce[8] & 0x80) && !(wps->e_nonce[12] & 0x80)) {
@ -1519,7 +1519,7 @@ static int check_empty_pin_half(const uint8_t *es, struct global *wps, const uin
return !memcmp(result, ehash, WPS_HASH_LEN); return !memcmp(result, ehash, WPS_HASH_LEN);
} }
/* returns 1 if numeric pin half found, -1 if empty pin found, 0 if not found */ /* Return 1 if numeric pin half found, -1 if empty pin found, 0 if not found */
static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_override) static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_override)
{ {
*pin = 0; *pin = 0;
@ -1538,7 +1538,7 @@ static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_ov
for (first_half = 0; first_half < 10000; first_half++) { for (first_half = 0; first_half < 10000; first_half++) {
uint_to_char_array(first_half, 4, pin); uint_to_char_array(first_half, 4, pin);
if (check_pin_half(&hc, pin, psk, es1, wps, wps->e_hash1)) { if (check_pin_half(&hc, pin, psk, es1, wps, wps->e_hash1)) {
pin[4] = 0; /* make sure pin string is zero-terminated */ pin[4] = 0; /* Make sure pin string is zero-terminated */
memcpy(wps->psk1, psk, sizeof psk); memcpy(wps->psk1, psk, sizeof psk);
return 1; return 1;
} }
@ -1547,7 +1547,7 @@ static int crack_first_half(struct global *wps, char *pin, const uint8_t *es1_ov
return 0; return 0;
} }
/* returns non-zero if pin found, -1 if empty pin found, 0 if not found */ /* Return non-zero if pin found, -1 if empty pin found, 0 if not found */
static int crack_second_half(struct global *wps, char *pin) static int crack_second_half(struct global *wps, char *pin)
{ {
if (!pin[0] && check_empty_pin_half(wps->e_s2, wps, wps->e_hash2)) { if (!pin[0] && check_empty_pin_half(wps->e_s2, wps, wps->e_hash2)) {
@ -1583,7 +1583,7 @@ static int crack_second_half(struct global *wps, char *pin)
uint_to_char_array(second_half, 4, s_pin); uint_to_char_array(second_half, 4, s_pin);
if (check_pin_half(&hc, s_pin, psk, wps->e_s2, wps, wps->e_hash2)) { if (check_pin_half(&hc, s_pin, psk, wps->e_s2, wps, wps->e_hash2)) {
memcpy(wps->psk2, psk, sizeof psk); memcpy(wps->psk2, psk, sizeof psk);
pin[8] = 0; /* make sure pin string is zero-terminated */ pin[8] = 0; /* Make sure pin string is zero-terminated */
return 1; return 1;
} }
} }
@ -1591,7 +1591,7 @@ static int crack_second_half(struct global *wps, char *pin)
return 0; return 0;
} }
/* PIN cracking attempt - returns 0 for success, 1 for failure */ /* PIN cracking attempt, return 0 for success, 1 for failure */
static int crack(struct global *wps, char *pin) static int crack(struct global *wps, char *pin)
{ {
return !(crack_first_half(wps, pin, 0) && crack_second_half(wps, pin)); return !(crack_first_half(wps, pin, 0) && crack_second_half(wps, pin));

View File

@ -87,13 +87,12 @@ const uint8_t wps_rtl_pke[] = {
0x66,0xA5,0xA4,0x90, 0x47,0x2C,0xEB,0xA9, 0xE3,0xB4,0x22,0x4F, 0x3D,0x89,0xFB,0x2B 0x66,0xA5,0xA4,0x90, 0x47,0x2C,0xEB,0xA9, 0xE3,0xB4,0x22,0x4F, 0x3D,0x89,0xFB,0x2B
}; };
/* Unused */ /* const uint8_t rtl_rnd_seed[] = {
const uint8_t rtl_rnd_seed[] = {
0x52,0x65,0x61,0x6c, 0x74,0x65,0x6b,0x20, 0x57,0x69,0x46,0x69, 0x20,0x53,0x69,0x6d, 0x52,0x65,0x61,0x6c, 0x74,0x65,0x6b,0x20, 0x57,0x69,0x46,0x69, 0x20,0x53,0x69,0x6d,
0x70,0x6c,0x65,0x2d, 0x43,0x6f,0x6e,0x66, 0x69,0x67,0x20,0x44, 0x61,0x65,0x6d,0x6f, 0x70,0x6c,0x65,0x2d, 0x43,0x6f,0x6e,0x66, 0x69,0x67,0x20,0x44, 0x61,0x65,0x6d,0x6f,
0x6e,0x20,0x70,0x72, 0x6f,0x67,0x72,0x61, 0x6d,0x20,0x32,0x30, 0x30,0x36,0x2d,0x30, 0x6e,0x20,0x70,0x72, 0x6f,0x67,0x72,0x61, 0x6d,0x20,0x32,0x30, 0x30,0x36,0x2d,0x30,
0x35,0x2d,0x31,0x35 0x35,0x2d,0x31,0x35
}; }; */
struct global { struct global {
char pin[WPS_PIN_LEN + 1]; char pin[WPS_PIN_LEN + 1];
@ -154,8 +153,6 @@ char usage[] =
"\n" "\n"
" -m, --r-nonce : Registrar nonce\n" " -m, --r-nonce : Registrar nonce\n"
" -b, --e-bssid : Enrollee BSSID\n" " -b, --e-bssid : Enrollee BSSID\n"
// " -S, --dh-small : Small Diffie-Hellman keys (PKr not needed) [No]\n"
// " -l, --length : Bruteforce entire pin length (experimental)\n"
" -v, --verbosity : Verbosity level 1-3, 1 is quietest [3]\n" " -v, --verbosity : Verbosity level 1-3, 1 is quietest [3]\n"
" -o, --output : Write output to file\n" " -o, --output : Write output to file\n"
" -j, --jobs : Number of parallel threads to use [Auto]\n" " -j, --jobs : Number of parallel threads to use [Auto]\n"
@ -286,7 +283,7 @@ static inline uint_fast8_t parse_mode(char *list, uint_fast8_t *dst, const uint8
return 0; return 0;
} }
/* Checks if passed mode is selected */ /* Check if passed mode is selected */
static inline uint_fast8_t is_mode_selected(const uint_fast8_t mode) static inline uint_fast8_t is_mode_selected(const uint_fast8_t mode)
{ {
for (uint_fast8_t i = 0; i < MODE_LEN && p_mode[i] != NONE; i++) { for (uint_fast8_t i = 0; i < MODE_LEN && p_mode[i] != NONE; i++) {

View File

@ -23,7 +23,7 @@
#include <sys/types.h> #include <sys/types.h>
/* Converts an hex string to a byte array */ /* Convert an hex string to a byte array */
unsigned int hex_string_to_byte_array(char *in, uint8_t *out, const unsigned int n_len) unsigned int hex_string_to_byte_array(char *in, uint8_t *out, const unsigned int n_len)
{ {
unsigned int len = strlen(in); unsigned int len = strlen(in);
@ -57,7 +57,7 @@ unsigned int hex_string_to_byte_array(char *in, uint8_t *out, const unsigned int
return 0; return 0;
} }
/* Converts an hex string to a byte array */ /* Convert an hex string to a byte array */
unsigned int hex_string_to_byte_array_max( unsigned int hex_string_to_byte_array_max(
char *in, uint8_t *out, const unsigned int max_len, unsigned int *m_len) char *in, uint8_t *out, const unsigned int max_len, unsigned int *m_len)
{ {
@ -111,7 +111,7 @@ end:
return 0; return 0;
} }
/* Converts a string into an integer */ /* Convert a string into an integer */
int get_int(char *in, int *out) int get_int(char *in, int *out)
{ {
int i, o = 0, len = strlen(in); int i, o = 0, len = strlen(in);
@ -172,7 +172,7 @@ time_t c_timegm(register struct tm *t)
return result; return result;
} }
/* Converts a [mm/]yyyy string to Unix date time */ /* Convert a [mm/]yyyy string to Unix date time */
unsigned int get_unix_datetime(char *s, time_t *datetime) unsigned int get_unix_datetime(char *s, time_t *datetime)
{ {
unsigned int len = strlen(s); unsigned int len = strlen(s);
@ -217,14 +217,10 @@ unsigned int get_unix_datetime(char *s, time_t *datetime)
*datetime = (time_t)0x7fffffff; *datetime = (time_t)0x7fffffff;
} }
else { else {
struct tm t; struct tm t = {
t.tm_sec = 0; .tm_year = year - 1900,
t.tm_min = 0; .tm_mon = month - 1,
t.tm_hour = 0; .tm_mday = 1 };
t.tm_mday = 1;
t.tm_mon = month - 1;
t.tm_year = year - 1900;
t.tm_isdst = 0;
*datetime = c_timegm(&t); *datetime = c_timegm(&t);
if (*datetime < 0) /* When time_t is 64 bits this check is pointless */ if (*datetime < 0) /* When time_t is 64 bits this check is pointless */
@ -234,13 +230,13 @@ unsigned int get_unix_datetime(char *s, time_t *datetime)
return 0; return 0;
} }
/* Returns the difference of time between the two in milliseconds */ /* Return the difference of time between the two in milliseconds */
unsigned long get_elapsed_ms(struct timeval *start, struct timeval *end) unsigned long get_elapsed_ms(struct timeval *start, struct timeval *end)
{ {
return (((end->tv_sec - start->tv_sec) * 1000000 + (end->tv_usec - start->tv_usec)) / 1000); return (((end->tv_sec - start->tv_sec) * 1000000 + (end->tv_usec - start->tv_usec)) / 1000);
} }
/* Converts an unsigned integer to a char array without termination */ /* Convert an unsigned integer to a char array without termination */
static inline void uint_to_char_array(unsigned int num, unsigned int len, char *dst) static inline void uint_to_char_array(unsigned int num, unsigned int len, char *dst)
{ {
unsigned int mul = 1; unsigned int mul = 1;
@ -250,14 +246,11 @@ static inline void uint_to_char_array(unsigned int num, unsigned int len, char *
} }
} }
/* Prints a byte array in hexadecimal */ /* Print a byte array in hexadecimal */
void byte_array_print(const uint8_t *buffer, const unsigned int length) void byte_array_print(const uint8_t *buffer, const unsigned int length)
{ {
for (unsigned int i = 0; i < length; i++) { for (unsigned int i = 0; i < length; i++)
printf("%02x", buffer[i]); printf("%02x", buffer[i]);
// if (i != length - 1)
// printf(":");
}
} }
#endif /* UTILS_H */ #endif /* UTILS_H */