From 8fc2bbcd956d7d6f9ebce5858a04a793250f7c3f Mon Sep 17 00:00:00 2001 From: Spacehuhn Date: Sun, 5 Jul 2020 15:48:39 +0200 Subject: [PATCH] Refactored settings --- esp8266_deauther/Attack.cpp | 28 +- esp8266_deauther/Attack.h | 2 - esp8266_deauther/CLI.cpp | 88 ++--- esp8266_deauther/CLI.h | 3 +- esp8266_deauther/DisplayUI.cpp | 12 +- esp8266_deauther/DisplayUI.h | 3 +- esp8266_deauther/LED.cpp | 8 +- esp8266_deauther/SSIDs.cpp | 2 + esp8266_deauther/SSIDs.h | 3 +- esp8266_deauther/Scan.cpp | 6 +- esp8266_deauther/Scan.h | 3 +- esp8266_deauther/Settings.cpp | 524 +++++++++++++------------- esp8266_deauther/Settings.h | 213 ++++------- esp8266_deauther/esp8266_deauther.ino | 27 +- esp8266_deauther/language.h | 48 +++ esp8266_deauther/wifi.h | 36 +- utils/web_converter/webConverter.py | 14 +- 17 files changed, 500 insertions(+), 520 deletions(-) diff --git a/esp8266_deauther/Attack.cpp b/esp8266_deauther/Attack.cpp index 01af1ab..76fe473 100644 --- a/esp8266_deauther/Attack.cpp +++ b/esp8266_deauther/Attack.cpp @@ -1,9 +1,11 @@ #include "Attack.h" +#include "settings.h" + Attack::Attack() { getRandomMac(mac); - if (settings.getAttackSettings().beacon_interval == INTERVAL_1S) { + if (settings::getAttackSettings().beacon_interval == INTERVAL_1S) { // 1s beacon interval beaconPacket[32] = 0xe8; beaconPacket[33] = 0x03; @@ -83,9 +85,9 @@ void Attack::updateCounter() { // deauth packets per second if (deauth.active) { - if (deauthAll) deauth.maxPkts = settings.getAttackSettings().deauths_per_target * + if (deauthAll) deauth.maxPkts = settings::getAttackSettings().deauths_per_target * (accesspoints.count() + stations.count() * 2 - names.selected()); - else deauth.maxPkts = settings.getAttackSettings().deauths_per_target * + else deauth.maxPkts = settings::getAttackSettings().deauths_per_target * (accesspoints.selected() + stations.selected() * 2 + names.selected() + names.stations()); } else { deauth.maxPkts = 0; @@ -95,17 +97,17 @@ void Attack::updateCounter() { if (beacon.active) { beacon.maxPkts = ssids.count(); - if (settings.getAttackSettings().beacon_interval == INTERVAL_100MS) beacon.maxPkts *= 10; + if (settings::getAttackSettings().beacon_interval == INTERVAL_100MS) beacon.maxPkts *= 10; } else { beacon.maxPkts = 0; } // probe packets per second - if (probe.active) probe.maxPkts = ssids.count() * settings.getAttackSettings().probe_frames_per_ssid; + if (probe.active) probe.maxPkts = ssids.count() * settings::getAttackSettings().probe_frames_per_ssid; else probe.maxPkts = 0; // random transmission power - if (settings.getAttackSettings().random_tx && (beacon.active || probe.active)) setOutputPower(random(21)); + if (settings::getAttackSettings().random_tx && (beacon.active || probe.active)) setOutputPower(random(21)); else setOutputPower(20.5f); // reset counters @@ -240,7 +242,7 @@ void Attack::deauthAllUpdate() { void Attack::probeUpdate() { if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) { if (probe.time <= currentTime - (1000 / probe.maxPkts)) { - if (settings.getAttackSettings().attack_all_ch) setWifiChannel(probe.tc % 11); + if (settings::getAttackSettings().attack_all_ch) setWifiChannel(probe.tc % 11); probe.tc += sendProbe(probe.tc); if (probe.tc >= ssids.count()) probe.tc = 0; @@ -259,18 +261,18 @@ void Attack::beaconUpdate() { } bool Attack::deauthStation(int num) { - return deauthDevice(stations.getAPMac(num), stations.getMac(num), settings.getAttackSettings().deauth_reason, stations.getCh(num)); + return deauthDevice(stations.getAPMac(num), stations.getMac(num), settings::getAttackSettings().deauth_reason, stations.getCh(num)); } bool Attack::deauthAP(int num) { - return deauthDevice(accesspoints.getMac(num), broadcast, settings.getAttackSettings().deauth_reason, accesspoints.getCh(num)); + return deauthDevice(accesspoints.getMac(num), broadcast, settings::getAttackSettings().deauth_reason, accesspoints.getCh(num)); } bool Attack::deauthName(int num) { if (names.isStation(num)) { - return deauthDevice(names.getBssid(num), names.getMac(num), settings.getAttackSettings().deauth_reason, names.getCh(num)); + return deauthDevice(names.getBssid(num), names.getMac(num), settings::getAttackSettings().deauth_reason, names.getCh(num)); } else { - return deauthDevice(names.getMac(num), broadcast, settings.getAttackSettings().deauth_reason, names.getCh(num)); + return deauthDevice(names.getMac(num), broadcast, settings::getAttackSettings().deauth_reason, names.getCh(num)); } } @@ -334,7 +336,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_ } bool Attack::sendBeacon(uint8_t tc) { - if (settings.getAttackSettings().attack_all_ch) setWifiChannel(tc % 11); + if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11); mac[5] = tc; return sendBeacon(mac, ssids.getName(tc).c_str(), wifi_channel, ssids.getWPA2(tc)); } @@ -380,7 +382,7 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) { } bool Attack::sendProbe(uint8_t tc) { - if (settings.getAttackSettings().attack_all_ch) setWifiChannel(tc % 11); + if (settings::getAttackSettings().attack_all_ch) setWifiChannel(tc % 11); mac[5] = tc; return sendProbe(mac, ssids.getName(tc).c_str(), wifi_channel); } diff --git a/esp8266_deauther/Attack.h b/esp8266_deauther/Attack.h index 2963538..6718136 100644 --- a/esp8266_deauther/Attack.h +++ b/esp8266_deauther/Attack.h @@ -10,10 +10,8 @@ extern "C" { #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; diff --git a/esp8266_deauther/CLI.cpp b/esp8266_deauther/CLI.cpp index 05a2da7..fb0fc66 100644 --- a/esp8266_deauther/CLI.cpp +++ b/esp8266_deauther/CLI.cpp @@ -1,5 +1,7 @@ #include "CLI.h" +#include "settings.h" + /* Shitty code used less resources so I will keep this clusterfuck as it is, but if you're interested I made a library for this: github.com/spacehuhn/SimpleCLI @@ -224,7 +226,7 @@ void CLI::runCommand(String input) { return; } - if (settings.getCLISettings().serial_echo) { + if (settings::getCLISettings().serial_echo) { // print command prnt(CLI_INPUT_PREFIX); prntln(input); @@ -613,7 +615,7 @@ void CLI::runCommand(String input) { if ((list->size() == 1) || eqlsCMD(1, CLI_ALL)) { load ? ssids.load() : ssids.save(false); load ? names.load() : names.save(false); - load ? settings.load() : settings.save(false); + load ? settings::load() : settings::save(false); if (!load) scan.save(false); return; @@ -622,12 +624,12 @@ void CLI::runCommand(String input) { if (list->size() == 3) { // Todo: check if -f or filename if (eqlsCMD(1, CLI_SSID)) load ? ssids.load(list->get(2)) : ssids.save(true, list->get(2)); else if (eqlsCMD(1, CLI_NAME)) load ? names.load(list->get(2)) : names.save(true, list->get(2)); - // else if (eqlsCMD(1, CLI_SETTING)) load ? settings.load(list->get(2)) : settings.save(true, list->get(2)); + // else if (eqlsCMD(1, CLI_SETTING)) load ? settings::load(list->get(2)) : settings::save(true, list->get(2)); else parameterError(list->get(1)); } else { if (eqlsCMD(1, CLI_SSID)) load ? ssids.load() : ssids.save(true); else if (eqlsCMD(1, CLI_NAME)) load ? names.load() : names.save(true); - else if (eqlsCMD(1, CLI_SETTING)) load ? settings.load() : settings.save(true); + else if (eqlsCMD(1, CLI_SETTING)) load ? settings::load() : settings::save(true); else if ((eqlsCMD(1, CLI_SCAN) || eqlsCMD(1, CLI_AP) || eqlsCMD(1, CLI_STATION)) && !load) scan.save(true); else parameterError(list->get(1)); } @@ -653,7 +655,7 @@ void CLI::runCommand(String input) { bool deauthAll = false; bool probe = false; bool output = true; - uint32_t timeout = settings.getAttackSettings().timeout * 1000; + uint32_t timeout = settings::getAttackSettings().timeout * 1000; for (int i = 1; i < list->size(); i++) { if (eqlsCMD(i, CLI_BEACON)) beacon = true; @@ -677,53 +679,53 @@ void CLI::runCommand(String input) { String _tmp = list->get(1); const char* str = _tmp.c_str(); - if (eqls(str, "settings")) settings.print(); + if (eqls(str, "settings")) settings::print(); // Version else if (eqls(str, S_JSON_VERSION)) prntln(DEAUTHER_VERSION); - else if (eqls(str, S_JSON_AUTOSAVE)) prntln(settings.getAutosaveSettings().enabled); - else if (eqls(str, S_JSON_AUTOSAVETIME)) prntln(settings.getAutosaveSettings().time); + else if (eqls(str, S_JSON_AUTOSAVE)) prntln(settings::getAutosaveSettings().enabled); + else if (eqls(str, S_JSON_AUTOSAVETIME)) prntln(settings::getAutosaveSettings().time); // Attack - else if (eqls(str, S_JSON_BEACONCHANNEL)) prntln((int)settings.getAttackSettings().attack_all_ch); - else if (eqls(str, S_JSON_RANDOMTX)) prntln(settings.getAttackSettings().random_tx); - else if (eqls(str, S_JSON_ATTACKTIMEOUT)) prntln(settings.getAttackSettings().timeout); - else if (eqls(str, S_JSON_DEAUTHSPERTARGET)) prntln(settings.getAttackSettings().deauths_per_target); - else if (eqls(str, S_JSON_DEAUTHREASON)) prntln(settings.getAttackSettings().deauth_reason); - else if (eqls(str, S_JSON_BEACONINTERVAL)) prntln((bool)settings.getAttackSettings().beacon_interval); - else if (eqls(str, S_JSON_PROBESPERSSID)) prntln(settings.getAttackSettings().probe_frames_per_ssid); + else if (eqls(str, S_JSON_BEACONCHANNEL)) prntln((int)settings::getAttackSettings().attack_all_ch); + else if (eqls(str, S_JSON_RANDOMTX)) prntln(settings::getAttackSettings().random_tx); + else if (eqls(str, S_JSON_ATTACKTIMEOUT)) prntln(settings::getAttackSettings().timeout); + else if (eqls(str, S_JSON_DEAUTHSPERTARGET)) prntln(settings::getAttackSettings().deauths_per_target); + else if (eqls(str, S_JSON_DEAUTHREASON)) prntln(settings::getAttackSettings().deauth_reason); + else if (eqls(str, S_JSON_BEACONINTERVAL)) prntln((bool)settings::getAttackSettings().beacon_interval); + else if (eqls(str, S_JSON_PROBESPERSSID)) prntln(settings::getAttackSettings().probe_frames_per_ssid); // WiFi - else if (eqls(str, S_JSON_CHANNEL)) prntln(settings.getWifiSettings().channel); - else if (eqls(str, S_JSON_MACST)) prntln(macToStr(settings.getWifiSettings().mac_st)); - else if (eqls(str, S_JSON_MACAP)) prntln(macToStr(settings.getWifiSettings().mac_ap)); + else if (eqls(str, S_JSON_CHANNEL)) prntln(settings::getWifiSettings().channel); + else if (eqls(str, S_JSON_MACST)) prntln(macToStr(settings::getWifiSettings().mac_st)); + else if (eqls(str, S_JSON_MACAP)) prntln(macToStr(settings::getWifiSettings().mac_ap)); // Sniffer - else if (eqls(str, S_JSON_CHTIME)) prntln(settings.getSnifferSettings().channel_time); - else if (eqls(str, S_JSON_MIN_DEAUTHS)) prntln(settings.getSnifferSettings().min_deauth_frames); + else if (eqls(str, S_JSON_CHTIME)) prntln(settings::getSnifferSettings().channel_time); + else if (eqls(str, S_JSON_MIN_DEAUTHS)) prntln(settings::getSnifferSettings().min_deauth_frames); // AP - else if (eqls(str, S_JSON_SSID)) prntln(settings.getAccessPointSettings().ssid); - else if (eqls(str, S_JSON_PASSWORD)) prntln(settings.getAccessPointSettings().password); - else if (eqls(str, S_JSON_HIDDEN)) prntln(settings.getAccessPointSettings().hidden); - else if (eqls(str, S_JSON_IP)) prntln(settings.getAccessPointSettings().ip); + else if (eqls(str, S_JSON_SSID)) prntln(settings::getAccessPointSettings().ssid); + else if (eqls(str, S_JSON_PASSWORD)) prntln(settings::getAccessPointSettings().password); + else if (eqls(str, S_JSON_HIDDEN)) prntln(settings::getAccessPointSettings().hidden); + else if (eqls(str, S_JSON_IP)) prntln(settings::getAccessPointSettings().ip); // Web - else if (eqls(str, S_JSON_WEBINTERFACE)) prntln(settings.getWebSettings().enabled); - else if (eqls(str, S_JSON_CAPTIVEPORTAL)) prntln(settings.getWebSettings().captive_portal); - else if (eqls(str, S_JSON_WEB_SPIFFS)) prntln(settings.getWebSettings().use_spiffs); - else if (eqls(str, S_JSON_LANG)) prntln(settings.getWebSettings().lang, 3); + else if (eqls(str, S_JSON_WEBINTERFACE)) prntln(settings::getWebSettings().enabled); + else if (eqls(str, S_JSON_CAPTIVEPORTAL)) prntln(settings::getWebSettings().captive_portal); + else if (eqls(str, S_JSON_WEB_SPIFFS)) prntln(settings::getWebSettings().use_spiffs); + else if (eqls(str, S_JSON_LANG)) prntln(settings::getWebSettings().lang, 3); // CLI - else if (eqls(str, S_JSON_SERIALINTERFACE)) prntln(settings.getCLISettings().enabled); - else if (eqls(str, S_JSON_SERIAL_ECHO)) prntln(settings.getCLISettings().serial_echo); + else if (eqls(str, S_JSON_SERIALINTERFACE)) prntln(settings::getCLISettings().enabled); + else if (eqls(str, S_JSON_SERIAL_ECHO)) prntln(settings::getCLISettings().serial_echo); // LED - else if (eqls(str, S_JSON_LEDENABLED)) prntln(settings.getLEDSettings().enabled); + else if (eqls(str, S_JSON_LEDENABLED)) prntln(settings::getLEDSettings().enabled); // Display - else if (eqls(str, S_JSON_DISPLAYINTERFACE)) prntln(settings.getDisplaySettings().enabled); - else if (eqls(str, S_JSON_DISPLAY_TIMEOUT)) prntln(settings.getDisplaySettings().timeout); + else if (eqls(str, S_JSON_DISPLAYINTERFACE)) prntln(settings::getDisplaySettings().enabled); + else if (eqls(str, S_JSON_DISPLAY_TIMEOUT)) prntln(settings::getDisplaySettings().timeout); else { prnt(_tmp); @@ -741,7 +743,7 @@ void CLI::runCommand(String input) { int intVal = strVal.toInt(); uint32_t unsignedVal = intVal < 0 ? 0 : (uint32_t)intVal; - settings_t newSettings = settings.getAllSettings(); + settings_t newSettings = settings::getAllSettings(); // Autosave if (eqls(str, S_JSON_AUTOSAVE)) newSettings.autosave.enabled = boolVal; @@ -799,7 +801,7 @@ void CLI::runCommand(String input) { prnt(" = "); prntln(strVal); - settings.setAllSettings(newSettings); + settings::setAllSettings(newSettings); } // ====== CHICKEN ===== // @@ -837,7 +839,7 @@ void CLI::runCommand(String input) { prntln(String(s)); prnt(CLI_SYSTEM_CHANNEL); - prntln(settings.getWifiSettings().channel); + prntln(settings::getWifiSettings().channel); uint8_t mac[6]; @@ -873,7 +875,7 @@ void CLI::runCommand(String input) { // ===== RESET ===== // // reset else if (eqlsCMD(0, CLI_RESET)) { - settings.reset(); + settings::reset(); } // ===== CLEAR ===== // @@ -1097,11 +1099,11 @@ void CLI::runCommand(String input) { led.update(); // update LED color // auto-save - if (settings.getAutosaveSettings().enabled && (currentTime - autosaveTime > settings.getAutosaveSettings().time)) { + if (settings::getAutosaveSettings().enabled && (currentTime - autosaveTime > settings::getAutosaveSettings().time)) { autosaveTime = currentTime; names.save(false); ssids.save(false); - settings.save(false); + settings::save(false); } // ------- loop function end ----- // yield(); @@ -1186,11 +1188,11 @@ void CLI::runCommand(String input) { // startap [-p ] [-pswd ] [-ch ] [-h] [-cp] else if (eqlsCMD(0, CLI_STARTAP)) { String path = String(F("/web")); - String ssid = settings.getAccessPointSettings().ssid; - String password = settings.getAccessPointSettings().password; + String ssid = settings::getAccessPointSettings().ssid; + String password = settings::getAccessPointSettings().password; int ch = wifi_channel; - bool hidden = settings.getAccessPointSettings().hidden; - bool captivePortal = settings.getWebSettings().captive_portal; + bool hidden = settings::getAccessPointSettings().hidden; + bool captivePortal = settings::getWebSettings().captive_portal; for (int i = 1; i < list->size(); i++) { if (eqlsCMD(i, CLI_PATH)) { diff --git a/esp8266_deauther/CLI.h b/esp8266_deauther/CLI.h index 8dd005e..9dc7100 100644 --- a/esp8266_deauther/CLI.h +++ b/esp8266_deauther/CLI.h @@ -10,7 +10,6 @@ extern "C" { #include "language.h" #include "A_config.h" #include "SimpleList.h" -#include "Settings.h" #include "Names.h" #include "SSIDs.h" #include "Scan.h" @@ -19,7 +18,7 @@ extern "C" { #include "LED.h" extern LED led; -extern Settings settings; + extern Names names; extern SSIDs ssids; extern Accesspoints accesspoints; diff --git a/esp8266_deauther/DisplayUI.cpp b/esp8266_deauther/DisplayUI.cpp index 5321166..7dcfd17 100644 --- a/esp8266_deauther/DisplayUI.cpp +++ b/esp8266_deauther/DisplayUI.cpp @@ -1,5 +1,7 @@ #include "DisplayUI.h" +#include "settings.h" + // ===== adjustable ===== // void DisplayUI::configInit() { // initialize display @@ -395,7 +397,7 @@ void DisplayUI::setup() { if (attack.isRunning()) { attack.start(beaconSelected, deauthSelected, false, probeSelected, true, - settings.getAttackSettings().timeout * 1000); + settings::getAttackSettings().timeout * 1000); } }); addMenuNode(&attackMenu, [this]() { // *BEACON 0/0 @@ -408,7 +410,7 @@ void DisplayUI::setup() { if (attack.isRunning()) { attack.start(beaconSelected, deauthSelected, false, probeSelected, true, - settings.getAttackSettings().timeout * 1000); + settings::getAttackSettings().timeout * 1000); } }); addMenuNode(&attackMenu, [this]() { // *PROBE 0/0 @@ -421,7 +423,7 @@ void DisplayUI::setup() { if (attack.isRunning()) { attack.start(beaconSelected, deauthSelected, false, probeSelected, true, - settings.getAttackSettings().timeout * 1000); + settings::getAttackSettings().timeout * 1000); } }); addMenuNode(&attackMenu, [this]() { // START @@ -430,7 +432,7 @@ void DisplayUI::setup() { }, [this]() { if (attack.isRunning()) attack.stop(); else attack.start(beaconSelected, deauthSelected, false, probeSelected, true, - settings.getAttackSettings().timeout * 1000); + settings::getAttackSettings().timeout * 1000); }); }); @@ -461,7 +463,7 @@ void DisplayUI::update() { draw(); - uint32_t timeout = settings.getDisplaySettings().timeout * 1000; + uint32_t timeout = settings::getDisplaySettings().timeout * 1000; if (currentTime > timeout) { if (!tempOff) { diff --git a/esp8266_deauther/DisplayUI.h b/esp8266_deauther/DisplayUI.h index f2f5e17..f87f06f 100644 --- a/esp8266_deauther/DisplayUI.h +++ b/esp8266_deauther/DisplayUI.h @@ -3,7 +3,6 @@ #include "language.h" #include "A_config.h" -#include "Settings.h" #include "Names.h" #include "SSIDs.h" #include "Scan.h" @@ -28,7 +27,7 @@ using namespace simplebutton; -extern Settings settings; + extern Names names; extern SSIDs ssids; extern Accesspoints accesspoints; diff --git a/esp8266_deauther/LED.cpp b/esp8266_deauther/LED.cpp index cf04148..88fd242 100644 --- a/esp8266_deauther/LED.cpp +++ b/esp8266_deauther/LED.cpp @@ -2,13 +2,13 @@ // ===== [Includes] ===== // // used for update() -#include "Settings.h" +#include "settings.h" #include "Attack.h" #include "Scan.h" // ===== [External] ===== // // used for update() -extern Settings settings; + extern Attack attack; extern Scan scan; @@ -83,9 +83,9 @@ void LED::setup() { } void LED::update() { - if (!settings.getLEDSettings().enabled) { + if (!settings::getLEDSettings().enabled) { setMode(OFF); - } else if (scan.isScanning() && (scan.deauths < settings.getSnifferSettings().min_deauth_frames)) { + } else if (scan.isScanning() && (scan.deauths < settings::getSnifferSettings().min_deauth_frames)) { setMode(SCAN); } else if (attack.isRunning()) { setMode(ATTACK); diff --git a/esp8266_deauther/SSIDs.cpp b/esp8266_deauther/SSIDs.cpp index f1459f3..5a4c60f 100644 --- a/esp8266_deauther/SSIDs.cpp +++ b/esp8266_deauther/SSIDs.cpp @@ -1,5 +1,7 @@ #include "SSIDs.h" +#include "settings.h" + SSIDs::SSIDs() { list = new SimpleList; } diff --git a/esp8266_deauther/SSIDs.h b/esp8266_deauther/SSIDs.h index 85e9659..4131982 100644 --- a/esp8266_deauther/SSIDs.h +++ b/esp8266_deauther/SSIDs.h @@ -10,12 +10,11 @@ extern "C" { #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; diff --git a/esp8266_deauther/Scan.cpp b/esp8266_deauther/Scan.cpp index 8abeb41..9ac19a4 100644 --- a/esp8266_deauther/Scan.cpp +++ b/esp8266_deauther/Scan.cpp @@ -1,5 +1,7 @@ #include "Scan.h" +#include "settings.h" + Scan::Scan() { list = new SimpleList; } @@ -126,7 +128,7 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu else if (mode == SCAN_MODE_OFF) { wifi_promiscuous_enable(false); - if (settings.getWebSettings().enabled) resumeAP(); + if (settings::getWebSettings().enabled) resumeAP(); prntln(SC_STOPPED); save(true); @@ -181,7 +183,7 @@ void Scan::update() { } // channel hopping - if (channelHop && (currentTime - snifferChannelTime > settings.getSnifferSettings().channel_time)) { + if (channelHop && (currentTime - snifferChannelTime > settings::getSnifferSettings().channel_time)) { snifferChannelTime = currentTime; if (scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on diff --git a/esp8266_deauther/Scan.h b/esp8266_deauther/Scan.h index 1d63162..d01b6d4 100644 --- a/esp8266_deauther/Scan.h +++ b/esp8266_deauther/Scan.h @@ -6,7 +6,6 @@ #include "Stations.h" #include "Names.h" #include "SSIDs.h" -#include "Settings.h" #include "language.h" #include "SimpleList.h" @@ -23,7 +22,7 @@ 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); diff --git a/esp8266_deauther/Settings.cpp b/esp8266_deauther/Settings.cpp index e8dcabd..4072b48 100644 --- a/esp8266_deauther/Settings.cpp +++ b/esp8266_deauther/Settings.cpp @@ -1,7 +1,20 @@ -#include "Settings.h" +/* + Copyright (c) 2020 Stefan Kremser (@Spacehuhn) + This software is licensed under the MIT License. See the license file for details. + Source: github.com/spacehuhn/esp8266_deauther + */ + +#include "settings.h" -#include // sha1() used in calcHash() +#include // sha1() used in calc_hash() +#include "A_config.h" // Default Settings +#include "language.h" // prnt and prntln #include "EEPROMHelper.h" // To load and save settings_t +#include "debug.h" + +extern bool writeFile(String path, String& buf); +extern void getRandomMac(uint8_t* mac); +extern bool macValid(uint8_t* mac); // ===== INTERNAL ===== // bool operator==(settings_hash_t a, settings_hash_t b) { @@ -14,301 +27,302 @@ bool operator==(version_t a, version_t b) { return a.major == b.major && a.minor == b.minor && a.revision == b.revision; } -void jsonStr(String& str, const char* name, const char* value) { - str += '"'; - str += String(name); - str += '"'; - str += ':'; - str += '"'; - str += String(value); - str += '"'; - str += ','; -} +#define JSON_FLAG(_NAME,_VALUE)\ + str += String('"') + str(_NAME) + String(F("\":")) + String(_VALUE?"true":"false") + String(','); -void jsonFlag(String& str, const char* name, bool value) { - str += '"'; - str += String(name); - str += '"'; - str += ':'; - str += value ? String(S_JSON_TRUE) : String(S_JSON_FALSE); - str += ','; -} +#define JSON_VALUE(_NAME,_VALUE)\ + str += String('"') + str(_NAME) + String(F("\":")) + String(_VALUE) + String(','); -void jsonValue(String& str, const char* name, int value) { - str += '"'; - str += String(name); - str += '"'; - str += ':'; - str += String(value); - str += ','; -} +#define JSON_HEX(_NAME,_BYTES,_LEN)\ + str += String('"') + str(_NAME) + String(F("\":"));\ + for (int i = 0; i<_LEN; i++) {\ + if (i > 0) str += ':';\ + if (_BYTES[i] < 0x10) str += '0';\ + str += String(_BYTES[i], HEX);\ + }\ + str += String(F("\",")); -void jsonHex(String& str, const char* name, uint8_t* byteArr, int len) { - str += '"'; - str += String(name); - str += '"'; - str += ':'; +#define JSON_DEC(_NAME,_BYTES,_LEN)\ + str += String('"') + str(_NAME) + String(F("\":"));\ + for (int i = 0; i<_LEN; i++) {\ + if (i > 0) str += '.';\ + str += String(_BYTES[i]);\ + }\ + str += String(F("\",")); - str += '"'; - for (int i = 0; i 0) str += ':'; - if (byteArr[i] < 0x10) str += '0'; - str += String(byteArr[i], HEX); +namespace settings { + // ========== PRIVATE ========== // + const char* SETTINGS_PATH = "/settings.json"; + + settings_t data; + bool changed = false; + + settings_hash_t calc_hash(settings_t data) { + settings_hash_t hash; + sha1((uint8_t*)&data, sizeof(settings_t), hash.hash); + + return hash; } - str += '"'; - str += ','; -} + void get_json(String& str) { + str = String(); + str.reserve(600); -void jsonDec(String& str, const char* name, uint8_t* byteArr, int len) { - str += '"'; - str += String(name); - str += '"'; - str += ':'; + str += '{'; + + // Version + JSON_VALUE(S_JSON_VERSION, DEAUTHER_VERSION); - str += '"'; + // Autosave + JSON_FLAG(S_JSON_AUTOSAVE, data.autosave.enabled); + JSON_VALUE(S_JSON_AUTOSAVETIME, data.autosave.time); - for (int i = 0; i 0) str += '.'; - str += String(byteArr[i]); + // Attack + JSON_FLAG(S_JSON_BEACONCHANNEL, data.attack.attack_all_ch); + JSON_FLAG(S_JSON_RANDOMTX, data.attack.random_tx); + JSON_VALUE(S_JSON_ATTACKTIMEOUT, data.attack.timeout); + JSON_VALUE(S_JSON_DEAUTHSPERTARGET, data.attack.deauths_per_target); + JSON_VALUE(S_JSON_DEAUTHREASON, data.attack.deauth_reason); + JSON_FLAG(S_JSON_BEACONINTERVAL, data.attack.beacon_interval == INTERVAL_1S); + JSON_VALUE(S_JSON_PROBESPERSSID, data.attack.probe_frames_per_ssid); + + // WiFi + JSON_VALUE(S_JSON_CHANNEL, data.wifi.channel); + JSON_HEX(S_JSON_MACST, data.wifi.mac_st, 6); + JSON_HEX(S_JSON_MACAP, data.wifi.mac_ap, 6); + + // Sniffer + JSON_VALUE(S_JSON_CHTIME, data.sniffer.channel_time); + JSON_VALUE(S_JSON_MIN_DEAUTHS, data.sniffer.min_deauth_frames); + + // Access Point + JSON_VALUE(S_JSON_SSID, data.ap.ssid); + JSON_VALUE(S_JSON_PASSWORD, data.ap.password); + JSON_FLAG(S_JSON_HIDDEN, data.ap.hidden); + JSON_DEC(S_JSON_IP, data.ap.ip, 4); + + // Web Interface + JSON_FLAG(S_JSON_WEBINTERFACE, data.web.enabled); + JSON_FLAG(S_JSON_CAPTIVEPORTAL, data.web.captive_portal); + JSON_FLAG(S_JSON_WEB_SPIFFS, data.web.use_spiffs); + JSON_VALUE(S_JSON_LANG, data.web.lang); + + // CLI + JSON_FLAG(S_JSON_SERIALINTERFACE, data.cli.enabled); + JSON_FLAG(S_JSON_SERIAL_ECHO, data.cli.serial_echo); + + // LED + JSON_FLAG(S_JSON_LEDENABLED, data.led.enabled); + + // Display + JSON_FLAG(S_JSON_DISPLAYINTERFACE, data.display.enabled); + JSON_VALUE(S_JSON_DISPLAY_TIMEOUT, data.display.timeout); + + str.setCharAt(str.length()-1, '}'); } - str += '"'; - str += ','; -} + // ========== PUBLIC ========== // + void load() { + debugF("Loading settings..."); -// ========== PRIVATE ========== // -settings_hash_t Settings::calcHash(settings_t data) { - settings_hash_t hash; + // read hash from eeprom + settings_hash_t hash; + EEPROMHelper::getObject(SETTINGS_HASH_ADDR, hash); - sha1((uint8_t*)&data, sizeof(settings_t), &hash.hash[0]); - return hash; -} + // read data from eeproms + settings_t newData; + EEPROMHelper::getObject(SETTINGS_ADDR, newData); -String Settings::getJsonStr() { - String str((char*)0); - - str.reserve(600); - - str += '{'; - - // Version - jsonStr(str, S_JSON_VERSION, DEAUTHER_VERSION); - - // Autosave - jsonFlag(str, S_JSON_AUTOSAVE, data.autosave.enabled); - jsonValue(str, S_JSON_AUTOSAVETIME, data.autosave.time); - - // Attack - jsonFlag(str, S_JSON_BEACONCHANNEL, data.attack.attack_all_ch); - jsonFlag(str, S_JSON_RANDOMTX, data.attack.random_tx); - jsonValue(str, S_JSON_ATTACKTIMEOUT, data.attack.timeout); - jsonValue(str, S_JSON_DEAUTHSPERTARGET, data.attack.deauths_per_target); - jsonValue(str, S_JSON_DEAUTHREASON, data.attack.deauth_reason); - jsonFlag(str, S_JSON_BEACONINTERVAL, data.attack.beacon_interval == INTERVAL_1S); - jsonValue(str, S_JSON_PROBESPERSSID, data.attack.probe_frames_per_ssid); - - // WiFi - jsonValue(str, S_JSON_CHANNEL, data.wifi.channel); - jsonHex(str, S_JSON_MACST, data.wifi.mac_st, 6); - jsonHex(str, S_JSON_MACAP, data.wifi.mac_ap, 6); - - // Sniffer - jsonValue(str, S_JSON_CHTIME, data.sniffer.channel_time); - jsonValue(str, S_JSON_MIN_DEAUTHS, data.sniffer.min_deauth_frames); - - // Access Point - jsonStr(str, S_JSON_SSID, data.ap.ssid); - jsonStr(str, S_JSON_PASSWORD, data.ap.password); - jsonFlag(str, S_JSON_HIDDEN, data.ap.hidden); - jsonDec(str, S_JSON_IP, data.ap.ip, 4); - - // Web Interface - jsonFlag(str, S_JSON_WEBINTERFACE, data.web.enabled); - jsonFlag(str, S_JSON_CAPTIVEPORTAL, data.web.captive_portal); - jsonFlag(str, S_JSON_WEB_SPIFFS, data.web.use_spiffs); - jsonStr(str, S_JSON_LANG, data.web.lang); - - // CLI - jsonFlag(str, S_JSON_SERIALINTERFACE, data.cli.enabled); - jsonFlag(str, S_JSON_SERIAL_ECHO, data.cli.serial_echo); - - // LED - jsonFlag(str, S_JSON_LEDENABLED, data.led.enabled); - - // Display - jsonFlag(str, S_JSON_DISPLAYINTERFACE, data.display.enabled); - jsonValue(str, S_JSON_DISPLAY_TIMEOUT, data.display.timeout); - - str[str.length()-1] = '}'; - - return str; -} - -// ========== PUBLIC ========== // -void Settings::load() { - prnt(S_SETTINGS_LOADED); - - // read hash from eeprom - settings_hash_t hash; - - EEPROMHelper::getObject(SETTINGS_HASH_ADDR, hash); - - // read data from eeproms - settings_t newData; - EEPROMHelper::getObject(SETTINGS_ADDR, newData); - - // calc and check hash - if ((newData.version == data.version) && (calcHash(newData) == hash)) { - this->data = newData; - prntln(S_OK); - } else { - prntln(S_INVALID_HASH); - } - - // check and fix mac - if (!macValid(data.wifi.mac_st)) getRandomMac(data.wifi.mac_st); - if (!macValid(data.wifi.mac_ap)) getRandomMac(data.wifi.mac_ap); - - changed = true; -} - -void Settings::reset() { - settings_t newData; - - this->data = newData; - - prntln(S_SETTINGS_RESETED); -} - -void Settings::save(bool force) { - if (force || changed) { - EEPROMHelper::saveObject(SETTINGS_HASH_ADDR, calcHash(data)); - EEPROMHelper::saveObject(SETTINGS_ADDR, data); - - changed = false; - - String buf = getJsonStr(); - if (writeFile(SETTINGS_PATH, buf)) { - prnt(S_SETTINGS_SAVED); + // calc and check hash + if ((newData.version == data.version) && (calc_hash(newData) == hash)) { + data = newData; + debuglnF("OK"); } else { - prnt(S_ERROR_SAVING); + debuglnF("Invalid Hash - reseted to default"); } - prntln(SETTINGS_PATH); + + // check and fix mac + if (!macValid(data.wifi.mac_st)) getRandomMac(data.wifi.mac_st); + if (!macValid(data.wifi.mac_ap)) getRandomMac(data.wifi.mac_ap); + + changed = true; } -} -void Settings::print() { - String settingsJson = getJsonStr(); + void reset() { + data.version.major = DEAUTHER_VERSION_MAJOR; + data.version.minor = DEAUTHER_VERSION_MINOR; + data.version.revision = DEAUTHER_VERSION_REVISION; + + data.attack.attack_all_ch = ATTACK_ALL_CH; + data.attack.random_tx = RANDOM_TX; + data.attack.timeout = ATTACK_TIMEOUT; + data.attack.deauths_per_target = DEAUTHS_PER_TARGET; + data.attack.deauth_reason = DEAUTH_REASON; + data.attack.beacon_interval = beacon_interval_t::INTERVAL_100MS; + data.attack.probe_frames_per_ssid = PROBE_FRAMES_PER_SSID; + + data.wifi.channel = 1; + getRandomMac(data.wifi.mac_st); + getRandomMac(data.wifi.mac_ap); - settingsJson.replace("\":", " = "); - settingsJson.replace("= 0\r\n", "= false\r\n"); - settingsJson.replace("= 1\r\n", "= true\r\n"); - settingsJson.replace("\"", ""); - settingsJson.replace("{", ""); - settingsJson.replace("}", ""); - settingsJson.replace(",", "\r\n"); + data.sniffer.channel_time = CH_TIME; + data.sniffer.min_deauth_frames = MIN_DEAUTH_FRAMES; - prntln(S_SETTINGS_HEADER); - prntln(settingsJson); -} + strncpy(data.ap.ssid, AP_SSID, 32); + strncpy(data.ap.password, AP_PASSWD, 64); + data.ap.hidden = AP_HIDDEN; + uint8_t ip[4] = AP_IP_ADDR; + memcpy(data.ap.ip, ip, 4); -// ===== GETTERS ===== // + data.web.enabled = WEB_ENABLED; + data.web.captive_portal = WEB_CAPTIVE_PORTAL; + data.web.use_spiffs = WEB_USE_SPIFFS; + memcpy(data.web.lang, DEFAULT_LANG, 3); -const settings_t& Settings::getAllSettings() { - return data; -} + data.cli.enabled = true; + data.cli.serial_echo = CLI_ECHO; -const version_t& Settings::getVersion() { - return data.version; -} + data.led.enabled = USE_LED; -const autosave_settings_t& Settings::getAutosaveSettings() { - return data.autosave; -} + data.display.enabled = USE_DISPLAY; + data.display.timeout = DISPLAY_TIMEOUT; + + debuglnF("Settings reset"); + } -const attack_settings_t& Settings::getAttackSettings() { - return data.attack; -} + void save(bool force) { + if (force || changed) { + EEPROMHelper::saveObject(SETTINGS_HASH_ADDR, calc_hash(data)); + EEPROMHelper::saveObject(SETTINGS_ADDR, data); -const wifi_settings_t& Settings::getWifiSettings() { - return data.wifi; -} + changed = false; + + String json_buffer; + get_json(json_buffer); -const sniffer_settings_t& Settings::getSnifferSettings() { - return data.sniffer; -} + if (writeFile(SETTINGS_PATH, json_buffer)) { + debugF("Settings saved in "); + } else { + debugF("ERROR: saving "); + } -const access_point_settings_t& Settings::getAccessPointSettings() { - return data.ap; -} + debugln(SETTINGS_PATH); + } + } + + void print() { + String json_buffer; + get_json(json_buffer); -const web_settings_t& Settings::getWebSettings() { - return data.web; -} + json_buffer.replace("\":", " = "); + json_buffer.replace("= 0\r\n", "= false\r\n"); + json_buffer.replace("= 1\r\n", "= true\r\n"); + json_buffer.replace("\"", ""); + json_buffer.replace("{", ""); + json_buffer.replace("}", ""); + json_buffer.replace(",", "\r\n"); -const cli_settings_t& Settings::getCLISettings() { - return data.cli; -} + debuglnF("[========== Settings ==========]"); + debugln(json_buffer); + } -const led_settings_t& Settings::getLEDSettings() { - return data.led; -} + // ===== GETTERS ===== // -const display_settings_t& Settings::getDisplaySettings() { - return data.display; -} + const settings_t& getAllSettings() { + return data; + } -// ===== SETTERS ===== // + const version_t& getVersion() { + return data.version; + } -void Settings::setAllSettings(settings_t& newSettings) { - newSettings.version = this->data.version; - data = newSettings; - changed = true; -} + const autosave_settings_t& getAutosaveSettings() { + return data.autosave; + } -void Settings::setAutosaveSettings(const autosave_settings_t& autosave) { - data.autosave = autosave; - changed = true; -} + const attack_settings_t& getAttackSettings() { + return data.attack; + } -void Settings::setAttackSettings(const attack_settings_t& attack) { - data.attack = attack; - changed = true; -} + const wifi_settings_t& getWifiSettings() { + return data.wifi; + } -void Settings::setWifiSettings(const wifi_settings_t& wifi) { - data.wifi = wifi; - changed = true; -} + const sniffer_settings_t& getSnifferSettings() { + return data.sniffer; + } -void Settings::setSnifferSettings(const sniffer_settings_t& sniffer) { - data.sniffer = sniffer; - changed = true; -} + const access_point_settings_t& getAccessPointSettings() { + return data.ap; + } -void Settings::setAccessPointSettings(const access_point_settings_t& ap) { - data.ap = ap; - changed = true; -} + const web_settings_t& getWebSettings() { + return data.web; + } -void Settings::setWebSettings(const web_settings_t& web) { - data.web = web; - changed = true; -} + const cli_settings_t& getCLISettings() { + return data.cli; + } -void Settings::setCLISettings(const cli_settings_t& cli) { - data.cli = cli; - changed = true; -} + const led_settings_t& getLEDSettings() { + return data.led; + } -void Settings::setLEDSettings(const led_settings_t& led) { - data.led = led; - changed = true; -} + const display_settings_t& getDisplaySettings() { + return data.display; + } + + // ===== SETTERS ===== // -void Settings::setDisplaySettings(const display_settings_t& display) { - data.display = display; - changed = true; + void setAllSettings(settings_t& newSettings) { + newSettings.version = data.version; + data = newSettings; + changed = true; + } + + void setAutosaveSettings(const autosave_settings_t& autosave) { + data.autosave = autosave; + changed = true; + } + + void setAttackSettings(const attack_settings_t& attack) { + data.attack = attack; + changed = true; + } + + void setWifiSettings(const wifi_settings_t& wifi) { + data.wifi = wifi; + changed = true; + } + + void setSnifferSettings(const sniffer_settings_t& sniffer) { + data.sniffer = sniffer; + changed = true; + } + + void setAccessPointSettings(const access_point_settings_t& ap) { + data.ap = ap; + changed = true; + } + + void setWebSettings(const web_settings_t& web) { + data.web = web; + changed = true; + } + + void setCLISettings(const cli_settings_t& cli) { + data.cli = cli; + changed = true; + } + + void setLEDSettings(const led_settings_t& led) { + data.led = led; + changed = true; + } + + void setDisplaySettings(const display_settings_t& display) { + data.display = display; + changed = true; + } } \ No newline at end of file diff --git a/esp8266_deauther/Settings.h b/esp8266_deauther/Settings.h index 4cbf995..67b859d 100644 --- a/esp8266_deauther/Settings.h +++ b/esp8266_deauther/Settings.h @@ -1,166 +1,94 @@ -#ifndef Settings_h -#define Settings_h +/* + Copyright (c) 2020 Stefan Kremser (@Spacehuhn) + This software is licensed under the MIT License. See the license file for details. + Source: github.com/spacehuhn/esp8266_deauther + */ + +#pragma once -// ====== Includes ====== // -// Libraries #include // Arduino String, Serial -#include // SPIFFS - -// Local files -#include "A_config.h" // Default Settings -#include "language.h" // prnt and prntln - -// ====== Constants ====== // -#define SETTINGS_PATH "/settings.json" - -// ====== External Functions ===== // -extern bool writeFile(String path, String& buf); -extern void getRandomMac(uint8_t* mac); -extern bool macValid(uint8_t* mac); - -// ====== Strings ===== // -const char S_OK[] PROGMEM = "OK"; -const char S_INVALID_HASH[] PROGMEM = "Invalid Hash - reseted to default"; -const char S_SETTINGS_LOADED[] PROGMEM = "Loading settings..."; -const char S_SETTINGS_RESETED[] PROGMEM = "Settings reseted"; -const char S_SETTINGS_SAVED[] PROGMEM = "Settings saved in "; -const char S_ERROR_SAVING[] PROGMEM = "ERROR: saving "; -const char S_SETTINGS_HEADER[] PROGMEM = "[========== Settings ==========]"; -const char S_CHANGED_SETTING[] PROGMEM = "Changed setting "; - -// ===== JSON Strings ====== // -// General -const char S_JSON_TRUE[] PROGMEM = "true"; -const char S_JSON_FALSE[] PROGMEM = "false"; - -// Version -const char S_JSON_VERSION[] PROGMEM = "version"; - -// Autosave -const char S_JSON_AUTOSAVE[] PROGMEM = "autosave"; -const char S_JSON_AUTOSAVETIME[] PROGMEM = "autosavetime"; - -// Attack -const char S_JSON_BEACONCHANNEL[] PROGMEM = "beaconchannel"; -const char S_JSON_RANDOMTX[] PROGMEM = "randomTX"; -const char S_JSON_ATTACKTIMEOUT[] PROGMEM = "attacktimeout"; -const char S_JSON_DEAUTHSPERTARGET[] PROGMEM = "deauthspertarget"; -const char S_JSON_DEAUTHREASON[] PROGMEM = "deauthReason"; -const char S_JSON_BEACONINTERVAL[] PROGMEM = "beaconInterval"; -const char S_JSON_PROBESPERSSID[] PROGMEM = "probesPerSSID"; - -// WiFi -const char S_JSON_CHANNEL[] PROGMEM = "channel"; -const char S_JSON_MACST[] PROGMEM = "macSt"; -const char S_JSON_MACAP[] PROGMEM = "macAP"; - -// Sniffer -const char S_JSON_CHTIME[] PROGMEM = "chtime"; -const char S_JSON_MIN_DEAUTHS[] PROGMEM = "minDeauths"; - -// AP -const char S_JSON_SSID[] PROGMEM = "ssid"; -const char S_JSON_PASSWORD[] PROGMEM = "password"; -const char S_JSON_HIDDEN[] PROGMEM = "hidden"; -const char S_JSON_IP[] PROGMEM = "ip"; - -// Web -const char S_JSON_WEBINTERFACE[] PROGMEM = "webinterface"; -const char S_JSON_CAPTIVEPORTAL[] PROGMEM = "captivePortal"; -const char S_JSON_WEB_SPIFFS[] PROGMEM = "webSpiffs"; -const char S_JSON_LANG[] PROGMEM = "lang"; - -// CLI -const char S_JSON_SERIALINTERFACE[] PROGMEM = "serial"; -const char S_JSON_SERIAL_ECHO[] PROGMEM = "serialEcho"; - -// LED -const char S_JSON_LEDENABLED[] PROGMEM = "led"; - -// Display -const char S_JSON_DISPLAYINTERFACE[] PROGMEM = "display"; -const char S_JSON_DISPLAY_TIMEOUT[] PROGMEM = "displayTimeout"; +#include "A_config.h" // ===== VERSION ===== // typedef struct version_t { - uint8_t major = DEAUTHER_VERSION_MAJOR; - uint8_t minor = DEAUTHER_VERSION_MINOR; - uint8_t revision = DEAUTHER_VERSION_REVISION; + uint8_t major; + uint8_t minor; + uint8_t revision; } version_t; // ===== AUTOSAVE ===== // typedef struct autosave_settings_t { - bool enabled = AUTOSAVE_ENABLED; - uint32_t time = AUTOSAVE_TIME; + bool enabled; + uint32_t time; } autosave_t; // ===== ATTACK ===== // typedef enum beacon_interval_t { - INTERVAL_1S = 0, + INTERVAL_1S = 0, INTERVAL_100MS = 1 } beacon_interval_t; typedef struct attack_settings_t { // General - bool attack_all_ch = ATTACK_ALL_CH; - bool random_tx = RANDOM_TX; - uint32_t timeout = ATTACK_TIMEOUT; + bool attack_all_ch; + bool random_tx; + uint32_t timeout; // Deauth - uint8_t deauths_per_target = DEAUTHS_PER_TARGET; - uint8_t deauth_reason = DEAUTH_REASON; + uint8_t deauths_per_target; + uint8_t deauth_reason; // Beacon - beacon_interval_t beacon_interval = (beacon_interval_t)(int)BEACON_INTERVAL_100MS; + beacon_interval_t beacon_interval; // Probe - uint8_t probe_frames_per_ssid = PROBE_FRAMES_PER_SSID; + uint8_t probe_frames_per_ssid; } attack_settings_t; // ====== WIFI ====== // typedef struct wifi_settings_t { - uint8_t channel = 1; + uint8_t channel; uint8_t mac_st[6]; uint8_t mac_ap[6]; } wifi_settings_t; // ===== SNIFFER ===== // typedef struct sniffer_settings_t { - uint16_t channel_time = CH_TIME; - uint16_t min_deauth_frames = MIN_DEAUTH_FRAMES; + uint16_t channel_time; + uint16_t min_deauth_frames; } sniffer_settings_t; // ===== ACCESS POINT ===== // typedef struct access_point_settings_t { - char ssid[33] = AP_SSID; - char password[65] = AP_PASSWD; - bool hidden = AP_HIDDEN; - uint8_t ip[4] = AP_IP_ADDR; + char ssid[33]; + char password[65]; + bool hidden; + uint8_t ip[4]; } access_point_settings_t; // ===== WEB INTERFACE ===== // typedef struct web_settings_t { - bool enabled = WEB_ENABLED; - bool captive_portal = WEB_CAPTIVE_PORTAL; - bool use_spiffs = WEB_USE_SPIFFS; - char lang[3] = DEFAULT_LANG; + bool enabled; + bool captive_portal; + bool use_spiffs; + char lang[3]; } web_settings_t; // ===== CLI ===== // typedef struct cli_settings_t { - bool enabled = CLI_ENABLED; - bool serial_echo = CLI_ECHO; + bool enabled; + bool serial_echo; } cli_settings_t; // ===== LED ===== // typedef struct led_settings_t { - bool enabled = USE_LED; + bool enabled; } led_settings_t; // ===== DISPLAY ===== // typedef struct display_settings_t { - bool enabled = USE_DISPLAY; - uint32_t timeout = DISPLAY_TIMEOUT; + bool enabled; + uint32_t timeout; } display_settings_t; // ===== SETTINGS ===== // @@ -182,46 +110,33 @@ typedef struct settings_hash_t { uint8_t hash[20]; } settings_hash_t; -// ===== SETTINGS ===== // -class Settings { - private: - settings_t data; +namespace settings { + void load(); + void save(bool force = false); - bool changed = false; + void reset(); + void print(); - settings_hash_t calcHash(settings_t data); + const settings_t& getAllSettings(); + const version_t & getVersion(); + const autosave_settings_t& getAutosaveSettings(); + const attack_settings_t & getAttackSettings(); + const wifi_settings_t & getWifiSettings(); + const sniffer_settings_t & getSnifferSettings(); + const access_point_settings_t& getAccessPointSettings(); + const web_settings_t& getWebSettings(); + const cli_settings_t& getCLISettings(); + const led_settings_t& getLEDSettings(); + const display_settings_t& getDisplaySettings(); - String getJsonStr(); - - public: - void load(); - void save(bool force = false); - - void reset(); - void print(); - - const settings_t& getAllSettings(); - const version_t & getVersion(); - const autosave_settings_t& getAutosaveSettings(); - const attack_settings_t & getAttackSettings(); - const wifi_settings_t & getWifiSettings(); - const sniffer_settings_t & getSnifferSettings(); - const access_point_settings_t& getAccessPointSettings(); - const web_settings_t& getWebSettings(); - const cli_settings_t& getCLISettings(); - const led_settings_t& getLEDSettings(); - const display_settings_t& getDisplaySettings(); - - void setAllSettings(settings_t& settings); - void setAutosaveSettings(const autosave_settings_t& autosave); - void setAttackSettings(const attack_settings_t& attack); - void setWifiSettings(const wifi_settings_t& wifi); - void setSnifferSettings(const sniffer_settings_t& sniffer); - void setAccessPointSettings(const access_point_settings_t& ap); - void setWebSettings(const web_settings_t& web); - void setCLISettings(const cli_settings_t& cli); - void setLEDSettings(const led_settings_t& led); - void setDisplaySettings(const display_settings_t& display); -}; - -#endif // ifndef Settings_h \ No newline at end of file + void setAllSettings(settings_t& settings); + void setAutosaveSettings(const autosave_settings_t& autosave); + void setAttackSettings(const attack_settings_t& attack); + void setWifiSettings(const wifi_settings_t& wifi); + void setSnifferSettings(const sniffer_settings_t& sniffer); + void setAccessPointSettings(const access_point_settings_t& ap); + void setWebSettings(const web_settings_t& web); + void setCLISettings(const cli_settings_t& cli); + void setLEDSettings(const led_settings_t& led); + void setDisplaySettings(const display_settings_t& display); +} \ No newline at end of file diff --git a/esp8266_deauther/esp8266_deauther.ino b/esp8266_deauther/esp8266_deauther.ino index 8811aa2..c87f4f6 100644 --- a/esp8266_deauther/esp8266_deauther.ino +++ b/esp8266_deauther/esp8266_deauther.ino @@ -25,7 +25,7 @@ extern "C" { #include "oui.h" #include "language.h" #include "functions.h" -#include "Settings.h" +#include "settings.h" #include "Names.h" #include "SSIDs.h" #include "Scan.h" @@ -39,7 +39,6 @@ extern "C" { // Run-Time Variables // LED led; -Settings settings; Names names; SSIDs ssids; Accesspoints accesspoints; @@ -102,15 +101,15 @@ void setup() { // load settings #ifndef RESET_SETTINGS - settings.load(); + settings::load(); #else // ifndef RESET_SETTINGS - settings.reset(); - settings.save(); + settings::reset(); + settings::save(); #endif // ifndef RESET_SETTINGS // set mac address - wifi_set_macaddr(STATION_IF, (uint8_t*)settings.getWifiSettings().mac_st); - wifi_set_macaddr(SOFTAP_IF, (uint8_t*)settings.getWifiSettings().mac_ap); + wifi_set_macaddr(STATION_IF, (uint8_t*)settings::getWifiSettings().mac_st); + wifi_set_macaddr(SOFTAP_IF, (uint8_t*)settings::getWifiSettings().mac_ap); // start WiFi WiFi.mode(WIFI_OFF); @@ -120,7 +119,7 @@ void setup() { }); // start display - if (settings.getDisplaySettings().enabled) { + if (settings::getDisplaySettings().enabled) { displayUI.setup(); displayUI.mode = displayUI.DISPLAY_MODE::INTRO; } @@ -137,13 +136,13 @@ void setup() { scan.setup(); // set channel - setWifiChannel(settings.getWifiSettings().channel); + setWifiChannel(settings::getWifiSettings().channel); // load Wifi settings: SSID, password,... loadWifiConfigDefaults(); // dis/enable serial command interface - if (settings.getCLISettings().enabled) { + if (settings::getCLISettings().enabled) { cli.enable(); } else { prntln(SETUP_SERIAL_WARNING); @@ -152,7 +151,7 @@ void setup() { } // start access point/web interface - if (settings.getWebSettings().enabled) startAP(); + if (settings::getWebSettings().enabled) startAP(); // STARTED prntln(SETUP_STARTED); @@ -176,12 +175,12 @@ void loop() { ssids.update(); // run random mode, if enabled // auto-save - if (settings.getAutosaveSettings().enabled - && (currentTime - autosaveTime > settings.getAutosaveSettings().time)) { + if (settings::getAutosaveSettings().enabled + && (currentTime - autosaveTime > settings::getAutosaveSettings().time)) { autosaveTime = currentTime; names.save(false); ssids.save(false); - settings.save(false); + settings::save(false); } if (!booted) { diff --git a/esp8266_deauther/language.h b/esp8266_deauther/language.h index b84fa8f..b7d89e9 100644 --- a/esp8266_deauther/language.h +++ b/esp8266_deauther/language.h @@ -542,4 +542,52 @@ const char W_BAD_PATH[] PROGMEM = "BAD PATH"; const char W_FILE_NOT_FOUND[] PROGMEM = "ERROR 404 File Not Found"; const char W_STARTED_AP[] PROGMEM = "Started AP"; +// ===== SETTINGS ====== // +// Version +const char S_JSON_VERSION[] PROGMEM = "version"; + +// Autosave +const char S_JSON_AUTOSAVE[] PROGMEM = "autosave"; +const char S_JSON_AUTOSAVETIME[] PROGMEM = "autosavetime"; + +// Attack +const char S_JSON_BEACONCHANNEL[] PROGMEM = "beaconchannel"; +const char S_JSON_RANDOMTX[] PROGMEM = "randomTX"; +const char S_JSON_ATTACKTIMEOUT[] PROGMEM = "attacktimeout"; +const char S_JSON_DEAUTHSPERTARGET[] PROGMEM = "deauthspertarget"; +const char S_JSON_DEAUTHREASON[] PROGMEM = "deauthReason"; +const char S_JSON_BEACONINTERVAL[] PROGMEM = "beaconInterval"; +const char S_JSON_PROBESPERSSID[] PROGMEM = "probesPerSSID"; + +// WiFi +const char S_JSON_CHANNEL[] PROGMEM = "channel"; +const char S_JSON_MACST[] PROGMEM = "macSt"; +const char S_JSON_MACAP[] PROGMEM = "macAP"; + +// Sniffer +const char S_JSON_CHTIME[] PROGMEM = "chtime"; +const char S_JSON_MIN_DEAUTHS[] PROGMEM = "minDeauths"; + +// AP +const char S_JSON_SSID[] PROGMEM = "ssid"; +const char S_JSON_PASSWORD[] PROGMEM = "password"; +const char S_JSON_HIDDEN[] PROGMEM = "hidden"; +const char S_JSON_IP[] PROGMEM = "ip"; + +// Web +const char S_JSON_WEBINTERFACE[] PROGMEM = "webinterface"; +const char S_JSON_CAPTIVEPORTAL[] PROGMEM = "captivePortal"; +const char S_JSON_WEB_SPIFFS[] PROGMEM = "webSpiffs"; +const char S_JSON_LANG[] PROGMEM = "lang"; + +// CLI +const char S_JSON_SERIALINTERFACE[] PROGMEM = "serial"; +const char S_JSON_SERIAL_ECHO[] PROGMEM = "serialEcho"; + +// LED +const char S_JSON_LEDENABLED[] PROGMEM = "led"; + +// Display +const char S_JSON_DISPLAYINTERFACE[] PROGMEM = "display"; +const char S_JSON_DISPLAY_TIMEOUT[] PROGMEM = "displayTimeout"; #endif // ifndef language_h \ No newline at end of file diff --git a/esp8266_deauther/wifi.h b/esp8266_deauther/wifi.h index 50fc393..258da7a 100644 --- a/esp8266_deauther/wifi.h +++ b/esp8266_deauther/wifi.h @@ -229,7 +229,7 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, // ================================================================ // post here the output of the webConverter.py #ifdef USE_PROGMEM_WEB_FILES - if (!settings.getWebSettings().use_spiffs) { + if (!settings::getWebSettings().use_spiffs) { server.on(String(SLASH).c_str(), HTTP_GET, [] () { sendProgmem(indexhtml, sizeof(indexhtml), W_HTML); }); @@ -301,21 +301,21 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, }); } server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [] () { - if (!settings.getWebSettings().use_spiffs) { - if (String(settings.getWebSettings().lang) == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("es"))) sendProgmem(eslang, sizeof(eslang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("fi"))) sendProgmem(filang, sizeof(filang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON); - else if (String(settings.getWebSettings().lang) == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON); + if (!settings::getWebSettings().use_spiffs) { + if (String(settings::getWebSettings().lang) == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("es"))) sendProgmem(eslang, sizeof(eslang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("fi"))) sendProgmem(filang, sizeof(filang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON); + else if (String(settings::getWebSettings().lang) == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON); - else handleFileRead(String(F("/web/lang/")) + String(settings.getWebSettings().lang) + String(F(".lang"))); + else handleFileRead(String(F("/web/lang/")) + String(settings::getWebSettings().lang) + String(F(".lang"))); } else { - handleFileRead(String(F("/web/lang/")) + String(settings.getWebSettings().lang) + String(F(".lang"))); + handleFileRead(String(F("/web/lang/")) + String(settings::getWebSettings().lang) + String(F(".lang"))); } }); #endif /* ifdef USE_PROGMEM_WEB_FILES */ @@ -393,10 +393,10 @@ void startAP(String path) { } void loadWifiConfigDefaults() { - wifi_config_hidden = settings.getAccessPointSettings().hidden; - wifi_config_ssid = settings.getAccessPointSettings().ssid; - wifi_config_password = settings.getAccessPointSettings().password; - wifi_config_captivePortal = settings.getWebSettings().captive_portal; + wifi_config_hidden = settings::getAccessPointSettings().hidden; + wifi_config_ssid = settings::getAccessPointSettings().ssid; + wifi_config_password = settings::getAccessPointSettings().password; + wifi_config_captivePortal = settings::getWebSettings().captive_portal; wifi_config_path = str(W_WEBINTERFACE); } diff --git a/utils/web_converter/webConverter.py b/utils/web_converter/webConverter.py index 71f362d..8d2a64d 100644 --- a/utils/web_converter/webConverter.py +++ b/utils/web_converter/webConverter.py @@ -182,9 +182,9 @@ for file in lang_files: copy_files_function += ' if(!SPIFFS.exists(String(F("/web/lang/' + base_file + '.gz"))) || force) progmemToSpiffs(' + array_name + ', sizeof(' + array_name + '), String(F("/web/lang/' + base_file + '.gz")));\n' webserver_events += 'server.on(String(F("/lang/' + base_file + '")).c_str(), HTTP_GET, [](){\n sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n});\n' if(len(load_lang) > 0): - load_lang += ' else if(settings.getLang() == String(F("'+lang_name+'"))) sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n' + load_lang += ' else if(settings::getLang() == String(F("'+lang_name+'"))) sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n' else: - load_lang += ' if(settings.getLang() == String(F("'+lang_name+'"))) sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n' + load_lang += ' if(settings::getLang() == String(F("'+lang_name+'"))) sendProgmem(' + array_name + ', sizeof(' + array_name + '), W_JSON);\n' base_file = os.path.basename(license_file_path) new_file = str(os.path.join(str(compressed), str("LICENSE"))) @@ -222,7 +222,7 @@ f.write("#endif\n") f.write("\n") f.write("void copyWebFiles(bool force){\n") f.write("#ifdef USE_PROGMEM_WEB_FILES\n") -f.write("if(settings.getWebSettings().use_spiffs){\n") +f.write("if(settings::getWebSettings().use_spiffs){\n") f.write(copy_files_function) f.write("}\n") f.write("#endif\n") @@ -234,17 +234,17 @@ f.close() print("\n[+] Done, happy uploading :)") print("Here are the updated functions for wifi.h, in case you added or removed files:") print(); -print('if(!settings.getWebSpiffs()){') +print('if(!settings::getWebSpiffs()){') print(' server.on(String(SLASH).c_str(), HTTP_GET, [](){') print(' sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);') print('});') print(webserver_events) print('}') print("server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){") -print(" if(!settings.getWebSpiffs()){") +print(" if(!settings::getWebSpiffs()){") print(load_lang) -print(' else handleFileRead(String(F("/web/lang/"))+settings.getLang()+String(F(".lang")));') +print(' else handleFileRead(String(F("/web/lang/"))+settings::getLang()+String(F(".lang")));') print(' } else {') -print(' handleFileRead(String(F("/web/lang/"))+settings.getLang()+String(F(".lang")));') +print(' handleFileRead(String(F("/web/lang/"))+settings::getLang()+String(F(".lang")));') print(' }') print("});");