Skip to content

Commit 2930dae

Browse files
Merge pull request #1098 from justcallmekoko/develop
Overhaul EAPOL sniffer
2 parents 2b405e4 + 5d3cdc9 commit 2930dae

File tree

4 files changed

+128
-73
lines changed

4 files changed

+128
-73
lines changed

esp32_marauder/MenuFunctions.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ void MenuFunctions::main(uint32_t currentTime)
414414
(wifi_scan_obj.currentScanMode != WIFI_SCAN_CHAN_ANALYZER) &&
415415
(wifi_scan_obj.currentScanMode != WIFI_SCAN_CHAN_ACT) &&
416416
(wifi_scan_obj.currentScanMode != WIFI_SCAN_SIG_STREN) &&
417-
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_FUNNY_BEACON) &&
417+
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_FUNNY_BEACON) &&
418+
(wifi_scan_obj.currentScanMode != WIFI_SCAN_EAPOL) &&
418419
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_RICK_ROLL))
419420
{
420421
// Need this to set all keys to false
@@ -474,7 +475,7 @@ void MenuFunctions::main(uint32_t currentTime)
474475
else
475476
wifi_scan_obj.dual_band_channel_index = 0;
476477

477-
wifi_scan_obj.changeChannel(wifi_scan_obj.dual_band_channel[wifi_scan_obj.dual_band_channel_index]);
478+
wifi_scan_obj.changeChannel(wifi_scan_obj.dual_band_channels[wifi_scan_obj.dual_band_channel_index]);
478479
#endif
479480
}
480481
else if (wifi_scan_obj.currentScanMode == WIFI_SCAN_CHAN_ACT) {
@@ -1657,6 +1658,8 @@ void MenuFunctions::RunSetup()
16571658
});
16581659
#ifdef HAS_ILI9341
16591660
this->addNodes(&wifiSnifferMenu, text_table1[46], TFTVIOLET, NULL, EAPOL, [this]() {
1661+
display_obj.clearScreen();
1662+
this->drawStatusBar();
16601663
wifi_scan_obj.StartScan(WIFI_SCAN_EAPOL, TFT_VIOLET);
16611664
});
16621665
this->addNodes(&wifiSnifferMenu, text_table1[45], TFTBLUE, NULL, PACKET_MONITOR, [this]() {

esp32_marauder/WiFiScan.cpp

Lines changed: 120 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -2496,6 +2496,7 @@ void WiFiScan::StopScan(uint8_t scan_mode)
24962496
this->eapol_frames = 0;
24972497
this->min_rssi = 0;
24982498
this->max_rssi = -128;
2499+
this->send_deauth = false;
24992500

25002501
evil_portal_obj.cleanup();
25012502
#endif
@@ -4341,10 +4342,12 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
43414342
#else
43424343
led_obj.setMode(MODE_SNIFF);
43434344
#endif
4345+
4346+
this->send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
43444347

43454348
num_eapol = 0;
43464349

4347-
#ifdef HAS_ILI9341
4350+
/*#ifdef HAS_ILI9341
43484351
#ifdef HAS_SCREEN
43494352
display_obj.init();
43504353
display_obj.tft.setRotation(1);
@@ -4372,7 +4375,7 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
43724375
display_obj.tftDrawChannelScaleButtons(set_channel);
43734376
display_obj.tftDrawExitScaleButtons();
43744377
#endif
4375-
#else
4378+
#else*/
43764379
startPcap("eapol");
43774380

43784381
#ifdef HAS_SCREEN
@@ -4385,15 +4388,17 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
43854388
display_obj.tft.setTextColor(TFT_WHITE, color);
43864389
#ifdef HAS_FULL_SCREEN
43874390
display_obj.tft.fillRect(0,16,TFT_WIDTH,16, color);
4388-
display_obj.tft.drawCentreString(text_table4[38],TFT_WIDTH / 2,16,2);
4389-
#endif
4390-
#ifdef HAS_ILI9341
4391-
display_obj.touchToExit();
4391+
display_obj.tft.drawCentreString("EAPOL Sniff",TFT_WIDTH / 2,16,2);
43924392
#endif
4393+
//#ifdef HAS_ILI9341
4394+
// display_obj.touchToExit();
4395+
//#endif
43934396
display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
43944397
display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA);
4398+
display_obj.tftDrawChannelScaleButtons(set_channel, false);
4399+
display_obj.tftDrawExitScaleButtons(false);
43954400
#endif
4396-
#endif
4401+
// #endif
43974402

43984403
esp_wifi_init(&cfg);
43994404
#ifdef HAS_IDF_3
@@ -4405,7 +4410,17 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
44054410

44064411
esp_err_t err;
44074412
wifi_config_t conf;
4408-
err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR);
4413+
#ifndef HAS_DUAL_BAND
4414+
err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR);
4415+
#else
4416+
wifi_protocols_t p = {
4417+
.ghz_2g = WIFI_PROTOCOL_11B | WIFI_PROTOCOL_11G | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_LR,
4418+
.ghz_5g = WIFI_PROTOCOL_11A | WIFI_PROTOCOL_11N | WIFI_PROTOCOL_11AC | WIFI_PROTOCOL_11AX,
4419+
};
4420+
4421+
err = esp_wifi_set_protocols(WIFI_IF_AP, &p);
4422+
#endif
4423+
44094424
if (err != 0)
44104425
{
44114426
Serial.print(F("could not set protocol : err=0x"));
@@ -9759,21 +9774,39 @@ void WiFiScan::wifiSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
97599774
void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
97609775
{
97619776
extern WiFiScan wifi_scan_obj;
9762-
bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
9777+
9778+
bool is_beacon = false;
9779+
bool is_eapol = false;
97639780

97649781
wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
97659782
WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
97669783
wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)snifferPacket->rx_ctrl;
97679784
int len = snifferPacket->rx_ctrl.sig_len;
97689785

9769-
String display_string = "";
97709786

97719787
if (type == WIFI_PKT_MGMT)
97729788
{
97739789
len -= 4;
9790+
wifi_scan_obj.mgmt_frames++;
97749791
int fctl = ntohs(frameControl->fctl);
97759792
const wifi_ieee80211_packet_t *ipkt = (wifi_ieee80211_packet_t *)snifferPacket->payload;
97769793
const WifiMgmtHdr *hdr = &ipkt->hdr;
9794+
9795+
// Do our counts
9796+
if (snifferPacket->payload[0] == 0x40) // Probe request
9797+
wifi_scan_obj.req_frames++;
9798+
else if (snifferPacket->payload[0] == 0x50) // Probe response
9799+
wifi_scan_obj.resp_frames++;
9800+
else if (snifferPacket->payload[0] == 0x80) { // Beacon
9801+
is_beacon = true;
9802+
wifi_scan_obj.beacon_frames++;
9803+
}
9804+
else if (snifferPacket->payload[0] == 0xC0) // Deauth
9805+
wifi_scan_obj.deauth_frames++;
9806+
else if (((snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e) || ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e))) // eapol
9807+
wifi_scan_obj.eapol_frames++;
9808+
} else {
9809+
wifi_scan_obj.data_frames++;
97779810
}
97789811

