move windows_volumes and bitlocker to win-volumes
Signed-off-by: si458 <simonsmith5521@gmail.com>
si458 committed
Dec 6, 2024 at 13:56 UTC
624d61db435d0dcf52d01f51de5ccd54639453ec
3 files changed
+86
-95
agents/meshcore.js
+4
-12
@@ -1936,9 +1936,9 @@ function getSystemInformation(func) {
1936
if (process.platform == 'win32')
1937
{
1938
results.pendingReboot = require('win-info').pendingReboot(); // Pending reboot
1939
- if (require('computer-identifiers').volumes_promise != null)
1939
+ if (require('win-volumes').volumes_promise != null)
1940
{
1941
- var p = require('computer-identifiers').volumes_promise();
1941
+ var p = require('win-volumes').volumes_promise();
1942
p.then(function (res)
1943
{
1944
results.hardware.windows.volumes = cleanGetBitLockerVolumeInfo(res);
@@ -1946,12 +1946,6 @@ function getSystemInformation(func) {
1946
func(results);
1947
});
1948
}
1949
- else if (require('computer-identifiers').volumes != null)
1950
- {
1951
- results.hardware.windows.volumes = cleanGetBitLockerVolumeInfo(require('computer-identifiers').volumes());
1952
- results.hash = hasher.syncHash(JSON.stringify(results)).toString('hex');
1953
- func(results);
1954
- }
1949
else
1950
{
1951
results.hash = hasher.syncHash(JSON.stringify(results)).toString('hex');
@@ -4044,11 +4038,9 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
4038
break;
4039
case 'bitlocker':
4040
if (process.platform == 'win32') {
4047
- if (require('computer-identifiers').volumes_promise != null) {
4048
- var p = require('computer-identifiers').volumes_promise();
4041
+ if (require('win-volumes').volumes_promise != null) {
4042
+ var p = require('win-volumes').volumes_promise();
4043
p.then(function (res) { sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(res), null, 1), this.session); });
4050
- } else if (require('computer-identifiers').volumes != null) {
4051
- sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(require('computer-identifiers').volumes()), null, 1), this.session);
4044
}
4045
}
4046
break;
agents/modules_meshcore/computer-identifiers.js
-74
@@ -422,75 +422,6 @@ function windows_wmic_results(str)
422
return (result);
423
}
424
425
-function windows_volumes()
426
-{
427
- var promise = require('promise');
428
- var p1 = new promise(function (res, rej) { this._res = res; this._rej = rej; });
429
- var ret = {};
430
- var values = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_LogicalDisk', ['DeviceID', 'VolumeName', 'FileSystem', 'Size', 'FreeSpace', 'DriveType']);
431
- if(values[0]){
432
- for (var i = 0; i < values.length; ++i) {
433
- var drive = values[i]['DeviceID'].slice(0,-1);
434
- ret[drive] = {
435
- name: (values[i]['VolumeName'] ? values[i]['VolumeName'] : ""),
436
- type: (values[i]['FileSystem'] ? values[i]['FileSystem'] : "Unknown"),
437
- size: (values[i]['Size'] ? values[i]['Size'] : 0),
438
- sizeremaining: (values[i]['FreeSpace'] ? values[i]['FreeSpace'] : 0),
439
- removable: (values[i]['DriveType'] == 2),
440
- cdrom: (values[i]['DriveType'] == 5)
441
- };
442
- }
443
- }
444
- try {
445
- values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume', ['DriveLetter','ConversionStatus','ProtectionStatus']);
446
- if(values[0]){
447
- for (var i = 0; i < values.length; ++i) {
448
- var drive = values[i]['DriveLetter'].slice(0,-1);
449
- var statuses = {
450
- 0: 'FullyDecrypted',
451
- 1: 'FullyEncrypted',
452
- 2: 'EncryptionInProgress',
453
- 3: 'DecryptionInProgress',
454
- 4: 'EncryptionPaused',
455
- 5: 'DecryptionPaused'
456
- };
457
- ret[drive].volumeStatus = statuses.hasOwnProperty(values[i].ConversionStatus) ? statuses[values[i].ConversionStatus] : 'FullyDecrypted';
458
- ret[drive].protectionStatus = (values[i].ProtectionStatus == 0 ? 'Off' : (values[i].ProtectionStatus == 1 ? 'On' : 'Unknown'));
459
- try {
460
- var foundIDMarkedLine = false, foundMarkedLine = false, identifier = '', password = '';
461
- var keychild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'manage-bde -protectors -get ' + drive + ': -Type recoverypassword'], {});
462
- keychild.stdout.str = ''; keychild.stdout.on('data', function (c) { this.str += c.toString(); });
463
- keychild.waitExit();
464
- var lines = keychild.stdout.str.trim().split('\r\n');
465
- for (var x = 0; x < lines.length; x++) { // Loop each line
466
- var abc = lines[x].trim();
467
- var englishidpass = (abc !== '' && abc.includes('Numerical Password:')); // English ID
468
- var germanidpass = (abc !== '' && abc.includes('Numerisches Kennwort:')); // German ID
469
- var frenchidpass = (abc !== '' && abc.includes('Mot de passe num')); // French ID
470
- var englishpass = (abc !== '' && abc.includes('Password:') && !abc.includes('Numerical Password:')); // English Password
471
- var germanpass = (abc !== '' && abc.includes('Kennwort:') && !abc.includes('Numerisches Kennwort:')); // German Password
472
- var frenchpass = (abc !== '' && abc.includes('Mot de passe :') && !abc.includes('Mot de passe num')); // French Password
473
- if (englishidpass || germanidpass || frenchidpass|| englishpass || germanpass || frenchpass) {
474
- var nextline = lines[x + 1].trim();
475
- if (x + 1 < lines.length && (nextline !== '' && (nextline.startsWith('ID:') || nextline.startsWith('ID :')) )) {
476
- identifier = nextline.replace('ID:','').replace('ID :', '').trim();
477
- foundIDMarkedLine = true;
478
- }else if (x + 1 < lines.length && nextline !== '') {
479
- password = nextline;
480
- foundMarkedLine = true;
481
- }
482
- }
483
- }
484
- ret[drive].identifier = (foundIDMarkedLine ? identifier : ''); // Set Bitlocker Identifier
485
- ret[drive].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password
486
- } catch(ex) { } // just carry on as we cant get bitlocker key
487
- }
488
- }
489
- p1._res(ret);
490
- } catch (ex) { p1._res(ret); } // just return volumes as cant get encryption/bitlocker
491
- return (p1);
492
-}
493
-
425
function windows_identifiers()
426
{
427
var ret = { windows: {} };
@@ -962,11 +893,6 @@ module.exports.isVM = function isVM()
893
return (ret);
894
};
895
965
-if (process.platform == 'win32')
966
-{
967
- module.exports.volumes_promise = windows_volumes;
968
-}
969
-
896
// bios_date = BIOS->ReleaseDate
897
// bios_vendor = BIOS->Manufacturer
898
// bios_version = BIOS->SMBIOSBIOSVersion
agents/modules_meshcore/win-volumes.js
+82
-9
@@ -39,17 +39,90 @@ function getVolumes()
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)
42
+ try {
43
+ v = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume');
44
+ for (i in v)
45
{
49
- ret[tmp.DeviceID][k] = tmp[k];
46
+ var tmp = trimObject(v[i]);
47
+ for (var k in tmp)
48
+ {
49
+ ret[tmp.DeviceID][k] = tmp[k];
50
+ }
51
}
51
- }
52
+ } catch (ex) { }
53
return (ret);
54
}
55
55
-module.exports = { getVolumes: function () { try { return (getVolumes()); } catch (x) { return ({}); } } };
\ No newline at end of file
56
+function windows_volumes()
57
+{
58
+ var promise = require('promise');
59
+ var p1 = new promise(function (res, rej) { this._res = res; this._rej = rej; });
60
+ var ret = {};
61
+ var values = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_LogicalDisk', ['DeviceID', 'VolumeName', 'FileSystem', 'Size', 'FreeSpace', 'DriveType']);
62
+ if(values[0]){
63
+ for (var i = 0; i < values.length; ++i) {
64
+ var drive = values[i]['DeviceID'].slice(0,-1);
65
+ ret[drive] = {
66
+ name: (values[i]['VolumeName'] ? values[i]['VolumeName'] : ""),
67
+ type: (values[i]['FileSystem'] ? values[i]['FileSystem'] : "Unknown"),
68
+ size: (values[i]['Size'] ? values[i]['Size'] : 0),
69
+ sizeremaining: (values[i]['FreeSpace'] ? values[i]['FreeSpace'] : 0),
70
+ removable: (values[i]['DriveType'] == 2),
71
+ cdrom: (values[i]['DriveType'] == 5)
72
+ };
73
+ }
74
+ }
75
+ try {
76
+ values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume', ['DriveLetter','ConversionStatus','ProtectionStatus']);
77
+ if(values[0]){
78
+ for (var i = 0; i < values.length; ++i) {
79
+ var drive = values[i]['DriveLetter'].slice(0,-1);
80
+ var statuses = {
81
+ 0: 'FullyDecrypted',
82
+ 1: 'FullyEncrypted',
83
+ 2: 'EncryptionInProgress',
84
+ 3: 'DecryptionInProgress',
85
+ 4: 'EncryptionPaused',
86
+ 5: 'DecryptionPaused'
87
+ };
88
+ ret[drive].volumeStatus = statuses.hasOwnProperty(values[i].ConversionStatus) ? statuses[values[i].ConversionStatus] : 'FullyDecrypted';
89
+ ret[drive].protectionStatus = (values[i].ProtectionStatus == 0 ? 'Off' : (values[i].ProtectionStatus == 1 ? 'On' : 'Unknown'));
90
+ try {
91
+ var foundIDMarkedLine = false, foundMarkedLine = false, identifier = '', password = '';
92
+ var keychild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'manage-bde -protectors -get ' + drive + ': -Type recoverypassword'], {});
93
+ keychild.stdout.str = ''; keychild.stdout.on('data', function (c) { this.str += c.toString(); });
94
+ keychild.waitExit();
95
+ var lines = keychild.stdout.str.trim().split('\r\n');
96
+ for (var x = 0; x < lines.length; x++) { // Loop each line
97
+ var abc = lines[x].trim();
98
+ var englishidpass = (abc !== '' && abc.includes('Numerical Password:')); // English ID
99
+ var germanidpass = (abc !== '' && abc.includes('Numerisches Kennwort:')); // German ID
100
+ var frenchidpass = (abc !== '' && abc.includes('Mot de passe num')); // French ID
101
+ var englishpass = (abc !== '' && abc.includes('Password:') && !abc.includes('Numerical Password:')); // English Password
102
+ var germanpass = (abc !== '' && abc.includes('Kennwort:') && !abc.includes('Numerisches Kennwort:')); // German Password
103
+ var frenchpass = (abc !== '' && abc.includes('Mot de passe :') && !abc.includes('Mot de passe num')); // French Password
104
+ if (englishidpass || germanidpass || frenchidpass|| englishpass || germanpass || frenchpass) {
105
+ var nextline = lines[x + 1].trim();
106
+ if (x + 1 < lines.length && (nextline !== '' && (nextline.startsWith('ID:') || nextline.startsWith('ID :')) )) {
107
+ identifier = nextline.replace('ID:','').replace('ID :', '').trim();
108
+ foundIDMarkedLine = true;
109
+ }else if (x + 1 < lines.length && nextline !== '') {
110
+ password = nextline;
111
+ foundMarkedLine = true;
112
+ }
113
+ }
114
+ }
115
+ ret[drive].identifier = (foundIDMarkedLine ? identifier : ''); // Set Bitlocker Identifier
116
+ ret[drive].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password
117
+ } catch(ex) { } // just carry on as we cant get bitlocker key
118
+ }
119
+ }
120
+ p1._res(ret);
121
+ } catch (ex) { p1._res(ret); } // just return volumes as cant get encryption/bitlocker
122
+ return (p1);
123
+}
124
+
125
+module.exports = {
126
+ getVolumes: function () { try { return (getVolumes()); } catch (x) { return ({}); } },
127
+ volumes_promise: windows_volumes
128
+};
\ No newline at end of file