Détection d’une VM
Comment en 2013 détecter si nous sommes dans une machine virtuelle ? Avant pour Vmware, Xen, Kvm et Virtual PC c’était assez la foire, de sombres in/out dans les backdoors systèmes, des instructions non documentées ou longues comme le bras, Red/Blue Pills … Etc
http://handlers.sans.org/tliston/ThwartingVMDetection_Liston_Skoudis.pdf
http://brundlelab.wordpress.com/2012/10/21/detecting-vmware/
http://my.opera.com/jaelanicu/blog/just-another-vm-detection-was-vm-detection-combo
C’est tellement la foire que les Malwares de tous poils n’hésitent pas à labourer la registry à la recherche des mac addresses et de nom de drivers spécifiques.
Arrivé en 2013, Avec l’avènement des CPU ‘awares en virtualisation’, l’industrie semble s’être enfin organisée, Voici donc une solution simple; l’instruction CpuID permet de savoir si la machine est Virtualisée. C’est le Bit 31 de ECX pour un appel à Cpuid avec EAX à 1.
Si Ensuite on fait un appel à l’instruction CpuID avec EAX à 0x4000000 le résultat dans EBX,ECX,EDX donne une string sans équivoque;
"VMwareVMware" : Vmware Workstation/Fusion/EsX "KVMKVMVKM" : Kvm "Microsoft Hv" : HyperV "XenVMMXe" : Xen
http://msdn.microsoft.com/en-us/library/windows/hardware/ff542428(v=vs.85).aspx
http://www.mjmwired.net/kernel/Documentation/kvm/cpuid.txt
Pour finir un petit “Poc” qui fonctionne bien, dispo pour les plus courageux ici
; Find Virtualisation Engine
global _start ; visibility for linker
extern ExitProcess, MessageBoxA ; externals calls
section .data
boxtitle db "Detection",0
boxtext db "Types : 0 None, 1 Generic, 2 Vmware, 3 Xen, 4 Kvm, 5 HyperV", 0x0D
db "Detected Type :"
vm db 0
legend db 0x0D, "String: "
sebx db ' '
secx db ' '
sedx db ' '
zero db 0
section .text code align=16
_start:
mov eax,1 ; Eax = 1
cpuid ; Cpuid
shr ecx,31 ; Selection bit 31
mov byte [vm],cl ; Virtualisation found
dec cl ; test cl = 1
jnz nothyperv ; Si cl = 0, c'est pas Virtual
mov eax,0x40000000 ; Info Virtualisation
cpuid
mov dword [sebx],ebx ; Conserve les Jolie String
mov dword [secx],ecx ;
mov dword [sedx],edx ;
xor ebx,ecx ; Genere un Hash pas cher
cmp ebx,'VMwa' ^ 'reVM' ; Est-ce Vmware
jne notvm
mov byte [vm],2
notvm:
cmp ebx,'XenV' ^ 'MMXe' ; Est-ce Xen
jne notxen
mov byte [vm],3
notxen:
cmp ebx,'KVMK' ^ 'VMKV' ; Est-ce KVM
jne notkvm
mov byte [vm],4
notkvm:
cmp ebx, 'Micr' ^ 'osof' ; Est-ce HyperV
jne nothyperv
mov byte [vm],5
nothyperv:
.print:
add byte [vm],0x30 ; Convert to Ascii
push 0 ; Type okbox
push boxtitle ; Caption
push boxtext ; Title
push 0 ; Handle Optionnal
call MessageBoxA ; Print
push 0 ; exitcode
call ExitProcess ; Quit
.end
