// Estas leyendo...

C \\ C++

Detectar Maquina Virtual VM en C++

Codigo en C++ que nos permite detectar si nuestra aplicación esta siendo ejecutada en una maquina virtual (virtual machine).

/*
Virtual Machine Detection
   Coded by stoopid

Credits to Cobein
*/

#include <stdio.h>
#include <windows.h>

char* sProduct[] = { "*VMWARE*", "*VBOX*", "*VIRTUAL*" };

bool DetectVM()
{
    HKEY hKey;
    char szBuffer[64];
    unsigned long hSize = sizeof(szBuffer)1;

    if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\ControlSet001\\Services\\Disk\\Enum", 0, KEY_READ, &amp;hKey ) == ERROR_SUCCESS )
    {
        if( RegQueryValueEx( hKey, "0", NULL, NULL, (unsigned char *)szBuffer,&hSize ) == ERROR_SUCCESS)
        {
            for( int i = 0; i < ( sizeof( sProduct ) / sizeof( char* ) ); i++ )
            {
                if( strstr( szBuffer, sProduct[ i ] ) )
                {
                    RegCloseKey( hKey );
                    return true;
                }
            }
        }
        RegCloseKey( hKey );
    }
    return false;
}

int main()
{
    if ( DetectVM() ) {
        printf ( "VM detected\n" );
    }
    else {
        printf ( "No VM detected\n" );
    }
    return 0;
}

Comentarios

4 comments para “Detectar Maquina Virtual VM en C++”

  1. Hay un error en el codigo:

    (…)RegQueryValueEx( hKey, “0″, NULL, NULL, (unsigned char *)szBuffer, &hSize ) == ERROR_SUCCESS(..)

    fijate que &hSize lo encodeó a html

    Posted by Lorena | agosto 5, 2008, 21:13
  2. Gracias por la info Lorena.
    Post Editado.

    Posted by octalh | agosto 6, 2008, 1:21
  3. Muito bom, posta mais funções usando o Visual Studio C++ 2010, nos deixe atualizado com essa IDE com códigos, sou seu fã

    Posted by Jacques | junio 14, 2010, 5:23
  4. Hola!, crees que esto podria ayudar a detectar un Rootkit ring -1?

    Posted by WALL-E | diciembre 27, 2010, 21:01

Deja un comentario