From 2189b92745f2fdb406b124598096e1c8a4299091 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 5 Jul 2022 22:12:11 -0700 Subject: [PATCH] Fixed Intel AMT server IDE-redirect session not closing correctly. --- amt/amt-ider-module.js | 4 ++-- amt/amt-ider.js | 6 +++--- amt/amt-redir-mesh.js | 16 ++++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/amt/amt-ider-module.js b/amt/amt-ider-module.js index 60483c1d..78be7d36 100644 --- a/amt/amt-ider-module.js +++ b/amt/amt-ider-module.js @@ -122,7 +122,7 @@ module.exports.CreateAmtRemoteIder = function (webserver, meshcentral) { } obj.Start = function () { - if (obj.debug) { console.log("IDER-Start"); console.log(obj.floppy, obj.cdrom); } + if (obj.debug) { console.log('IDER-Start'); console.log(obj.floppy, obj.cdrom); } obj.bytesToAmt = 0; obj.bytesFromAmt = 0; obj.inSequence = 0; @@ -143,7 +143,7 @@ module.exports.CreateAmtRemoteIder = function (webserver, meshcentral) { } obj.Stop = function () { - if (obj.debug) console.log("IDER-Stop"); + if (obj.debug) console.log('IDER-Stop'); //if (obj.pingTimer) { clearInterval(obj.pingTimer); obj.pingTimer = null; } obj.parent.Stop(); } diff --git a/amt/amt-ider.js b/amt/amt-ider.js index bc39e5ba..361e70a8 100644 --- a/amt/amt-ider.js +++ b/amt/amt-ider.js @@ -127,8 +127,8 @@ module.exports.CreateAmtIderSession = function (parent, db, ws, req, args, domai if ((command.args.floppyPath != null) && (typeof command.args.floppyPath != 'string')) { command.args.floppyPath = null; } else { command.args.floppyPath = decodeURIComponent(command.args.floppyPath); } if ((command.args.cdromPath != null) && (typeof command.args.cdromPath != 'string')) { command.args.cdromPath = null; } else { command.args.cdromPath = decodeURIComponent(command.args.cdromPath); } // TODO: Double check that "." or ".." are not used. - if ((command.args.floppyPath != null) && (command.args.floppyPath.indexOf("..") >= 0)) { delete command.args.floppyPath; } - if ((command.args.cdromPath != null) && (command.args.cdromPath.indexOf("..") >= 0)) { delete command.args.cdromPath; } + if ((command.args.floppyPath != null) && (command.args.floppyPath.indexOf('..') >= 0)) { delete command.args.floppyPath; } + if ((command.args.cdromPath != null) && (command.args.cdromPath.indexOf('..') >= 0)) { delete command.args.cdromPath; } // Get the disk image paths var domainx = 'domain' + ((domain.id == '') ? '' : ('-' + domain.id)); @@ -148,7 +148,7 @@ module.exports.CreateAmtIderSession = function (parent, db, ws, req, args, domai var iderError = obj.ider.m.diskSetup(floppyPath, cdromPath); // Error with the disk images, unable to start IDER - if (iderError != 0) { try { ws.send(JSON.stringify({ action: "error", code: iderError })); } catch (ex) { } break; } + if (iderError != 0) { try { ws.send(JSON.stringify({ action: 'error', code: iderError })); } catch (ex) { } break; } // Start the IDER session obj.ider.Start(req.query.host, req.query.port, req.query.tls); diff --git a/amt/amt-redir-mesh.js b/amt/amt-redir-mesh.js index cdc49342..1b624349 100644 --- a/amt/amt-redir-mesh.js +++ b/amt/amt-redir-mesh.js @@ -479,16 +479,12 @@ module.exports.CreateAmtRedirect = function (module, domain, user, webserver, me obj.xxSend = function (x) { if (typeof x == 'string') { - //if (obj.redirTrace) { - //console.log("REDIR-SEND1(" + x.length + "): " + Buffer.from(x, 'binary').toString('hex'), typeof x); - //} + if (obj.redirTrace) { console.log("REDIR-SEND(" + x.length + "): " + Buffer.from(x, 'binary').toString('hex'), typeof x); } //obj.Debug("Send(" + x.length + "): " + webserver.common.rstr2hex(x)); //obj.forwardclient.write(x); // FIXES CIRA obj.forwardclient.write(Buffer.from(x, 'binary')); } else { - //if (obj.redirTrace) { - //console.log("REDIR-SEND2(" + x.length + "): " + x.toString('hex'), typeof x); - //} + if (obj.redirTrace) { console.log("REDIR-SEND(" + x.length + "): " + x.toString('hex'), typeof x); } //obj.Debug("Send(" + x.length + "): " + webserver.common.rstr2hex(x)); //obj.forwardclient.write(x); // FIXES CIRA obj.forwardclient.write(x); @@ -508,7 +504,7 @@ module.exports.CreateAmtRedirect = function (module, domain, user, webserver, me obj.xxRandomValueHex = function(len) { return obj.crypto.randomBytes(Math.ceil(len / 2)).toString('hex').slice(0, len); } obj.xxOnSocketClosed = function () { - if (obj.redirTrace) { console.log("REDIR-CLOSED"); } + if (obj.redirTrace) { console.log('REDIR-CLOSED'); } //obj.Debug("Socket Closed"); obj.Stop(); } @@ -521,12 +517,12 @@ module.exports.CreateAmtRedirect = function (module, domain, user, webserver, me } obj.Stop = function () { - if (obj.redirTrace) { console.log("REDIR-CLOSED"); } + if (obj.redirTrace) { console.log('REDIR-CLOSED'); } //obj.Debug("Socket Stopped"); obj.xxStateChange(0); obj.connectstate = -1; - obj.amtaccumulator = ""; - if (obj.forwardclient != null) { try { obj.forwardclient.close(); } catch (ex) { } delete obj.forwardclient; } + obj.amtaccumulator = ''; + if (obj.forwardclient != null) { try { obj.forwardclient.destroy(); } catch (ex) { } delete obj.forwardclient; } if (obj.amtkeepalivetimer != null) { clearInterval(obj.amtkeepalivetimer); delete obj.amtkeepalivetimer; } }