Skip to content

Commit

Permalink
a little optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
wangqinghua committed Jun 16, 2021
1 parent 8eeb755 commit 5c9443b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
11 changes: 4 additions & 7 deletions remote_payloads_cli/remote_payloads_cli.ino
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <Hash.h>

String _username = "wangqinghua"; // 自定义用户名
String _password = "hacker"; // 自定义密码
String _password = "4dcc4173d80a2817206e196a38f0dbf7850188ff"; // 自定义密码(example: sha1 of 'hacker')
ESP8266WiFiMulti wifier; // 建立ESP8266WiFiMulti对象,对象名称是 'wifier'
ESP8266WebServer shell(80); // 建立cli服务器对象shell,该对象用于响应cli请求。监听端口(80)
String _cookie = "";
Expand All @@ -29,7 +29,6 @@ void setup() {
wifier.addAP("ssid_1", "pass_1");
wifier.addAP("ssid_1", "pass_2");
Serial.print("Connecting to ");
int i = 0;
while (wifier.run() != WL_CONNECTED) {
delay(1000);
Serial.print('.');
Expand All @@ -47,7 +46,7 @@ void setup() {
//启动shell
shell.on("/cookie", handleCookie);
shell.on("/up", HTTP_POST, respondOK, handleFileUpload);
shell.on("/log", handleLogs);
shell.on("/logs", handleLogs);
shell.on("/cmd", handleCmd);
shell.onNotFound(handler);
shell.collectHeaders(headerKeys, sizeof(headerKeys) / sizeof(headerKeys[0]));
Expand Down Expand Up @@ -157,9 +156,7 @@ bool handleCmd() {
return false;
}
String cmd = shell.arg("cmd");
if (cmd == "hello") {
shell.send(200, "text/plain", "hello " + _username + "!");
} else if (cmd == "ls") {
if (cmd == "ls") {
String dir = shell.arg("dir");
_ls(dir);
} else if (cmd == "cat") {
Expand All @@ -184,7 +181,7 @@ void _ls(String dir) {
while (dir_.next()) {
dirList += dir_.fileName() + "\n";
}
shell.send(200, "text/plain", dirList);
shell.send(200, "text/plain", dirList.substring(0, dirList.length() - 1));
}

void _cat(String filePath) {
Expand Down
8 changes: 3 additions & 5 deletions remote_payloads_cli/remote_payloads_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
password = ""
cookie = ""
headers = {}
proxy = {'http': '127.0.0.1:8080'}
def main():
global url
global username
Expand Down Expand Up @@ -86,7 +85,7 @@ def authentication():
return False
if (password == ""):
password = getpass.getpass("password: ")
authen = hashlib.sha1((password + cookie).encode()).hexdigest()
authen = hashlib.sha1((hashlib.sha1(password.encode()).hexdigest() + cookie).encode()).hexdigest()
checkCookie = requests.post(url=url + "/cookie", data={'cookie': cookie, 'authen': authen})
if (checkCookie.status_code == 200):
headers['cookie'] = cookie
Expand All @@ -102,9 +101,9 @@ def shell():
nack = username + "@" + url + " /$ "
cmd = input(nack).split()
if (cmd):
print(cmd)
if cmd[0] == 'exit':
requests.post(url + "/cmd", headers=headers, data={'cmd': 'exit'})
response = requests.post(url + "/cmd", headers=headers, data={'cmd': 'exit'})
print(response.text)
sys.exit(0)
try:
if cmd[0] == 'help':
Expand Down Expand Up @@ -157,7 +156,6 @@ def rm_(filePath):
global url
global headers
response = requests.post(url + "/cmd", headers=headers, data={'cmd': 'rm', 'filePath': filePath})
print(response.text)

if __name__ == '__main__':
main()

0 comments on commit 5c9443b

Please sign in to comment.