Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TagTinker
Submodule TagTinker added at 12b0c0
Binary file added sd_files/portals/media/gorilla.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added sd_files/portals/media/rickroll.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 64 additions & 16 deletions src/modules/wifi/evil_portal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ EvilPortal::EvilPortal(
)
: apName(tssid), _channel(channel), _deauth(deauth), _verifyPwd(verifyPwd), _autoMode(autoMode),
_backgroundMode(backgroundMode), webServer(80), _launchTime(millis()) {

_originalWifiMode = WiFi.getMode();
_wifiWasConnected = (WiFi.status() == WL_CONNECTED);

if (!setup()) return;
cleanlyStopWebUiForWiFiFeature();
beginAP();
Expand Down Expand Up @@ -67,7 +67,8 @@ bool EvilPortal::setup() {
}

options = {
{"Custom Html", [this]() { loadCustomHtml(); }}
{"Custom Html", [this]() { loadCustomHtml(); }},
{"Meme Portal", [this]() { loadMemeHtml(); }}
};
addOptionToMainMenu();

Expand Down Expand Up @@ -200,6 +201,18 @@ void EvilPortal::setupRoutes() {
request->send(response);
});

webServer.on("/media", HTTP_GET, [this](AsyncWebServerRequest *request) {
if (fsMedia == nullptr || _memeFilePath == "") {
request->send(404, "text/plain", "Not found");
return;
}
String contentType = "image/jpeg";
if (_memeFilePath.endsWith(".gif")) contentType = "image/gif";
else if (_memeFilePath.endsWith(".png")) contentType = "image/png";
else if (_memeFilePath.endsWith(".mp4")) contentType = "video/mp4";
request->send(*fsMedia, _memeFilePath, contentType);
});

webServer.on("/", [this](AsyncWebServerRequest *request) { portalController(request); });
webServer.on("/post", [this](AsyncWebServerRequest *request) { credsController(request); });

Expand Down Expand Up @@ -246,17 +259,17 @@ void EvilPortal::restartWiFi(bool reset) {
webServer.end();
dnsServer.stop();
vTaskDelay(100 / portTICK_PERIOD_MS);

_captiveHandler = nullptr;

wifiDisconnect();
WiFi.softAP(apName, emptyString, _channel);
vTaskDelay(100 / portTICK_PERIOD_MS);

setupRoutes();
dnsServer.start(53, "*", WiFi.softAPIP());
webServer.begin();

if (reset) resetCapturedCredentials();
}

Expand Down Expand Up @@ -309,24 +322,24 @@ void EvilPortal::loop() {
}},
{"Resume", [&shouldRedraw]() { shouldRedraw = true; }}
};

loopOptions(options);
if (exitPortal) {
displayTextLine("Shutting down...");
vTaskDelay(100 / portTICK_PERIOD_MS);

webServer.end();
vTaskDelay(200 / portTICK_PERIOD_MS);

dnsServer.stop();
vTaskDelay(100 / portTICK_PERIOD_MS);

WiFi.mode(_originalWifiMode);
vTaskDelay(100 / portTICK_PERIOD_MS);

wifiDisconnect();
vTaskDelay(100 / portTICK_PERIOD_MS);

return;
}
shouldRedraw = true;
Expand Down Expand Up @@ -380,7 +393,7 @@ void EvilPortal::recordPageView() {
bool EvilPortal::shouldTerminate() {
unsigned long currentTime = millis();
unsigned long elapsed = currentTime - _launchTime;

if (_durationExtended) {
return elapsed > (_extendedDurationSec * 1000);
} else {
Expand All @@ -390,7 +403,7 @@ bool EvilPortal::shouldTerminate() {

void EvilPortal::checkAndExtendDuration() {
if (_durationExtended) return;

if (hasRecentActivity()) {
_durationExtended = true;
Serial.println("[PORTAL] Activity detected, extending duration");
Expand Down Expand Up @@ -488,6 +501,41 @@ void EvilPortal::loadCustomHtml() {
}
}

void EvilPortal::loadMemeHtml() {
fsMedia = nullptr;

options = {};
if (sdcardMounted)
options.push_back({"SD Card", [this]() { fsMedia = &SD; }});
if (checkLittleFsSizeNM())
options.push_back({"LittleFS", [this]() { fsMedia = &LittleFS; }});

if (options.empty()) { loadDefaultHtml(); return; }
loopOptions(options);
if (returnToMenu || fsMedia == nullptr) return;

String startPath = fsMedia->exists("/portals/media") ? "/portals/media" : "/";

apName = "";
apName_from_keyboard();
if (returnToMenu) return;

String pickedFile = loopSD(*fsMedia, true, "JPG|JPEG|PNG|GIF|MP4", startPath);
if (pickedFile == "" || returnToMenu) return;

_memeFilePath = pickedFile;
String tag;
if (pickedFile.endsWith(".mp4"))
tag = "<video autoplay loop src='/media'></video>";
else
tag = "<img src='/media'>";

htmlPage = "<html><head><meta charset='UTF-8'><meta name='viewport' content='width=device-width,initial-scale=1'><style>body{margin:0;background:#000;display:flex;justify-content:center;align-items:center;height:100vh;}img,video{max-width:100%;max-height:100vh;}</style></head><body>" + tag + "</body></html>";
outputFile = "meme_creds.csv";
isDefaultHtml = true;
}


String EvilPortal::wifiLoadPage() {
return String(
"<!DOCTYPE html><html><head> <meta charset='UTF-8'> <meta name='viewport' "
Expand Down Expand Up @@ -814,4 +862,4 @@ bool EvilPortal::verifyCreds(String &Ssid, String &Password) {
WiFi.disconnect(false);
_deauth = temp;
return isConnected;
}
}
9 changes: 6 additions & 3 deletions src/modules/wifi/evil_portal.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ class EvilPortal {
bool _verifyPwd;
bool _autoMode;
bool _backgroundMode;

wifi_mode_t _originalWifiMode;
bool _wifiWasConnected;

AsyncWebServer webServer;

DNSServer dnsServer;
Expand All @@ -72,6 +72,8 @@ class EvilPortal {
String htmlFileName;
bool isDefaultHtml = true;
FS *fsHtmlFile;
FS *fsMedia;
String _memeFilePath;

String lastCred;
int totalCapturedCredentials = 0;
Expand All @@ -97,6 +99,7 @@ class EvilPortal {
void printDeauthStatus(void);
void printLastCapturedCredential(void);
void loadCustomHtml(void);
void loadMemeHtml(void);
void loadDefaultHtml(void);
void loadDefaultHtml_one(void);
String wifiLoadPage(void);
Expand All @@ -111,4 +114,4 @@ class EvilPortal {
void apName_from_keyboard(void);
};

#endif
#endif