From d8517189ffd73a3f026f16b39bd97602880c1b57 Mon Sep 17 00:00:00 2001 From: wangqinghua Date: Mon, 21 Jun 2021 00:55:27 +0800 Subject: [PATCH] fix Command cat --- remote_payloads_cli/remote_payloads_cli.ino | 16 ++++++---------- .../remote_payloads_sd_cli.ino | 15 +++++++-------- 2 files changed, 13 insertions(+), 18 deletions(-) diff --git a/remote_payloads_cli/remote_payloads_cli.ino b/remote_payloads_cli/remote_payloads_cli.ino index 10b3b50..8b365d2 100644 --- a/remote_payloads_cli/remote_payloads_cli.ino +++ b/remote_payloads_cli/remote_payloads_cli.ino @@ -19,7 +19,7 @@ //#define DEBUG; String username = "wangqinghua"; String password = "4dcc4173d80a2817206e196a38f0dbf7850188ff"; // sha1 of password "hacker" -String hidenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI +String hiddenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI //-----config-end-----// ESP8266WiFiMulti wifier; // 建立ESP8266WiFiMulti对象,对象名称是 'wifier' ESP8266WebServer shell(80); // 建立cli服务器对象shell,该对象用于响应cli请求。监听端口(80) @@ -164,7 +164,7 @@ void handleLogs() { logs += shell.argName(i) + ": " + shell.arg(i) + "\n"; } logs += "\n"; - File logFile = SPIFFS.open("/payloads/logs", "a"); + File logFile = SPIFFS.open("/" + hiddenDir + "logs", "a"); logFile.println(logs); logFile.close(); if (toUrl) { @@ -179,7 +179,7 @@ void handleList() { String dirList = "remote payloads"; dirList += "

ESP8266 SPIFFS Remote Payloads


"; while (dir.next()) { - if (dir.fileName().indexOf(hidenDir) < 0) { + if (dir.fileName().indexOf(hiddenDir) < 0) { dirList += "" + dir.fileName() + "
"; } } @@ -236,12 +236,8 @@ void _ls(String dir) { void _cat(String filePath) { File dataFile = SPIFFS.open(filePath, "r"); - String data = ""; - for (int i = 0; i < dataFile.size(); i++) { - data += (char)dataFile.read(); - } - dataFile.close(); - shell.send(200, "text/plain", data); + shell.streamFile(dataFile, "text/plain"); + dataFile.close(); } void _rm(String filePath) { @@ -345,7 +341,7 @@ bool handler() { return false; } // 黑名单认证 - if (webAddress.indexOf(hidenDir) > 0) { + if (webAddress.indexOf(hiddenDir) > 0) { if (!cookieNow) { shell.send(403, "text/plain", "no cookie!"); return false; diff --git a/remote_payloads_sd_cli/remote_payloads_sd_cli.ino b/remote_payloads_sd_cli/remote_payloads_sd_cli.ino index b1623b4..c545d26 100644 --- a/remote_payloads_sd_cli/remote_payloads_sd_cli.ino +++ b/remote_payloads_sd_cli/remote_payloads_sd_cli.ino @@ -27,7 +27,7 @@ //#define TIME; // remove comment if you want to know date of each file String username = "wangqinghua"; String password = "4dcc4173d80a2817206e196a38f0dbf7850188ff"; // sha1 of password "hacker" -String hidenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI +String hiddenDir = "wangqinghua/"; //url including hidenDir is forbidden to browser but accessible to CLI //-----config-end-----// ESP8266WiFiMulti wifier; // 建立ESP8266WiFiMulti对象,对象名称是 'wifier' ESP8266WebServer shell(80); @@ -138,7 +138,7 @@ void handleLogs() { for (int i = 0; i < shell.args(); i++) { logs += shell.argName(i) + ": " + shell.arg(i) + "\n"; } - File logFile = SD.open("/payloads/logs", FILE_WRITE); + File logFile = SD.open("/" + hiddenDir + "logs", FILE_WRITE); logFile.println(logs); logFile.close(); if (toUrl) { @@ -166,6 +166,9 @@ void deviation(struct tm * tmstruct, int* year, int* month, int* day, int* hour, void printDirectory(File dir, String dirPath, int numTabs, String* result, bool html) { while (true) { + if ((html) && (dirPath.indexOf(hiddenDir))) { + break; + } File entry = dir.openNextFile(); if (!entry) { break; @@ -269,12 +272,8 @@ void _ls(String dirPath) { void _cat(String filePath) { File dataFile = SD.open(filePath, FILE_READ); - String data = ""; - for (int i = 0; i < dataFile.size(); i++) { - data += (char)dataFile.read(); - } - dataFile.close(); - shell.send(200, "text/plain", data); + shell.streamFile(dataFile, "text/plain"); + dataFile.close(); } void rmDir(String filePath) {