SEBWIN-653: Added Hyper-V to virtual machine detector.

This commit is contained in:
Damian Büchel 2023-03-07 23:41:56 +01:00
parent a5202e3a53
commit 7967087ee6

View file

@ -14,12 +14,16 @@ namespace SafeExamBrowser.SystemComponents
{ {
public class VirtualMachineDetector : IVirtualMachineDetector public class VirtualMachineDetector : IVirtualMachineDetector
{ {
/// <summary> private static readonly string[] DEVICE_BLACKLIST =
/// Virtualbox: VBOX, 80EE / RedHat: QUEMU, 1AF4, 1B36
/// </summary>
private static readonly string[] PCI_VENDOR_BLACKLIST =
{ {
"vbox", "vid_80ee", "qemu", "ven_1af4", "ven_1b36", "subsys_11001af4", "PROD_VMWARE", "VEN_VMWARE", "VMWARE_IDE" // Hyper-V
"PROD_VIRTUAL", "HYPER_V",
// QEMU
"qemu", "ven_1af4", "ven_1b36", "subsys_11001af4",
// VirtualBox
"vbox", "vid_80ee",
// VMware
"PROD_VMWARE", "VEN_VMWARE", "VMWARE_IDE"
}; };
private static readonly string QEMU_MAC_PREFIX = "525400"; private static readonly string QEMU_MAC_PREFIX = "525400";
private static readonly string VIRTUALBOX_MAC_PREFIX = "080027"; private static readonly string VIRTUALBOX_MAC_PREFIX = "080027";
@ -40,24 +44,25 @@ namespace SafeExamBrowser.SystemComponents
var macAddress = systemInfo.MacAddress; var macAddress = systemInfo.MacAddress;
var manufacturer = systemInfo.Manufacturer.ToLower(); var manufacturer = systemInfo.Manufacturer.ToLower();
var model = systemInfo.Model.ToLower(); var model = systemInfo.Model.ToLower();
var plugAndPlayDeviceIds = systemInfo.PlugAndPlayDeviceIds; var devices = systemInfo.PlugAndPlayDeviceIds;
isVirtualMachine |= biosInfo.Contains("vmware"); isVirtualMachine |= biosInfo.Contains("hyper-v");
isVirtualMachine |= biosInfo.Contains("virtualbox"); isVirtualMachine |= biosInfo.Contains("virtualbox");
isVirtualMachine |= biosInfo.Contains("vmware");
isVirtualMachine |= manufacturer.Contains("microsoft corporation") && !model.Contains("surface"); isVirtualMachine |= manufacturer.Contains("microsoft corporation") && !model.Contains("surface");
isVirtualMachine |= manufacturer.Contains("vmware");
isVirtualMachine |= manufacturer.Contains("parallels software"); isVirtualMachine |= manufacturer.Contains("parallels software");
isVirtualMachine |= model.Contains("virtualbox");
isVirtualMachine |= manufacturer.Contains("qemu"); isVirtualMachine |= manufacturer.Contains("qemu");
isVirtualMachine |= manufacturer.Contains("vmware");
isVirtualMachine |= model.Contains("virtualbox");
if (macAddress != null && macAddress.Count() > 2) if (macAddress != null && macAddress.Count() > 2)
{ {
isVirtualMachine |= macAddress.StartsWith(QEMU_MAC_PREFIX) || macAddress.StartsWith(VIRTUALBOX_MAC_PREFIX); isVirtualMachine |= macAddress.StartsWith(QEMU_MAC_PREFIX) || macAddress.StartsWith(VIRTUALBOX_MAC_PREFIX);
} }
foreach (var device in plugAndPlayDeviceIds) foreach (var device in devices)
{ {
isVirtualMachine |= PCI_VENDOR_BLACKLIST.Any(v => device.ToLower().Contains(v.ToLower())); isVirtualMachine |= DEVICE_BLACKLIST.Any(d => device.ToLower().Contains(d.ToLower()));
} }
logger.Debug($"Computer '{systemInfo.Name}' appears {(isVirtualMachine ? "" : "not ")}to be a virtual machine."); logger.Debug($"Computer '{systemInfo.Name}' appears {(isVirtualMachine ? "" : "not ")}to be a virtual machine.");