diff --git a/agents/meshcore.js b/agents/meshcore.js index fcf246df..f9d8dfd7 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -3067,7 +3067,7 @@ function createMeshCore(agent) { if (args['_'].length < 1) { response = 'Proper usage: eval "JavaScript code"'; // Display correct command usage } else { - response = JSON.stringify(mesh.eval(args['_'][0])); + response = JSON.stringify(mesh.eval(args['_'][0])); // This can only be run by trusted administrator. } break; } diff --git a/agents/modules_meshcore/amt-manage.js b/agents/modules_meshcore/amt-manage.js index e64eccfe..c8ed799a 100644 --- a/agents/modules_meshcore/amt-manage.js +++ b/agents/modules_meshcore/amt-manage.js @@ -560,14 +560,15 @@ function AmtManager(agent, db, isdebug) { // Activate Intel AMT to CCM // - function makePass(length) { - var text = "", possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; - for (var i = 0; i < length; i++) { text += possible.charAt(Math.floor(Math.random() * possible.length)); } + obj.makePass = function(length) { + var buf = Buffer.alloc(length), text = "", possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; + buf.randomFill(); // Fills buffer with secure random from OpenSSL. + for (var i = 0; i < length; i++) { text += possible.charAt(buf[i] % possible.length); } return text; } obj.activeToCCM = function (adminpass) { - if ((adminpass == null) || (adminpass == '')) { adminpass = 'P@0s' + makePass(23); } + if ((adminpass == null) || (adminpass == '')) { adminpass = 'P@0s' + obj.makePass(23); } intelAmtAdminPass = adminpass; if (osamtstack != null) { osamtstack.BatchEnum(null, ['*AMT_GeneralSettings', '*IPS_HostBasedSetupService'], activeToCCMEx2, adminpass); diff --git a/amt/amt-wsman-comm.js b/amt/amt-wsman-comm.js index 8e1c3042..7d1bb155 100644 --- a/amt/amt-wsman-comm.js +++ b/amt/amt-wsman-comm.js @@ -17,12 +17,6 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, parent, obj.noncecounter = 1; obj.authcounter = 0; - obj.Address = '/wsman'; - obj.challengeParams = null; - obj.noncecounter = 1; - obj.authcounter = 0; - obj.cnonce = Math.random().toString(36).substring(7); // Generate a random client nonce - obj.net = require('net'); obj.tls = require('tls'); obj.crypto = require('crypto'); @@ -32,6 +26,12 @@ var CreateWsmanComm = function (host, port, user, pass, tls, tlsoptions, parent, obj.kerberosDone = 0; obj.amtVersion = null; + obj.Address = '/wsman'; + obj.challengeParams = null; + obj.noncecounter = 1; + obj.authcounter = 0; + obj.cnonce = obj.crypto.randomBytes(16).toString('hex'); // Generate a random client nonce + obj.host = host; obj.port = port; obj.user = user; diff --git a/certoperations.js b/certoperations.js index 5cac4922..6a0e920e 100644 --- a/certoperations.js +++ b/certoperations.js @@ -307,7 +307,7 @@ module.exports.CertificateOperations = function (parent) { var keys = obj.pki.rsa.generateKeyPair({ bits: (strong == true) ? 3072 : 2048, e: 0x10001 }); var cert = obj.pki.createCertificate(); cert.publicKey = keys.publicKey; - cert.serialNumber = String(Math.floor((Math.random() * 100000) + 1)); + cert.serialNumber = require('crypto').randomInt(1, 100000); cert.validity.notBefore = new Date(2018, 0, 1); cert.validity.notAfter = new Date(2049, 11, 31); if (addThumbPrintToName === true) { commonName += '-' + obj.pki.getPublicKeyFingerprint(cert.publicKey, { encoding: 'hex' }).substring(0, 6); } @@ -329,7 +329,7 @@ module.exports.CertificateOperations = function (parent) { var keys = obj.pki.rsa.generateKeyPair({ bits: (strong == true) ? 3072 : 2048, e: 0x10001 }); var cert = obj.pki.createCertificate(); cert.publicKey = keys.publicKey; - cert.serialNumber = String(Math.floor((Math.random() * 100000) + 1)); + cert.serialNumber = require('crypto').randomInt(1, 100000); cert.validity.notBefore = new Date(2018, 0, 1); cert.validity.notAfter = new Date(2049, 11, 31); if (addThumbPrintToName === true) { commonName += "-" + obj.pki.getPublicKeyFingerprint(cert.publicKey, { encoding: 'hex' }).substring(0, 6); } diff --git a/common.js b/common.js index b925c9c4..376be61a 100644 --- a/common.js +++ b/common.js @@ -96,7 +96,7 @@ module.exports.data2blob = function (data) { }; // Generate random numbers -module.exports.random = function (max) { return Math.floor(Math.random() * max); }; +module.exports.random = function (max) { require('crypto').randomInt(0, max); }; // Split a comma seperated string, ignoring commas in quotes. module.exports.quoteSplit = function (str) { @@ -187,13 +187,6 @@ module.exports.checkPasswordRequirements = function(password, requirements) { // Limits the number of tasks running to a fixed limit placing the rest in a pending queue. // This is useful to limit the number of agents upgrading at the same time, to not swamp // the network with traffic. - -// taskLimiterQueue.launch(somethingToDo, argument, priority); -// -// function somethingToDo(argument, taskid, taskLimiterQueue) { -// setTimeout(function () { taskLimiterQueue.completed(taskid); }, Math.random() * 2000); -// } - module.exports.createTaskLimiterQueue = function (maxTasks, maxTaskTime, cleaningInterval) { var obj = { maxTasks: maxTasks, maxTaskTime: (maxTaskTime * 1000), nextTaskId: 0, currentCount: 0, current: {}, pending: [[], [], []], timer: null }; diff --git a/multiserver.js b/multiserver.js index 80ad6b5a..1857ece6 100644 --- a/multiserver.js +++ b/multiserver.js @@ -172,7 +172,7 @@ module.exports.CreateMultiServer = function (parent, args) { // Get the next retry time in milliseconds function getConnectRetryTime() { - if (obj.retryBackoff < 30000) { obj.retryBackoff += Math.floor((Math.random() * 3000) + 1000); } + if (obj.retryBackoff < 30000) { obj.retryBackoff += require('crypto').randomInt(1000, 4000); } return obj.retryBackoff; } diff --git a/views/default.handlebars b/views/default.handlebars index 971ad1dd..268a312d 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2301,27 +2301,23 @@ if (message.trustedCert == true) { // Trusted certificate, use HTTPS port. var rdpurl = window.location.origin + domainUrl + 'clickonce/minirouter/MeshMiniRouter.application?WS=wss%3A%2F%2F' + window.location.hostname + '%2Fmeshrelay.ashx%3Fauth=' + message.cookie + '&CH={{{webcerthash}}}&AP=' + message.protocol + ((debugmode == 1) ? '' : '&HOL=1'); - var newWindow = window.open(rdpurl, '_blank'); - newWindow.opener = null; + safeNewWindow(rdpurl, '_blank'); } else { // Not a trusted certificate, use HTTP port. var basicPort = ('{{{serverRedirPort}}}'.toLowerCase() == '') ? '{{{serverPublicPort}}}' : '{{{serverRedirPort}}}'; var rdpurl = 'http://' + window.location.hostname + ':' + basicPort + domainUrl + 'clickonce/minirouter/MeshMiniRouter.application?WS=wss%3A%2F%2F' + window.location.hostname + '%2Fmeshrelay.ashx%3Fauth=' + message.cookie + '&CH={{{webcerthash}}}&AP=' + message.protocol + ((debugmode == 1) ? '' : '&HOL=1'); - var newWindow = window.open(rdpurl, '_blank'); - newWindow.opener = null; + safeNewWindow(rdpurl, '_blank'); } } else if (message.tag == 'novnc') { var vncurl = window.location.origin + domainUrl + 'novnc/vnc.html?ws=wss%3A%2F%2F' + window.location.host + encodeURIComponentEx(domainUrl) + 'meshrelay.ashx%3Fauth%3D' + message.cookie + '&show_dot=1' + (urlargs.key?('&key=' + urlargs.key):'') + '&l={{{lang}}}'; var node = getNodeFromId(message.nodeid); if (node != null) { vncurl += '&name=' + encodeURIComponentEx(node.name); } - var newWindow = window.open(vncurl, 'mcnovnc/' + message.nodeid); - newWindow.opener = null; + safeNewWindow(vncurl, 'mcnovnc/' + message.nodeid); } else if (message.tag == 'mstsc') { var rdpurl = window.location.origin + domainUrl + 'mstsc.html?ws=' + message.cookie + (urlargs.key?('&key=' + urlargs.key):''); var node = getNodeFromId(message.nodeid); if (node != null) { rdpurl += '&name=' + encodeURIComponentEx(node.name); } - var newWindow = window.open(rdpurl, 'mcmstsc/' + message.nodeid); - newWindow.opener = null; + safeNewWindow(rdpurl, 'mcmstsc/' + message.nodeid); } break; } @@ -3014,7 +3010,7 @@ if (message.consent & 64) { y.push("Privacy bar"); } if (y.length == 0) { y.push("None"); } x += addHtmlValue("User Consent", y.join(', ')); - x += '
'; + x += ''; setDialogMode(2, "Share Device", 1, null, x); break; } @@ -4133,7 +4129,7 @@ x += '