From 2e17c8c1981d38d5a60e66e4d0f25f382ea9e549 Mon Sep 17 00:00:00 2001 From: Pirata Date: Thu, 30 May 2024 21:56:06 -0300 Subject: [PATCH 1/2] SSH, LittleFS, mykeyboard # SSH Fixed SSH, working now # LittleFS migrated from SPIFFS to LittleFS to enhance performance and allow compatibility with OrcaOneFS # mykeyboard Enhanced keyboard to avoid flickering.. --- html/WebUI.html | 43 ++++-- src/TV-B-Gone.cpp | 4 +- src/bad_usb.cpp | 4 +- src/clients.cpp | 354 ++++++++++++++++++++++--------------------- src/clients.h | 4 +- src/display.cpp | 2 +- src/evil_portal.cpp | 6 +- src/globals.h | 7 +- src/main.cpp | 9 +- src/mykeyboard.cpp | 129 ++++++++++++---- src/scan_hosts.cpp | 14 +- src/scan_hosts.h | 4 +- src/sd_functions.cpp | 18 ++- src/sd_functions.h | 2 +- src/settings.cpp | 2 +- src/webInterface.cpp | 28 ++-- src/webInterface.h | 32 ++-- src/wg.h | 2 +- 18 files changed, 388 insertions(+), 276 deletions(-) diff --git a/html/WebUI.html b/html/WebUI.html index 0443e0b3..7b4f7acd 100644 --- a/html/WebUI.html +++ b/html/WebUI.html @@ -250,12 +250,17 @@

BRUCE Firmware

Firmware for offensive pranks and pentest studies and analysis. For educational purposes only. Don't use in environments where you are not allowed. All responsibilities for irresponsible usage of this firmware rest on your fin, sharky. Sincerely, Bruce.

Firmware version: %FIRMWARE%

-

Free Storage: %FREESD% | Used: %USEDSD% | Total: %TOTALSD%

+

SD Free Storage: %FREESD% | Used: %USEDSD% | Total: %TOTALSD%

+

LittleFS Free Storage: %FREELittleFS% | Used: %USEDLittleFS% | Total: %TOTALLittleFS%

-

+
+ + +
- + +

@@ -295,10 +300,11 @@

