Advertisement
PepperPotts

Antidebug DeviceIoControl(IOCTL_STORAGE_QUERY_PROPERTY)

Aug 21st, 2018
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. Antidebug trick DeviceIoControl(IOCTL_STORAGE_QUERY_PROPERTY), check matches against qemu, virtual, vmware, xen, vbox,...
  2.  
  3. FROM SAMPLE: 9f7149a0965adc1103a67db4980d6e81a3cce1c37ba6e334610a0ea6b34cd860
  4.  
  5. char sub_401000()
  6. {
  7.   DWORD v0; // eax
  8.   unsigned int j; // [esp+0h] [ebp-24Ch]
  9.   int i; // [esp+4h] [ebp-248h]
  10.   int v4; // [esp+Ch] [ebp-240h]
  11.   DWORD BytesReturned; // [esp+14h] [ebp-238h]
  12.   int Dst; // [esp+18h] [ebp-234h]
  13.   int v7; // [esp+24h] [ebp-228h]
  14.   HANDLE hDevice; // [esp+28h] [ebp-224h]
  15.   __int16 Str[130]; // [esp+2Ch] [ebp-220h]
  16.   int v10; // [esp+130h] [ebp-11Ch]
  17.   __int16 OutBuffer[8]; // [esp+134h] [ebp-118h]
  18.   int v12; // [esp+144h] [ebp-108h]
  19.   wchar_t *SubStr; // [esp+234h] [ebp-18h]
  20.   const wchar_t *v14; // [esp+238h] [ebp-14h]
  21.   const wchar_t *v15; // [esp+23Ch] [ebp-10h]
  22.   const wchar_t *v16; // [esp+240h] [ebp-Ch]
  23.   const wchar_t *v17; // [esp+244h] [ebp-8h]
  24.   int v18; // [esp+248h] [ebp-4h]
  25.  
  26.   SubStr = L"qemu";
  27.   v14 = L"virtual";
  28.   v15 = L"vmware";
  29.   v16 = L"xen";
  30.   v17 = L"vbox";
  31.   v18 = 0;
  32.   v7 = 0;
  33.   v10 = 0;
  34.   hDevice = CreateFileW(L"\\\\.\\PhysicalDrive0", 0, 3u, 0, 3u, 0, 0);
  35.   if ( hDevice != (HANDLE)-1 )
  36.   {
  37.     BytesReturned = 0;
  38.     memset(&Dst, 0, 0xCu);
  39.     Dst = 0;
  40.     memset(OutBuffer, 0, 0x100u);
  41.     memset(Str, 0, 0x100u);
  42.     //IOCTL_STORAGE_QUERY_PROPERTY = 0x2D1400
  43.     if ( DeviceIoControl(hDevice, 0x2D1400u, &Dst, 0xCu, OutBuffer, 0x100u, &BytesReturned, 0) )
  44.     {
  45.       v4 = 0;
  46.       for ( i = v12; OutBuffer[i]; ++i )
  47.         Str[v4++] = OutBuffer[i];
  48.       v0 = wcslen((const wchar_t *)Str);
  49.       CharLowerBuffW((LPWSTR)Str, v0);
  50.       for ( j = 0; j < 5; ++j )
  51.       {
  52.         if ( *(&SubStr)[j] && dowcsstr((wchar_t *)Str, (&SubStr)[j]) )
  53.           return 1;
  54.       }
  55.     }
  56.     CloseHandle(hDevice);
  57.   }
  58.   return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement