mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-27 02:04:30 +03:00
1 line
6.0 KiB
JavaScript
1 line
6.0 KiB
JavaScript
var CreateAmtRedirect=function(e,o){var x={};function y(e){return String.fromCharCode.apply(null,e)}return((x.m=e).parent=x).authCookie=o,x.State=0,x.socket=null,x.host=null,x.port=0,x.user=null,x.pass=null,x.authuri="/RedirectionService",x.tlsv1only=0,x.inDataCount=0,x.connectstate=0,x.protocol=e.protocol,x.acc=null,x.amtsequence=1,x.amtkeepalivetimer=null,x.onStateChanged=null,x.Start=function(e,t,n,r,a){x.host=e,x.port=t,x.user=n,x.pass=r,x.connectstate=0,x.inDataCount=0;e=window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/webrelay.ashx?p=2&host="+e+"&port="+t+"&tls="+a+("*"==n?"&serverauth=1":"")+(void 0===r?"&serverauth=1&user="+n:"");null!=o&&""!=o&&(e+="&auth="+o),x.socket=new WebSocket(e),x.socket.binaryType="arraybuffer",x.socket.onopen=x.xxOnSocketConnected,x.socket.onmessage=x.xxOnMessage,x.socket.onclose=x.xxOnSocketClosed,x.xxStateChange(1)},x.xxOnSocketConnected=function(){x.xxStateChange(2),1==x.protocol&&x.directSend(new Uint8Array([16,0,0,0,83,79,76,32])),2==x.protocol&&x.directSend(new Uint8Array([16,1,0,0,75,86,77,82])),3==x.protocol&&x.directSend(new Uint8Array([16,0,0,0,73,68,69,82]))},x.xxOnMessage=function(e){if(e.data&&-1!=x.connectstate){if(x.inDataCount++,1==x.connectstate&&(2==x.protocol||3==x.protocol))return x.m.ProcessBinaryData?x.m.ProcessBinaryData(e.data):x.m.ProcessData(y(e.data));var t;for(null==x.acc?x.acc=e.data:((t=new Uint8Array(x.acc.byteLength+e.data.byteLength)).set(new Uint8Array(x.acc),0),t.set(new Uint8Array(e.data),x.acc.byteLength),x.acc=t.buffer);null!=x.acc&&1<=x.acc.byteLength;){var n=0,r=new Uint8Array(x.acc);switch(r[0]){case 17:if(r.byteLength<4)return;var a=r[1];if(0===a){if(r.byteLength<13)return;a=r[12];if(r.byteLength<13+a)return;x.directSend(new Uint8Array([19,0,0,0,0,0,0,0,0])),n=13+a}else x.Stop(1);break;case 20:if(r.byteLength<9)return;var o=new DataView(x.acc).getUint32(5,!0);if(r.byteLength<9+o)return;var a=r[1],c=r[4],s=[];for(i=0;i<o;i++)s.push(r[9+i]);var l=new Uint8Array(x.acc.slice(9,9+o)),n=9+o;if(0==c)0<=s.indexOf(4)?x.xxSend(String.fromCharCode(19,0,0,0,4)+IntToStrX(x.user.length+x.authuri.length+8)+String.fromCharCode(x.user.length)+x.user+String.fromCharCode(0,0)+String.fromCharCode(x.authuri.length)+x.authuri+String.fromCharCode(0,0,0,0)):x.Stop(2);else if(3!=c&&4!=c||1!=a)if(0==a)switch(x.protocol){case 1:x.xxSend(String.fromCharCode(32,0,0,0)+IntToStrX(x.amtsequence++)+ShortToStrX(1e4)+ShortToStrX(100)+ShortToStrX(0)+ShortToStrX(1e4)+ShortToStrX(100)+ShortToStrX(0)+IntToStrX(0));break;case 2:x.directSend(new Uint8Array([64,0,0,0,0,0,0,0]));break;case 3:x.connectstate=1,x.xxStateChange(3)}else x.Stop(3);else{var h=0,u=l[0],S=y(new Uint8Array(l.buffer.slice(1,1+u))),u=l[h+=u+1],d=y(new Uint8Array(l.buffer.slice(h+1,h+1+u))),u=(h+=u+1,null),f=function(e){for(var t="",n=0;n<e;n++)t+="abcdef0123456789".charAt(Math.floor(16*Math.random()));return t}(32),g="00000002",C="",l=(4==c&&(m=l[h],u=y(new Uint8Array(l.buffer.slice(h+1,h+1+m))),C=g+":"+f+":"+u+":"),hex_md5(hex_md5(x.user+":"+S+":"+x.pass)+":"+d+":"+C+hex_md5("POST:"+x.authuri))),h=x.user.length+S.length+d.length+x.authuri.length+f.length+g.length+l.length+7,m=(4==c&&(h+=u.length+1),String.fromCharCode(19,0,0,0,c)+IntToStrX(h)+String.fromCharCode(x.user.length)+x.user+String.fromCharCode(S.length)+S+String.fromCharCode(d.length)+d+String.fromCharCode(x.authuri.length)+x.authuri+String.fromCharCode(f.length)+f+String.fromCharCode(g.length)+g+String.fromCharCode(l.length)+l);4==c&&(m+=String.fromCharCode(u.length)+u),x.xxSend(m)}break;case 33:if(r.byteLength<23)break;n=23,x.xxSend(String.fromCharCode(39,0,0,0)+IntToStrX(x.amtsequence++)+String.fromCharCode(0,0,27,0,0,0)),1==x.protocol&&(x.amtkeepalivetimer=setInterval(x.xxSendAmtKeepAlive,2e3)),x.connectstate=1,x.xxStateChange(3);break;case 41:if(r.byteLength<10)break;n=10;break;case 42:if(r.byteLength<10)break;C=10+(r[9]<<8)+r[8];if(r.byteLength<C)break;x.m.ProcessBinaryData?x.m.ProcessBinaryData(new Uint8Array(r.buffer.slice(10,C))):x.m.ProcessData(y(new Uint8Array(r.buffer.slice(10,C)))),n=C;break;case 43:if(r.byteLength<8)break;n=8;break;case 65:if(r.byteLength<8)break;x.connectstate=1,x.m.Start(),8<r.byteLength&&(x.m.ProcessBinaryData?x.m.ProcessBinaryData(new Uint8Array(r.buffer.slice(8))):x.m.ProcessData(y(new Uint8Array(r.buffer.slice(8))))),n=r.byteLength;break;case 240:x.serverIsRecording=!0,n=1;break;default:return console.log("Unknown Intel AMT command: "+r[0]+" acclen="+r.byteLength),void x.Stop(4)}if(0==n)return;n!=x.acc.byteLength?x.acc=x.acc.slice(n):x.acc=null}}},x.directSend=function(e){try{x.socket.send(e.buffer)}catch(e){}},x.xxSend=function(e){if(null!=x.socket&&x.socket.readyState==WebSocket.OPEN){for(var t=new Uint8Array(e.length),n=0;n<e.length;++n)t[n]=e.charCodeAt(n);try{x.socket.send(t.buffer)}catch(e){}}},x.Send=x.send=function(e){null!=x.socket&&1==x.connectstate&&(1==x.protocol?x.xxSend(String.fromCharCode(40,0,0,0)+IntToStrX(x.amtsequence++)+ShortToStrX(e.length)+e):x.xxSend(e))},x.xxSendAmtKeepAlive=function(){null!=x.socket&&x.xxSend(String.fromCharCode(43,0,0,0)+IntToStrX(x.amtsequence++))},x.xxOnSocketClosed=function(){0==x.inDataCount&&0==x.tlsv1only?(x.tlsv1only=1,x.socket=new WebSocket(window.location.protocol.replace("http","ws")+"//"+window.location.host+window.location.pathname.substring(0,window.location.pathname.lastIndexOf("/"))+"/webrelay.ashx?p=2&host="+x.host+"&port="+x.port+"&tls="+x.tls+"&tls1only=1"+("*"==x.user?"&serverauth=1":"")+("undefined"==typeof pass?"&serverauth=1&user="+x.user:"")),x.socket.binaryType="arraybuffer",x.socket.onopen=x.xxOnSocketConnected,x.socket.onmessage=x.xxOnMessage,x.socket.onclose=x.xxOnSocketClosed):x.Stop(5)},x.xxStateChange=function(e){x.State!=e&&(x.State=e,x.m.xxStateChange(x.State),null!=x.onStateChanged&&x.onStateChanged(x,x.State))},x.Stop=function(e){x.xxStateChange(0),x.connectstate=-1,(x.acc=null)!=x.socket&&(x.socket.close(),x.socket=null),null!=x.amtkeepalivetimer&&(clearInterval(x.amtkeepalivetimer),x.amtkeepalivetimer=null)},x} |