From edbfd62e4cf81fe1dd5fcbd5d72c3cb7f598b18d Mon Sep 17 00:00:00 2001 From: Just Call Me Koko Date: Mon, 24 Mar 2025 11:32:30 -0400 Subject: [PATCH] Add BLE analyzer --- esp32_marauder/MenuFunctions.cpp | 24 +++++++++++---- esp32_marauder/MenuFunctions.h | 2 +- esp32_marauder/WiFiScan.cpp | 53 ++++++++++++++++++++++++++++---- esp32_marauder/WiFiScan.h | 5 +-- 4 files changed, 69 insertions(+), 15 deletions(-) diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index 8032d06..a791209 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -650,7 +650,8 @@ void MenuFunctions::main(uint32_t currentTime) this->updateStatusBar(); // Do channel analyzer stuff - if (wifi_scan_obj.currentScanMode == WIFI_SCAN_CHAN_ANALYZER) { + if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_CHAN_ANALYZER) || + (wifi_scan_obj.currentScanMode == BT_SCAN_ANALYZER)){ this->setGraphScale(this->graphScaleCheck(wifi_scan_obj._analyzer_values)); this->drawGraph(wifi_scan_obj._analyzer_values); @@ -818,7 +819,8 @@ void MenuFunctions::main(uint32_t currentTime) (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_EAPOL) || (wifi_scan_obj.currentScanMode == WIFI_SCAN_ACTIVE_LIST_EAPOL) || (wifi_scan_obj.currentScanMode == WIFI_PACKET_MONITOR) || - (wifi_scan_obj.currentScanMode == WIFI_SCAN_CHAN_ANALYZER)) + (wifi_scan_obj.currentScanMode == WIFI_SCAN_CHAN_ANALYZER) || + (wifi_scan_obj.currentScanMode == BT_SCAN_ANALYZER)) { wifi_scan_obj.StartScan(WIFI_SCAN_OFF); @@ -1587,7 +1589,7 @@ void MenuFunctions::RunSetup() this->addNodes(&wifiSnifferMenu, "Channel Analyzer", TFTCYAN, NULL, PACKET_MONITOR, [this]() { display_obj.clearScreen(); this->drawStatusBar(); - this->renderGraphUI(); + this->renderGraphUI(WIFI_SCAN_CHAN_ANALYZER); wifi_scan_obj.StartScan(WIFI_SCAN_CHAN_ANALYZER, TFT_CYAN); }); #endif @@ -2023,6 +2025,12 @@ void MenuFunctions::RunSetup() this->drawStatusBar(); wifi_scan_obj.StartScan(BT_SCAN_SKIMMERS, TFT_MAGENTA); }); + this->addNodes(&bluetoothSnifferMenu, "Bluetooth Analyzer", TFTCYAN, NULL, PACKET_MONITOR, [this]() { + display_obj.clearScreen(); + this->drawStatusBar(); + this->renderGraphUI(BT_SCAN_ANALYZER); + wifi_scan_obj.StartScan(BT_SCAN_ANALYZER, TFT_CYAN); + }); // Bluetooth Attack menu bluetoothAttackMenu.parentMenu = &bluetoothMenu; // Second Menu is third menu parent @@ -2691,9 +2699,12 @@ void MenuFunctions::drawGraph(int16_t *values) { this->drawMaxLine(total / TFT_WIDTH, TFT_ORANGE); // Draw average } -void MenuFunctions::renderGraphUI() { +void MenuFunctions::renderGraphUI(uint8_t scan_mode) { display_obj.tft.setTextColor(TFT_WHITE, TFT_BLACK); - display_obj.tft.drawCentreString("Frames/" + (String)BANNER_TIME + "ms", TFT_WIDTH / 2, TFT_HEIGHT - GRAPH_VERT_LIM - (CHAR_WIDTH * 2), 1); + if (scan_mode == WIFI_SCAN_CHAN_ANALYZER) + display_obj.tft.drawCentreString("Frames/" + (String)BANNER_TIME + "ms", TFT_WIDTH / 2, TFT_HEIGHT - GRAPH_VERT_LIM - (CHAR_WIDTH * 2), 1); + else if (scan_mode == BT_SCAN_ANALYZER) + display_obj.tft.drawCentreString("BLE Beacons/" + (String)BANNER_TIME + "ms", TFT_WIDTH / 2, TFT_HEIGHT - GRAPH_VERT_LIM - (CHAR_WIDTH * 2), 1); display_obj.tft.drawLine(0, TFT_HEIGHT - GRAPH_VERT_LIM - 1, TFT_WIDTH, TFT_HEIGHT - GRAPH_VERT_LIM - 1, TFT_WHITE); display_obj.tft.setCursor(0, TFT_HEIGHT - GRAPH_VERT_LIM - (CHAR_WIDTH * 8)); display_obj.tft.setTextSize(1); @@ -2702,7 +2713,8 @@ void MenuFunctions::renderGraphUI() { display_obj.tft.setTextColor(TFT_ORANGE, TFT_BLACK); display_obj.tft.println("Average"); display_obj.tft.setTextColor(TFT_RED, TFT_BLACK); - display_obj.tft.println("Channel Marker"); + if (scan_mode != BT_SCAN_ANALYZER) + display_obj.tft.println("Channel Marker"); } uint16_t MenuFunctions::getColor(uint16_t color) { diff --git a/esp32_marauder/MenuFunctions.h b/esp32_marauder/MenuFunctions.h index 2866db4..dc7fc38 100644 --- a/esp32_marauder/MenuFunctions.h +++ b/esp32_marauder/MenuFunctions.h @@ -197,7 +197,7 @@ class MenuFunctions float calculateGraphScale(int16_t value); float graphScaleCheck(const int16_t array[TFT_WIDTH]); void drawGraph(int16_t *values); - void renderGraphUI(); + void renderGraphUI(uint8_t scan_mode = 0); //void addNodes(Menu* menu, String name, uint16_t color, Menu* child, int place, std::function callable, bool selected = false, String command = ""); void addNodes(Menu* menu, String name, uint8_t color, Menu* child, int place, std::function callable, bool selected = false, String command = ""); void battery(bool initial = false); diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index a535b08..c2fc456 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -440,6 +440,9 @@ extern "C" { } #endif } + else if (wifi_scan_obj.currentScanMode == BT_SCAN_ANALYZER) { + wifi_scan_obj._analyzer_value++; + } } }; @@ -781,7 +784,7 @@ void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color) this->startWiFiAttacks(scan_mode, color, text_table4[47]); else if (scan_mode == WIFI_ATTACK_AP_SPAM) this->startWiFiAttacks(scan_mode, color, " AP Beacon Spam "); - else if ((scan_mode == BT_SCAN_ALL) || (scan_mode == BT_SCAN_AIRTAG) || (scan_mode == BT_SCAN_FLIPPER)){ + else if ((scan_mode == BT_SCAN_ALL) || (scan_mode == BT_SCAN_AIRTAG) || (scan_mode == BT_SCAN_FLIPPER) || (scan_mode == BT_SCAN_ANALYZER)){ #ifdef HAS_BT RunBluetoothScan(scan_mode, color); #endif @@ -905,6 +908,8 @@ bool WiFiScan::shutdownWiFi() { #else led_obj.setMode(MODE_OFF); #endif + + this->_analyzer_value = 0; this->wifi_initialized = false; return true; @@ -923,6 +928,8 @@ bool WiFiScan::shutdownBLE() { pBLEScan->clearResults(); NimBLEDevice::deinit(); + + this->_analyzer_value = 0; this->ble_initialized = false; } @@ -978,9 +985,11 @@ void WiFiScan::StopScan(uint8_t scan_mode) { this->shutdownWiFi(); - for (int i = 0; i < TFT_WIDTH; i++) { - this->_analyzer_values[i] = 0; - } + #ifdef HAS_SCREEN + for (int i = 0; i < TFT_WIDTH; i++) { + this->_analyzer_values[i] = 0; + } + #endif } @@ -996,9 +1005,16 @@ void WiFiScan::StopScan(uint8_t scan_mode) (currentScanMode == BT_SPOOF_AIRTAG) || (currentScanMode == BT_SCAN_WAR_DRIVE) || (currentScanMode == BT_SCAN_WAR_DRIVE_CONT) || - (currentScanMode == BT_SCAN_SKIMMERS)) + (currentScanMode == BT_SCAN_SKIMMERS) || + (currentScanMode == BT_SCAN_ANALYZER)) { #ifdef HAS_BT + #ifdef HAS_SCREEN + for (int i = 0; i < TFT_WIDTH; i++) { + this->_analyzer_values[i] = 0; + } + #endif + this->shutdownBLE(); #endif } @@ -2800,6 +2816,9 @@ void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color) NimBLEDevice::setScanFilterMode(CONFIG_BTDM_SCAN_DUPL_TYPE_DEVICE); NimBLEDevice::setScanDuplicateCacheSize(200); } + else if ((scan_mode == BT_SCAN_WAR_DRIVE_CONT) || (scan_mode == BT_SCAN_ANALYZER)) { + NimBLEDevice::setScanDuplicateCacheSize(0); + } NimBLEDevice::init(""); pBLEScan = NimBLEDevice::getScan(); //create new scan if ((scan_mode == BT_SCAN_ALL) || (scan_mode == BT_SCAN_AIRTAG) || (scan_mode == BT_SCAN_FLIPPER)) @@ -2894,10 +2913,31 @@ void WiFiScan::RunBluetoothScan(uint8_t scan_mode, uint16_t color) #endif pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanSkimmersCallback(), false); } + else if (scan_mode == BT_SCAN_ANALYZER) { + #ifdef HAS_SCREEN + display_obj.TOP_FIXED_AREA_2 = 48; + display_obj.tteBar = true; + display_obj.initScrollValues(true); + display_obj.tft.setTextWrap(false); + display_obj.tft.setTextColor(TFT_BLACK, color); + #ifdef HAS_FULL_SCREEN + display_obj.tft.fillRect(0,16,240,16, color); + display_obj.tft.drawCentreString("Bluetooth Analyzer", 120, 16, 2); + #ifdef HAS_ILI9341 + display_obj.touchToExit(); + #endif + #endif + display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK); + display_obj.setupScrollArea(display_obj.TOP_FIXED_AREA_2, BOT_FIXED_AREA); + #endif + pBLEScan->setAdvertisedDeviceCallbacks(new bluetoothScanAllCallback(), false); + } pBLEScan->setActiveScan(true); //active scan uses more power, but get results faster pBLEScan->setInterval(100); pBLEScan->setWindow(99); // less or equal setInterval value pBLEScan->setMaxResults(0); + if ((scan_mode == BT_SCAN_WAR_DRIVE_CONT) || (scan_mode == BT_SCAN_ANALYZER)) + pBLEScan->setDuplicateFilter(false); pBLEScan->start(0, scanCompleteCB, false); Serial.println("Started BLE Scan"); this->ble_initialized = true; @@ -5330,7 +5370,8 @@ void WiFiScan::main(uint32_t currentTime) channelHop(); } } - else if ((currentScanMode == WIFI_SCAN_CHAN_ANALYZER)) { + else if ((currentScanMode == WIFI_SCAN_CHAN_ANALYZER) || + (currentScanMode == BT_SCAN_ANALYZER)) { this->channelAnalyzerLoop(currentTime); } else if ((currentScanMode == BT_ATTACK_SWIFTPAIR_SPAM) || diff --git a/esp32_marauder/WiFiScan.h b/esp32_marauder/WiFiScan.h index 3bf4ebb..8bc59af 100644 --- a/esp32_marauder/WiFiScan.h +++ b/esp32_marauder/WiFiScan.h @@ -99,6 +99,7 @@ #define BT_SPOOF_AIRTAG 44 #define BT_SCAN_FLIPPER 45 #define WIFI_SCAN_CHAN_ANALYZER 46 +#define BT_SCAN_ANALYZER 47 #define BASE_MULTIPLIER 4 @@ -177,8 +178,6 @@ class WiFiScan // Wardriver thanks to https://github.com/JosephHewitt struct mac_addr mac_history[mac_history_len]; - int16_t _analyzer_value = 0; - // Settings uint mac_history_cursor = 0; uint8_t channel_hop_delay = 1; @@ -373,6 +372,8 @@ class WiFiScan uint8_t old_channel = 0; + int16_t _analyzer_value = 0; + bool orient_display = false; bool wifi_initialized = false; bool ble_initialized = false;