Improved Raritan IP-KVM port security.
Ylian Saint-Hilaire committed
Jan 1, 2022 at 14:41 UTC
8e04955b38a8d1f7ec920c757a8fccd9f1496449
1 file changed
+15
-2
meshipkvm.js
+15
-2
@@ -654,7 +654,7 @@ function CreateRaritanKX3Manager(parent, hostname, port, username, password) {
654
reqinfo.kvmport.wsClient.on('open', function () {
655
parent.parent.debug('relay', 'IPKVM: Relay websocket open');
656
this.wsBrowser.on('message', function (data) {
657
- //console.log('KVM browser data', data, data.toString());
657
+ //console.log('KVM browser data', data.toString('hex'), data.toString('utf8'));
658
659
// Replace the authentication command that used the dummy cookie with a command that has the correct hash
660
if ((this.xAuthNonce != null) && (this.xAuthNonce != 1) && (data.length == 67) && (data[0] == 0x21) && (data[1] == 0x41)) {
@@ -666,6 +666,19 @@ function CreateRaritanKX3Manager(parent, hostname, port, username, password) {
666
this.xAuthNonce = 1;
667
}
668
669
+ // Check the port name
670
+ if ((data[0] == 0x89) && (data.length > 4)) {
671
+ const portNameLen = (data[2] << 8) + data[3];
672
+ if (data.length == (4 + portNameLen)) {
673
+ const portName = data.slice(4).toString('utf8');
674
+ if (reqinfo.kvmport.portid != portName) {
675
+ // The browser required an unexpected port for remote control, disconnect not.
676
+ try { this._socket.close(); } catch (ex) { }
677
+ return;
678
+ }
679
+ }
680
+ }
681
+
682
try { this.wsClient.kvmport.bytesOut += data.length; } catch (ex) { }
683
this._socket.pause();
684
try { this.wsClient.send(data); } catch (ex) { }
@@ -694,7 +707,7 @@ function CreateRaritanKX3Manager(parent, hostname, port, username, password) {
707
this.wsBrowser._socket.resume();
708
});
709
reqinfo.kvmport.wsClient.on('message', function (data) { // Make sure to handle flow control.
697
- //console.log('KVM switch data', data, data.length, data.toString());
710
+ //console.log('KVM switch data', data, data.length, data.toString('hex'));
711
712
// If the data start with 0x21 and 0x41 followed by {SHA256}, store the authenticate nonce
713
if ((this.wsBrowser.xAuthNonce == null) && (data.length == 67) && (data[0] == 0x21) && (data[1] == 0x41) && (data[2] == 0x7b) && (data[3] == 0x53) && (data[4] == 0x48)) {