From 396d8e69fee44966f8a634a81544b9a0e9968dc3 Mon Sep 17 00:00:00 2001 From: Stefan Kremser Date: Mon, 9 Apr 2018 12:24:36 +0200 Subject: [PATCH] Improved the way stations save their AP There was the problem that when the AP list get's sorted (when starting an attack for example), the pointers to the stations would become messed up. --- esp8266_deauther/Accesspoints.cpp | 19 +++++++++++-------- esp8266_deauther/Accesspoints.h | 7 +++++-- esp8266_deauther/Attack.cpp | 2 +- esp8266_deauther/Names.cpp | 13 +++---------- esp8266_deauther/Names.h | 1 + esp8266_deauther/Scan.cpp | 6 +++--- esp8266_deauther/SerialInterface.cpp | 2 +- esp8266_deauther/Stations.cpp | 26 +++++++++++++++----------- esp8266_deauther/Stations.h | 3 +++ esp8266_deauther/functions.h | 12 ------------ web_interface/js/scan.js | 7 +++++-- 11 files changed, 48 insertions(+), 50 deletions(-) diff --git a/esp8266_deauther/Accesspoints.cpp b/esp8266_deauther/Accesspoints.cpp index fe5fe5b..3cd3d75 100644 --- a/esp8266_deauther/Accesspoints.cpp +++ b/esp8266_deauther/Accesspoints.cpp @@ -141,13 +141,7 @@ uint8_t* Accesspoints::getMac(int num) { String Accesspoints::getMacStr(int num) { if (!check(num)) return String(); uint8_t* mac = getMac(num); - String value; - for (int i = 0; i < 6; i++) { - if (mac[i] < 0x10) value += ZERO; - value += String(mac[i], HEX); - if (i < 5) value += DOUBLEPOINT; - } - return value; + return bytesToStr(mac, 6); } String Accesspoints::getVendorStr(int num) { @@ -165,7 +159,7 @@ bool Accesspoints::getSelected(int num) { return list->get(num).selected; } -int Accesspoints::getID(int num){ +uint8_t Accesspoints::getID(int num){ if (!check(num)) return -1; return list->get(num).id; } @@ -224,6 +218,15 @@ void Accesspoints::removeAll() { changed = true; } +int Accesspoints::find(uint8_t id){ + int s = list->size(); + for(int i=0;iget(i).id == id) + return i; + } + return -1; +} + int Accesspoints::count() { return list->size(); } diff --git a/esp8266_deauther/Accesspoints.h b/esp8266_deauther/Accesspoints.h index 314880c..9b27a84 100644 --- a/esp8266_deauther/Accesspoints.h +++ b/esp8266_deauther/Accesspoints.h @@ -14,7 +14,8 @@ extern Names names; extern String searchVendor(uint8_t* mac); extern String buildString(String left, String right, int maxLen); -String fixUtf8(String str); +extern String fixUtf8(String str); +extern String bytesToStr(uint8_t* b, uint32_t size); struct AP{ uint8_t id; @@ -49,12 +50,14 @@ class Accesspoints { String getSelectedStr(int num); uint8_t getCh(int num); uint8_t getEnc(int num); - int getID(int num); + uint8_t getID(int num); int getRSSI(int num); uint8_t* getMac(int num); bool getHidden(int num); bool getSelected(int num); + int find(uint8_t id); + int count(); int selected(); diff --git a/esp8266_deauther/Attack.cpp b/esp8266_deauther/Attack.cpp index 33160de..00c7107 100644 --- a/esp8266_deauther/Attack.cpp +++ b/esp8266_deauther/Attack.cpp @@ -241,7 +241,7 @@ void Attack:: beaconUpdate() { } bool Attack::deauthStation(int num) { - return deauthDevice(accesspoints.getMac(stations.getAP(num)), stations.getMac(num), settings.getDeauthReason(), accesspoints.getCh(stations.getAP(num))); + return deauthDevice(stations.getAPMac(num), stations.getMac(num), settings.getDeauthReason(), stations.getCh(num)); } bool Attack::deauthAP(int num) { diff --git a/esp8266_deauther/Names.cpp b/esp8266_deauther/Names.cpp index ebaf2d8..3389da7 100644 --- a/esp8266_deauther/Names.cpp +++ b/esp8266_deauther/Names.cpp @@ -340,16 +340,9 @@ uint8_t* Names::getBssid(int num) { } String Names::getMacStr(int num) { - String value; - if (check(num)) { - uint8_t* mac = getMac(num); - for (int i = 0; i < 6; i++) { - if (mac[i] < 0x10) value += ZERO; - value += String(mac[i], HEX); - if (i < 5) value += DOUBLEPOINT; - } - } - return value; + if (!check(num)) return String(); + uint8_t* mac = getMac(num); + return bytesToStr(mac, 6); } String Names::getVendorStr(int num) { diff --git a/esp8266_deauther/Names.h b/esp8266_deauther/Names.h index 998777b..4245db2 100644 --- a/esp8266_deauther/Names.h +++ b/esp8266_deauther/Names.h @@ -23,6 +23,7 @@ extern String searchVendor(uint8_t* mac); extern String fixUtf8(String str); extern String buildString(String left, String right, int maxLen); extern String escape(String str); +extern String bytesToStr(uint8_t* b, uint32_t size); class Names { public: diff --git a/esp8266_deauther/Scan.cpp b/esp8266_deauther/Scan.cpp index 5614c6e..381ca59 100644 --- a/esp8266_deauther/Scan.cpp +++ b/esp8266_deauther/Scan.cpp @@ -27,13 +27,13 @@ void Scan::sniffer(uint8_t* buf, uint16_t len) { if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) || macMulticast(macFrom)) return; - int16_t accesspointNum = findAccesspoint(macFrom); + int accesspointNum = findAccesspoint(macFrom); if (accesspointNum >= 0) { - stations.add(macTo, accesspointNum); + stations.add(macTo, accesspoints.getID(accesspointNum)); } else { accesspointNum = findAccesspoint(macTo); if (accesspointNum >= 0) { - stations.add(macFrom, accesspointNum); + stations.add(macFrom, accesspoints.getID(accesspointNum)); } } } diff --git a/esp8266_deauther/SerialInterface.cpp b/esp8266_deauther/SerialInterface.cpp index 0f41290..2831c88 100644 --- a/esp8266_deauther/SerialInterface.cpp +++ b/esp8266_deauther/SerialInterface.cpp @@ -423,7 +423,7 @@ void SerialInterface::runCommand(String input) { else if (eqlsCMD(i, CLI_AP)) mac = accesspoints.getMacStr(list->get(i + 1).toInt()); else if (eqlsCMD(i, CLI_STATION)) { mac = stations.getMacStr(list->get(i + 1).toInt()); - bssid = accesspoints.getMacStr(stations.getAP(list->get(i + 1).toInt())); + bssid = stations.getAPMacStr(list->get(i + 1).toInt()); } else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt(); else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1); diff --git a/esp8266_deauther/Stations.cpp b/esp8266_deauther/Stations.cpp index 665846f..ba69916 100644 --- a/esp8266_deauther/Stations.cpp +++ b/esp8266_deauther/Stations.cpp @@ -121,9 +121,20 @@ String Stations::getAPStr(int num) { return accesspoints.getSSID(getAP(num)); } +uint8_t* Stations::getAPMac(int num){ + if (!check(num)) return 0; + return WiFi.BSSID(list->get(num).ap); +} + +String Stations::getAPMacStr(int num){ + if (!check(num)) return String(); + uint8_t* mac = getAPMac(num); + return bytesToStr(mac, 6); +} + uint8_t Stations::getAP(int num) { if (!check(num)) return 0; - return list->get(num).ap; + return accesspoints.find(list->get(num).ap); } String Stations::getNameStr(int num) { @@ -142,16 +153,9 @@ uint8_t* Stations::getMac(int num) { } String Stations::getMacStr(int num) { - String value = ""; - if (check(num)) { - uint8_t* mac = getMac(num); - for (int i = 0; i < 6; i++) { - if (mac[i] < 0x10) value += "0"; - value += String(mac[i], HEX); - if (i < 5) value += ":"; - } - } - return value; + if (!check(num)) return String(); + uint8_t* mac = getMac(num); + return bytesToStr(mac, 6); } String Stations::getMacVendorStr(int num) { diff --git a/esp8266_deauther/Stations.h b/esp8266_deauther/Stations.h index 3e4943d..22d9354 100644 --- a/esp8266_deauther/Stations.h +++ b/esp8266_deauther/Stations.h @@ -20,6 +20,7 @@ extern String searchVendor(uint8_t* mac); extern bool macMulticast(uint8_t* mac); extern bool macValid(uint8_t* mac); extern bool macBroadcast(uint8_t* mac); +extern String bytesToStr(uint8_t* b, uint32_t size); class Stations { public: @@ -45,6 +46,8 @@ class Stations { String getVendorStr(int num); String getTimeStr(int num); String getSelectedStr(int num); + uint8_t* getAPMac(int num); + String getAPMacStr(int num); uint8_t* getMac(int num); uint32_t* getPkts(int num); uint32_t* getTime(int num); diff --git a/esp8266_deauther/functions.h b/esp8266_deauther/functions.h index 3ba370f..8f5d614 100644 --- a/esp8266_deauther/functions.h +++ b/esp8266_deauther/functions.h @@ -689,18 +689,6 @@ String formatBytes(size_t bytes) { else return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB"; } -/* - void parseBytes(const char* str, char sep, byte* bytes, int maxBytes, int base) { - for (int i = 0; i < maxBytes; i++) { - bytes[i] = strtoul(str, NULL, base); // Convert byte - str = strchr(str, sep); // Find next separator - if (str == NULL || *str == '\0') { - break; // No more separators, exit - } - str++; // Point to next character after separator - } - } -*/ #endif diff --git a/web_interface/js/scan.js b/web_interface/js/scan.js index a6636b5..eb4b8f1 100644 --- a/web_interface/js/scan.js +++ b/web_interface/js/scan.js @@ -68,7 +68,10 @@ function drawScan(){ for(var i=0;i= 0) + ap = esc(scanJson.aps[scanJson.stations[i][5]][0]); + html += (selected ? "" : "") + ""+i+"" // ID + ""+esc(scanJson.stations[i][3])+"" // Vendor @@ -76,7 +79,7 @@ function drawScan(){ + ""+esc(scanJson.stations[i][1])+"" // Ch + ""+(scanJson.stations[i][2].length > 0 ? esc(scanJson.stations[i][2]) : "")+"" // Name + ""+esc(scanJson.stations[i][4])+"" // Pkts - + ""+esc(scanJson.aps[scanJson.stations[i][5]][0])+"" // AP + + ""+ap+"" // AP + ""+esc(scanJson.stations[i][6])+"" // Last seen // Select + ""