From c01eea2b9d650fe1c0e3303cdd52249dff345329 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 24 Nov 2019 19:29:53 +0100 Subject: [PATCH 1/3] Use PTY if python is available Problem: starting bash with -i will only make the current shell interactive, but not further sub shells (if you switch user for example). Fix: Use a PTY --- agents/meshcore.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index e757f832..3bc93976 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1099,7 +1099,11 @@ function createMeshCore(agent) { this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false }); this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); }); } else { - if (fs.existsSync("/bin/bash")) { + if (fs.existsSync("/usr/bin/python") && fs.existsSync("/bin/bash")) { + this.httprequest.process = childProcess.execFile("/usr/bin/python", [ "python", "-c", "import pty; pty.spawn([\"/bin/bash\"])" ], { type: childProcess.SpawnTypes.TERM }); + if (process.platform == 'linux') { this.httprequest.process.stdin.write("export TERM='xterm'\nalias ls='ls --color=auto'\nclear\n"); } + } + else if (fs.existsSync("/bin/bash")) { this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM }); if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); } } else { From 527add155f83156ca5c96ef141fe1069ac34249c Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 24 Nov 2019 20:03:08 +0100 Subject: [PATCH 2/3] Fix broken fix Fixes c01eea2b9d650fe1c0e3303cdd52249dff345329 --- agents/meshcore.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 3bc93976..87578b1f 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -1100,7 +1100,7 @@ function createMeshCore(agent) { this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); }); } else { if (fs.existsSync("/usr/bin/python") && fs.existsSync("/bin/bash")) { - this.httprequest.process = childProcess.execFile("/usr/bin/python", [ "python", "-c", "import pty; pty.spawn([\"/bin/bash\"])" ], { type: childProcess.SpawnTypes.TERM }); + this.httprequest.process = childProcess.execFile("/usr/bin/python", [ "python", "-c", "import pty; pty.spawn([\"/bin/bash\"])" ]); if (process.platform == 'linux') { this.httprequest.process.stdin.write("export TERM='xterm'\nalias ls='ls --color=auto'\nclear\n"); } } else if (fs.existsSync("/bin/bash")) { From c9590fb8340529b50e56d7a0c76136d8fe655ea2 Mon Sep 17 00:00:00 2001 From: TotallyNotElite <1yourexperiment@protonmail.com> Date: Sun, 24 Nov 2019 20:07:19 +0100 Subject: [PATCH 3/3] Update agents/meshcore.min.js --- agents/meshcore.min.js | 93 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/agents/meshcore.min.js b/agents/meshcore.min.js index c02bbdea..87578b1f 100644 --- a/agents/meshcore.min.js +++ b/agents/meshcore.min.js @@ -1099,11 +1099,15 @@ function createMeshCore(agent) { this.pipe(this.httprequest._term, { dataTypeSkip: 1, end: false }); this.prependListener('end', function () { this.httprequest._term.end(function () { console.log('Terminal was closed'); }); }); } else { - if (fs.existsSync("/bin/bash")) { + if (fs.existsSync("/usr/bin/python") && fs.existsSync("/bin/bash")) { + this.httprequest.process = childProcess.execFile("/usr/bin/python", [ "python", "-c", "import pty; pty.spawn([\"/bin/bash\"])" ]); + if (process.platform == 'linux') { this.httprequest.process.stdin.write("export TERM='xterm'\nalias ls='ls --color=auto'\nclear\n"); } + } + else if (fs.existsSync("/bin/bash")) { this.httprequest.process = childProcess.execFile("/bin/bash", ["bash", "-i"], { type: childProcess.SpawnTypes.TERM }); if (process.platform == 'linux') { this.httprequest.process.stdin.write("alias ls='ls --color=auto'\nclear\n"); } } else { - this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM }); + this.httprequest.process = childProcess.execFile("/bin/sh", ["sh"], { type: childProcess.SpawnTypes.TERM }); // , uid: require('user-sessions').consoleUid() if (process.platform == 'linux') { this.httprequest.process.stdin.write("stty erase ^H\nalias ls='ls --color=auto'\nPS1='\\u@\\h:\\w\\$ '\nclear\n"); } } this.httprequest.process.tunnel = this; @@ -1788,6 +1792,78 @@ function createMeshCore(agent) { response = 'Available commands: \r\n' + fin + '.'; break; } + case 'wallpaper': + if (process.platform != 'win32' && !(process.platform == 'linux' && require('linux-gnome-helpers').available)) + { + response = 'wallpaper command not supported on this platform' + } + else + { + if (args['_'].length != 1) + { + response = 'Proper usage: wallpaper (GET|TOGGLE)'; // Display usage + } + else + { + switch (args['_'][0].toUpperCase()) + { + default: + response = 'Proper usage: wallpaper (GET|TOGGLE)'; // Display usage + break; + case 'GET': + case 'TOGGLE': + if (process.platform == 'win32') + { + var id = require('user-sessions').getProcessOwnerName(process.pid).tsid == 0 ? 1 : 0; + var child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0='], { type: id }); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stderr.on('data', function () { }); + child.waitExit(); + var current = child.stdout.str.trim(); + if (args['_'][0].toUpperCase() == 'GET') + { + response = current; + break; + } + if (current != '') + { + require('MeshAgent')._wallpaper = current; + response = 'Wallpaper cleared'; + } + else + { + response = 'Wallpaper restored'; + } + child = require('child_process').execFile(process.execPath, [process.execPath.split('\\').pop(), '-b64exec', 'dmFyIFNQSV9HRVRERVNLV0FMTFBBUEVSID0gMHgwMDczOwp2YXIgU1BJX1NFVERFU0tXQUxMUEFQRVIgPSAweDAwMTQ7CnZhciBHTSA9IHJlcXVpcmUoJ19HZW5lcmljTWFyc2hhbCcpOwp2YXIgdXNlcjMyID0gR00uQ3JlYXRlTmF0aXZlUHJveHkoJ3VzZXIzMi5kbGwnKTsKdXNlcjMyLkNyZWF0ZU1ldGhvZCgnU3lzdGVtUGFyYW1ldGVyc0luZm9BJyk7CgppZiAocHJvY2Vzcy5hcmd2Lmxlbmd0aCA9PSAzKQp7CiAgICB2YXIgdiA9IEdNLkNyZWF0ZVZhcmlhYmxlKDEwMjQpOwogICAgdXNlcjMyLlN5c3RlbVBhcmFtZXRlcnNJbmZvQShTUElfR0VUREVTS1dBTExQQVBFUiwgdi5fc2l6ZSwgdiwgMCk7CiAgICBjb25zb2xlLmxvZyh2LlN0cmluZyk7CiAgICBwcm9jZXNzLmV4aXQoKTsKfQplbHNlCnsKICAgIHZhciBuYiA9IEdNLkNyZWF0ZVZhcmlhYmxlKHByb2Nlc3MuYXJndlszXSk7CiAgICB1c2VyMzIuU3lzdGVtUGFyYW1ldGVyc0luZm9BKFNQSV9TRVRERVNLV0FMTFBBUEVSLCBuYi5fc2l6ZSwgbmIsIDApOwogICAgcHJvY2Vzcy5leGl0KCk7Cn0=', current != '' ? '""' : require('MeshAgent')._wallpaper], { type: id }); + child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stderr.on('data', function () { }); + child.waitExit(); + } + else + { + var id = require('user-sessions').consoleUid(); + var current = require('linux-gnome-helpers').getDesktopWallpaper(id); + if (args['_'][0].toUpperCase() == 'GET') + { + response = current; + break; + } + if (current != '/dev/null') + { + require('MeshAgent')._wallpaper = current; + response = 'Wallpaper cleared'; + } + else + { + response = 'Wallpaper restored'; + } + require('linux-gnome-helpers').setDesktopWallpaper(id, current != '/dev/null' ? undefined : require('MeshAgent')._wallpaper); + } + break; + } + } + } + break; case 'safemode': if (process.platform != 'win32') { @@ -1815,6 +1891,19 @@ function createMeshCore(agent) { break; case 'STATUS': var nextboot = require('win-bcd').getKey('safeboot'); + if (nextboot) + { + switch(nextboot) + { + case 'Network': + case 'network': + nextboot = 'SAFE_MODE_NETWORK'; + break; + default: + nextboot = 'SAFE_MODE'; + break; + } + } response = 'Current: ' + require('win-bcd').bootMode + ' , NextBoot: ' + (nextboot ? nextboot : 'NORMAL'); break; }