From 0909f8cd8a4532036d8128171a6a85129815abd3 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 15 Nov 2019 14:36:41 -0800 Subject: [PATCH] Randomized Intel AMT Env Detection. --- package.json | 2 +- translate/translate.js | 2 +- webserver.js | 17 +++++++++++++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index fb080e2b..f040b0fd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.4.4-b", + "version": "0.4.4-c", "keywords": [ "Remote Management", "Intel AMT", diff --git a/translate/translate.js b/translate/translate.js index c5e51769..6c2bda67 100644 --- a/translate/translate.js +++ b/translate/translate.js @@ -462,7 +462,7 @@ function InstallModule(modulename, func, tag1, tag2) { if ((__dirname.endsWith('/node_modules/meshcentral')) || (__dirname.endsWith('\\node_modules\\meshcentral')) || (__dirname.endsWith('/node_modules/meshcentral/')) || (__dirname.endsWith('\\node_modules\\meshcentral\\'))) { parentpath = require('path').join(__dirname, '../..'); } // Looks like we need to keep a global reference to the child process object for this to work correctly. - InstallModuleChildProcess = child_process.exec('npm install --no-optional --save ' + modulename, { maxBuffer: 512000, timeout: 10000, cwd: parentpath }, function (error, stdout, stderr) { + InstallModuleChildProcess = child_process.exec('npm install --no-optional --save ' + modulename, { maxBuffer: 512000, timeout: 120000, cwd: parentpath }, function (error, stdout, stderr) { InstallModuleChildProcess = null; if ((error != null) && (error != '')) { console.log('ERROR: Unable to install required module "' + modulename + '". May not have access to npm, or npm may not have suffisent rights to load the new module. Try "npm install ' + modulename + '" to manualy install this module.\r\n'); diff --git a/webserver.js b/webserver.js index 759a5fbc..67702a91 100644 --- a/webserver.js +++ b/webserver.js @@ -1775,8 +1775,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { scriptFile.mescript = Buffer.from(scriptEngine.script_compile(runscript), 'binary').toString('base64'); scriptFile.scriptText = runscript; + // Randomize the environement detection + var randomDnsName; + do { randomDnsName = getRandomLowerCase(14); } while (randomDnsName == 'aabbccddeeffgg'); + var text = JSON.stringify(scriptFile, null, ' '); + for (var i = 0; i < 5; i++) { text = text.replace('aabbccddeeffgg', randomDnsName); } + // Send the script - func(Buffer.from(JSON.stringify(scriptFile, null, ' '))); + func(Buffer.from(text)); }); } else { // Server name is a hostname @@ -1800,8 +1806,14 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { scriptFile.mescript = Buffer.from(scriptEngine.script_compile(runscript), 'binary').toString('base64'); scriptFile.scriptText = runscript; + // Randomize the environement detection + var randomDnsName; + do { randomDnsName = getRandomLowerCase(14); } while (randomDnsName == 'aabbccddeeffgg'); + var text = JSON.stringify(scriptFile, null, ' '); + for (var i = 0; i < 5; i++) { text = text.replace('aabbccddeeffgg', randomDnsName); } + // Send the script - func(Buffer.from(JSON.stringify(scriptFile, null, ' '))); + func(Buffer.from(text)); }); } } @@ -3970,6 +3982,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) { function checkAmtPassword(p) { return (p.length > 7) && (/\d/.test(p)) && (/[a-z]/.test(p)) && (/[A-Z]/.test(p)) && (/\W/.test(p)); } function getRandomAmtPassword() { var p; do { p = Buffer.from(obj.crypto.randomBytes(9), 'binary').toString('base64').split('/').join('@'); } while (checkAmtPassword(p) == false); return p; } function getRandomPassword() { return Buffer.from(obj.crypto.randomBytes(9), 'binary').toString('base64').split('/').join('@'); } + function getRandomLowerCase(len) { var r = '', random = obj.crypto.randomBytes(len); for (var i = 0; i < len; i++) { r += String.fromCharCode(97 + (random[i] % 26)); } return r; } // Clean a IPv6 address that encodes a IPv4 address function cleanRemoteAddr(addr) { if (typeof addr != 'string') { return null; } if (addr.indexOf('::ffff:') == 0) { return addr.substring(7); } else { return addr; } }