From ba78910fc9c614bf1e787bc8d844566087788de5 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 5 Aug 2019 11:30:07 -0700 Subject: [PATCH] Fixed AV status on Windows Server, started work on session recording --- agents/meshcore.js | 4 +- agents/meshcore.min.js | 4 +- agents/modules_meshcore/win-info.js | 2 + agents/modules_meshcore_min/win-info.min.js | 2 +- meshcentral.js | 2 + meshrelay.js | 54 +++++++++++++++++---- package.json | 2 +- views/default-min.handlebars | 2 +- views/default.handlebars | 9 ++-- 9 files changed, 61 insertions(+), 20 deletions(-) diff --git a/agents/meshcore.js b/agents/meshcore.js index 3ff349dc..6b93e891 100644 --- a/agents/meshcore.js +++ b/agents/meshcore.js @@ -2241,8 +2241,8 @@ function createMeshCore(agent) if ((flags & 4) && (process.platform == 'win32')) { // Update anti-virus information - var av = []; - //try { av = require('win-info').av(); } catch (ex) { av = [ { product: 'Error', updated: false, enabled: false } ]; } + var av; + try { av = require('win-info').av(); } catch (ex) { av = []; } if ((meshCoreObj.av == null) || (JSON.stringify(meshCoreObj.av) != JSON.stringify(av))) { meshCoreObj.av = av; mesh.SendCommand(meshCoreObj); } } } diff --git a/agents/meshcore.min.js b/agents/meshcore.min.js index 3ff349dc..6b93e891 100644 --- a/agents/meshcore.min.js +++ b/agents/meshcore.min.js @@ -2241,8 +2241,8 @@ function createMeshCore(agent) if ((flags & 4) && (process.platform == 'win32')) { // Update anti-virus information - var av = []; - //try { av = require('win-info').av(); } catch (ex) { av = [ { product: 'Error', updated: false, enabled: false } ]; } + var av; + try { av = require('win-info').av(); } catch (ex) { av = []; } if ((meshCoreObj.av == null) || (JSON.stringify(meshCoreObj.av) != JSON.stringify(av))) { meshCoreObj.av = av; mesh.SendCommand(meshCoreObj); } } } diff --git a/agents/modules_meshcore/win-info.js b/agents/modules_meshcore/win-info.js index fae48adc..f14e6beb 100644 --- a/agents/modules_meshcore/win-info.js +++ b/agents/modules_meshcore/win-info.js @@ -20,6 +20,7 @@ function qfe() { var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', 'qfe', 'list', 'full', '/FORMAT:CSV']); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }); child.waitExit(); var lines = child.stdout.str.trim().split('\r\n'); @@ -44,6 +45,7 @@ function av() { var child = require('child_process').execFile(process.env['windir'] + '\\System32\\wbem\\wmic.exe', ['wmic', '/Namespace:\\\\root\\SecurityCenter2', 'Path', 'AntiVirusProduct', 'get', '/FORMAT:CSV']); child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); + child.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); }) child.waitExit(); var lines = child.stdout.str.trim().split('\r\n'); diff --git a/agents/modules_meshcore_min/win-info.min.js b/agents/modules_meshcore_min/win-info.min.js index 600d2f5e..ef3c8e5f 100644 --- a/agents/modules_meshcore_min/win-info.min.js +++ b/agents/modules_meshcore_min/win-info.min.js @@ -1 +1 @@ -var promise=require("promise");function qfe(){var a=require("child_process").execFile(process.env.windir+"\\System32\\wbem\\wmic.exe",["wmic","qfe","list","full","/FORMAT:CSV"]);a.stdout.str="";a.stdout.on("data",function(i){this.str+=i.toString()});a.waitExit();var e=a.stdout.str.trim().split("\r\n");var d=e[0].split(",");var b,c;var h;var g=[];for(b=1;b ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ')'); // Log the connection - if (user) { - var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: user._id, username: parent.users[user._id].name, msg: 'Started relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) }; + if (sessionUser) { + var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: sessionUser._id, username: sessionUser.name, msg: 'Started relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) }; parent.parent.DispatchEvent(['*', user._id], obj, event); - } else if (obj.peer.user) { - var event = { etype: 'relay', action: 'relaylog', domain: domain.id, userid: obj.peer.user._id, username: parent.users[obj.peer.user._id].name, msg: 'Started relay session \"' + obj.id + '\" from ' + cleanRemoteAddr(obj.peer.ws._socket.remoteAddress) + ' to ' + cleanRemoteAddr(ws._socket.remoteAddress) }; - parent.parent.DispatchEvent(['*', obj.peer.user._id], obj, event); } } else { // Connected already, drop (TODO: maybe we should re-connect?) @@ -215,7 +229,25 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie //if (typeof data == 'string') { console.log('Relay: ' + data); } else { console.log('Relay:' + data.length + ' byte(s)'); } try { this._socket.pause(); - this.peer.send(data, ws.flushSink); + if ((this.logfile != null) && (this.logfile.lock == false)) { + // Write data to log file then perform relay + /* + var xthis = this; + console.log('Write', data.length, typeof data, data); + this.logfile.lock = true; + try { + parent.parent.fs.write(this.logfile.fd, data, function (err, bytesWritten, buffer) { + xthis.logfile.lock = false; + console.log('WriteDone', err, bytesWritten, buffer.length); + xthis.peer.send(data, ws.flushSink); + }); + } catch (ex) { console.log(ex); } + */ + this.peer.send(data, ws.flushSink); + } else { + // Perform relay + this.peer.send(data, ws.flushSink); + } } catch (ex) { console.log(ex); } } }); @@ -240,8 +272,12 @@ module.exports.CreateMeshRelay = function (parent, ws, req, domain, user, cookie var relayinfo = parent.wsrelays[obj.id]; if (relayinfo != null) { if (relayinfo.state == 2) { - // Disconnect the peer var peer = (relayinfo.peer1 == obj) ? relayinfo.peer2 : relayinfo.peer1; + + // Close the recording file + if (ws.logfile != null) { console.log('CloseLog'); parent.parent.fs.close(ws.logfile.fd); ws.logfile = null; peer.ws.logfile = null; } + + // Disconnect the peer try { if (peer.relaySessionCounted) { parent.relaySessionCount--; delete peer.relaySessionCounted; } } catch (ex) { console.log(ex); } parent.parent.debug(1, 'Relay disconnect: ' + obj.id + ' (' + cleanRemoteAddr(ws._socket.remoteAddress) + ' --> ' + cleanRemoteAddr(peer.ws._socket.remoteAddress) + ')'); try { peer.ws.close(); } catch (e) { } // Soft disconnect diff --git a/package.json b/package.json index 44ded550..cd1d1ed1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.3.9-c", + "version": "0.3.9-e", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default-min.handlebars b/views/default-min.handlebars index c9a076d0..1a1a0846 100644 --- a/views/default-min.handlebars +++ b/views/default-min.handlebars @@ -1 +1 @@ - {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file + {{{title}}}
{{{title}}}
{{{title2}}}

{{{logoutControl}}}

 

\ No newline at end of file diff --git a/views/default.handlebars b/views/default.handlebars index ac23e579..cc9ec051 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -4907,12 +4907,13 @@ if (e.shiftKey == true) { enterBrowserFullscreen(Q('deskarea0')); browserfullscreen = true; } } else { QC('body').remove("fulldesk"); - exitBrowserFullscreen(); - browserfullscreen = false; - toggleFullScreen(); + if (browserfullscreen == true) { + exitBrowserFullscreen(); + browserfullscreen = false; + toggleFullScreen(); + } } deskAdjust(); - //deskAdjust(); updateDesktopButtons(); }