Skip to content

Commit

Permalink
Tracks how many times timeouts with deauth request without NACK
Browse files Browse the repository at this point in the history
Automatically treat the timeout as NACK if receive deauth request while waiting
for M5/M7 when deauth_is_nack_count >= MAX_DEAUTH_IS_NACK_COUNT and it have
never received WSC_NACK.
The count value is stored in .wpc file, the -1 equal the AP sends NACK.
  • Loading branch information
feitoi committed Jul 18, 2023
1 parent 4091bf2 commit 1c28ca1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/argsparser.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void init_default_settings(void)
pixie.do_pixie = 0;
set_pin_string_mode(0);
set_mac_changer(0);
set_deauth_is_nack_count(0);
}

/* Parses the recurring delay optarg */
Expand Down
2 changes: 2 additions & 0 deletions src/defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
#define EAPOL_START_MAX_TRIES 10
#define WARN_FAILURE_COUNT 10

#define MAX_DEAUTH_IS_NACK_COUNT 10

#define EAPOL_START 1
#define EAP_IDENTITY 0x01
#define EAP_EXPANDED 0xFE
Expand Down
26 changes: 21 additions & 5 deletions src/exchange.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ enum wps_result do_wps_exchange()
{
/* The AP is properly sending WSC_NACKs, so don't treat future timeouts as pin failures. */
set_timeout_is_nack(0);
set_deauth_is_nack_count(-1);

ret_val = KEY_REJECTED;

Expand Down Expand Up @@ -267,16 +268,31 @@ enum wps_result do_wps_exchange()
(last_msg == M3 || last_msg == M5))
{
ret_val = KEY_REJECTED;
/* Got timeout instead of an M5 message, when cracking second half */
if (!get_pin_string_mode() && last_msg == M3 && get_key_status() == KEY2_WIP) {
ret_val = UNKNOWN_ERROR;
cprintf(WARNING, "[!] WARNING: Potential first half pin has changed!\n");
}
}
/*
* Some WPS implementations sending deauth request instead of sending a NACK.
* Treat the timeout as NACK if receive deauth request while waiting for M5/M7.
*/
else if (deauth_flag && (last_msg == M3 || last_msg == M5)
&& get_deauth_is_nack_count() >= MAX_DEAUTH_IS_NACK_COUNT)
{
ret_val = KEY_REJECTED;
}
else
{
/* If we timed out at any other point in the session, then we need to try the pin again */
ret_val = RX_TIMEOUT;
/* increase by 1 for timeout with deauth request without NACK count value */
if (deauth_flag && (last_msg == M3 || last_msg == M5)
&& get_deauth_is_nack_count() >= 0 && get_deauth_is_nack_count() < MAX_DEAUTH_IS_NACK_COUNT)
{
set_deauth_is_nack_count(get_deauth_is_nack_count() + 1);
}
}
/* Got timeout instead of an M5 message when cracking second half */
if (ret_val == KEY_REJECTED && !get_pin_string_mode() && last_msg == M3 && get_key_status() == KEY2_WIP) {
ret_val = UNKNOWN_ERROR;
cprintf(WARNING, "[!] WARNING: Potential first half pin has changed!\n");
}
}
/*
Expand Down
9 changes: 9 additions & 0 deletions src/globule.c
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,15 @@ enum nack_code get_nack_reason()
return globule->nack_reason;
}

void set_deauth_is_nack_count(int value)
{
globule->deauth_is_nack_count = value;
}
int get_deauth_is_nack_count()
{
return globule->deauth_is_nack_count;
}

void set_handle(pcap_t *value)
{
globule->handle = value;
Expand Down
4 changes: 4 additions & 0 deletions src/globule.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct globals

int timeout_is_nack; /* Treat M5/M7 receive timeouts as NACKs (only needed for shoddy WPS implementations) */

int deauth_is_nack_count; /* Tracks how many times M5/M7 receive timeouts with deauth request without NACK. -1: AP sends NACK */

int m57_timeout; /* Timeout period for receiving an M5/M7 response (uSeconds) */

int out_of_time; /* Set to 1 when sigalrm sounds */
Expand Down Expand Up @@ -252,6 +254,8 @@ void set_external_association(int value);
int get_external_association(void);
void set_nack_reason(enum nack_code value);
enum nack_code get_nack_reason();
void set_deauth_is_nack_count(int value);
int get_deauth_is_nack_count();
void set_handle(pcap_t *value);
pcap_t *get_handle();
void set_wps(struct wps_data *value);
Expand Down
8 changes: 8 additions & 0 deletions src/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ int restore_session()
}
}

/* Get the timeout with deauth request without NACKs count value */
if (fgets(line, MAX_LINE_SIZE, fp) != NULL) {
set_deauth_is_nack_count(atoi(line));
}

return ret_val;
}

Expand Down Expand Up @@ -240,6 +245,9 @@ int save_session()
/* Save all the p2 values */
for(i=0; i<P2_SIZE; i++) fprintf(fp, "%s\n", get_p2(i));

/* Save timeout with deauth request without NACKs count value */
fprintf(fp, "%d\n", get_deauth_is_nack_count());

fclose(fp);
return 1;
}
Expand Down

0 comments on commit 1c28ca1

Please sign in to comment.