97799812
#ifdef HAS_SCREEN
@@ -9782,8 +9815,15 @@ void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
97829815
int buff = 0;
97839816
#endif
97849817

9818+
// Get min/max rssi
9819+
if (snifferPacket->rx_ctrl.rssi < wifi_scan_obj.min_rssi)
9820+
wifi_scan_obj.min_rssi = snifferPacket->rx_ctrl.rssi;
9821+
9822+
if (snifferPacket->rx_ctrl.rssi > wifi_scan_obj.max_rssi)
9823+
wifi_scan_obj.max_rssi = snifferPacket->rx_ctrl.rssi;
9824+
97859825
// Found beacon frame. Decide whether to deauth
9786-
if (send_deauth) {
9826+
if (wifi_scan_obj.send_deauth) {
97879827
if (snifferPacket->payload[0] == 0x80) {
97889828
// Build packet
97899829

@@ -9802,7 +9842,8 @@ void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
98029842
wifi_scan_obj.deauth_frame_default[21] = snifferPacket->payload[15];
98039843

98049844
// Send packet
9805-
esp_wifi_80211_tx(WIFI_IF_AP, wifi_scan_obj.deauth_frame_default, sizeof(wifi_scan_obj.deauth_frame_default), false);
9845+
for (int i = 0; i < 3; i++)
9846+
esp_wifi_80211_tx(WIFI_IF_AP, wifi_scan_obj.deauth_frame_default, sizeof(wifi_scan_obj.deauth_frame_default), false);
98069847
delay(1);
98079848
}
98089849

@@ -9833,41 +9874,28 @@ void WiFiScan::eapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
98339874
}
98349875

98359876
if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
9836-
num_eapol++;
9837-
Serial.println(F("Received EAPOL:"));
9877+
is_eapol = true;
9878+
wifi_scan_obj.eapol_frames++;
9879+
Serial.print(F("Received EAPOL: "));
98389880

98399881
char addr[] = "00:00:00:00:00:00";
98409882
getMAC(addr, snifferPacket->payload, 10);
9841-
display_string.concat(addr);
98429883

9843-
int temp_len = display_string.length();
9844-
9845-
#ifdef HAS_SCREEN
9846-
for (int i = 0; i < 40 - temp_len; i++)
9847-
{
9848-
display_string.concat(" ");
9849-
}
9850-
9851-
Serial.print(F(" "));
9852-
9853-
#ifdef SCREEN_BUFFER
9854-
#ifndef HAS_ILI9341
9855-
display_obj.display_buffer->add(display_string);
9856-
#endif
9857-
#endif
9858-
#else
9859-
Serial.println(addr);
9860-
#endif
9884+
Serial.print(addr);
9885+
Serial.println();
98619886
}
98629887

