mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-03-09 15:40:18 +00:00 
			
		
		
		
	fix win7+server2008r2 powershell/wmi
Signed-off-by: si458 <simonsmith5521@gmail.com>
This commit is contained in:
		
							parent
							
								
									ef4d764ab4
								
							
						
					
					
						commit
						c41eb72a2c
					
				
					 3 changed files with 66 additions and 92 deletions
				
			
		| 
						 | 
				
			
			@ -4047,7 +4047,6 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
 | 
			
		|||
                    if (require('computer-identifiers').volumes_promise != null) {
 | 
			
		||||
                        var p = require('computer-identifiers').volumes_promise();
 | 
			
		||||
                        p.then(function (res) { sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(res), null, 1), this.session); });
 | 
			
		||||
                        response = "Please wait...";
 | 
			
		||||
                    } else if (require('computer-identifiers').volumes != null) {
 | 
			
		||||
                        sendConsoleText(JSON.stringify(cleanGetBitLockerVolumeInfo(require('computer-identifiers').volumes()), null, 1), this.session);
 | 
			
		||||
                    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -426,67 +426,39 @@ function windows_volumes()
 | 
			
		|||
{
 | 
			
		||||
    var promise = require('promise');
 | 
			
		||||
    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 = {};
 | 
			
		||||
 | 
			
		||||
        a = this.stdout.str.trim().split('\r\n');
 | 
			
		||||
        for (i = 1; i < a.length; ++i)
 | 
			
		||||
        {
 | 
			
		||||
            tokens = a[i].split(',');
 | 
			
		||||
            if (tokens[0] != '' && tokens[1] != undefined)
 | 
			
		||||
            {
 | 
			
		||||
                ret[tokens[0].split('"')[1]] =
 | 
			
		||||
                    {
 | 
			
		||||
                        name: tokens[1].split('"')[1],
 | 
			
		||||
                        type: tokens[2].split('"')[1],
 | 
			
		||||
                        size: tokens[3].split('"')[1],
 | 
			
		||||
                        sizeremaining: tokens[4].split('"')[1],
 | 
			
		||||
                        removable: tokens[5].split('"')[1] == 'Removable',
 | 
			
		||||
                        cdrom: tokens[5].split('"')[1] == 'CD-ROM'
 | 
			
		||||
    var values = require('win-wmi').query('ROOT\\CIMV2', 'SELECT * FROM Win32_LogicalDisk', ['DeviceID', 'VolumeName', 'FileSystem', 'Size', 'FreeSpace', 'DriveType']);
 | 
			
		||||
    if(values[0]){
 | 
			
		||||
        for (var i = 0; i < values.length; ++i) {
 | 
			
		||||
            var drive = values[i]['DeviceID'].slice(0,-1);
 | 
			
		||||
            ret[drive] = {
 | 
			
		||||
                name: (values[i]['VolumeName'] ? values[i]['VolumeName'] : ""),
 | 
			
		||||
                type: (values[i]['FileSystem'] ? values[i]['FileSystem'] : "Unknown"),
 | 
			
		||||
                size: (values[i]['Size'] ? values[i]['Size'] : 0),
 | 
			
		||||
                sizeremaining: (values[i]['FreeSpace'] ? values[i]['FreeSpace'] : 0),
 | 
			
		||||
                removable: (values[i]['DriveType'] == 2),
 | 
			
		||||
                cdrom: (values[i]['DriveType'] == 5)
 | 
			
		||||
            };
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
        this.promise._res({ r: ret, t: tokens });
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    p1.then(function (j)
 | 
			
		||||
    {
 | 
			
		||||
        var ret = j.r;
 | 
			
		||||
        var tokens = j.t;
 | 
			
		||||
 | 
			
		||||
        var child = require('child_process').execFile(process.env['windir'] + '\\System32\\WindowsPowerShell\\v1.0\\powershell.exe', ['powershell', '-noprofile', '-nologo', '-command', '-']);
 | 
			
		||||
        p2.child = child;
 | 
			
		||||
        child.promise = p2;
 | 
			
		||||
        child.tokens = tokens;
 | 
			
		||||
        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');
 | 
			
		||||
        child.on('exit', function ()
 | 
			
		||||
        {
 | 
			
		||||
            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 {
 | 
			
		||||
        values = require('win-wmi').query('ROOT\\CIMV2\\Security\\MicrosoftVolumeEncryption', 'SELECT * FROM Win32_EncryptableVolume', ['DriveLetter','ConversionStatus','ProtectionStatus']);
 | 
			
		||||
        if(values[0]){
 | 
			
		||||
            for (var i = 0; i < values.length; ++i) {
 | 
			
		||||
                var drive = values[i]['DriveLetter'].slice(0,-1);
 | 
			
		||||
                var statuses = {
 | 
			
		||||
                    0: 'FullyDecrypted',
 | 
			
		||||
                    1: 'FullyEncrypted',
 | 
			
		||||
                    2: 'EncryptionInProgress',
 | 
			
		||||
                    3: 'DecryptionInProgress',
 | 
			
		||||
                    4: 'EncryptionPaused',
 | 
			
		||||
                    5: 'DecryptionPaused'
 | 
			
		||||
                };
 | 
			
		||||
                ret[drive].volumeStatus = statuses.hasOwnProperty(values[i].ConversionStatus) ? statuses[values[i].ConversionStatus] : 'FullyDecrypted';
 | 
			
		||||
                ret[drive].protectionStatus = (values[i].ProtectionStatus == 0 ? 'Off' : (values[i].ProtectionStatus == 1 ? 'On' : 'Unknown'));
 | 
			
		||||
                try {
 | 
			
		||||
                    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.waitExit();
 | 
			
		||||
                    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[key].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password
 | 
			
		||||
                    } catch(ex) { }
 | 
			
		||||
                    ret[drive].identifier = (foundIDMarkedLine ? identifier : ''); // Set Bitlocker Identifier
 | 
			
		||||
                    ret[drive].recoveryPassword = (foundMarkedLine ? password : ''); // Set Bitlocker Password
 | 
			
		||||
                } catch(ex) { } // just carry on as we cant get bitlocker key
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
            this.promise._res(ret);
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
    return (p2);
 | 
			
		||||
        p1._res(ret);
 | 
			
		||||
    } catch (ex) { p1._res(ret); } // just return volumes as cant get encryption/bitlocker
 | 
			
		||||
    return (p1);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
function windows_identifiers()
 | 
			
		||||
| 
						 | 
				
			
			@ -806,7 +777,7 @@ function win_chassisType()
 | 
			
		|||
    child.descriptorMetadata = 'process-manager';
 | 
			
		||||
    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.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.waitExit();
 | 
			
		||||
    try {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -251,8 +251,12 @@ function defender(){
 | 
			
		|||
    ret.child.stdin.write('exit\r\n');
 | 
			
		||||
    ret.child.on('exit', function (c) { 
 | 
			
		||||
        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 });
 | 
			
		||||
        } catch (ex) { 
 | 
			
		||||
            this.promise._resolve({}); return;
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
    return (ret);
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue