Approaches to hardware detection
Virtual environments imitate hardware devices and leave specific traces in their descriptions, which can be queried to determine the non-host OS.
Checking the HDD
One of the techniques is verifying that the HDD vendor ID has a specific value. For this logic, the following function is used:
BOOL DeviceIoControl( HANDLE hDevice, DWORD dwIoControlCode, LPVOID lpInBuffer, DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize, LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped );
The full source code of this logic can be found here: https://github.com/PacktPublishing/Malware-Development-for-Ethical-Hackers/blob/main/chapter06/02-hardware/hack.c.
Demo
Let’s compile our example:
$...