From d519546a6c722f15b67b219f1bd7b29720f7176a Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 11 Aug 2022 17:37:42 -0700 Subject: [PATCH] Added support for changing the Windows agent bitmap logo within the executable. Agent needs to be changed to fully support this. --- authenticode.js | 1 + meshcentral.js | 57 ++++++++++++++++++++++++++++++++++++++++ views/default.handlebars | 3 ++- 3 files changed, 60 insertions(+), 1 deletion(-) diff --git a/authenticode.js b/authenticode.js index 5fffe240..821cf7ae 100644 --- a/authenticode.js +++ b/authenticode.js @@ -2482,4 +2482,5 @@ if (require.main === module) { start(); } module.exports.createAuthenticodeHandler = createAuthenticodeHandler; module.exports.loadCertificates = loadCertificates; module.exports.loadIcon = loadIcon; +module.exports.loadBitmap = loadBitmap; module.exports.hashObject = hashObject; \ No newline at end of file diff --git a/meshcentral.js b/meshcentral.js index 0c80d3dd..6f809491 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -1384,6 +1384,22 @@ function CreateMeshCentralServer(config, args) { // Invalid icon file path delete obj.config.domains[i].agentfileinfo.icon; } + if (typeof obj.config.domains[i].agentfileinfo.logo == 'string') { + // Load the agent .bmp file + var logo = null; + try { logo = require('./authenticode.js').loadBitmap(obj.path.join(obj.datapath, obj.config.domains[i].agentfileinfo.logo)); } catch (ex) { } + if (logo != null) { + // The logo file was correctly loaded + obj.config.domains[i].agentfileinfo.logo = logo; + } else { + // Failed to load the icon file, display a server warning + addServerWarning("Unable to load agent logo file: " + obj.config.domains[i].agentfileinfo.logo + ".", 24, [obj.config.domains[i].agentfileinfo.logo]); + delete obj.config.domains[i].agentfileinfo.logo; + } + } else { + // Invalid icon file path + delete obj.config.domains[i].agentfileinfo.logo; + } } } @@ -3022,6 +3038,35 @@ function CreateMeshCentralServer(config, args) { } } } + + // Check the agent logo + if (destinationAgentOk == true) { + if ((domain.agentfileinfo != null) && (domain.agentfileinfo.logo != null)) { + // Check if the destination agent matches the logo we want + const agentBitmaps = destinationAgent.getBitmapInfo(); + if (agentBitmaps != null) { + const agentBitmapNames = Object.keys(agentBitmaps); + if (agentBitmapNames.length > 0) { + const agentMainBitmap = agentBitmaps[agentBitmapNames[0]]; + const agentMainBitmapHash = require('./authenticode.js').hashObject(agentMainBitmap); + const bitmapHash = require('./authenticode.js').hashObject(domain.agentfileinfo.logo); + if (agentMainBitmapHash != bitmapHash) { destinationAgentOk = false; } // If the existing agent logo does not match the desired logo, we need to re-sign the agent. + } + } + } else { + // Check if the destination agent has the default icon + const agentBitmaps1 = destinationAgent.getBitmapInfo(); + const agentBitmaps2 = originalAgent.getBitmapInfo(); + const agentBitmapNames = Object.keys(agentBitmaps1); + if (agentBitmapNames.length == 0) { + destinationAgentOk = false; + } else { + const iconHash1 = require('./authenticode.js').hashObject(agentBitmaps1[agentBitmapNames[0]]); + const iconHash2 = require('./authenticode.js').hashObject(agentBitmaps2[agentBitmapNames[0]]); + if (iconHash1 != iconHash2) { destinationAgentOk = false; } // If the existing agent icon does not match the desired icon, we need to re-sign the agent. + } + } + } } // If everything looks ok, runs a hash of the original and destination agent .text, .data and .rdata sections. If different, sign the agent again. @@ -3084,6 +3129,18 @@ function CreateMeshCentralServer(config, args) { } } } + + // Change the agent logo + if (domain.agentfileinfo.logo != null) { + const agentBitmaps = originalAgent.getBitmapInfo(); + if (agentBitmaps != null) { + const agentBitmapNames = Object.keys(agentBitmaps); + if (agentBitmapNames.length > 0) { + agentBitmaps[agentBitmapNames[0]] = domain.agentfileinfo.logo; + originalAgent.setBitmapInfo(agentBitmaps); + } + } + } } const signingArguments = { out: signeedagentpath, desc: signDesc, url: signUrl, time: timeStampUrl, proxy: timeStampProxy }; // Shallow clone diff --git a/views/default.handlebars b/views/default.handlebars index 2e105332..aaa25a18 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2329,7 +2329,8 @@ 20: "Invalid \"LoginCookieEncryptionKey\" in config.json.", 21: "Backup path can't be set within meshcentral-data folder, backup settings ignored.", 22: "Failed to sign agent {0}: {1}", - 23: "Unable to load agent icon file: {0}." + 23: "Unable to load agent icon file: {0}.", + 24: "Unable to load agent logo file: {0}." }; var x = ''; for (var i in message.warnings) {