Added windows COM/WMI support for enumerating volumes and bitlocker status
Bryan Roe committed
Mar 14, 2022 at 22:43 UTC
7db4a57f41a347cb7536bbed7e42f7a1e57b1a77
2 files changed
+59
-1
agents/meshcore.js
+4
-1
@@ -3238,7 +3238,7 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3238
var fin = '', f = '', availcommands = 'translations,agentupdate,errorlog,msh,timerinfo,coreinfo,coredump,service,fdsnapshot,fdcount,startupoptions,alert,agentsize,versions,help,info,osinfo,args,print,type,dbkeys,dbget,dbset,dbcompact,eval,parseuri,httpget,wslist,plugin,wsconnect,wssend,wsclose,notify,ls,ps,kill,netinfo,location,power,wakeonlan,setdebug,smbios,rawsmbios,toast,lock,users,openurl,getscript,getclip,setclip,log,av,cpuinfo,sysinfo,apf,scanwifi,wallpaper,agentmsg,task';
3239
if (require('os').dns != null) { availcommands += ',dnsinfo'; }
3240
try { require('linux-dhcp'); availcommands += ',dhcp'; } catch (ex) { }
3241
- if (process.platform == 'win32') { availcommands += ',cs,safemode,wpfhwacceleration,uac'; }
3241
+ if (process.platform == 'win32') { availcommands += ',cs,safemode,wpfhwacceleration,uac,volumes'; }
3242
if (amt != null) { availcommands += ',amt,amtconfig,amtevents'; }
3243
if (process.platform != 'freebsd') { availcommands += ',vm'; }
3244
if (require('MeshAgent').maxKvmTileSize != null) { availcommands += ',kvmmode'; }
@@ -3257,6 +3257,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
3257
response = JSON.stringify(coretranslations, null, 2);
3258
break;
3259
}
3260
+ case 'volumes':
3261
+ response = JSON.stringify(require('win-volumes').getVolumes(), null, 1);
3262
+ break;
3263
case 'dhcp': // This command is only supported on Linux, this is because Linux does not give us the DNS suffix for each network adapter independently so we have to ask the DHCP server.
3264
{
3265
try { require('linux-dhcp'); } catch (ex) { response = 'Unknown command "dhcp", type "help" for list of avaialble commands.'; break; }
agents/modules_meshcore/win-volumes.js
new
+55
@@ -0,0 +1,55 @@
1
+/*
2
+Copyright 2022 Intel Corporation
3
+@author Bryan Roe
4
+
5
+Licensed under the Apache License, Version 2.0 (the "License");
6
+you may not use this file except in compliance with the License.
7
+You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+Unless required by applicable law or agreed to in writing, software
12
+distributed under the License is distributed on an "AS IS" BASIS,
13
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+See the License for the specific language governing permissions and
15
+limitations under the License.
16
+
17
+*/
18
+
19
+function trimObject(j)
20
+{
21
+ var i;
22
+ for(i in j)
23
+ {
24
+ if (j[i] == null || (typeof(j[i])=='string' && j[i]=='') || i.startsWith('__')) { delete j[i];}
25
+ }
26
+ if (j['SerialNumber'] < 0) { var tmp = Buffer.alloc(4); tmp.writeInt32LE(j['SerialNumber']); j['SerialNumber'] = tmp.readUInt32LE(); }
27
+ return (j);
28
+}
29
+
30
+
31
+function getVolumes()
32
+{
33
+ var v = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_Volume');
34
+ var i;
35
+
36
+ var ret = {};
37
+
38
+ for (i in v)
39
+ {
40
+ ret[v[i].DeviceID] = trimObject(v[i]);
41
+ }
42
+
43
+ v = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume');
44
+ for (i in v)
45
+ {
46
+ var tmp = trimObject(v[i]);
47
+ for (var k in tmp)
48
+ {
49
+ ret[tmp.DeviceID][k] = tmp[k];
50
+ }
51
+ }
52
+ return (ret);
53
+}
54
+
55
+module.exports = { getVolumes: function () { try { return (getVolumes()); } catch (x) { return ({}); } } };
\ No newline at end of file