9863-
buffer_obj.append(snifferPacket, len);
9888+
if ((is_eapol) || (is_beacon))
9889+
buffer_obj.append(snifferPacket, len);
98649890
}
98659891

98669892
void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
98679893
{
9894+
bool is_beacon = false;
9895+
bool is_eapol = false;
98689896
extern WiFiScan wifi_scan_obj;
98699897

9870-
bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
9898+
//bool send_deauth = settings_obj.loadSetting<bool>(text_table4[5]);
98719899

98729900
wifi_promiscuous_pkt_t *snifferPacket = (wifi_promiscuous_pkt_t*)buf;
98739901
WifiMgmtHdr *frameControl = (WifiMgmtHdr*)snifferPacket->payload;
@@ -9885,6 +9913,7 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t
98859913
// Found beacon frame. Decide whether to deauth
98869914

98879915
if (snifferPacket->payload[0] == 0x80) {
9916+
is_beacon = true;
98889917

98899918
// Do target stuff
98909919
if (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_LIST_EAPOL) {
@@ -9941,12 +9970,14 @@ void WiFiScan::activeEapolSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t
99419970

99429971

99439972
if (( (snifferPacket->payload[30] == 0x88 && snifferPacket->payload[31] == 0x8e)|| ( snifferPacket->payload[32] == 0x88 && snifferPacket->payload[33] == 0x8e) )){
9973+
is_eapol = true;
99449974
num_eapol++;
99459975
Serial.println(F("Received EAPOL:"));
99469976

99479977
}
99489978

9949-
buffer_obj.append(snifferPacket, len);
9979+
if ((is_beacon) || (is_eapol))
9980+
buffer_obj.append(snifferPacket, len);
99509981
}
99519982

99529983
bool WiFiScan::filterActive() {
@@ -10695,6 +10726,13 @@ void WiFiScan::renderRawStats() {
1069510726
display_obj.tft.println(" Deauth: " + (String)this->deauth_frames);
1069610727
display_obj.tft.println(" EAPOL: " + (String)this->eapol_frames);
1069710728
display_obj.tft.println(" RSSI: " + (String)this->min_rssi + " - " + (String)this->max_rssi);
10729+
if (this->send_deauth) {
10730+
display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
10731+
display_obj.tft.println(F("\nDEAUTH TX: TRUE"));
10732+
} else {
10733+
display_obj.tft.setTextColor(TFT_RED, TFT_BLACK);
10734+
display_obj.tft.println(F("\nDEAUTH TX: FALSE"));
10735+
}
1069810736

1069910737
#endif
1070010738

@@ -10707,6 +10745,10 @@ void WiFiScan::renderRawStats() {
1070710745
Serial.println(" Deauth: " + (String)this->deauth_frames);
1070810746
Serial.println(" EAPOL: " + (String)this->eapol_frames);
1070910747
Serial.println(" RSSI: " + (String)this->min_rssi + " - " + (String)this->max_rssi);
10748+
if (this->send_deauth)
10749+
Serial.println(F("\nDEAUTH TX: TRUE"));
10750+
else
10751+
Serial.println(F("\nDEAUTH TX: FALSE"));
1071010752
}
1071110753

1071210754
void WiFiScan::renderPacketRate() {
@@ -10746,7 +10788,9 @@ void WiFiScan::packetRateLoop(uint32_t tick) {
1074610788
this->initTime = millis();
1074710789
if (this->currentScanMode == WIFI_SCAN_PACKET_RATE)
1074810790
this->renderPacketRate();
10749-
else if (this->currentScanMode == WIFI_SCAN_RAW_CAPTURE)
10791+
else if ((this->currentScanMode == WIFI_SCAN_RAW_CAPTURE) ||
10792+
(this->currentScanMode == WIFI_SCAN_EAPOL) ||
10793+
(this->currentScanMode == WIFI_SCAN_ACTIVE_EAPOL))
1075010794
this->renderRawStats();
1075110795

1075210796
}
@@ -10760,24 +10804,46 @@ void WiFiScan::packetRateLoop(uint32_t tick) {
1076010804
return;
1076110805
}
1076210806
else if (b == 4) {
10763-
if (set_channel > 1) {
10764-
set_channel--;
10765-
display_obj.tftDrawChannelScaleButtons(set_channel, false);
10766-
display_obj.tftDrawExitScaleButtons(false);
10767-
changeChannel();
10768-
return;
10769-
}
10807+
#ifndef HAS_DUAL_BAND
10808+
if (set_channel > 1) {
10809+
set_channel--;
10810+
display_obj.tftDrawChannelScaleButtons(set_channel, false);
10811+
display_obj.tftDrawExitScaleButtons(false);
10812+
changeChannel(set_channel);
10813+
return;
10814+
}
10815+
#else
10816+
if (this->dual_band_channel_index > 1) {
10817+
this->dual_band_channel_index--;
10818+
this->set_channel = this->dual_band_channels[this->dual_band_channel_index];
10819+
display_obj.tftDrawChannelScaleButtons(this->set_channel, false);
10820+
display_obj.tftDrawExitScaleButtons(false);
10821+
changeChannel(this->set_channel);
10822+
return;
10823+
}
10824+
#endif
1077010825
}
1077110826

1077210827
// Channel + button pressed
1077310828
else if (b == 5) {
10774-
if (set_channel < MAX_CHANNEL) {
10775-
set_channel++;
10776-
display_obj.tftDrawChannelScaleButtons(set_channel, false);
10777-
display_obj.tftDrawExitScaleButtons(false);
10778-
changeChannel();
10779-
return;
10780-
}
10829+
#ifndef HAS_DUAL_BAND
10830+
if (set_channel < MAX_CHANNEL) {
10831+
set_channel++;
10832+
display_obj.tftDrawChannelScaleButtons(set_channel, false);
10833+
display_obj.tftDrawExitScaleButtons(false);
10834+
changeChannel(set_channel);
10835+
return;
10836+
}
10837+
#else
10838+
if (this->dual_band_channel_index < DUAL_BAND_CHANNELS - 1) {
10839+
this->dual_band_channel_index++;
10840+
this->set_channel = this->dual_band_channels[this->dual_band_channel_index];
10841+
display_obj.tftDrawChannelScaleButtons(this->set_channel, false);
10842+
display_obj.tftDrawExitScaleButtons(false);
10843+
changeChannel(this->set_channel);
10844+
return;
10845+
}
10846+
#endif
1078110847
}
1078210848
#endif
1078310849
}
@@ -11454,18 +11520,13 @@ void WiFiScan::main(uint32_t currentTime)
1145411520
else if ((currentScanMode == WIFI_SCAN_EAPOL) ||
1145511521
(currentScanMode == WIFI_SCAN_ACTIVE_EAPOL))
1145611522
{
11457-
#ifdef HAS_SCREEN
11523+
/*#ifdef HAS_SCREEN
1145811524
#ifdef HAS_ILI9341
1145911525
eapolMonitorMain(currentTime);
1146011526
#endif
11461-
#endif
11527+
#endif*/
11528+
this->packetRateLoop(currentTime);
1146211529
}
11463-
/*else if (currentScanMode == WIFI_SCAN_ACTIVE_EAPOL)
11464-
{
11465-
#ifdef HAS_SCREEN
11466-
eapolMonitorMain(currentTime);
11467-
#endif
11468-
}*/
1146911530
else if (currentScanMode == WIFI_SCAN_ACTIVE_LIST_EAPOL) {
1147011531
if (currentTime - initTime >= 1000) {
1147111532
initTime = millis();
@@ -11475,17 +11536,6 @@ void WiFiScan::main(uint32_t currentTime)
1147511536
eapolMonitorMain(currentTime);
1147611537
#endif
1147711538
}
11478-
/*else if ((currentScanMode == BT_SCAN_SIMPLE) || (currentScanMode == BT_SCAN_SIMPLE_TWO)) {
11479-
if (currentTime - initTime >= 1000) {
11480-
initTime = millis();
11481-
String displayString = "BT Frames: ";
11482-
displayString.concat(this->bt_frames);
11483-
#ifdef HAS_SCREEN
11484-
display_obj.tft.setTextColor(TFT_GREEN, TFT_BLACK);
11485-
display_obj.showCenterText(displayString, TFT_HEIGHT / 2);
11486-
#endif
11487-
}
11488-
}*/
1148911539
else if (currentScanMode == WIFI_ATTACK_AUTH) {
1149011540
for (int i = 0; i < 55; i++)
1149111541
this->sendProbeAttack(currentTime);

esp32_marauder/WiFiScan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,8 @@ class WiFiScan
657657
volatile bool bt_cb_busy = false;
658658
volatile bool bt_pending_clear = false;
659659

660+
bool send_deauth = false;
661+
660662

661663
static MacEntry mac_entries[mac_history_len_half];
662664
static uint8_t mac_entry_state[mac_history_len_half];

0 commit comments

Comments
 (0)