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:
$...