MeshCMD is now signed using the MeshCentral code signing cert.
Ylian Saint-Hilaire committed
Aug 31, 2022 at 01:36 UTC
d4d1f7d45471bd32a54ee0035dd162bfe2316e56
4 files changed
+24
-16
agents/MeshCmd.exe
renamed
Binary files a/agents/MeshCmd-signed.exe and b/agents/MeshCmd.exe differ
agents/MeshCmd64.exe
renamed
Binary files a/agents/MeshCmd64-signed.exe and b/agents/MeshCmd64.exe differ
meshcentral.js
+16
-10
@@ -2899,8 +2899,12 @@ function CreateMeshCentralServer(config, args) {
2899
37: { id: 37, localname: 'meshagent_openbsd_x86-64', rname: 'meshagent', desc: 'OpenBSD x86-64', update: true, amt: false, platform: 'linux', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery', tcore: 'linux-tiny' }, // OpenBSD x86-64
2900
40: { id: 40, localname: 'meshagent_mipsel24kc', rname: 'meshagent', desc: 'Linux MIPSEL24KC (OpenWRT)', update: true, amt: false, platform: 'linux', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery', tcore: 'linux-tiny' }, // MIPS Router with OpenWRT
2901
41: { id: 41, localname: 'meshagent_aarch64-cortex-a53', rname: 'meshagent', desc: 'ARMADA/CORTEX-A53/MUSL (OpenWRT)', update: true, amt: false, platform: 'linux', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery', tcore: 'linux-tiny' }, // OpenWRT Routers
2902
+ 10003: { id: 10003, localname: 'MeshService.exe', rname: 'meshagent32.exe', desc: 'Windows x86-32 service', update: true, amt: true, platform: 'win32', core: 'windows-amt', rcore: 'windows-recovery', arcore: 'windows-agentrecovery', tcore: 'windows-tiny', unsigned: true },
2903
+ 10004: { id: 10004, localname: 'MeshService64.exe', rname: 'meshagent64.exe', desc: 'Windows x86-64 service', update: true, amt: true, platform: 'win32', core: 'windows-amt', rcore: 'windows-recovery', arcore: 'windows-agentrecovery', tcore: 'windows-tiny', unsigned: true },
2904
10005: { id: 10005, localname: 'meshagent_osx-universal-64', rname: 'meshagent', desc: 'Apple macOS Universal Binary', update: true, amt: false, platform: 'osx', core: 'linux-noamt', rcore: 'linux-recovery', arcore: 'linux-agentrecovery', tcore: 'linux-tiny' }, // Apple Silicon + x86 universal binary
2903
- 10006: { id: 10006, localname: 'MeshCentralAssistant.exe', rname: 'MeshCentralAssistant.exe', desc: 'MeshCentral Assistant for Windows', update: false, amt: false, platform: 'win32' } // MeshCentral Assistant
2905
+ 10006: { id: 10006, localname: 'MeshCentralAssistant.exe', rname: 'MeshCentralAssistant.exe', desc: 'MeshCentral Assistant for Windows', update: false, amt: false, platform: 'win32' }, // MeshCentral Assistant
2906
+ 11000: { id: 11000, localname: 'MeshCmd.exe', rname: 'MeshCmd.exe', desc: 'Windows x86-32 meshcmd', update: false, amt: true, platform: 'win32', codesign: true }, // MeshCMD for Windows 32-bit
2907
+ 11001: { id: 11001, localname: 'MeshCmd64.exe', rname: 'MeshCmd64.exe', desc: 'Windows x86-64 meshcmd', update: false, amt: true, platform: 'win32', codesign: true } // MeshCMD for Windows 64-bit
2908
};
2909
2910
// Sign windows agents
@@ -2965,7 +2969,7 @@ function CreateMeshCentralServer(config, args) {
2969
if (obj.fs.existsSync(agentpath2)) { agentpath = agentpath2; delete obj.meshAgentsArchitectureNumbers[archid].codesign; } // If the agent is present in "meshcentral-data/agents", use that one instead.
2970
} else {
2971
// When processing an extra domain, only load agents that are specific to that domain
2968
- var agentpath = obj.path.join(obj.datapath, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
2972
+ agentpath = obj.path.join(obj.datapath, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
2973
if (obj.fs.existsSync(agentpath)) { delete obj.meshAgentsArchitectureNumbers[archid].codesign; } else { continue; } // If the agent is not present in "meshcentral-data/agents" skip.
2974
}
2975
@@ -3093,10 +3097,10 @@ function CreateMeshCentralServer(config, args) {
3097
const xagentSignedFunc = function agentSignedFunc(err, size) {
3098
if (err == null) {
3099
// Agent was signed succesfuly
3096
- console.log(obj.common.format('Code signed agent {0}.', agentSignedFunc.objx.meshAgentsArchitectureNumbers[agentSignedFunc.archid].localname));
3100
+ console.log(obj.common.format('Code signed {0}.', agentSignedFunc.objx.meshAgentsArchitectureNumbers[agentSignedFunc.archid].localname));
3101
} else {
3102
// Failed to sign agent
3099
- addServerWarning('Failed to sign agent \"' + agentSignedFunc.objx.meshAgentsArchitectureNumbers[agentSignedFunc.archid].localname + '\": ' + err, 22, [ agentSignedFunc.objx.meshAgentsArchitectureNumbers[agentSignedFunc.archid].localname, err ]);
3103
+ addServerWarning('Failed to sign \"' + agentSignedFunc.objx.meshAgentsArchitectureNumbers[agentSignedFunc.archid].localname + '\": ' + err, 22, [ agentSignedFunc.objx.meshAgentsArchitectureNumbers[agentSignedFunc.archid].localname, err ]);
3104
}
3105
if (--pendingOperations === 0) { agentSignedFunc.func(); }
3106
}
@@ -3153,7 +3157,7 @@ function CreateMeshCentralServer(config, args) {
3157
}
3158
3159
const signingArguments = { out: signeedagentpath, desc: signDesc, url: signUrl, time: timeStampUrl, proxy: timeStampProxy }; // Shallow clone
3156
- obj.debug('main', "Code signing agent with arguments: " + JSON.stringify(signingArguments));
3160
+ obj.debug('main', "Code signing with arguments: " + JSON.stringify(signingArguments));
3161
if (resChanges == false) {
3162
// Sign the agent the simple way, without changing any resources.
3163
originalAgent.sign(agentSignCertInfo, signingArguments, xagentSignedFunc);
@@ -3200,13 +3204,15 @@ function CreateMeshCentralServer(config, args) {
3204
if (domain.id == '') {
3205
// Load all agents when processing the default domain
3206
agentpath = obj.path.join(__dirname, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3203
- const agentpath2 = obj.path.join(obj.datapath, 'signedagents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3204
- if (obj.fs.existsSync(agentpath2)) { agentpath = agentpath2; } // If the agent is present in "meshcentral-data/signedagents", use that one instead.
3205
- const agentpath3 = obj.path.join(obj.datapath, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3206
- if (obj.fs.existsSync(agentpath3)) { agentpath = agentpath3; } // If the agent is present in "meshcentral-data/agents", use that one instead.
3207
+ if (obj.meshAgentsArchitectureNumbers[archid].unsigned !== true) {
3208
+ const agentpath2 = obj.path.join(obj.datapath, 'signedagents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3209
+ if (obj.fs.existsSync(agentpath2)) { agentpath = agentpath2; } // If the agent is present in "meshcentral-data/signedagents", use that one instead.
3210
+ const agentpath3 = obj.path.join(obj.datapath, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3211
+ if (obj.fs.existsSync(agentpath3)) { agentpath = agentpath3; } // If the agent is present in "meshcentral-data/agents", use that one instead.
3212
+ }
3213
} else {
3214
// When processing an extra domain, only load agents that are specific to that domain
3209
- var agentpath = obj.path.join(obj.datapath, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3215
+ agentpath = obj.path.join(obj.datapath, 'agents' + suffix, obj.meshAgentsArchitectureNumbers[archid].localname);
3216
if (obj.fs.existsSync(agentpath)) { delete obj.meshAgentsArchitectureNumbers[archid].codesign; } else { continue; } // If the agent is not present in "meshcentral-data/agents" skip.
3217
}
3218
webserver.js
+8
-6
@@ -5237,19 +5237,20 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
5237
5238
// Send meshcmd for a specific platform back
5239
var agentid = parseInt(req.query.meshcmd);
5240
+
5241
// If the agentid is 3 or 4, check if we have a signed MeshCmd.exe
5241
- if ((agentid == 3)) { // Signed Windows MeshCmd.exe x86
5242
- var stats = null, meshCmdPath = obj.path.join(__dirname, 'agents', 'MeshCmd-signed.exe');
5242
+ if ((agentid == 3) && (obj.parent.meshAgentBinaries[11000] != null)) { // Signed Windows MeshCmd.exe x86
5243
+ var stats = null, meshCmdPath = obj.parent.meshAgentBinaries[11000].path;
5244
try { stats = obj.fs.statSync(meshCmdPath); } catch (e) { }
5245
if ((stats != null)) {
5245
- setContentDispositionHeader(res, 'application/octet-stream', 'meshcmd' + ((req.query.meshcmd <= 3) ? '.exe' : ''), null, 'meshcmd');
5246
+ setContentDispositionHeader(res, 'application/octet-stream', 'meshcmd.exe', null, 'meshcmd');
5247
res.sendFile(meshCmdPath); return;
5248
}
5248
- } else if ((agentid == 4)) { // Signed Windows MeshCmd64.exe x64
5249
- var stats = null, meshCmd64Path = obj.path.join(__dirname, 'agents', 'MeshCmd64-signed.exe');
5249
+ } else if ((agentid == 4) && (obj.parent.meshAgentBinaries[11001] != null)) { // Signed Windows MeshCmd64.exe x64
5250
+ var stats = null, meshCmd64Path = obj.parent.meshAgentBinaries[11001].path;
5251
try { stats = obj.fs.statSync(meshCmd64Path); } catch (e) { }
5252
if ((stats != null)) {
5252
- setContentDispositionHeader(res, 'application/octet-stream', 'meshcmd' + ((req.query.meshcmd <= 4) ? '.exe' : ''), null, 'meshcmd');
5253
+ setContentDispositionHeader(res, 'application/octet-stream', 'meshcmd.exe', null, 'meshcmd');
5254
res.sendFile(meshCmd64Path); return;
5255
}
5256
}
@@ -5267,6 +5268,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
5268
res.sendFile(argentInfo.signedMeshCmdPath);
5269
} else {
5270
// Merge JavaScript to a unsigned agent and send that.
5271
+ console.log('aa', argentInfo.path);
5272
obj.parent.exeHandler.streamExeWithJavaScript({ platform: argentInfo.platform, sourceFileName: argentInfo.path, destinationStream: res, js: Buffer.from(obj.parent.defaultMeshCmd, 'utf8'), peinfo: argentInfo.pe });
5273
}
5274
return;