mirror of
https://github.com/wiire-a/pixiewps.git
synced 2025-07-28 16:24:55 +02:00
Fixed a few warnings
Warnings were found with GCC, Clang and Cppcheck.
This commit is contained in:
parent
81301b7e71
commit
6bdf8e8f37
@ -159,7 +159,7 @@ static void init_crack_jobs(struct global *wps) {
|
|||||||
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 */
|
/* Converting enrollee nonce to the sequence may be generated by current random function */
|
||||||
int i, j = 0;
|
int i, j = 0;
|
||||||
for (int i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
job_control.randr_enonce[i] |= wps->e_nonce[j++];
|
job_control.randr_enonce[i] |= wps->e_nonce[j++];
|
||||||
job_control.randr_enonce[i] <<= 8;
|
job_control.randr_enonce[i] <<= 8;
|
||||||
job_control.randr_enonce[i] |= wps->e_nonce[j++];
|
job_control.randr_enonce[i] |= wps->e_nonce[j++];
|
||||||
@ -523,7 +523,7 @@ usage_err:
|
|||||||
|
|
||||||
printf("\n Pixiewps %s\n", SHORT_VERSION);
|
printf("\n Pixiewps %s\n", SHORT_VERSION);
|
||||||
if (wps->verbosity > 1) {
|
if (wps->verbosity > 1) {
|
||||||
printf("\n [*] Mode: %u (%s)", RTL819x, p_mode_name[RTL819x]);
|
printf("\n [*] Mode: %d (%s)", RTL819x, p_mode_name[RTL819x]);
|
||||||
}
|
}
|
||||||
vtag_t *vtag;
|
vtag_t *vtag;
|
||||||
if (wps->verbosity > 2) {
|
if (wps->verbosity > 2) {
|
||||||
@ -532,24 +532,24 @@ usage_err:
|
|||||||
printf("\n [*] AuthKey: "); byte_array_print(wps->authkey, WPS_AUTHKEY_LEN);
|
printf("\n [*] AuthKey: "); byte_array_print(wps->authkey, WPS_AUTHKEY_LEN);
|
||||||
printf("\n [*] EMSK: "); byte_array_print(wps->emsk, WPS_EMSK_LEN);
|
printf("\n [*] EMSK: "); byte_array_print(wps->emsk, WPS_EMSK_LEN);
|
||||||
printf("\n [*] KeyWrapKey: "); byte_array_print(wps->wrapkey, WPS_KEYWRAPKEY_LEN);
|
printf("\n [*] KeyWrapKey: "); byte_array_print(wps->wrapkey, WPS_KEYWRAPKEY_LEN);
|
||||||
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_KEYWRAP_AUTH, WPS_TAG_KEYWRAP_AUTH_LEN)) {
|
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_KEYWRAP_AUTH, WPS_TAG_KEYWRAP_AUTH_LEN))) {
|
||||||
memcpy(buffer, vtag->data, WPS_TAG_KEYWRAP_AUTH_LEN);
|
memcpy(buffer, vtag->data, WPS_TAG_KEYWRAP_AUTH_LEN);
|
||||||
printf("\n [*] KeyWrap Authenticator: "); byte_array_print(buffer, WPS_TAG_KEYWRAP_AUTH_LEN);
|
printf("\n [*] KeyWrap Authenticator: "); byte_array_print(buffer, WPS_TAG_KEYWRAP_AUTH_LEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (vtag = find_vtag(decrypted5, wps->m5_encr_len - 16, WPS_TAG_E_SNONCE_1, WPS_NONCE_LEN)) {
|
if ((vtag = find_vtag(decrypted5, wps->m5_encr_len - 16, WPS_TAG_E_SNONCE_1, WPS_NONCE_LEN))) {
|
||||||
printf("\n [*] ES-1: "); byte_array_print(vtag->data, WPS_NONCE_LEN);
|
printf("\n [*] ES-1: "); byte_array_print(vtag->data, WPS_NONCE_LEN);
|
||||||
}
|
}
|
||||||
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_E_SNONCE_2, WPS_NONCE_LEN)) {
|
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_E_SNONCE_2, WPS_NONCE_LEN))) {
|
||||||
printf("\n [*] ES-2: "); byte_array_print(vtag->data, WPS_NONCE_LEN);
|
printf("\n [*] ES-2: "); byte_array_print(vtag->data, WPS_NONCE_LEN);
|
||||||
}
|
}
|
||||||
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_SSID, 0)) {
|
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_SSID, 0))) {
|
||||||
int tag_size = be16_to_h(vtag->len);
|
int tag_size = be16_to_h(vtag->len);
|
||||||
memcpy(buffer, vtag->data, tag_size);
|
memcpy(buffer, vtag->data, tag_size);
|
||||||
buffer[tag_size] = '\0';
|
buffer[tag_size] = '\0';
|
||||||
printf("\n [*] SSID: %s", buffer);
|
printf("\n [*] SSID: %s", buffer);
|
||||||
}
|
}
|
||||||
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_NET_KEY, 0)) {
|
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_NET_KEY, 0))) {
|
||||||
int tag_size = be16_to_h(vtag->len);
|
int tag_size = be16_to_h(vtag->len);
|
||||||
memcpy(buffer, vtag->data, tag_size);
|
memcpy(buffer, vtag->data, tag_size);
|
||||||
buffer[tag_size] = '\0';
|
buffer[tag_size] = '\0';
|
||||||
@ -715,9 +715,12 @@ usage_err:
|
|||||||
/* KDK = HMAC-SHA-256{DHKey}(Enrollee nonce || Enrollee MAC || Registrar nonce) */
|
/* KDK = HMAC-SHA-256{DHKey}(Enrollee nonce || Enrollee MAC || Registrar nonce) */
|
||||||
hmac_sha256(wps->dhkey, WPS_HASH_LEN, buffer, WPS_NONCE_LEN * 2 + WPS_BSSID_LEN, wps->kdk);
|
hmac_sha256(wps->dhkey, WPS_HASH_LEN, buffer, WPS_NONCE_LEN * 2 + WPS_BSSID_LEN, wps->kdk);
|
||||||
|
|
||||||
buffer = realloc(buffer, WPS_HASH_LEN * 3);
|
uint8_t *nbuffer = realloc(buffer, WPS_HASH_LEN * 3);
|
||||||
if (!buffer)
|
if (!nbuffer) {
|
||||||
|
free(buffer);
|
||||||
goto memory_err;
|
goto memory_err;
|
||||||
|
}
|
||||||
|
buffer = nbuffer;
|
||||||
|
|
||||||
/* Key derivation function */
|
/* Key derivation function */
|
||||||
kdf(wps->kdk, buffer);
|
kdf(wps->kdk, buffer);
|
||||||
@ -776,7 +779,7 @@ usage_err:
|
|||||||
uint32_t s2_seed = 0;
|
uint32_t s2_seed = 0;
|
||||||
|
|
||||||
/* Main loop */
|
/* Main loop */
|
||||||
while (!found_p_mode && p_mode[k] != NONE && k < MODE_LEN) {
|
while (!found_p_mode && k < MODE_LEN && p_mode[k] != NONE) {
|
||||||
|
|
||||||
/* 1 */
|
/* 1 */
|
||||||
if (p_mode[k] == RT) {
|
if (p_mode[k] == RT) {
|
||||||
@ -867,7 +870,7 @@ usage_err:
|
|||||||
wps->warning = calloc(256, 1);
|
wps->warning = calloc(256, 1);
|
||||||
if (!wps->warning)
|
if (!wps->warning)
|
||||||
goto memory_err;
|
goto memory_err;
|
||||||
snprintf(wps->warning, 256, " [!] Small DH keys is not supported for mode %u!\n\n", RTL819x);
|
snprintf(wps->warning, 256, " [!] Small DH keys is not supported for mode %d!\n\n", RTL819x);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -1266,7 +1269,6 @@ int int_pow(int a, int exp) {
|
|||||||
/* PIN cracking attempt */
|
/* PIN cracking attempt */
|
||||||
uint_fast8_t crack(struct global *g, char *pin) {
|
uint_fast8_t crack(struct global *g, char *pin) {
|
||||||
struct global *wps = g;
|
struct global *wps = g;
|
||||||
unsigned int i, j, count;
|
|
||||||
unsigned int first_half = 0;
|
unsigned int first_half = 0;
|
||||||
unsigned int second_half = 0;
|
unsigned int second_half = 0;
|
||||||
uint8_t s_pin[4];
|
uint8_t s_pin[4];
|
||||||
@ -1278,16 +1280,18 @@ uint_fast8_t crack(struct global *g, char *pin) {
|
|||||||
return MEM_ERROR;
|
return MEM_ERROR;
|
||||||
|
|
||||||
uint8_t *result = malloc(WPS_HASH_LEN);
|
uint8_t *result = malloc(WPS_HASH_LEN);
|
||||||
if (!result)
|
if (!result) {
|
||||||
|
free(buffer);
|
||||||
return MEM_ERROR;
|
return MEM_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
if (wps->anylength) {
|
if (wps->anylength) {
|
||||||
/* Brute-force entire pin space */
|
|
||||||
for (i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
first_half = 0;
|
|
||||||
count = int_pow(10, i);
|
|
||||||
|
|
||||||
|
/* Brute-force entire pin space */
|
||||||
|
for (unsigned int i = 0; i < 5; i++) {
|
||||||
|
unsigned int count = int_pow(10, i);
|
||||||
|
|
||||||
|
first_half = 0;
|
||||||
while (first_half < count) {
|
while (first_half < count) {
|
||||||
uint_to_char_array(first_half, i, s_pin);
|
uint_to_char_array(first_half, i, s_pin);
|
||||||
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, i, wps->psk1);
|
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, i, wps->psk1);
|
||||||
@ -1313,11 +1317,10 @@ uint_fast8_t crack(struct global *g, char *pin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (first_half < count) {
|
if (first_half < count) {
|
||||||
for (j = 0; j < 5; j++)
|
for (unsigned int j = 0; j < 5; j++) {
|
||||||
{
|
|
||||||
second_half = 0;
|
|
||||||
count = int_pow(10, j);
|
count = int_pow(10, j);
|
||||||
|
|
||||||
|
second_half = 0;
|
||||||
while (second_half < count) {
|
while (second_half < count) {
|
||||||
uint_to_char_array(second_half, j, s_pin);
|
uint_to_char_array(second_half, j, s_pin);
|
||||||
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, j, wps->psk2);
|
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, j, wps->psk2);
|
||||||
@ -1400,13 +1403,11 @@ uint_fast8_t crack(struct global *g, char *pin) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (first_half < 10000) { /* First half found */
|
if (first_half < 10000) { /* First half found */
|
||||||
uint_fast8_t checksum_digit;
|
|
||||||
unsigned int c_second_half;
|
|
||||||
|
|
||||||
/* Testing with checksum digit */
|
/* Testing with checksum digit */
|
||||||
while (second_half < 1000) {
|
while (second_half < 1000) {
|
||||||
checksum_digit = wps_pin_checksum(first_half * 1000 + second_half);
|
unsigned int checksum_digit = wps_pin_checksum(first_half * 1000 + second_half);
|
||||||
c_second_half = second_half * 10 + checksum_digit;
|
unsigned int c_second_half = second_half * 10 + checksum_digit;
|
||||||
uint_to_char_array(c_second_half, 4, s_pin);
|
uint_to_char_array(c_second_half, 4, s_pin);
|
||||||
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, 4, wps->psk2);
|
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, 4, wps->psk2);
|
||||||
memcpy(buffer, wps->e_s2, WPS_SECRET_NONCE_LEN);
|
memcpy(buffer, wps->e_s2, WPS_SECRET_NONCE_LEN);
|
||||||
|
@ -114,7 +114,7 @@ struct global {
|
|||||||
uint8_t mode_auto;
|
uint8_t mode_auto;
|
||||||
uint8_t bruteforce;
|
uint8_t bruteforce;
|
||||||
uint8_t anylength;
|
uint8_t anylength;
|
||||||
unsigned jobs;
|
int jobs;
|
||||||
int verbosity;
|
int verbosity;
|
||||||
char *error;
|
char *error;
|
||||||
char *warning;
|
char *warning;
|
||||||
@ -263,7 +263,7 @@ static inline uint_fast8_t parse_mode(char *list, uint_fast8_t *dst, const uint8
|
|||||||
|
|
||||||
/* Checks if passed mode is selected */
|
/* Checks 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; p_mode[i] != NONE && i < MODE_LEN; i++) {
|
for (uint_fast8_t i = 0; i < MODE_LEN && p_mode[i] != NONE; i++) {
|
||||||
if (p_mode[i] == mode)
|
if (p_mode[i] == mode)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -130,9 +130,6 @@ void m_srandom_r(unsigned int seed, struct m_random_data *buf)
|
|||||||
Returns a pointer to the old state. */
|
Returns a pointer to the old state. */
|
||||||
void m_initstate_r(unsigned int seed, char *arg_state, struct m_random_data *buf)
|
void m_initstate_r(unsigned int seed, char *arg_state, struct m_random_data *buf)
|
||||||
{
|
{
|
||||||
int type;
|
|
||||||
int degree;
|
|
||||||
int separation;
|
|
||||||
int32_t *state = &((int32_t *)arg_state)[1]; /* First location */
|
int32_t *state = &((int32_t *)arg_state)[1]; /* First location */
|
||||||
|
|
||||||
/* Must set END_PTR before srandom */
|
/* Must set END_PTR before srandom */
|
||||||
|
26
src/utils.h
26
src/utils.h
@ -29,15 +29,14 @@
|
|||||||
|
|
||||||
/* Converts an hex string to a byte array */
|
/* Converts 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) {
|
||||||
uint_fast8_t o;
|
|
||||||
unsigned int len = strlen(in);
|
unsigned int len = strlen(in);
|
||||||
unsigned int b_len = n_len * 2 + n_len - 1;
|
unsigned int b_len = n_len * 2 + n_len - 1;
|
||||||
|
|
||||||
if (len != n_len * 2 && len != b_len)
|
if (len != n_len * 2 && len != b_len)
|
||||||
return 1;
|
return 1;
|
||||||
for (unsigned int i = 0; i < n_len; i++) {
|
for (unsigned int i = 0; i < n_len; i++) {
|
||||||
o = 0;
|
unsigned char o = 0;
|
||||||
for (uint_fast8_t j = 0; j < 2; j++) {
|
for (unsigned char j = 0; j < 2; j++) {
|
||||||
o <<= 4;
|
o <<= 4;
|
||||||
if (*in >= 'A' && *in <= 'F')
|
if (*in >= 'A' && *in <= 'F')
|
||||||
*in += 'a'-'A';
|
*in += 'a'-'A';
|
||||||
@ -70,12 +69,14 @@ unsigned int hex_string_to_byte_array_max(char *in, uint8_t *out, const unsigned
|
|||||||
if (len > 2)
|
if (len > 2)
|
||||||
if (in[2] == ':' || in[2] == '-' || in[2] == ' ')
|
if (in[2] == ':' || in[2] == '-' || in[2] == ' ')
|
||||||
separator = 1;
|
separator = 1;
|
||||||
if (separator)
|
if (separator) {
|
||||||
if ((len + 1) / 3 > max_len)
|
if ((len + 1) / 3 > max_len)
|
||||||
return 1;
|
return 1;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
if (len / 2 > max_len)
|
if (len / 2 > max_len)
|
||||||
return 1;
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < max_len; i++) {
|
for (unsigned int i = 0; i < max_len; i++) {
|
||||||
o = 0;
|
o = 0;
|
||||||
@ -189,7 +190,7 @@ unsigned int get_unix_datetime(char *s, time_t *datetime) {
|
|||||||
|
|
||||||
if (get_int(s_month, &month) || get_int(s_year, &year))
|
if (get_int(s_month, &month) || get_int(s_year, &year))
|
||||||
return 1;
|
return 1;
|
||||||
if ((year < 1970 && year > 2037) || (month < 1 && month > 12))
|
if (year < 1970 || year > 2038 || month < 1 || month > 12)
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
return 1;
|
||||||
@ -238,16 +239,12 @@ void byte_array_print(const uint8_t *buffer, const unsigned int length) {
|
|||||||
uint32_t h32_to_be(const uint32_t num) {
|
uint32_t h32_to_be(const uint32_t num) {
|
||||||
uint32_t tmp = num;
|
uint32_t tmp = num;
|
||||||
uint32_t res;
|
uint32_t res;
|
||||||
uint32_t b0, b1, b2, b3;
|
|
||||||
unsigned int i = 1;
|
unsigned int i = 1;
|
||||||
char *p = (char *) &i;
|
char *p = (char *) &i;
|
||||||
|
|
||||||
if (p[0] == 1) { /* LE */
|
if (p[0] == 1) { /* LE */
|
||||||
b0 = (tmp & 0x000000ff) << 24;
|
res = ((tmp & 0x000000ff) << 24) | ((tmp & 0x0000ff00) << 8) |
|
||||||
b1 = (tmp & 0x0000ff00) << 8;
|
((tmp & 0x00ff0000) >> 8) | ((tmp & 0xff000000) >> 24);
|
||||||
b2 = (tmp & 0x00ff0000) >> 8;
|
|
||||||
b3 = (tmp & 0xff000000) >> 24;
|
|
||||||
res = b0 | b1 | b2 | b3;
|
|
||||||
} else { /* BE */
|
} else { /* BE */
|
||||||
res = num;
|
res = num;
|
||||||
}
|
}
|
||||||
@ -258,14 +255,11 @@ uint32_t h32_to_be(const uint32_t num) {
|
|||||||
uint16_t be16_to_h(const uint16_t num) {
|
uint16_t be16_to_h(const uint16_t num) {
|
||||||
uint16_t tmp = num;
|
uint16_t tmp = num;
|
||||||
uint16_t res;
|
uint16_t res;
|
||||||
uint16_t b0, b1;
|
|
||||||
unsigned int i = 1;
|
unsigned int i = 1;
|
||||||
char *p = (char *) &i;
|
char *p = (char *) &i;
|
||||||
|
|
||||||
if (p[0] == 1) { /* LE */
|
if (p[0] == 1) { /* LE */
|
||||||
b0 = (tmp & 0x000000ff) << 8;
|
res = ((tmp & 0x000000ff) << 8) | ((tmp & 0x0000ff00) >> 8);
|
||||||
b1 = (tmp & 0x0000ff00) >> 8;
|
|
||||||
res = b0 | b1;
|
|
||||||
} else { /* BE */
|
} else { /* BE */
|
||||||
res = num;
|
res = num;
|
||||||
}
|
}
|
||||||
|
@ -64,12 +64,13 @@ struct ie_vtag {
|
|||||||
typedef struct ie_vtag vtag_t;
|
typedef struct ie_vtag vtag_t;
|
||||||
#define VTAG_SIZE (sizeof(vtag_t))
|
#define VTAG_SIZE (sizeof(vtag_t))
|
||||||
|
|
||||||
vtag_t *find_vtag(void *vtagp, int vtagl, uint8_t *vid, int vlen) {
|
vtag_t *find_vtag(void *vtagp, int vtagl, void *vidp, int vlen) {
|
||||||
vtag_t *vtag = (vtag_t*)vtagp;
|
uint8_t *vid = vidp;
|
||||||
|
vtag_t *vtag = vtagp;
|
||||||
while (0 < vtagl) {
|
while (0 < vtagl) {
|
||||||
if (vid && memcmp(vid, &vtag->id, 2) != 0)
|
if (vid && memcmp(vid, &vtag->id, 2) != 0)
|
||||||
goto next_vtag;
|
goto next_vtag;
|
||||||
if (!vlen || be16_to_h(vtag->len) == vlen);
|
if (!vlen || be16_to_h(vtag->len) == vlen)
|
||||||
return vtag;
|
return vtag;
|
||||||
|
|
||||||
next_vtag:
|
next_vtag:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user