Version 0.8.19

This commit is contained in:
Ylian Saint-Hilaire 2021-04-24 10:53:13 -07:00
parent dfe87578a7
commit c3ad38cd33
3 changed files with 2970 additions and 3023 deletions

View File

@ -17,10 +17,8 @@ limitations under the License.
process.on('uncaughtException', function (ex) { process.on('uncaughtException', function (ex) {
require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "uncaughtException1: " + ex }); require('MeshAgent').SendCommand({ action: 'msg', type: 'console', value: "uncaughtException1: " + ex });
}); });
if (process.platform == 'win32' && require('user-sessions').getDomain == null) if (process.platform == 'win32' && require('user-sessions').getDomain == null) {
{ require('user-sessions').getDomain = function getDomain(uid) {
require('user-sessions').getDomain = function getDomain(uid)
{
return (this.getSessionAttribute(uid, this.InfoClass.WTSDomainName)); return (this.getSessionAttribute(uid, this.InfoClass.WTSDomainName));
}; };
} }
@ -745,13 +743,11 @@ function getServerTargetUrlEx(url) {
return url; return url;
} }
function sendWakeOnLanEx_interval() function sendWakeOnLanEx_interval() {
{
var t = require('MeshAgent').wakesockets; var t = require('MeshAgent').wakesockets;
if (t.list.length == 0) if (t.list.length == 0) {
{
clearInterval(t); clearInterval(t);
require('MeshAgent').wakesockets = null; delete require('MeshAgent').wakesockets;
return; return;
} }
@ -760,35 +756,27 @@ function sendWakeOnLanEx_interval()
for (var x = 1; x <= 16; ++x) { magic += mac; } for (var x = 1; x <= 16; ++x) { magic += mac; }
var magicbin = Buffer.from(magic, 'hex'); var magicbin = Buffer.from(magic, 'hex');
for(var i in t.sockets) for (var i in t.sockets) {
{
t.sockets[i].send(magicbin, 7, '255.255.255.255'); t.sockets[i].send(magicbin, 7, '255.255.255.255');
//sendConsoleText('Sending wake packet on ' + JSON.stringify(t.sockets[i].address())); //sendConsoleText('Sending wake packet on ' + JSON.stringify(t.sockets[i].address()));
} }
} }
function sendWakeOnLanEx(hexMacList) function sendWakeOnLanEx(hexMacList) {
{
var ret = 0; var ret = 0;
if (require('MeshAgent').wakesockets == null) if (require('MeshAgent').wakesockets == null) {
{
// Create a new interval timer // Create a new interval timer
require('MeshAgent').wakesockets = setInterval(sendWakeOnLanEx_interval, 10); require('MeshAgent').wakesockets = setInterval(sendWakeOnLanEx_interval, 10);
require('MeshAgent').wakesockets.sockets = []; require('MeshAgent').wakesockets.sockets = [];
require('MeshAgent').wakesockets.list = hexMacList; require('MeshAgent').wakesockets.list = hexMacList;
var interfaces = require('os').networkInterfaces(); var interfaces = require('os').networkInterfaces();
for (var adapter in interfaces) for (var adapter in interfaces) {
{ if (interfaces.hasOwnProperty(adapter)) {
if (interfaces.hasOwnProperty(adapter)) for (var i = 0; i < interfaces[adapter].length; ++i) {
{
for (var i = 0; i < interfaces[adapter].length; ++i)
{
var addr = interfaces[adapter][i]; var addr = interfaces[adapter][i];
if ((addr.family == 'IPv4') && (addr.mac != '00:00:00:00:00:00')) if ((addr.family == 'IPv4') && (addr.mac != '00:00:00:00:00:00')) {
{ try {
try
{
var socket = require('dgram').createSocket({ type: 'udp4' }); var socket = require('dgram').createSocket({ type: 'udp4' });
socket.bind({ address: addr.address }); socket.bind({ address: addr.address });
socket.setBroadcast(true); socket.setBroadcast(true);
@ -804,11 +792,9 @@ function sendWakeOnLanEx(hexMacList)
} }
} }
} }
else else {
{
// Append to an existing interval timer // Append to an existing interval timer
for(var i in hexMacList) for (var i in hexMacList) {
{
require('MeshAgent').wakesockets.list.push(hexMacList[i]); require('MeshAgent').wakesockets.list.push(hexMacList[i]);
} }
ret = require('MeshAgent').wakesockets.sockets.length; ret = require('MeshAgent').wakesockets.sockets.length;
@ -1016,25 +1002,20 @@ function handleServerCommand(data) {
case 'setclip': { case 'setclip': {
// Set the load clipboard to a user value // Set the load clipboard to a user value
//sendConsoleText('setClip: ' + JSON.stringify(data)); //sendConsoleText('setClip: ' + JSON.stringify(data));
if (typeof data.data == 'string') if (typeof data.data == 'string') {
{
MeshServerLogEx(22, [data.data.length], "Setting clipboard content, " + data.data.length + " byte(s)", data); MeshServerLogEx(22, [data.data.length], "Setting clipboard content, " + data.data.length + " byte(s)", data);
if (require('MeshAgent').isService) if (require('MeshAgent').isService) {
{ if (process.platform != 'win32') {
if (process.platform != 'win32')
{
require('clipboard').dispatchWrite(data.data); require('clipboard').dispatchWrite(data.data);
} }
else else {
{
var tmp = "require('clipboard')(" + JSON.stringify(data.data) + ');process.exit();'; var tmp = "require('clipboard')(" + JSON.stringify(data.data) + ');process.exit();';
tmp = Buffer.from(tmp).toString('base64'); tmp = Buffer.from(tmp).toString('base64');
var uid = require('user-sessions').consoleUid(); var uid = require('user-sessions').consoleUid();
var domain = require('user-sessions').getDomain(uid); var domain = require('user-sessions').getDomain(uid);
var user = domain + '\\' + require('user-sessions').getUsername(uid); var user = domain + '\\' + require('user-sessions').getUsername(uid);
var taskoptions = { env: { _target: process.execPath, _args: '-b64exec ' + tmp, _user: user } }; var taskoptions = { env: { _target: process.execPath, _args: '-b64exec ' + tmp, _user: user } };
for (var c1e in process.env) for (var c1e in process.env) {
{
taskoptions.env[c1e] = process.env[c1e]; taskoptions.env[c1e] = process.env[c1e];
} }
@ -1061,8 +1042,7 @@ function handleServerCommand(data) {
child.waitExit(); child.waitExit();
} }
} }
else else {
{
require("clipboard")(data.data); require("clipboard")(data.data);
} // Set the clipboard } // Set the clipboard
mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true }); mesh.SendCommand({ action: 'msg', type: 'setclip', sessionid: data.sessionid, success: true });
@ -1375,8 +1355,7 @@ function onFileWatcher(a, b) {
*/ */
function getSystemInformation(func) { function getSystemInformation(func) {
try try {
{
var results = { hardware: require('identifiers').get() }; // Hardware info var results = { hardware: require('identifiers').get() }; // Hardware info
if (results.hardware && results.hardware.windows) { if (results.hardware && results.hardware.windows) {
@ -2746,8 +2725,7 @@ function openUserDesktopUrl(url) {
var user = require('user-sessions').getUsername(uid); var user = require('user-sessions').getUsername(uid);
var domain = require('user-sessions').getDomain(uid); var domain = require('user-sessions').getDomain(uid);
var taskoptions = { env: { _target: process.env['windir'] + '\\system32\\cmd.exe', _args: '/C START ' + url.split('&').join('^&'), _user: '"' + domain + '\\' + user + '"' } }; var taskoptions = { env: { _target: process.env['windir'] + '\\system32\\cmd.exe', _args: '/C START ' + url.split('&').join('^&'), _user: '"' + domain + '\\' + user + '"' } };
for (var c1e in process.env) for (var c1e in process.env) {
{
taskoptions.env[c1e] = process.env[c1e]; taskoptions.env[c1e] = process.env[c1e];
} }
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], taskoptions); var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-'], taskoptions);
@ -2809,41 +2787,33 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
break; break;
} }
case 'cs': case 'cs':
if (process.platform != 'win32') if (process.platform != 'win32') {
{
response = 'Unknown command "cs", type "help" for list of avaialble commands.'; response = 'Unknown command "cs", type "help" for list of avaialble commands.';
break; break;
} }
switch (args['_'].length) switch (args['_'].length) {
{
case 0: case 0:
try try {
{
var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled'); var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED"); response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED");
} }
catch(e) catch (e) {
{
response = "This machine does not support Connected Standby"; response = "This machine does not support Connected Standby";
} }
break; break;
case 1: case 1:
if ((args['_'][0].toUpperCase() != 'ENABLE' && args['_'][0].toUpperCase() != 'DISABLE')) if ((args['_'][0].toUpperCase() != 'ENABLE' && args['_'][0].toUpperCase() != 'DISABLE')) {
{
response = "Proper usage:\r\n cs [ENABLE|DISABLE]"; response = "Proper usage:\r\n cs [ENABLE|DISABLE]";
} }
else else {
{ try {
try
{
var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled'); var cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled', args['_'][0].toUpperCase() == 'ENABLE' ? 1 : 0); require('win-registry').WriteKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled', args['_'][0].toUpperCase() == 'ENABLE' ? 1 : 0);
cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled'); cs = require('win-registry').QueryKey(require('win-registry').HKEY.LocalMachine, 'System\\CurrentControlSet\\Control\\Power', 'CsEnabled');
response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED"); response = "Connected Standby: " + (cs == 1 ? "ENABLED" : "DISABLED");
} }
catch (e) catch (e) {
{
response = "This machine does not support Connected Standby"; response = "This machine does not support Connected Standby";
} }
} }
@ -2865,8 +2835,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
} }
break; break;
case 'errorlog': case 'errorlog':
switch(args['_'].length) switch (args['_'].length) {
{
case 0: case 0:
// All Error Logs // All Error Logs
response = JSON.stringify(require('util-agentlog').read(), null, 1); response = JSON.stringify(require('util-agentlog').read(), null, 1);
@ -2884,17 +2853,14 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
response = JSON.stringify(_MSH(), null, 2); response = JSON.stringify(_MSH(), null, 2);
break; break;
case 'dnsinfo': case 'dnsinfo':
if (require('os').dns == null) if (require('os').dns == null) {
{
response = "Unknown command \"" + cmd + "\", type \"help\" for list of avaialble commands."; response = "Unknown command \"" + cmd + "\", type \"help\" for list of avaialble commands.";
} }
else else {
{
response = 'DNS Servers: '; response = 'DNS Servers: ';
var dns = require('os').dns(); var dns = require('os').dns();
for(var i=0;i<dns.length;++i) for (var i = 0; i < dns.length; ++i) {
{ if (i > 0) { response += ', '; }
if (i > 0) { response += ', ';}
response += dns[i]; response += dns[i];
} }
} }
@ -3371,19 +3337,14 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
} }
break; break;
case 'setclip': { case 'setclip': {
if (args['_'].length != 1) if (args['_'].length != 1) {
{
response = 'Proper usage: setclip "sample text"'; response = 'Proper usage: setclip "sample text"';
} else } else {
{ if (require('MeshAgent').isService) {
if (require('MeshAgent').isService) if (process.platform != 'win32') {
{
if (process.platform != 'win32')
{
require('clipboard').dispatchWrite(args['_'][0]); require('clipboard').dispatchWrite(args['_'][0]);
} }
else else {
{
var tmp = "require('clipboard')(\"" + (args['_'][0]).split('"').join('\\"') + '");process.exit();'; var tmp = "require('clipboard')(\"" + (args['_'][0]).split('"').join('\\"') + '");process.exit();';
tmp = Buffer.from(tmp).toString('base64'); tmp = Buffer.from(tmp).toString('base64');
@ -3392,8 +3353,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
var domain = require('user-sessions').getDomain(uid); var domain = require('user-sessions').getDomain(uid);
var taskoptions = { env: { _target: process.execPath, _args: '-b64exec ' + tmp, _user: domain + '\\' + user } }; var taskoptions = { env: { _target: process.execPath, _args: '-b64exec ' + tmp, _user: domain + '\\' + user } };
for (var c1e in process.env) for (var c1e in process.env) {
{
taskoptions.env[c1e] = process.env[c1e]; taskoptions.env[c1e] = process.env[c1e];
} }
@ -3421,8 +3381,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
} }
response = 'Setting clipboard to: "' + args['_'][0] + '"'; response = 'Setting clipboard to: "' + args['_'][0] + '"';
} }
else else {
{
require("clipboard")(args['_'][0]); response = 'Setting clipboard to: "' + args['_'][0] + '"'; require("clipboard")(args['_'][0]); response = 'Setting clipboard to: "' + args['_'][0] + '"';
} }
} }
@ -3770,11 +3729,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
break; break;
} }
case 'wakeonlan': { // Send wake-on-lan case 'wakeonlan': { // Send wake-on-lan
if ((args['_'].length != 1) || (args['_'][0].length != 12)) if ((args['_'].length != 1) || (args['_'][0].length != 12)) {
{
response = 'Proper usage: wakeonlan [mac], for example "wakeonlan 010203040506".'; response = 'Proper usage: wakeonlan [mac], for example "wakeonlan 010203040506".';
} else } else {
{
var count = sendWakeOnLanEx([args['_'][0]]); var count = sendWakeOnLanEx([args['_'][0]]);
sendWakeOnLanEx([args['_'][0]]); sendWakeOnLanEx([args['_'][0]]);
sendWakeOnLanEx([args['_'][0]]); sendWakeOnLanEx([args['_'][0]]);
@ -3998,10 +3955,8 @@ function sendAgentMessage(msg, icon) {
sendAgentMessage.messages[sendAgentMessage.nextid++] = { msg: msg, icon: icon }; sendAgentMessage.messages[sendAgentMessage.nextid++] = { msg: msg, icon: icon };
require('MeshAgent').SendCommand({ action: 'sessions', type: 'msg', value: sendAgentMessage.messages }); require('MeshAgent').SendCommand({ action: 'sessions', type: 'msg', value: sendAgentMessage.messages });
} }
function getOpenDescriptors() function getOpenDescriptors() {
{ switch (process.platform) {
switch (process.platform)
{
case "freebsd": case "freebsd":
var child = require('child_process').execFile('/bin/sh', ['sh']); var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
@ -4026,12 +3981,10 @@ function getOpenDescriptors()
child.stdin.write('\nexit\n'); child.stdin.write('\nexit\n');
child.waitExit(); child.waitExit();
try try {
{
return (JSON.parse(child.stdout.str.trim())); return (JSON.parse(child.stdout.str.trim()));
} }
catch (e) catch (e) {
{
return ([]); return ([]);
} }
break; break;
@ -4054,12 +4007,10 @@ function getOpenDescriptors()
child.stdin.write('\nexit\n'); child.stdin.write('\nexit\n');
child.waitExit(); child.waitExit();
try try {
{
return (JSON.parse(child.stdout.str.trim())); return (JSON.parse(child.stdout.str.trim()));
} }
catch (e) catch (e) {
{
return ([]); return ([]);
} }
break; break;
@ -4067,49 +4018,39 @@ function getOpenDescriptors()
return ([]); return ([]);
} }
} }
function closeDescriptors(libc, descriptors) function closeDescriptors(libc, descriptors) {
{
var fd = null; var fd = null;
while (descriptors.length > 0) while (descriptors.length > 0) {
{
fd = descriptors.pop(); fd = descriptors.pop();
if (fd > 2) if (fd > 2) {
{
libc.close(fd); libc.close(fd);
} }
} }
} }
function linux_execv(name, agentfilename, sessionid) function linux_execv(name, agentfilename, sessionid) {
{
var libs = require('monitor-info').getLibInfo('libc'); var libs = require('monitor-info').getLibInfo('libc');
var libc = null; var libc = null;
if ((libs.length == 0 || libs.length == null) && require('MeshAgent').ARCHID == 33) if ((libs.length == 0 || libs.length == null) && require('MeshAgent').ARCHID == 33) {
{
var child = require('child_process').execFile('/bin/sh', ['sh']); var child = require('child_process').execFile('/bin/sh', ['sh']);
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }); child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write("ls /lib/libc.* | tr '\\n' '`' | awk -F'`' '{ " + ' printf "["; DEL=""; for(i=1;i<NF;++i) { printf "%s{\\"path\\":\\"%s\\"}",DEL,$i; DEL=""; } printf "]"; }\'\nexit\n'); child.stdin.write("ls /lib/libc.* | tr '\\n' '`' | awk -F'`' '{ " + ' printf "["; DEL=""; for(i=1;i<NF;++i) { printf "%s{\\"path\\":\\"%s\\"}",DEL,$i; DEL=""; } printf "]"; }\'\nexit\n');
child.waitExit(); child.waitExit();
try try {
{
libs = JSON.parse(child.stdout.str.trim()); libs = JSON.parse(child.stdout.str.trim());
} }
catch(e) catch (e) {
{
} }
} }
while (libs.length > 0) while (libs.length > 0) {
{ try {
try
{
libc = require('_GenericMarshal').CreateNativeProxy(libs.pop().path); libc = require('_GenericMarshal').CreateNativeProxy(libs.pop().path);
break; break;
} }
catch (e) catch (e) {
{
libc = null; libc = null;
continue; continue;
} }
@ -4228,16 +4169,13 @@ function bsd_execv(name, agentfilename, sessionid) {
sendAgentMessage('Self Update failed because execv() failed', 3); sendAgentMessage('Self Update failed because execv() failed', 3);
} }
function windows_execve(name, agentfilename, sessionid) function windows_execve(name, agentfilename, sessionid) {
{
var libc; var libc;
try try {
{
libc = require('_GenericMarshal').CreateNativeProxy('msvcrt.dll'); libc = require('_GenericMarshal').CreateNativeProxy('msvcrt.dll');
libc.CreateMethod('_wexecve'); libc.CreateMethod('_wexecve');
} }
catch (xx) catch (xx) {
{
sendConsoleText('Self Update failed because msvcrt.dll is missing', sessionid); sendConsoleText('Self Update failed because msvcrt.dll is missing', sessionid);
sendAgentMessage('Self Update failed because msvcrt.dll is missing', 3); sendAgentMessage('Self Update failed because msvcrt.dll is missing', 3);
return; return;

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.8.18", "version": "0.8.19",
"keywords": [ "keywords": [
"Remote Device Management", "Remote Device Management",
"Remote Device Monitoring", "Remote Device Monitoring",

File diff suppressed because it is too large Load Diff