2020-01-06 15:11:57 +01:00
|
|
|
|
/*
|
2021-02-03 00:45:33 +01:00
|
|
|
|
* Copyright (c) 2021 ETH Zürich, Educational Development and Technology (LET)
|
2020-01-06 15:11:57 +01:00
|
|
|
|
*
|
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
|
*/
|
|
|
|
|
|
2020-09-29 14:37:54 +02:00
|
|
|
|
using System.Linq;
|
2020-01-06 15:11:57 +01:00
|
|
|
|
using SafeExamBrowser.Logging.Contracts;
|
|
|
|
|
using SafeExamBrowser.SystemComponents.Contracts;
|
|
|
|
|
|
|
|
|
|
namespace SafeExamBrowser.SystemComponents
|
|
|
|
|
{
|
|
|
|
|
public class VirtualMachineDetector : IVirtualMachineDetector
|
|
|
|
|
{
|
2020-09-29 14:37:54 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// 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" };
|
2020-07-13 18:55:42 +02:00
|
|
|
|
private static readonly string VIRTUALBOX_MAC_PREFIX = "080027";
|
|
|
|
|
private static readonly string QEMU_MAC_PREFIX = "525400";
|
2020-05-06 18:44:08 +02:00
|
|
|
|
|
2020-01-06 15:11:57 +01:00
|
|
|
|
private ILogger logger;
|
|
|
|
|
private ISystemInfo systemInfo;
|
2020-05-06 18:44:08 +02:00
|
|
|
|
|
2020-01-06 15:11:57 +01:00
|
|
|
|
public VirtualMachineDetector(ILogger logger, ISystemInfo systemInfo)
|
|
|
|
|
{
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.systemInfo = systemInfo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public bool IsVirtualMachine()
|
|
|
|
|
{
|
|
|
|
|
var isVirtualMachine = false;
|
|
|
|
|
var manufacturer = systemInfo.Manufacturer.ToLower();
|
|
|
|
|
var model = systemInfo.Model.ToLower();
|
2020-05-06 18:44:08 +02:00
|
|
|
|
var macAddress = systemInfo.MacAddress;
|
2020-05-07 13:21:57 +02:00
|
|
|
|
var plugAndPlayDeviceIds = systemInfo.PlugAndPlayDeviceIds;
|
|
|
|
|
|
2020-01-06 15:11:57 +01:00
|
|
|
|
isVirtualMachine |= manufacturer.Contains("microsoft corporation") && !model.Contains("surface");
|
|
|
|
|
isVirtualMachine |= manufacturer.Contains("vmware");
|
|
|
|
|
isVirtualMachine |= manufacturer.Contains("parallels software");
|
|
|
|
|
isVirtualMachine |= model.Contains("virtualbox");
|
2020-04-28 13:28:59 +02:00
|
|
|
|
isVirtualMachine |= manufacturer.Contains("qemu");
|
2020-05-07 13:21:57 +02:00
|
|
|
|
|
|
|
|
|
if (macAddress != null && macAddress.Count() > 2)
|
|
|
|
|
{
|
2020-09-29 14:37:54 +02:00
|
|
|
|
isVirtualMachine |= macAddress.StartsWith(QEMU_MAC_PREFIX) || macAddress.StartsWith(VIRTUALBOX_MAC_PREFIX);
|
2020-05-07 13:21:57 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var device in plugAndPlayDeviceIds)
|
2020-05-06 21:45:04 +02:00
|
|
|
|
{
|
|
|
|
|
isVirtualMachine |= PCI_VENDOR_BLACKLIST.Any(device.ToLower().Contains);
|
|
|
|
|
}
|
2020-05-07 13:21:57 +02:00
|
|
|
|
|
2020-01-06 15:11:57 +01:00
|
|
|
|
logger.Debug($"Computer '{systemInfo.Name}' appears to {(isVirtualMachine ? "" : "not ")}be a virtual machine.");
|
|
|
|
|
|
|
|
|
|
return isVirtualMachine;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|