BRUCE Firmware

} } -function listFilesButton(folders) { +function listFilesButton(folders, fs = 'SD') { xmlhttp=new XMLHttpRequest(); document.getElementById("actualFolder").value = ""; document.getElementById("actualFolder").value = folders; + document.getElementById("actualFS").value = fs; xmlhttp.onload = function() { if (xmlhttp.status === 200) { @@ -311,7 +317,7 @@

BRUCE Firmware

console.error('Erro na rede ou falha na requisição.'); }; - xmlhttp.open("GET", "/listfiles?folder=" + folders, true); + xmlhttp.open("GET", "/listfiles?fs=" + fs + "&folder=" + folders, true); xmlhttp.send(); document.getElementById("detailsheader").innerHTML = "

Files

"; @@ -321,24 +327,28 @@

BRUCE Firmware

function renameFile(filePath, oldName) { var actualFolder = document.getElementById("actualFolder").value; + var fs = document.getElementById("actualFS").value; let fileName = prompt("Enter the new name: ", oldName); if (fileName == null || fileName == "") { window.alert("Invalid Name"); } else { const ajax5 = new XMLHttpRequest(); const formdata5 = new FormData(); + formdata5.append("fs", fs); formdata5.append("filePath", filePath); formdata5.append("fileName", fileName); ajax5.open("POST", "/rename", false); ajax5.send(formdata5); document.getElementById("status").innerHTML = ajax5.responseText; - listFilesButton(actualFolder); + var fs = document.getElementById("actualFS").value; + listFilesButton(actualFolder, fs); } } function downloadDeleteButton(filename, action) { - var urltocall = "/file?name=" + filename + "&action=" + action; + var fs = document.getElementById("actualFS").value; + var urltocall = "/file?name=" + filename + "&action=" + action + "&fs=" + fs; var actualFolder = document.getElementById("actualFolder").value; var option; if (action == "delete") { @@ -350,7 +360,8 @@

BRUCE Firmware

xmlhttp.open("GET", urltocall, false); xmlhttp.send(); document.getElementById("status").innerHTML = xmlhttp.responseText; - listFilesButton(actualFolder); + var fs = document.getElementById("actualFS").value; + listFilesButton(actualFolder, fs); } if (action == "download") { document.getElementById("status").innerHTML = ""; @@ -359,9 +370,11 @@

BRUCE Firmware

} function showCreateFolder(folders) { + var fs = document.getElementById("actualFS").value; + var uploadform = ""; //document.getElementById("updetailsheader").innerHTML = "

Create new Folder

" document.getElementById("status").innerHTML = ""; - var uploadform = + uploadform = "

Creating folder at: " + folders + ""+ "

" + "" + @@ -384,7 +397,7 @@

BRUCE Firmware

"

Send file to " + folders + "

"+ "" + "" + - "
" + + "
" + "" + "

" + "

" + @@ -395,6 +408,7 @@

BRUCE Firmware

return document.getElementById(el); } function uploadFile(folder) { + var fs = document.getElementById("actualFS").value; var file = _("file1").files[0]; var folder = _("folder").value; // alert(file.name+" | "+file.size+" | "+file.type); @@ -406,7 +420,7 @@

BRUCE Firmware

ajax.addEventListener("load", completeHandler, false); // doesnt appear to ever get called even upon success ajax.addEventListener("error", errorHandler, false); ajax.addEventListener("abort", abortHandler, false); - ajax.open("POST", "/upload"); + ajax.open("POST", "/upload" + fs); ajax.send(formdata); } function progressHandler(event) { @@ -423,7 +437,8 @@

BRUCE Firmware

_("progressBar").value = 0; var actualFolder = document.getElementById("actualFolder").value document.getElementById("status").innerHTML = "File Uploaded"; - listFilesButton(actualFolder); + var fs = document.getElementById("actualFS").value; + listFilesButton(actualFolder, fs); } function errorHandler(event) { _("status").innerHTML = "Upload Failed"; @@ -433,7 +448,9 @@

BRUCE Firmware

} window.addEventListener("load", function() { - listFilesButton("/"); + var actualFolder = document.getElementById("actualFolder").value + var fs = document.getElementById("actualFS").value; + listFilesButton(actualFolder, fs); }); diff --git a/src/TV-B-Gone.cpp b/src/TV-B-Gone.cpp index d79e04b7..9691e530 100644 --- a/src/TV-B-Gone.cpp +++ b/src/TV-B-Gone.cpp @@ -196,11 +196,11 @@ void otherIRcodes() { bool teste=false; options = { {"SD Card", [&]() { fs=&SD; }}, - {"Spiffs", [&]() { fs=&SPIFFS; }}, + {"LittleFS", [&]() { fs=&LittleFS; }}, }; delay(200); loopOptions(options); - } else fs=&SPIFFS; + } else fs=&LittleFS; filepath = loopSD(*fs, true); diff --git a/src/bad_usb.cpp b/src/bad_usb.cpp index 9025a10c..0ee19948 100644 --- a/src/bad_usb.cpp +++ b/src/bad_usb.cpp @@ -229,11 +229,11 @@ void usb_setup() { bool teste=false; options = { {"SD Card", [&]() { fs=&SD; }}, - {"Spiffs", [&]() { fs=&SPIFFS; }}, + {"LittleFS", [&]() { fs=&LittleFS; }}, }; delay(200); loopOptions(options); - } else fs=&SPIFFS; + } else fs=&LittleFS; bad_script = loopSD(*fs,true); tft.fillScreen(BGCOLOR); diff --git a/src/clients.cpp b/src/clients.cpp index 8404f327..655fc83b 100644 --- a/src/clients.cpp +++ b/src/clients.cpp @@ -26,14 +26,13 @@ String ssh_host = ""; String ssh_user = ""; String ssh_port = ""; String ssh_password = ""; - char* ssh_port_char; // M5Cardputer setup //M5Canvas canvas(&DISP); -// String commandBuffer = "> "; + String commandBuffer = "> "; int cursorY = 0; -const int lineHeight = 32; +const int lineHeight = 32; //32 unsigned long lastKeyPressMillis = 0; const unsigned long debounceDelay = 200; // Adjust debounce delay as needed @@ -57,194 +56,77 @@ char* stringTochar(String s) bool filterAnsiSequences = true; // Set to false to disable ANSI sequence filtering +void ssh_setup(String host) { + if(!wifiConnected) wifiConnectMenu(false); -void ssh_loop() { - String message = ""; - //for(;;){ - #ifdef CARDPUTER - if (Keyboard.isChange() && Keyboard.isPressed()) { - unsigned long currentMillis = millis(); - if (currentMillis - lastKeyPressMillis >= debounceDelay) { - lastKeyPressMillis = currentMillis; - Keyboard_Class::KeysState status = Keyboard.keysState(); - - for (auto i : status.word) { - //commandBuffer += i; - tft.print(i); - cursorY = tft.getCursorY(); - } - - if (status.del > 2) { - //commandBuffer.remove(commandBuffer.length() - 1); - tft.setCursor( - tft.getCursorX() - 6, - tft.getCursorY()); - tft.print(" "); - tft.setCursor( - tft.getCursorX() - 6, - tft.getCursorY()); - cursorY = tft.getCursorY(); - } - - if (status.enter) { - //commandBuffer.trim(); // Trim the command buffer to remove - // accidental TFT_WHITEspaces/newlines - //String message = commandBuffer.substring(2); // Get the command part, exclude the "> " - message = keyboard(message,76,"SSH Command: "); - ssh_channel_write(channel_ssh, message.c_str(), - message.length()); // Send the command - ssh_channel_write(channel_ssh, "\r", - 1); // Send exactly one carriage return (try - // "\n" or "\r\n" if needed) - - //commandBuffer = "> "; // Reset command buffer - tft.print( - '\n'); // Move to the next line on display - cursorY = - tft.getCursorY(); // Update cursor position - } - } - } - - #else - if(checkSelPress()) { - - while(checkSelPress()) { yield(); } // timerless debounce - //commandBuffer = keyboard(commandBuffer,76,"SSH Command: "); - message = keyboard(message,76,"SSH Command: "); - while(checkSelPress()) { yield(); } // timerless debounce - //commandBuffer.trim(); // Trim the command buffer to remove - // accidental TFT_WHITEspaces/newlines - - //if(commandBuffer.startsWith("> ")) message = commandBuffer.substring(2); // Get the command part, exclude the "> " - //else message = commandBuffer; - ssh_channel_write(channel_ssh, message.c_str(), - message.length()); // Send the command - ssh_channel_write(channel_ssh, "\r", - 1); // Send exactly one carriage return (try - // "\n" or "\r\n" if needed) - - //commandBuffer = "> "; // Reset command buffer - tft.print('\n'); // Move to the next line on display - cursorY =tft.getCursorY(); // Update cursor position - } - - #endif + tft.fillScreen(BGCOLOR); + tft.setCursor(0, 0); + if(host != "") ssh_host = host; + else { + //ssh_host=keyboard("",15,"SSH HOST (IP)"); + ssh_host=keyboard("192.168.3.60",15,"SSH HOST (IP)"); + } + ssh_port=keyboard("22",5,"SSH PORT"); - // Check if the cursor has reached the bottom of the display - if (cursorY > tft.height() - lineHeight) { - tft.setCursor(0, -lineHeight); - cursorY -= lineHeight; - tft.setCursor(tft.getCursorX(), - cursorY); - } + //ssh_user=keyboard("",76,"SSH USER"); + ssh_user=keyboard("ubuntu",76,"SSH USER"); + + //ssh_password=keyboard("",76,"SSH PASSWORD"); + ssh_password=keyboard("ubuntu",76,"SSH PASSWORD"); + + // Connect to SSH server + TaskHandle_t sshTaskHandle = NULL; + xTaskCreatePinnedToCore(ssh_loop, "SSH Task", 20000, NULL, 1, &sshTaskHandle, 1); + if (sshTaskHandle == NULL) { + Serial.println("Failed to create SSH Task"); + } - // Read data from SSH server and display it, handling ANSI sequences - char buffer[128]; // TFT_REDuced buffer size for less memory usage - int nbytes = - ssh_channel_read_nonblocking(channel_ssh, buffer, sizeof(buffer), 0); - bool isAnsiSequence = - false; // To track when we are inside an ANSI sequence + while(!returnToMenu) { } - if (nbytes > 0) { - for (int i = 0; i < nbytes; ++i) { - char c = buffer[i]; - if (filterAnsiSequences) { - if (c == '\033') { - isAnsiSequence = true; // Enter ANSI sequence mode - } else if (isAnsiSequence) { - if (isalpha(c)) { - isAnsiSequence = false; // Exit ANSI sequence mode at - // the end character - } - } else { - if (c == '\r') continue; // Ignore carriage return - tft.write(c); - cursorY = tft.getCursorY(); - } - } else { - if (c == '\r') continue; // Ignore carriage return - tft.write(c); - cursorY = tft.getCursorY(); - } - } - } + vTaskDelete(NULL); - // Handle channel closure and other conditions - if (nbytes < 0 || ssh_channel_is_closed(channel_ssh)) { - ssh_channel_close(channel_ssh); - ssh_channel_free(channel_ssh); - ssh_disconnect(my_ssh_session); - ssh_free(my_ssh_session); - displayRedStripe("\nSSH session closed."); - tft.setTextColor(FGCOLOR, BGCOLOR); - return; // Exit the loop upon session closure - } - //} } -void ssh_setup(){ - if(!wifiConnected) wifiConnectMenu(); - - // Disable watchdog - disableCore0WDT(); - //disableCore1WDT(); - //disableLoopWDT(); - +void ssh_loop(void *pvParameters) { + String message = ""; + tft.setTextSize(FP); tft.fillScreen(BGCOLOR); tft.setCursor(0, 0); - Serial.begin(115200); // Initialize serial communication for debugging - Serial.println("Starting Setup"); - - //auto cfg = M5.config(); - //M5Cardputer.begin(cfg, true); - tft.setRotation(1); - tft.setTextSize(1); // Set text size - cursorY = tft.getCursorY(); - - tft.setCursor(0, 0); - - ssh_host=keyboard("",76,"SSH HOST"); - - ssh_port=keyboard("",76,"SSH PORT"); - - ssh_port_char = stringTochar(ssh_port); - uint16_t ssh_port_int = atoi(ssh_port_char); - - //tft.print("\nSSH Username: "); - - //waitForInput(ssh_user); - ssh_user=keyboard("",76,"SSH USER"); - //tft.print("\nSSH Password: "); - - //waitForInput(ssh_password); - ssh_password=keyboard("",76,"SSH PASSWORD"); - - Serial.println("BEFORE SSH"); + log_d("BEFORE SSH"); my_ssh_session = ssh_new(); - Serial.println("AFTER SSH"); - + log_d("AFTER SSH"); + // Disable watchdog + disableCore0WDT(); + disableCore1WDT(); + disableLoopWDT(); if (my_ssh_session == NULL) { tft.setTextColor(TFT_RED, BGCOLOR); displayRedStripe("SSH Shell request error."); - Serial.println("SSH Session creation failed."); + log_d("SSH Session creation failed."); + returnToMenu=true; delay(5000); + vTaskDelete(NULL); return; } + ssh_port_char = stringTochar(ssh_port); + uint16_t ssh_port_int = atoi(ssh_port_char); + ssh_options_set(my_ssh_session, SSH_OPTIONS_HOST, ssh_host.c_str()); ssh_options_set(my_ssh_session, SSH_OPTIONS_PORT, &ssh_port_int); ssh_options_set(my_ssh_session, SSH_OPTIONS_USER, ssh_user.c_str()); - Serial.println("AFTER COMPARE AND OPTION SET"); + log_d("AFTER COMPARE AND OPTION SET"); if (ssh_connect(my_ssh_session) != SSH_OK) { tft.setTextColor(TFT_RED, BGCOLOR); displayRedStripe("SSH Shell request error."); - Serial.println("SSH Connect error."); + log_d("SSH Connect error."); ssh_free(my_ssh_session); delay(5000); + returnToMenu=true; + vTaskDelete(NULL); return; } @@ -252,10 +134,12 @@ void ssh_setup(){ SSH_AUTH_SUCCESS) { tft.setTextColor(TFT_RED, BGCOLOR); displayRedStripe("SSH Shell request error."); - Serial.println("SSH Authentication error."); + log_d("SSH Authentication error."); ssh_disconnect(my_ssh_session); ssh_free(my_ssh_session); delay(5000); + returnToMenu=true; + vTaskDelete(NULL); return; } @@ -263,46 +147,170 @@ void ssh_setup(){ if (channel_ssh == NULL || ssh_channel_open_session(channel_ssh) != SSH_OK) { tft.setTextColor(TFT_RED, BGCOLOR); displayRedStripe("SSH Shell request error."); - Serial.println("SSH Channel open error."); + log_d("SSH Channel open error."); ssh_disconnect(my_ssh_session); ssh_free(my_ssh_session); delay(5000); + returnToMenu=true; + vTaskDelete(NULL); return; } if (ssh_channel_request_pty(channel_ssh) != SSH_OK) { tft.setTextColor(TFT_RED, BGCOLOR); displayRedStripe("SSH Shell request error."); - Serial.println("SSH PTY request error."); + log_d("SSH PTY request error."); ssh_channel_close(channel_ssh); ssh_channel_free(channel_ssh); ssh_disconnect(my_ssh_session); ssh_free(my_ssh_session); delay(5000); + returnToMenu=true; + vTaskDelete(NULL); return; } if (ssh_channel_request_shell(channel_ssh) != SSH_OK) { tft.setTextColor(TFT_RED, BGCOLOR); displayRedStripe("SSH Shell request error."); - Serial.println("SSH Shell request error."); + log_d("SSH Shell request error."); ssh_channel_close(channel_ssh); ssh_channel_free(channel_ssh); ssh_disconnect(my_ssh_session); ssh_free(my_ssh_session); delay(5000); + returnToMenu=true; + vTaskDelete(NULL); return; } - Serial.println("SSH setup completed."); - tft.setTextColor(TFT_GREEN, BGCOLOR); - displayRedStripe("SSH Conected!", TFT_WHITE, TFT_DARKGREEN ); - delay(2000); + log_d("SSH setup completed."); tft.fillScreen(BGCOLOR); tft.setTextColor(TFT_WHITE, BGCOLOR); - ssh_loop(); + tft.setTextSize(FP); + char buffer[1024]; + int nbytes; + while(1) { + #ifdef CARDPUTER + Keyboard.update(); + if (Keyboard.isChange() && Keyboard.isPressed()) { + unsigned long currentMillis = millis(); + if (currentMillis - lastKeyPressMillis >= debounceDelay) { + lastKeyPressMillis = currentMillis; + Keyboard_Class::KeysState status = Keyboard.keysState(); + + for (auto i : status.word) { + commandBuffer += i; + tft.print(i); + cursorY = tft.getCursorY(); + } + + if (status.del && commandBuffer.length() > 2) { + commandBuffer.remove(commandBuffer.length() - 1); + tft.setCursor( + tft.getCursorX() - 6, + tft.getCursorY()); + tft.setTextColor(TFT_GREEN, BGCOLOR); + tft.print(" "); + tft.setCursor( + tft.getCursorX() - 6, + tft.getCursorY()); + cursorY = tft.getCursorY(); + } + + if (status.enter) { + tft.setTextColor(TFT_GREEN); + commandBuffer.trim(); + if(commandBuffer.substring(2) == "cls") { + tft.fillScreen(BGCOLOR); + tft.setCursor(0,0); + tft.print("> "); + commandBuffer = "> "; + } else { + String message = commandBuffer.substring(2) + "\r"; // Get the command part, exclude the "> " + ssh_channel_write(channel_ssh, message.c_str(), message.length()); // Send the command + } + cursorY = tft.getCursorY(); // Update cursor position + if(cursorY > tft.height()) { + tft.setCursor(0,tft.height()-10); + tft.fillRect(0,HEIGHT-11,WIDTH,11, BGCOLOR); + } + } + } + } + + #else + if(checkSelPress()) { + + while(checkSelPress()) { yield(); } // timerless debounce + message = keyboard("cls",76,"SSH Command: "); + while(checkSelPress()) { yield(); } // timerless debounce + if(message=="cls") { + tft.fillScreen(BGCOLOR); + tft.setCursor(0,0); + tft.print("> "); + } else { + message += "\r"; + ssh_channel_write(channel_ssh, message.c_str(), message.length()); // Send the command + log_d("%s",message); + } + + commandBuffer = "> " + message; + tft.setCursor(0, 0); + tft.setTextSize(FP); + + } + + #endif + + // Read data from SSH server and display it, handling ANSI sequences + nbytes = ssh_channel_read_nonblocking(channel_ssh, buffer, sizeof(buffer), 0); + + if (nbytes > 0) { + String msg = ""; + tft.setTextColor(TFT_WHITE); + for (int i = 0; i < nbytes; ++i) { + msg += char(buffer[i]); + if (buffer[i] == '\r') continue; // Ignore carriage return + tft.write(buffer[i]); + if(tft.getCursorY()>HEIGHT) { + tft.fillScreen(BGCOLOR); + tft.setCursor(0,0); + tft.setTextColor(TFT_GREEN); + tft.print(commandBuffer); // Move to the next line on display + tft.setTextColor(TFT_WHITE); + } + cursorY = tft.getCursorY(); + } + log_d("%s", msg); + + cursorY = tft.getCursorY(); // Update cursor position + if(cursorY > tft.height()) { + tft.setCursor(0,tft.height()-10); + tft.fillRect(0,HEIGHT-11,WIDTH,11, BGCOLOR); + } + commandBuffer = "> "; // Reset command buffer + tft.setTextColor(TFT_GREEN); + } + + // Handle channel closure and other conditions + if (nbytes < 0 || ssh_channel_is_closed(channel_ssh)) { + log_d("Encerrando"); + break; + } + } + //Clean Up + ssh_channel_close(channel_ssh); + ssh_channel_free(channel_ssh); + ssh_disconnect(my_ssh_session); + ssh_free(my_ssh_session); + displayRedStripe("SSH session closed."); + tft.setTextColor(FGCOLOR, BGCOLOR); + returnToMenu=true; + vTaskDelete(NULL); + } @@ -388,7 +396,7 @@ void telnet_loop() { } void telnet_setup() { - if(!wifiConnected) wifiConnectMenu(); + if(!wifiConnected) wifiConnectMenu(false); tft.fillScreen(BGCOLOR); tft.setCursor(0, 0); diff --git a/src/clients.h b/src/clients.h index cc3e6e9b..c9c53094 100644 --- a/src/clients.h +++ b/src/clients.h @@ -2,8 +2,8 @@ void telnet_setup(); -void ssh_setup(); +void ssh_setup(String host = ""); -void ssh_loop(); +void ssh_loop(void *pvParameters); char* stringTochar(String s); \ No newline at end of file diff --git a/src/display.cpp b/src/display.cpp index 93ac6d01..5c938428 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -122,7 +122,7 @@ void loopOptions(const std::vector> /*************************************************************************************** ** Function name: progressHandler ** Description: Função para manipular o progresso da atualização -** Dependencia: prog_handler =>> 0 - Flash, 1 - SPIFFS +** Dependencia: prog_handler =>> 0 - Flash, 1 - LittleFS ***************************************************************************************/ void progressHandler(int progress, size_t total) { #ifndef STICK_C diff --git a/src/evil_portal.cpp b/src/evil_portal.cpp index 94e29d6a..c0a4e57e 100644 --- a/src/evil_portal.cpp +++ b/src/evil_portal.cpp @@ -185,7 +185,7 @@ void startEvilPortal(String tssid, uint8_t channel, bool deauth) { void saveToCSV(const String &filename, const String &csvLine) { FS *fs; if(setupSdCard()) fs=&SD; - else fs=&SPIFFS; + else fs=&LittleFS; File file = (*fs).open(filename, FILE_APPEND); if (!file) { log_i("Error to open file"); @@ -262,11 +262,11 @@ void chooseHtml(bool def) { if(setupSdCard()) { options = { {"SD Card", [&]() { fs=&SD; }}, - {"Spiffs", [&]() { fs=&SPIFFS; }}, + {"LittleFS", [&]() { fs=&LittleFS; }}, }; delay(200); loopOptions(options); - } else fs=&SPIFFS; + } else fs=&LittleFS; html_file = loopSD(*fs,true); if(html_file.endsWith(".html")) { diff --git a/src/globals.h b/src/globals.h index c0ab426d..65ef5c73 100644 --- a/src/globals.h +++ b/src/globals.h @@ -8,7 +8,8 @@ #include #include #include -#include +//#include +#include #if defined (STICK_C_PLUS) || defined (STICK_C) @@ -26,7 +27,9 @@ extern TFT_eSPI tft; extern TFT_eSprite sprite; extern TFT_eSprite draw; -extern int prog_handler; // 0 - Flash, 1 - SPIFFS, 2 - Download +extern char timeStr[10]; + +extern int prog_handler; // 0 - Flash, 1 - LittleFS, 2 - Download extern bool sdcardMounted; // informa se o cartão está montado ou não, sem precisar chamar a função setupSdCard diff --git a/src/main.cpp b/src/main.cpp index de489b27..9b50ec08 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -8,12 +8,14 @@ #include "esp32-hal-psram.h" // Public Globals Variables -int prog_handler; // 0 - Flash, 1 - SPIFFS, 3 - Download +int prog_handler; // 0 - Flash, 1 - LittleFS, 3 - Download int rotation; bool sdcardMounted; bool wifiConnected; bool BLEConnected; bool returnToMenu; +char timeStr[10]; + String ssid; String pwd; std::vector>> options; @@ -80,6 +82,7 @@ void setup() { wifiConnected=false; BLEConnected=false; + // Setup GPIOs and stuff #if defined(STICK_C_PLUS2) pinMode(UP_BTN, INPUT); // Sets the power btn as an INPUT @@ -114,7 +117,7 @@ void setup() { bool change=false; tft.drawXBitmap(1,1,bits, bits_width, bits_height,TFT_BLACK,TFT_WHITE); - if(!SPIFFS.begin(true)) { SPIFFS.format(), SPIFFS.begin();} + if(!LittleFS.begin(true)) { LittleFS.format(), LittleFS.begin();} while(millis()2000) && (millis()-i)<2200) tft.fillScreen(TFT_BLACK); @@ -241,7 +244,7 @@ void loop() { {"TV-B-Gone", [=]() { StartTvBGone(); }}, {"Custom IR", [=]() { otherIRcodes(); }}, {"SD Card", [=]() { loopSD(SD); }}, - {"SPIFFS", [=]() { loopSD(SPIFFS); }}, + {"LittleFS", [=]() { loopSD(LittleFS); }}, {"WebUI", [=]() { loopOptionsWebUi(); }}, {"Megalodon", [=]() { shark_setup(); }}, }; diff --git a/src/mykeyboard.cpp b/src/mykeyboard.cpp index cfb2009c..02ade134 100644 --- a/src/mykeyboard.cpp +++ b/src/mykeyboard.cpp @@ -67,6 +67,8 @@ String keyboard(String mytext, int maxSize, String msg) { bool caps=false; int x=0; int y=-1; + int x2=0; + int y2=0; char keys[4][12][2] = { //4 lines, with 12 characteres, low and high caps { { '1', '!' },//1 @@ -127,42 +129,47 @@ String keyboard(String mytext, int maxSize, String msg) { }; int i=0; - int j=0; + int j=-1; bool redraw=true; delay(200); + int cX =0; + int cY =0; + tft.fillScreen(BGCOLOR); while(1) { if(redraw) { tft.setCursor(0,0); - tft.fillScreen(BGCOLOR); tft.setTextColor(TFT_WHITE, BGCOLOR); tft.setTextSize(FM); //Draw the rectangles - tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle - tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle - tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle - tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle - tft.drawRect(3,32,WIDTH-3,20,FGCOLOR); // mystring Rectangle - - - if(x==0 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("OK", 18, 4); - + if(y<0) { + tft.fillRect(0,1,WIDTH,22,BGCOLOR); + tft.drawRect(7,2,46,20,TFT_WHITE); // Ok Rectangle + tft.drawRect(55,2,50,20,TFT_WHITE); // CAP Rectangle + tft.drawRect(107,2,50,20,TFT_WHITE); // DEL Rectangle + tft.drawRect(159,2,74,20,TFT_WHITE); // SPACE Rectangle + tft.drawRect(3,32,WIDTH-3,20,FGCOLOR); // mystring Rectangle + + + if(x==0 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(7,2,50,20,TFT_WHITE); } + else tft.setTextColor(TFT_WHITE, BGCOLOR); + tft.drawString("OK", 18, 4); + + + if(x==1 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } + else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } + else tft.setTextColor(TFT_WHITE, BGCOLOR); + tft.drawString("CAP", 64, 4); - if(x==1 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(55,2,50,20,TFT_WHITE); } - else if(caps) { tft.fillRect(55,2,50,20,TFT_DARKGREY); tft.setTextColor(TFT_WHITE, TFT_DARKGREY); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("CAP", 64, 4); - - if(x==2 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("DEL", 115, 4); + if(x==2 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(107,2,50,20,TFT_WHITE); } + else tft.setTextColor(TFT_WHITE, BGCOLOR); + tft.drawString("DEL", 115, 4); - if(x>2 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } - else tft.setTextColor(TFT_WHITE, BGCOLOR); - tft.drawString("SPACE", 168, 4); + if(x>2 && y==-1) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(159,2,74,20,TFT_WHITE); } + else tft.setTextColor(TFT_WHITE, BGCOLOR); + tft.drawString("SPACE", 168, 4); + } tft.setTextSize(FP); tft.setTextColor(TFT_WHITE, 0x5AAB); @@ -170,7 +177,9 @@ String keyboard(String mytext, int maxSize, String msg) { tft.setTextSize(FM); - + // reseta o quadrado do texto + if (mytext.length() == 19 || mytext.length() == 20 || mytext.length() == 38 || mytext.length() == 39) tft.fillRect(3,32,WIDTH-3,20,BGCOLOR); // mystring Rectangle + // escreve o texto tft.setTextColor(TFT_WHITE); if(mytext.length()>19) { tft.setTextSize(FP); @@ -184,6 +193,8 @@ String keyboard(String mytext, int maxSize, String msg) { } else { tft.drawString(mytext, 5, 34); } + //desenha o retangulo colorido + tft.drawRect(3,32,WIDTH-3,20,FGCOLOR); // mystring Rectangle tft.setTextColor(TFT_WHITE, BGCOLOR); @@ -192,9 +203,12 @@ String keyboard(String mytext, int maxSize, String msg) { for(i=0;i<4;i++) { for(j=0;j<12;j++) { + //use last coordenate to paint only this letter + if(x2==j && y2==i) { tft.setTextColor(TFT_WHITE, BGCOLOR); tft.fillRect(j*18+11,i*19+54,21,19,BGCOLOR);} /* If selected, change font color and draw Rectangle*/ if(x==j && y==i) { tft.setTextColor(BGCOLOR, TFT_WHITE); tft.fillRect(j*18+11,i*19+54,21,19,TFT_WHITE);} + /* Print the letters */ if(!caps) tft.drawChar(keys[i][j][0], (j*18+16), (i*19+56)); else tft.drawChar(keys[i][j][1], (j*18+16), (i*19+56)); @@ -203,39 +217,96 @@ String keyboard(String mytext, int maxSize, String msg) { if(x==j && y==i) { tft.setTextColor(TFT_WHITE, BGCOLOR); } } } + // save actual key coordenate + x2=x; + y2=y; redraw = false; } + //cursor handler + if(mytext.length()>19) { + tft.setTextSize(FP); + if(mytext.length()>38) { + cY=42; + cX=5+(mytext.length()-38)*LW; + } + else { + cY=34; + cX=5+mytext.length()*LW; + } + } else { + cY=34; + cX=5+mytext.length()*LW*2; + } + /* When Select a key in keyboard */ #if defined (CARDPUTER) + Keyboard.update(); if (Keyboard.isPressed()) { + tft.setCursor(cX,cY); Keyboard_Class::KeysState status = Keyboard.keysState(); for (auto i : status.word) { - mytext += i; + if(mytext.length() 0) { // Handle backspace key mytext.remove(mytext.length() - 1); + int fS=FM; + if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } + else tft.setTextSize(FM); + tft.setCursor((cX-fS*LW),cY); + tft.setTextColor(FGCOLOR,BGCOLOR); + tft.print(" "); + tft.setTextColor(TFT_WHITE, 0x5AAB); + tft.setCursor(cX-fS*LW,cY); + cX=tft.getCursorX(); + cY=tft.getCursorY(); + if(mytext.length()==19) redraw = true; + if(mytext.length()==38) redraw = true; } if (status.enter) { break; } delay(150); - redraw = true; } if(checkSelPress()) break; #else if(checkSelPress()) { + tft.setCursor(cX,cY); int z=0; if(caps) z=1; else z=0; if(x==0 && y==-1) break; else if(x==1 && y==-1) caps=!caps; - else if(x==2 && y==-1 && mytext.length() > 0) mytext.remove(mytext.length()-1); + else if(x==2 && y==-1 && mytext.length() > 0) { + mytext.remove(mytext.length()-1); + int fS=FM; + if(mytext.length()>19) { tft.setTextSize(FP); fS=FP; } + else tft.setTextSize(FM); + tft.setCursor((cX-fS*LW),cY); + tft.setTextColor(FGCOLOR,BGCOLOR); + tft.print(" "); + tft.setTextColor(TFT_WHITE, 0x5AAB); + tft.setCursor(cX-fS*LW,cY); + cX=tft.getCursorX(); + cY=tft.getCursorY(); + } else if(x>2 && y==-1 && mytext.length()-1 && mytext.length()-1 && mytext.length()>> option; + option = { + {"Scan Ports", [=](){ scanPorts(ip); }}, + {"SSH Connect", [=](){ ssh_setup(ip.toString()); }}, + }; + loopOptions(option); + delay(200); +} void scanPorts(IPAddress host) { diff --git a/src/scan_hosts.h b/src/scan_hosts.h index 689ca1c1..398784b5 100644 --- a/src/scan_hosts.h +++ b/src/scan_hosts.h @@ -8,4 +8,6 @@ void local_scan_setup(); -void scanPorts(IPAddress host); \ No newline at end of file +void scanPorts(IPAddress host); + +void afterScanOptions(IPAddress ip); \ No newline at end of file diff --git a/src/sd_functions.cpp b/src/sd_functions.cpp index 85218b97..11cecf44 100644 --- a/src/sd_functions.cpp +++ b/src/sd_functions.cpp @@ -60,7 +60,8 @@ bool ToggleSDCard() { bool deleteFromSd(FS fs, String path) { File dir = fs.open(path); if (!dir.isDirectory()) { - return fs.remove(path.c_str()); + dir.close(); + return fs.remove(path); } dir.rewindDirectory(); @@ -71,10 +72,13 @@ bool ToggleSDCard() { if (file.isDirectory()) { success &= deleteFromSd(fs, file.path()); } else { - success &= fs.remove(file.path()); + String path2 = file.path(); + file.close(); + success &= fs.remove(path2); } file = dir.openNextFile(); } + file.close(); dir.close(); // Apaga a própria pasta depois de apagar seu conteúdo @@ -99,7 +103,7 @@ bool renameFile(FS fs, String path, String filename) { } /*************************************************************************************** ** Function name: copyToFs -** Description: copy file from SD or SPIFFS to SPIFFS or SD +** Description: copy file from SD or LittleFS to LittleFS or SD ***************************************************************************************/ bool copyToFs(FS from, FS to, String path) { // Tamanho do buffer para leitura/escrita @@ -108,7 +112,7 @@ bool copyToFs(FS from, FS to, String path) { bool result; if (!SD.begin()) { result = false; displayError("Error 1"); } - if(!SPIFFS.begin()) { result = false; displayError("Error 2"); } + if(!LittleFS.begin()) { result = false; displayError("Error 2"); } File source = from.open(path, FILE_READ); if (!source) { @@ -221,7 +225,7 @@ bool pasteFile(FS fs, String path) { ***************************************************************************************/ bool createFolder(FS fs, String path) { String foldername=keyboard("",76,"Folder Name: "); - if(!fs.mkdir(path + foldername)) { + if(!fs.mkdir(path + "/" + foldername)) { displayRedStripe("Couldn't create folder"); return false; } @@ -465,8 +469,8 @@ String loopSD(FS &fs, bool filePicker) { }; if(fileToCopy!="") options.push_back({"Paste", [=]() { pasteFile(fs, Folder); }}); options.push_back({"Delete", [=]() { deleteFromSd(fs, fileList[index][1]); }}); - if(&fs == &SD) options.push_back({"Copy->SPIFFS", [=]() { copyToFs(SD,SPIFFS, fileList[index][1]); }}); - if(&fs == &SPIFFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(SPIFFS, SD, fileList[index][1]); }}); + if(&fs == &SD) options.push_back({"Copy->LittleFS", [=]() { copyToFs(SD,LittleFS, fileList[index][1]); }}); + if(&fs == &LittleFS && sdcardMounted) options.push_back({"Copy->SD", [=]() { copyToFs(LittleFS, SD, fileList[index][1]); }}); options.push_back({"Main Menu", [=]() { backToMenu(); }}); delay(200); diff --git a/src/sd_functions.h b/src/sd_functions.h index 019ec6fe..86776150 100644 --- a/src/sd_functions.h +++ b/src/sd_functions.h @@ -1,5 +1,5 @@ #include -#include +#include #include #include diff --git a/src/settings.cpp b/src/settings.cpp index 7e049f4d..71f0fd03 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -153,7 +153,7 @@ void runClockLoop() { time_t localTime = myTZ.toLocal(timeClient.getEpochTime()); struct tm* timeInfo = localtime(&localTime); - char timeStr[10]; + snprintf(timeStr, sizeof(timeStr), "%02d:%02d", timeInfo->tm_hour, timeInfo->tm_min); Serial.print("Current time: "); diff --git a/src/webInterface.cpp b/src/webInterface.cpp index 34ba0517..3d854bca 100644 --- a/src/webInterface.cpp +++ b/src/webInterface.cpp @@ -83,7 +83,7 @@ String humanReadableSize(uint64_t bytes) { ** Function: listFiles ** list all of the files, if ishtml=true, return html rather than simple text **********************************************************************/ -String listFiles(FS fs, bool ishtml, String folder) { +String listFiles(FS fs, bool ishtml, String folder, bool isLittleFS) { String returnText = ""; Serial.println("Listing files stored on SD"); @@ -92,18 +92,20 @@ String listFiles(FS fs, bool ishtml, String folder) { } File root = fs.open(folder); File foundfile = root.openNextFile(); + String fileSys="SD"; + if (isLittleFS) fileSys="LittleFS"; if (folder=="//") folder = "/"; uploadFolder = folder; String PreFolder = folder; PreFolder = PreFolder.substring(0, PreFolder.lastIndexOf("/")); if(PreFolder=="") PreFolder= "/"; - returnText += "... \n"; + returnText += "... \n"; if (folder=="/") folder = ""; while (foundfile) { if(foundfile.isDirectory()) { if (ishtml) { - returnText += "\n" + String(foundfile.name()) + ""; + returnText += "\n" + String(foundfile.name()) + ""; returnText += "\n"; returnText += "  "; returnText += "  \n"; @@ -159,9 +161,9 @@ String processor(const String& var) { processedHtml.replace("%USEDSD%", humanReadableSize(SD.usedBytes())); processedHtml.replace("%TOTALSD%", humanReadableSize(SD.totalBytes())); - processedHtml.replace("%FREESPIFFS%", humanReadableSize(SPIFFS.totalBytes() - SPIFFS.usedBytes())); - processedHtml.replace("%USEDSPIFFS%", humanReadableSize(SPIFFS.usedBytes())); - processedHtml.replace("%TOTALSPIFFS%", humanReadableSize(SPIFFS.totalBytes())); + processedHtml.replace("%FREELittleFS%", humanReadableSize(LittleFS.totalBytes() - LittleFS.usedBytes())); + processedHtml.replace("%USEDLittleFS%", humanReadableSize(LittleFS.usedBytes())); + processedHtml.replace("%TOTALLittleFS%", humanReadableSize(LittleFS.totalBytes())); return processedHtml; } @@ -241,9 +243,9 @@ void configureWebServer() { }, []() {handleFileUpload(SD);}); // Uploadfile handler - server->on("/uploadSPIFFS", HTTP_POST, []() { + server->on("/uploadLittleFS", HTTP_POST, []() { server->send(200, "text/plain", "Upload iniciado"); - }, []() { handleFileUpload(SPIFFS); }); + }, []() { handleFileUpload(LittleFS); }); // Index page server->on("/", HTTP_GET, []() { @@ -271,7 +273,7 @@ void configureWebServer() { if (SD.rename(filePath, filePath2)) server->send(200, "text/plain", filePath + " renamed to " + filePath2); else server->send(200, "text/plain", "Fail renaming file."); } else { - if (SPIFFS.rename(filePath, filePath2)) server->send(200, "text/plain", filePath + " renamed to " + filePath2); + if (LittleFS.rename(filePath, filePath2)) server->send(200, "text/plain", filePath + " renamed to " + filePath2); else server->send(200, "text/plain", "Fail renaming file."); } @@ -287,7 +289,7 @@ void configureWebServer() { } }); - // List files of the SPIFFS + // List files of the LittleFS server->on("/listfiles", HTTP_GET, []() { if (checkUserWebAuth()) { String folder = "/"; @@ -297,8 +299,8 @@ void configureWebServer() { bool useSD = false; if (strcmp(server->arg("fs").c_str(), "SD") == 0) useSD = true; - if (useSD) server->send(200, "text/plain", listFiles(SD, true, folder)); - else server->send(200, "text/plain", listFiles(SPIFFS, true, folder)); + if (useSD) server->send(200, "text/plain", listFiles(SD, true, folder,false)); + else server->send(200, "text/plain", listFiles(LittleFS, true, folder, true)); } else { server->requestAuthentication(); @@ -317,7 +319,7 @@ void configureWebServer() { FS *fs; if (useSD) fs = &SD; - else fs = &SPIFFS; + else fs = &LittleFS; log_i("filename: %s", fileName); log_i("fileAction: %s", fileAction); diff --git a/src/webInterface.h b/src/webInterface.h index 592fa15f..212e946a 100644 --- a/src/webInterface.h +++ b/src/webInterface.h @@ -4,10 +4,11 @@ #include #include #include +#include // function defaults String humanReadableSize(uint64_t bytes); -String listFiles(FS fs, bool ishtml, String folder); +String listFiles(FS fs, bool ishtml, String folder, bool isLittleFS); String processor(const String& var); String readLineFromFile(File myFile); @@ -270,7 +271,7 @@ const char index_html[] PROGMEM = R"rawliteral(

Firmware for offensive pranks and pentest studies and analysis. For educational purposes only. Don't use in environments where you are not allowed. All responsibilities for irresponsible usage of this firmware rest on your fin, sharky. Sincerely, Bruce.

Firmware version: %FIRMWARE%

SD Free Storage: %FREESD% | Used: %USEDSD% | Total: %TOTALSD%

-

SPIFFS Free Storage: %FREESPIFFS% | Used: %USEDSPIFFS% | Total: %TOTALSPIFFS%

+

LittleFS Free Storage: %FREELittleFS% | Used: %USEDLittleFS% | Total: %TOTALLittleFS%

@@ -279,7 +280,7 @@ const char index_html[] PROGMEM = R"rawliteral( - +

@@ -391,22 +392,15 @@ function downloadDeleteButton(filename, action) { function showCreateFolder(folders) { var fs = document.getElementById("actualFS").value; var uploadform = ""; - if (fs =="SD") { - //document.getElementById("updetailsheader").innerHTML = "

Create new Folder

" - document.getElementById("status").innerHTML = ""; - uploadform = - "

Creating folder at: " + folders + ""+ - "" + - "" + - "" + - "" + - "

"; - } - else { - document.getElementById("status").innerHTML = ""; - uploadform = - "

SPIFFS don't support folders

"; - } + //document.getElementById("updetailsheader").innerHTML = "

Create new Folder

" + document.getElementById("status").innerHTML = ""; + uploadform = + "

Creating folder at: " + folders + ""+ + "

" + + "" + + "" + + "" + + "

"; document.getElementById("updetails").innerHTML = uploadform; } diff --git a/src/wg.h b/src/wg.h index ae3dab20..ce33cabf 100644 --- a/src/wg.h +++ b/src/wg.h @@ -1,4 +1,4 @@ -#include +#include #include extern bool isConnectedWireguard; From 15fc1d29f73ac436e486a9ba9ae747ae17a5774c Mon Sep 17 00:00:00 2001 From: Pirata Date: Thu, 30 May 2024 22:12:34 -0300 Subject: [PATCH 2/2] . --- src/clients.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/clients.cpp b/src/clients.cpp index 655fc83b..a76695a1 100644 --- a/src/clients.cpp +++ b/src/clients.cpp @@ -63,16 +63,16 @@ void ssh_setup(String host) { tft.setCursor(0, 0); if(host != "") ssh_host = host; else { - //ssh_host=keyboard("",15,"SSH HOST (IP)"); - ssh_host=keyboard("192.168.3.60",15,"SSH HOST (IP)"); + ssh_host=keyboard("",15,"SSH HOST (IP)"); + //ssh_host=keyboard("192.168.3.60",15,"SSH HOST (IP)"); } ssh_port=keyboard("22",5,"SSH PORT"); - //ssh_user=keyboard("",76,"SSH USER"); - ssh_user=keyboard("ubuntu",76,"SSH USER"); + ssh_user=keyboard("",76,"SSH USER"); + //ssh_user=keyboard("ubuntu",76,"SSH USER"); - //ssh_password=keyboard("",76,"SSH PASSWORD"); - ssh_password=keyboard("ubuntu",76,"SSH PASSWORD"); + ssh_password=keyboard("",76,"SSH PASSWORD"); + //ssh_password=keyboard("ubuntu",76,"SSH PASSWORD"); // Connect to SSH server TaskHandle_t sshTaskHandle = NULL;