Refactor EAPOL sniff filtering

This commit is contained in:
Just Call Me Koko
2025-10-09 15:39:08 -04:00
parent ba9ec4023e
commit feaae672da
4 changed files with 125 additions and 47 deletions

View File

@@ -2221,7 +2221,7 @@ void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
uint16_t calData[5] = { 272, 3648, 234, 3565, 7 };
Serial.println("Using CYD 3.5inch (join wifi)");
#elif defined(MARAUDER_V8)
uint16_t calData[5] = { 452, 3477, 263, 3524, 3 };
uint16_t calData[5] = { 362, 3489, 260, 3486, 7 };
#else if defined(TFT_DIY)
uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
Serial.println("Using TFT DIY (join wifi)");
@@ -2838,7 +2838,7 @@ void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
uint16_t calData[5] = { 272, 3648, 234, 3565, 7 }; // Landscape
Serial.println("Using CYD 3.5inch");
#elif defined(MARAUDER_V8)
uint16_t calData[5] = { 452, 3477, 263, 3524, 3 };
uint16_t calData[5] = { 362, 3489, 260, 3486, 7 };
#else if defined(TFT_DIY)
uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
Serial.println("Using TFT DIY");
@@ -2968,7 +2968,7 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
#elif defined(MARAUDER_CYD_3_5_INCH)
uint16_t calData[5] = { 272, 3648, 234, 3565, 7 };
#elif defined(MARAUDER_V8)
uint16_t calData[5] = { 452, 3477, 263, 3524, 3 };
uint16_t calData[5] = { 362, 3489, 260, 3486, 7 };
#else if defined(TFT_DIY)
uint16_t calData[5] = { 213, 3469, 320, 3446, 1 }; // Landscape TFT DIY
//Serial.println("Using TFT DIY");
@@ -7387,6 +7387,36 @@ void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
}
bool filter = false;
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).selected) {
filter = true;
break;
}
}
// Check for and apply filters
if (filter) {
bool found = false;
int ap_index = -1;
char addr[] = "00:00:00:00:00:00";
getMAC(addr, snifferPacket->payload, 10);
ap_index = wifi_scan_obj.checkMatchAP(addr);
if (ap_index < 0) {
char addr2[] = "00:00:00:00:00:00";
getMAC(addr2, snifferPacket->payload, 4);
ap_index = wifi_scan_obj.checkMatchAP(addr2);
}
if ((ap_index < 0) || (!access_points->get(ap_index).selected))
return;
//Serial.println("Received frame for " + access_points->get(ap_index).essid + ". Processing...");
}
if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
num_eapol++;
Serial.println("Received EAPOL:");
@@ -7504,6 +7534,15 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t
buffer_obj.append(snifferPacket, len);
}
bool WiFiScan::filterActive() {
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).selected)
return true;
}
return false;
}
#ifdef HAS_SCREEN
int8_t WiFiScan::checkAnalyzerButtons(uint32_t currentTime) {
boolean pressed = false;
@@ -7547,32 +7586,6 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t
y_pos_x = 0;
y_pos_y = 0;
y_pos_z = 0;
/*boolean pressed = false;
uint16_t t_x = 0, t_y = 0; // To store the touch coordinates
// Do the touch stuff
#ifdef HAS_ILI9341
pressed = display_obj.tft.getTouch(&t_x, &t_y);
#endif
// Check buttons for presses
for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
{
if (pressed && display_obj.key[b].contains(t_x, t_y))
{
display_obj.key[b].press(true);
} else {
display_obj.key[b].press(false);
}
}*/
// Which buttons pressed
//for (uint8_t b = 0; b < BUTTON_ARRAY_LEN; b++)
//{
// if (display_obj.key[b].justReleased())
// {
// do_break = true;
int8_t b = this->checkAnalyzerButtons(currentTime);
@@ -7621,6 +7634,12 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t
Serial.println("Max EAPOL number reached. Adjusting...");
num_eapol = 0;
}
// Also change channel while we're at it
this->channelHop(true);
display_obj.tft.fillRect(127, 0, 193, 28, TFT_BLACK);
display_obj.tftDrawChannelScaleButtons(set_channel);
display_obj.tftDrawExitScaleButtons();
//CODE FOR PLOTTING CONTINUOUS LINES!!!!!!!!!!!!
//Plot "X" value
@@ -7657,7 +7676,7 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t
display_obj.tft.fillRect(12, 0, 90, 32, TFT_BLACK); // key
display_obj.tftDrawChannelScaleButtons(set_channel);
display_obj.tftDrawExitScaleButtons();
display_obj.tftDrawEapolColorKey();
display_obj.tftDrawEapolColorKey(this->filterActive());
display_obj.tftDrawGraphObjects(x_scale);
}
@@ -7884,20 +7903,72 @@ void WiFiScan::changeChannel()
}
// Function to cycle to the next channel
void WiFiScan::channelHop()
void WiFiScan::channelHop(bool filtered)
{
#ifndef HAS_DUAL_BAND
this->set_channel = this->set_channel + 1;
if (this->set_channel > 14) {
this->set_channel = 1;
}
#else
this->set_channel = this->dual_band_channels[this->dual_band_channel_index];
if (this->dual_band_channel_index >= DUAL_BAND_CHANNELS)
this->dual_band_channel_index = 0;
else
this->dual_band_channel_index++;
#endif
bool channel_match = false;
bool ap_selected = true;
if (!filtered) {
#ifndef HAS_DUAL_BAND
this->set_channel = this->set_channel + 1;
if (this->set_channel > 14) {
this->set_channel = 1;
}
#else
if (this->dual_band_channel_index >= DUAL_BAND_CHANNELS)
this->dual_band_channel_index = 0;
else
this->dual_band_channel_index++;
this->set_channel = this->dual_band_channels[this->dual_band_channel_index];
#endif
}
else {
#ifndef HAS_DUAL_BAND
while ((!channel_match) && (ap_selected)) {
ap_selected = false;
// Pick channel like normal
this->set_channel = this->set_channel + 1;
if (this->set_channel > 14) {
this->set_channel = 1;
}
// Check if it matches a selected AP's channel
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).selected) {
ap_selected = true;
if (access_points->get(i).channel == this->set_channel) {
channel_match = true;
break;
}
}
}
}
#else
while ((!channel_match) && (ap_selected)) {
ap_selected = false;
// Pick channel like normal
if (this->dual_band_channel_index >= DUAL_BAND_CHANNELS)
this->dual_band_channel_index = 0;
else
this->dual_band_channel_index++;
this->set_channel = this->dual_band_channels[this->dual_band_channel_index];
// Check if it matches a selected AP's channel
for (int i = 0; i < access_points->size(); i++) {
if (access_points->get(i).selected) {
ap_selected = true;
if (access_points->get(i).channel == this->set_channel) {
Serial.println("Setting to channel " + (String)this->set_channel + " for AP " + access_points->get(i).essid);
channel_match = true;
break;
}
}
}
}
#endif
}
esp_wifi_set_channel(this->set_channel, WIFI_SECOND_CHAN_NONE);
delay(1);
@@ -8707,6 +8778,10 @@ void WiFiScan::main(uint32_t currentTime)
#endif
}
else if (currentScanMode == WIFI_SCAN_ACTIVE_LIST_EAPOL) {
if (currentTime - initTime >= 1000) {
initTime = millis();
this->channelHop(true);
}
#ifdef HAS_SCREEN
eapolMonitorMain(currentTime);
#endif