1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-02-12 11:01:52 +00:00

fix win7+server2008r2 powershell/wmi

Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
si458 2024-11-30 13:50:02 +00:00
parent ef4d764ab4
commit c41eb72a2c
3 changed files with 66 additions and 92 deletions

View file

@ -4047,7 +4047,6 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
if (require('computer-identifiers').volumes_promise != null) { if (require('computer-identifiers').volumes_promise != null) {
var p = require('computer-identifiers').volumes_promise(); var p = require('computer-identifiers').volumes_promise();
p.then(function (res) { sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(res), null, 1), this.session); }); p.then(function (res) { sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(res), null, 1), this.session); });
response = "Please wait...";
} else if (require('computer-identifiers').volumes != null) { } else if (require('computer-identifiers').volumes != null) {
sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(require('computer-identifiers').volumes()), null, 1), this.session); sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(require('computer-identifiers').volumes()), null, 1), this.session);
} }

View file

@ -426,67 +426,39 @@ function windows_volumes()
{ {
var promise = require('promise'); var promise = require('promise');
var p1 = new promise(function (res, rej) { this._res = res; this._rej = rej; }); var p1 = new promise(function (res, rej) { this._res = res; this._rej = rej; });
var p2 = new promise(function (res, rej) { this._res = res; this._rej = rej; });
p1._p2 = p2;
p2._p1 = p1;
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-']);
p1.child = child;
child.promise = p1;
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('Get-Volume | Select-Object -Property DriveLetter,FileSystemLabel,FileSystemType,Size,SizeRemaining,DriveType | ConvertTo-Csv -NoTypeInformation\r\nexit\r\n');
child.on('exit', function (c)
{
var a, i, tokens, key;
var ret = {}; var ret = {};
var values = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_LogicalDisk', ['DeviceID', 'VolumeName', 'FileSystem', 'Size', 'FreeSpace', 'DriveType']);
a = this.stdout.str.trim().split('\r\n'); if(values[0]){
for (i = 1; i < a.length; ++i) for (var i = 0; i < values.length; ++i) {
{ var drive = values[i]['DeviceID'].slice(0,-1);
tokens = a[i].split(','); ret[drive] = {
if (tokens[0] != '' && tokens[1] != undefined) name: (values[i]['VolumeName'] ? values[i]['VolumeName'] : ""),
{ type: (values[i]['FileSystem'] ? values[i]['FileSystem'] : "Unknown"),
ret[tokens[0].split('"')[1]] = size: (values[i]['Size'] ? values[i]['Size'] : 0),
{ sizeremaining: (values[i]['FreeSpace'] ? values[i]['FreeSpace'] : 0),
name: tokens[1].split('"')[1], removable: (values[i]['DriveType'] == 2),
type: tokens[2].split('"')[1], cdrom: (values[i]['DriveType'] == 5)
size: tokens[3].split('"')[1],
sizeremaining: tokens[4].split('"')[1],
removable: tokens[5].split('"')[1] == 'Removable',
cdrom: tokens[5].split('"')[1] == 'CD-ROM'
}; };
} }
} }
this.promise._res({ r: ret, t: tokens }); try {
}); values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume', ['DriveLetter','ConversionStatus','ProtectionStatus']);
if(values[0]){
p1.then(function (j) for (var i = 0; i < values.length; ++i) {
{ var drive = values[i]['DriveLetter'].slice(0,-1);
var ret = j.r; var statuses = {
var tokens = j.t; 0: 'FullyDecrypted',
1: 'FullyEncrypted',
var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-']); 2: 'EncryptionInProgress',
p2.child = child; 3: 'DecryptionInProgress',
child.promise = p2; 4: 'EncryptionPaused',
child.tokens = tokens; 5: 'DecryptionPaused'
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); };
child.stdin.write('Get-BitLockerVolume | Select-Object -Property MountPoint,VolumeStatus,ProtectionStatus | ConvertTo-Csv -NoTypeInformation\r\nexit\r\n'); ret[drive].volumeStatus = statuses.hasOwnProperty(values[i].ConversionStatus) ? statuses[values[i].ConversionStatus] : 'FullyDecrypted';
child.on('exit', function () ret[drive].protectionStatus = (values[i].ProtectionStatus == 0 ? 'Off' : (values[i].ProtectionStatus == 1 ? 'On' : 'Unknown'));
{
var i;
var a = this.stdout.str.trim().split('\r\n');
for (i = 1; i < a.length; ++i)
{
tokens = a[i].split(',');
key = tokens[0].split(':').shift().split('"').pop();
if (ret[key] != null)
{
ret[key].volumeStatus = tokens[1].split('"')[1];
ret[key].protectionStatus = tokens[2].split('"')[1];
try { try {
var foundIDMarkedLine = false, foundMarkedLine = false, identifier = '', password = ''; var foundIDMarkedLine = false, foundMarkedLine = false, identifier = '', password = '';
var keychild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'manage-bde -protectors -get ', tokens[0].split('"')[1], ' -Type recoverypassword'], {}); var keychild = require('child_process').execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'manage-bde -protectors -get ', drive, ' -Type recoverypassword'], {});
keychild.stdout.str = ''; keychild.stdout.on('data', function (c) { this.str += c.toString(); }); keychild.stdout.str = ''; keychild.stdout.on('data', function (c) { this.str += c.toString(); });
keychild.waitExit(); keychild.waitExit();
var lines = keychild.stdout.str.trim().split('\r\n'); var lines = keychild.stdout.str.trim().split('\r\n');
@ -509,15 +481,14 @@ function windows_volumes()
} }
} }
} }
ret[key].identifier = (foundIDMarkedLine ? identifier : ''); // Set Bitlocker Identifier ret[drive].identifier = (foundIDMarkedLine ? identifier : ''); // Set Bitlocker Identifier
ret[key].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password ret[drive].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password
} catch(ex) { } } catch(ex) { } // just carry on as we cant get bitlocker key
} }
} }
this.promise._res(ret); p1._res(ret);
}); } catch (ex) { p1._res(ret); } // just return volumes as cant get encryption/bitlocker
}); return (p1);
return (p2);
} }
function windows_identifiers() function windows_identifiers()
@ -806,7 +777,7 @@ function win_chassisType()
child.descriptorMetadata = 'process-manager'; child.descriptorMetadata = 'process-manager';
child.stdout.str = ''; child.stdout.on('data', function (c) { this.str += c.toString(); }); 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.stderr.str = ''; child.stderr.on('data', function (c) { this.str += c.toString(); });
child.stdin.write('Get-CimInstance Win32_SystemEnclosure| Select-Object -ExpandProperty ChassisTypes\r\n'); child.stdin.write('Get-WmiObject Win32_SystemEnclosure | Select-Object -ExpandProperty ChassisTypes\r\n');
child.stdin.write('exit\r\n'); child.stdin.write('exit\r\n');
child.waitExit(); child.waitExit();
try { try {

View file

@ -251,8 +251,12 @@ function defender(){
ret.child.stdin.write('exit\r\n'); ret.child.stdin.write('exit\r\n');
ret.child.on('exit', function (c) { ret.child.on('exit', function (c) {
if (this.stdout.str == '') { this.promise._resolve({}); return; } if (this.stdout.str == '') { this.promise._resolve({}); return; }
var abc = JSON.parse(this.stdout.str.trim()) try {
var abc = JSON.parse(this.stdout.str.trim());
this.promise._resolve({ RealTimeProtection: abc.RealTimeProtectionEnabled, TamperProtected: abc.IsTamperProtected }); this.promise._resolve({ RealTimeProtection: abc.RealTimeProtectionEnabled, TamperProtected: abc.IsTamperProtected });
} catch (ex) {
this.promise._resolve({}); return;
}
}); });
return (ret); return (ret);
} }