title: Anti-Virtual-Machine categories: [cheatsheets]
for Kernel Mode / Priviledged Operations, VMs use binary translation, so every instruction translated for emulation. These instructions are not given to the real Kernel, gut emulated by the VM Monitor. Use Mode / Unpriviledged Operations run directly on the CPU, (Binary translation would have a to big overhead), so there are some instructions that can be used to detect this behaviour.
sidt, sldt, sgdt are usermode instructions which get the Address of Instruction- /Local- /Global- Distriptor Tabel
-> Two attacks on this problem: Red-Pill and No-Pill
The Instruction Discriptor Table needs to be remapped by the VM, the remapping places are vencor specific.
0x80ffffff in Windows
0xe8XXXXXX in Virtual PC
0xffXXXXXX in VMware
To detect this:
push 8
push 0
lea eax, [ebp+Dst]
push eax
call _memset
add esp, 0Ch
lea eax, [ebp+Dst]
sidt fword ptr [eax] ; Contents of IDTR saved to memory location pointed to by EAX
mov al, [eax+5] ; Start of base memory address (5th byte offset) saved to AL
cmp al, 0FFh ; Check whether it is 0xFF (VMware signature)
jnz short loc_401E19
Important: This only works on single-core CPUs, with Multiple Cores, VMWare remapps multiple SDT's
sgdt & sldt is assigned to an CPU not an Operating System. On Windows this is mostly zero On VMWare its nonzero
Can be disabled in VMWare with: Settings->Processors->Disable Acceleration
Instruction used: in
mov eax, 'VMXh'
mov ebx, [ebp-var_result]
mov ecx, 0xA
mov dx, 'VX'
in eax, dx
mov [ebp-var_result], ebx
mov eax, [ebp-var_result]
cmp eax, 'VMXh'
je vmwaredetected
Anti-VM Instructions