Skip to content

Bug fixes & safety improvements: MAC randomization, GPS validation, button timeouts, WiFi cleanup, hardware detection#179

Open
RadDad87 wants to merge 5 commits into
cifertech:mainfrom
RadDad87:bugfixes-and-features
Open

Bug fixes & safety improvements: MAC randomization, GPS validation, button timeouts, WiFi cleanup, hardware detection#179
RadDad87 wants to merge 5 commits into
cifertech:mainfrom
RadDad87:bugfixes-and-features

Conversation

@RadDad87

Copy link
Copy Markdown

Summary

Security audit and improvement pass for ESP32-DIV v1.7.0. Fixes critical OPSEC bugs, adds safety mechanisms, and introduces a hardware detection module. All changes are backward-compatible drop-in replacements — no library changes required.

Bug Fixes

1. MAC Randomization Actually Applied (bluetooth.cpp) — HIGH severity

BLE Spoofer and SourApple generated random MAC addresses but never applied them to the BLE stack. The device was broadcasting attacks using its real, permanent MAC. Fixed by adding esp_ble_gap_set_rand_addr() + BLEDevice::setOwnAddrType(BLE_ADDR_TYPE_RANDOM). Also corrected the address mask from 0xF0 to 0xC0 (proper BLE random static address per Bluetooth spec).

2. Beats Fit Pro Typo + Missing Flag (bluetooth.cpp)

  • Renamed Betas_Fit_ProBeats_Fit_Pro
    • Added missing attack_state = 1; so the spoof actually triggers advertising

3. SourApple Uses True Random (bluetooth.cpp)

Replaced unseeded rand() with Arduino random() (hardware entropy on ESP32). Previously produced identical attack type sequences on every reboot.

4. NMEA Checksum Validation (gps.cpp)

Added validateAndStripChecksum() that computes XOR checksum before accepting GPS sentences. Previously, corrupted data was silently accepted, potentially logging wrong wardriving coordinates.

5. Button Release Timeout (ESP32-DIV.ino)

All 36 bare while(isButtonPressed()){} busy-wait loops replaced with waitForButtonRelease() — adds 5-second timeout + 10ms FreeRTOS yield. Prevents permanent device hang from stuck buttons.

New Features

WiFi Exit Cleanup Handlers (wifi.cpp)

Added exit() functions to PacketMonitor, BeaconSpammer, and WifiScan namespaces. Disables promiscuous mode, clears callbacks, and resets WiFi radio when leaving features.

Hardware Detection Module (hardware_detect.h — NEW FILE)

Boot-time SPI/I2C/Serial probes for NRF24, CC1101, GPS, and PCF8574. Shows hardware summary on TFT during boot. Guard function prevents launching features without required hardware.

Files Changed

File Type Changes
bluetooth.cpp fix MAC randomization, Beats Fit Pro, rand()
gps.cpp fix NMEA checksum validation
ESP32-DIV.ino fix 36 button timeout replacements + helpers
wifi.cpp feat Exit cleanup handlers
hardware_detect.h feat NEW — Hardware presence detection

Testing

  • All patches tested against v1.7.0 source, no new dependencies
    • Button timeout verified with BUTTON_RELEASE_TIMEOUT_MS = 5000
    • MAC randomization verified via BLE address type bits
    • Checksum validation tested with corrupted NMEA sentences

RadDad87 added 5 commits June 24, 2026 03:46
Adds hardware_detect.h with SPI/I2C/UART probes for NRF24, CC1101, GPS, PCF8574.
Displays detected hardware on TFT during boot.
Guard function warns before launching features that need missing hardware.
Prevents confusing failures when peripherals are disconnected.
- OPSEC FIX: Apply random MAC to BLE stack via esp_ble_gap_set_rand_addr (was generated but never applied)
- Fix Betas_Fit_Pro typo and add missing attack_state=1
- Fix SourApple using unseeded rand() instead of hardware random()
- Fix BLE address mask from 0xF0 to 0xC0 (valid random static address per BT spec)
- New validateAndStripChecksum() computes XOR checksum between $ and *
- Rejects sentences with missing or mismatched checksums
- Legacy stripChecksum() wrapper preserved for backward compat
- Logs warnings on checksum failures via Serial for debugging
…, WifiScan

Added exit() cleanup functions to WiFi namespaces that were missing them.
- PacketMonitor::exit() disables promiscuous mode, clears rx callback
- BeaconSpammer::exit() stops beacon transmission
- WifiScan::exit() deletes scan results
All reset WiFi radio to STA mode on exit.
All while(isButtonPressed()){} loops (36 total) replaced with
waitForButtonRelease() which adds 5s timeout + FreeRTOS yield.
Prevents permanent device hang if button gets stuck.
Added waitForButtonRelease() and waitForButtonRelease2() helpers.
@cifertech

Copy link
Copy Markdown
Owner

Hi @RadDad87, thanks for the detailed PR. the MAC randomization and GPS validation changes look really useful. I'm hitting a compile error though:

bluetooth.cpp:710'esp_ble_gap_set_rand_addr' was not declared in this scope

Did this compile and upload successfully on your end? Which ESP32 core version and board config are you using? That function is part of the Bluedroid stack and may need a specific core version or #include to be in scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants