Added Windows Security Center hooks
Bryan Roe committed
Jan 21, 2021 at 10:01 UTC
14c1a5f8608da22a1e69a784a6b89b1fb1bd1761
3 files changed
+238
-8
agents/meshcore.js
+36
-8
@@ -4147,14 +4147,17 @@ function createMeshCore(agent) {
4147
}
4148
4149
// Called periodically to check if we need to send updates to the server
4150
- function sendPeriodicServerUpdate(flags, force) {
4150
+ function sendPeriodicServerUpdate(flags, force)
4151
+ {
4152
if (meshServerConnectionState == 0) return; // Not connected to server, do nothing.
4153
if (!flags) { flags = 0xFFFFFFFF; }
4154
4155
// If we have a connected MEI, get Intel ME information
4155
- if ((flags & 1) && (amt != null) && (amt.state == 2)) {
4156
+ if ((flags & 1) && (amt != null) && (amt.state == 2))
4157
+ {
4158
delete meshCoreObj.intelamt;
4157
- amt.getMeiState(9, function (meinfo) {
4159
+ amt.getMeiState(9, function (meinfo)
4160
+ {
4161
meshCoreObj.intelamt = meinfo;
4162
meshCoreObj.intelamt.microlms = amt.lmsstate;
4163
meshCoreObjChanged();
@@ -4165,17 +4168,40 @@ function createMeshCore(agent) {
4168
if (flags & 2) { sendNetworkUpdateNagle(false); }
4169
4170
// Update anti-virus information
4168
- if ((flags & 4) && (process.platform == 'win32')) {
4171
+ if ((flags & 4) && (process.platform == 'win32'))
4172
+ {
4173
// Windows Command: "wmic /Namespace:\\root\SecurityCenter2 Path AntiVirusProduct get /FORMAT:CSV"
4174
try { meshCoreObj.av = require('win-info').av(); meshCoreObjChanged(); } catch (e) { av = null; } // Antivirus
4175
//if (process.platform == 'win32') { try { meshCoreObj.pr = require('win-info').pendingReboot(); meshCoreObjChanged(); } catch (e) { meshCoreObj.pr = null; } } // Pending reboot
4176
}
4177
+ if (process.platform == 'win32')
4178
+ {
4179
+ if(require('MeshAgent')._securitycenter == null)
4180
+ {
4181
+ try
4182
+ {
4183
+ require('MeshAgent')._securitycenter = require('win-securitycenter').status();
4184
+ meshCoreObj['windowsSecurityCenter'] = require('MeshAgent')._securitycenter;
4185
+ require('win-securitycenter').on('changed', function ()
4186
+ {
4187
+ require('MeshAgent')._securitycenter = require('win-securitycenter').status();
4188
+ meshCoreObj['windowsSecurityCenter'] = require('MeshAgent')._securitycenter;
4189
+ require('MeshAgent').SendCommand({ windowsSecurityCenter: require('MeshAgent')._securitycenter });
4190
+ });
4191
+ }
4192
+ catch(e)
4193
+ {
4194
+ }
4195
+ }
4196
+ }
4197
4198
// Send available data right now
4175
- if (force) {
4199
+ if (force)
4200
+ {
4201
meshCoreObj = sortObjRec(meshCoreObj);
4202
var x = JSON.stringify(meshCoreObj);
4178
- if (x != LastPeriodicServerUpdate) {
4203
+ if (x != LastPeriodicServerUpdate)
4204
+ {
4205
LastPeriodicServerUpdate = x;
4206
mesh.SendCommand(meshCoreObj);
4207
}
@@ -4186,11 +4212,13 @@ function createMeshCore(agent) {
4212
var LastPeriodicServerUpdate = null;
4213
var PeriodicServerUpdateNagleTimer = null;
4214
function meshCoreObjChanged() { if (PeriodicServerUpdateNagleTimer == null) { PeriodicServerUpdateNagleTimer = setTimeout(meshCoreObjChangedEx, 500); } }
4189
- function meshCoreObjChangedEx() {
4215
+ function meshCoreObjChangedEx()
4216
+ {
4217
PeriodicServerUpdateNagleTimer = null;
4218
meshCoreObj = sortObjRec(meshCoreObj);
4219
var x = JSON.stringify(meshCoreObj);
4193
- if (x != LastPeriodicServerUpdate) {
4220
+ if (x != LastPeriodicServerUpdate)
4221
+ {
4222
try { LastPeriodicServerUpdate = x; mesh.SendCommand(meshCoreObj); } catch (ex) { }
4223
}
4224
}
agents/modules_meshcmd/win-securitycenter.js
new
+101
@@ -0,0 +1,101 @@
1
+/*
2
+Copyright 2021 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+*/
16
+
17
+var seccenter = null;
18
+var WSC_SECURITY_PROVIDER_FIREWALL = 0x1;
19
+var WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS = 0x2;
20
+var WSC_SECURITY_PROVIDER_ANTIVIRUS = 0x4;
21
+var WSC_SECURITY_PROVIDER_ANTISPYWARE = 0x8;
22
+
23
+var WSC_SECURITY_PROVIDER_HEALTH_GOOD = 0; // Green pillar in English locales
24
+var WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED = 1; // Yellow pillar in English locales
25
+var WSC_SECURITY_PROVIDER_HEALTH_POOR = 2; // Red pillar in English locales
26
+var WSC_SECURITY_PROVIDER_HEALTH_SNOOZE = 3; // Yellow pillar in English locales
27
+
28
+try
29
+{
30
+ seccenter = require('_GenericMarshal').CreateNativeProxy('Wscapi.dll');
31
+ seccenter.CreateMethod('WscGetSecurityProviderHealth');
32
+ seccenter.CreateMethod('WscRegisterForChanges');
33
+ seccenter.CreateMethod('WscUnRegisterChanges');
34
+}
35
+catch(e)
36
+{
37
+}
38
+
39
+function statusString(val)
40
+{
41
+ var ret = 'UNKNOWN';
42
+
43
+ switch (val)
44
+ {
45
+ case 0:
46
+ ret = 'OK';
47
+ break;
48
+ case 1:
49
+ case 3:
50
+ ret = 'WARNING';
51
+ break;
52
+ case 2:
53
+ ret = 'PROBLEM';
54
+ break;
55
+ default:
56
+ ret = 'UNKNOWN';
57
+ break;
58
+ }
59
+ return (ret);
60
+}
61
+function getStatus()
62
+{
63
+ var ret = { firewall: 'UNKNOWN', antiVirus: 'UNKNOWN', autoUpdate: 'UNKNOWN' };
64
+ if (seccenter != null)
65
+ {
66
+ var status = require('_GenericMarshal').CreateVariable(4);
67
+ if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_FIREWALL, status).Val == 0) { ret.firewall = statusString(status.toBuffer().readUInt32LE()); }
68
+ if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ANTIVIRUS, status).Val == 0) { ret.antiVirus = statusString(status.toBuffer().readUInt32LE()); }
69
+ if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS, status).Val == 0) { ret.autoUpdate = statusString(status.toBuffer().readUInt32LE()); }
70
+ }
71
+ return (ret);
72
+}
73
+
74
+if (process.platform == 'win32' && seccenter != null)
75
+{
76
+ var j = { status: getStatus };
77
+ require('events').EventEmitter.call(j, true)
78
+ .createEvent('changed');
79
+ j._H = require('_GenericMarshal').CreatePointer();
80
+ j._EV = require('_GenericMarshal').GetGenericGlobalCallback(1);
81
+ j._EV.parent = j;
82
+ j._EV.on('GlobalCallback', function (p)
83
+ {
84
+ if (!this.ObjectToPtr_Verify(this.parent, p)) { return; } // This event is not for us
85
+ this.parent.emit('changed');
86
+ });
87
+ j.on('~', function ()
88
+ {
89
+ if (seccenter.WscUnRegisterChanges(this._H).Val == 0) { }
90
+ });
91
+
92
+ if (seccenter.WscRegisterForChanges(0, j._H, j._EV, require('_GenericMarshal').ObjectToPtr(j)).Val == 0)
93
+ {
94
+ j._H = j._H.Deref();
95
+ }
96
+ module.exports = j;
97
+}
98
+else
99
+{
100
+ throw ('win-securitycenter not supported on this platform');
101
+}
\ No newline at end of file
agents/modules_meshcore/win-securitycenter.js
new
+101
@@ -0,0 +1,101 @@
1
+/*
2
+Copyright 2021 Intel Corporation
3
+
4
+Licensed under the Apache License, Version 2.0 (the "License");
5
+you may not use this file except in compliance with the License.
6
+You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+Unless required by applicable law or agreed to in writing, software
11
+distributed under the License is distributed on an "AS IS" BASIS,
12
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+See the License for the specific language governing permissions and
14
+limitations under the License.
15
+*/
16
+
17
+var seccenter = null;
18
+var WSC_SECURITY_PROVIDER_FIREWALL = 0x1;
19
+var WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS = 0x2;
20
+var WSC_SECURITY_PROVIDER_ANTIVIRUS = 0x4;
21
+var WSC_SECURITY_PROVIDER_ANTISPYWARE = 0x8;
22
+
23
+var WSC_SECURITY_PROVIDER_HEALTH_GOOD = 0; // Green pillar in English locales
24
+var WSC_SECURITY_PROVIDER_HEALTH_NOTMONITORED = 1; // Yellow pillar in English locales
25
+var WSC_SECURITY_PROVIDER_HEALTH_POOR = 2; // Red pillar in English locales
26
+var WSC_SECURITY_PROVIDER_HEALTH_SNOOZE = 3; // Yellow pillar in English locales
27
+
28
+try
29
+{
30
+ seccenter = require('_GenericMarshal').CreateNativeProxy('Wscapi.dll');
31
+ seccenter.CreateMethod('WscGetSecurityProviderHealth');
32
+ seccenter.CreateMethod('WscRegisterForChanges');
33
+ seccenter.CreateMethod('WscUnRegisterChanges');
34
+}
35
+catch(e)
36
+{
37
+}
38
+
39
+function statusString(val)
40
+{
41
+ var ret = 'UNKNOWN';
42
+
43
+ switch (val)
44
+ {
45
+ case 0:
46
+ ret = 'OK';
47
+ break;
48
+ case 1:
49
+ case 3:
50
+ ret = 'WARNING';
51
+ break;
52
+ case 2:
53
+ ret = 'PROBLEM';
54
+ break;
55
+ default:
56
+ ret = 'UNKNOWN';
57
+ break;
58
+ }
59
+ return (ret);
60
+}
61
+function getStatus()
62
+{
63
+ var ret = { firewall: 'UNKNOWN', antiVirus: 'UNKNOWN', autoUpdate: 'UNKNOWN' };
64
+ if (seccenter != null)
65
+ {
66
+ var status = require('_GenericMarshal').CreateVariable(4);
67
+ if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_FIREWALL, status).Val == 0) { ret.firewall = statusString(status.toBuffer().readUInt32LE()); }
68
+ if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_ANTIVIRUS, status).Val == 0) { ret.antiVirus = statusString(status.toBuffer().readUInt32LE()); }
69
+ if (seccenter.WscGetSecurityProviderHealth(WSC_SECURITY_PROVIDER_AUTOUPDATE_SETTINGS, status).Val == 0) { ret.autoUpdate = statusString(status.toBuffer().readUInt32LE()); }
70
+ }
71
+ return (ret);
72
+}
73
+
74
+if (process.platform == 'win32' && seccenter != null)
75
+{
76
+ var j = { status: getStatus };
77
+ require('events').EventEmitter.call(j, true)
78
+ .createEvent('changed');
79
+ j._H = require('_GenericMarshal').CreatePointer();
80
+ j._EV = require('_GenericMarshal').GetGenericGlobalCallback(1);
81
+ j._EV.parent = j;
82
+ j._EV.on('GlobalCallback', function (p)
83
+ {
84
+ if (!this.ObjectToPtr_Verify(this.parent, p)) { return; } // This event is not for us
85
+ this.parent.emit('changed');
86
+ });
87
+ j.on('~', function ()
88
+ {
89
+ if (seccenter.WscUnRegisterChanges(this._H).Val == 0) { }
90
+ });
91
+
92
+ if (seccenter.WscRegisterForChanges(0, j._H, j._EV, require('_GenericMarshal').ObjectToPtr(j)).Val == 0)
93
+ {
94
+ j._H = j._H.Deref();
95
+ }
96
+ module.exports = j;
97
+}
98
+else
99
+{
100
+ throw ('win-securitycenter not supported on this platform');
101
+}
\ No newline at end of file