13 Security Lab

[anti-VM] vmware - VMSwitchUserControlClass [2](Src) 본문

Computer Security/Analysis

[anti-VM] vmware - VMSwitchUserControlClass [2](Src)

Maj0r Tom 2015. 12. 28. 13:34

VMware - VMSwitchUserControlClass

[VirtualMachineDetect.h]

 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// ------------------------------------------------ ------------------------
// Function to determine whether the application starts a virtual machine
// Defined VirtualBox, VMware, VirtualPC and Parallels Workstation
// ------------------------------------------------ ------------------------
#include <windows.h>
#include <tlhelp32.h>
#include <iphlpapi.h>
 
#pragma comment (lib, "IPHLPAPI.lib")
 
// Detect VMware to backdoor-port
bool VMwareDetect ();
 
// VirtualPC detection using the "wrong" command processor
bool VirtualPCDetect ();
 
VMware detection // window name "VMSwitchUserControlClass"
bool VMwareWindowDetect ();
 
// Detection VirtualBox window name "VBoxTrayToolWndClass"
bool VirtualBoxWindowDetect ();
 
// Detect VMware's BIOS version in the registry
bool VMwareBIOSDetect ();
 
// Detection VirtualBox on video BIOS version in the registry
bool VirtualBoxBIOSDetect ();
 
// Parallels Workstatin detection of the presence of the key in the registry PRLSACPI
bool ParallelsRegDetect ();
 
// Discovery called VirtualBox process "VBoxTray.exe"
bool VirtualBoxProcessDetect ();
 
// VirtualPC detection process called "vmusrvc.exe"
bool VirtualPCProcessDetect ();
 
// Detect VMware's process name "vmtoolsd.exe"
bool VMwareProcessDetect ();
 
// Discovery called VirtualBox object "Device \ VBoxMiniRdrDN" and "Device \ VBoxGuest"
bool VirtualBoxDevObjDetect ();
 
// VirtualPC detection by object name "Device \\ VMDRV"
bool VirtualPCDevObjDetect ();
 
// VirtualBox detection by the ID of the processor
bool VirtualBoxCPUIDDetect ();
 
// Detect VMware's CPU ID
bool VMwareCPUIDDetect ();
 
// Detection Parallels Workstatin by ID processor
bool ParallelsCPUIDDetect ();
 
// VirtualPC detection of MAC-address
bool VirtualPCMACDetect ();
 
// Detection VirtualBox for MAC-address
bool VirtualBoxMACDetect ();
 
// Detect VMware's MAC-address
bool VMwareMACDetect ();
 
// Detection Parallels Workstatin MAC-based address
bool ParallelsMACDetect ();
 
// Detect virtual machine identifier for the hard disk
// For VirtualPC IDDisk - "DiskVirtual"
// For VirtualBox IDDisk - "DiskVBOX_HARDDISK"
// For VMware IDDisk - "Prod_VMware_Virtual"
BOOL VirtualMachineIDDiskDetect (char * IDDisk);
 
// Detection Parallels Workstatin on the graphics card
bool ParallelsVideoCardDetect ();
 
// Detection VirtualBox on the graphics card
bool VirtualBoxVideoCardDetect ();
 
// Detection VirtualPC on the graphics card
bool VirtualPCVideoCardDetect ();

 

 
 
[VirtualMachineDetect.cpp]
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515    
#include "VirtualMachineDetect.h"
 
// ------------------------------------------------ ----------------------
bool VMwareDetect ()
{
__try
        {
        __asm
                {
                mov eax, 0x564d5868
                mov ecx, 0x0A
                mov edx, 0x5658
                in eax, dx
                }
        return true;
        }
__except (EXCEPTION_EXECUTE_HANDLER)
        {
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VirtualPCDetect ()
{
__try
        {
        __asm
                {
                xor ebx, ebx
                mov eax, 1
                __emit (0x0F)
                __emit (0x3F)
                __emit (0x07)
                __emit (0x0B)
                }
        return true;
        }
__except (EXCEPTION_EXECUTE_HANDLER)
        {
         return false;
        }
}
// ------------------------------------------------ ----------------------
bool VMwareWindowDetect ()
{
HWND VMwareWindow = NULL;
VMwareWindow = FindWindowA ( "VMSwitchUserControlClass"NULL);
if (VMwareWindow! = NULL)
        {
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualBoxWindowDetect ()
{
HWND VBoxWindow = NULL;
VBoxWindow = FindWindowA ( "VBoxTrayToolWndClass"NULL);
if (VBoxWindow! = NULL)
        {
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool VMwareBIOSDetect ()
{
HKEY rKey;
wchar_t RegKey [256];
wchar_t RegVMware [] = ;
DWORD RegPath = sizeof (RegKey);
 
RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                         L "HARDWARE \\ DESCRIPTION \\ System \\ BIOS",
                         0
                         KEY_QUERY_VALUE,
                         & Amp; rKey);
 
RegQueryValueEx (rKey,
                                L "SystemProductName",
                                NULL,
                                NULL,
                                (BYTE *) RegKey,
                                & Amp; RegPath);
 
RegCloseKey (rKey);
 
if (memcmp (RegKey, RegVMware, 48== 0)
        {
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualBoxBIOSDetect ()
{
HKEY rKey;
wchar_t RegKey [256];
wchar_t RegVBox [] = ;
DWORD RegPath = sizeof (RegKey);
 
RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                         L "HARDWARE \\ DESCRIPTION \\ System",
                         0
                         KEY_QUERY_VALUE,
                         & Amp; rKey);
 
RegQueryValueEx (rKey,
                                L "VideoBiosVersion",
                                NULL,
                                NULL,
                                (BYTE *) RegKey,
                                & Amp; RegPath);
 
RegCloseKey (rKey);
 
if (memcmp (RegKey, RegVBox, 40== 0)
        {
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool ParallelsRegDetect ()
{
HKEY rKey;
 
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                                L "HARDWARE \\ ACPI \\ DSDT \\ PRLS __ \\ PRLSACPI",
                                0
                                KEY_QUERY_VALUE,
                                & Amp; rKey) == ERROR_SUCCESS)
        {
        RegCloseKey (rKey);
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualBoxProcessDetect ()
{
wchar_t VBoxProcessName [] = ;
PROCESSENTRY32 pe;
HANDLE hSnapShot;
hSnapShot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
ZeroMemory (& amp; pe, sizeof (PROCESSENTRY32W));
pe.dwSize = sizeof (PROCESSENTRY32W);
Process32First (hSnapShot, & amp; pe);
do
{
if (memcmp (pe.szExeFile, VBoxProcessName, 24== 0)
        {
         CloseHandle (hSnapShot);
         return true;
        }
}
while (Process32Next (hSnapShot, & amp; pe));
CloseHandle (hSnapShot);
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualPCProcessDetect ()
{
wchar_t VirtualPCProcessName [] = ;
PROCESSENTRY32 pe;
HANDLE hSnapShot;
hSnapShot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
ZeroMemory (& amp; pe, sizeof (PROCESSENTRY32W));
pe.dwSize = sizeof (PROCESSENTRY32W);
Process32First (hSnapShot, & amp; pe);
do
{
if (memcmp (pe.szExeFile, VirtualPCProcessName, 22== 0)
        {
         CloseHandle (hSnapShot);
         return true;
        }
}
while (Process32Next (hSnapShot, & amp; pe));
CloseHandle (hSnapShot);
return false;
}
// ------------------------------------------------ ----------------------
bool VMwareProcessDetect ()
{
wchar_t VMwareProcessName [] = ;
PROCESSENTRY32 pe;
HANDLE hSnapShot;
hSnapShot = CreateToolhelp32Snapshot (TH32CS_SNAPPROCESS, 0);
ZeroMemory (& amp; pe, sizeof (PROCESSENTRY32W));
pe.dwSize = sizeof (PROCESSENTRY32W);
Process32First (hSnapShot, & amp; pe);
do
{
if (memcmp (pe.szExeFile, VMwareProcessName, 24== 0)
        {
         CloseHandle (hSnapShot);
         return true;
        }
}
while (Process32Next (hSnapShot, & amp; pe));
CloseHandle (hSnapShot);
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualBoxDevObjDetect ()
{
if ((CreateFile (L "\\\\. \\ VBoxMiniRdrDN"0,0,0, OPEN_EXISTING, 0,0)! =
        INVALID_HANDLE_VALUE) ||
        (CreateFile (L "\\\\. \\ VBoxGuest"0,0,0, OPEN_EXISTING, 0,0)! =
        INVALID_HANDLE_VALUE))
        {
        return true;
        }
else
        {
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VirtualPCDevObjDetect ()
{
if (CreateFile (L "\\\\. \\ VMDRV"0,0,0, OPEN_EXISTING, 0,0)! =
        INVALID_HANDLE_VALUE)
        {
        return true;
        }
else
        {
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VirtualBoxCPUIDDetect ()
{
DWORD ID_1, ID_2, ID_3;
_asm
        {
        mov eax, 0x1
        cpuid
        mov eax, 0x40000000
        cpuid
        mov ID_1, ebx
        mov ID_2, ecx
        mov ID_3, edx
        }
if ((ID_1 == 0x00000340) & amp; & amp; (ID_2 == 0x00000340))
        {
        return true;
        }
else
        {
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VMwareCPUIDDetect ()
{
DWORD ID_1, ID_2, ID_3;
_asm
        {
        mov eax, 0x1
        cpuid
        mov eax, 0x40000000
        cpuid
        mov ID_1, ebx
        mov ID_2, ecx
        mov ID_3, edx
        }
if ((ID_1 == 0x61774d56) & amp; & amp; (ID_2 == 0x4d566572) & amp; & amp; (ID_3 == 0x65726177))
        {
        return true;
        }
else
        {
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool ParallelsCPUIDDetect ()
{
DWORD ID_1, ID_2, ID_3;
_asm
        {
        mov eax, 0x1
        cpuid
        mov eax, 0x40000000
        cpuid
        mov ID_1, ebx
        mov ID_2, ecx
        mov ID_3, edx
        }
if ((ID_1 == 0x70726c20) & amp; & amp; (ID_2 == 0x68797065) & amp; & amp; (ID_3 == 0x72762020))
        {
        return true;
        }
else
        {
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VirtualPCMACDetect ()
{
PIP_ADAPTER_INFO AdapterInfo = NULL;
DWORD OutBufLen;
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
AdapterInfo = (PIP_ADAPTER_INFO) new (char [OutBufLen]);
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
if (((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x03) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xff||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x12) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x5a||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x1d) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xd8||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x15) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x5d||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x22) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x48||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x0d) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x3a||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x17) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xfa||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x25) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xae||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x50) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xf2||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x28) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x18) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x78||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x60) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x45) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xbd||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x7c) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x1e) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x52||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x7c) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0xed) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x8d||
        ((BYTE) AdapterInfo- & gt; Address [0== 0xdc) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0xb4) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0xc4))
        {
        delete (AdapterInfo);
        return true;
        }
else
        {
        delete (AdapterInfo);
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VirtualBoxMACDetect ()
{
PIP_ADAPTER_INFO AdapterInfo = NULL;
DWORD OutBufLen;
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
AdapterInfo = (PIP_ADAPTER_INFO) new (char [OutBufLen]);
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
if (((BYTE) AdapterInfo- & gt; Address [0== 0x08) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x27||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x08) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x20))
        {
        delete (AdapterInfo);
        return true;
        }
else
        {
        delete (AdapterInfo);
        return false;
        }
}
// ------------------------------------------------ ----------------------
 
bool VMwareMACDetect ()
{
PIP_ADAPTER_INFO AdapterInfo = NULL;
DWORD OutBufLen;
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
AdapterInfo = (PIP_ADAPTER_INFO) new (char [OutBufLen]);
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
if (((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x05) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x69||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x0c) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x29||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x1c) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x14||
        ((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x50) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x56))
        {
        delete (AdapterInfo);
        return true;
        }
else
        {
        delete (AdapterInfo);
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool ParallelsMACDetect ()
{
PIP_ADAPTER_INFO AdapterInfo = NULL;
DWORD OutBufLen;
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
AdapterInfo = (PIP_ADAPTER_INFO) new (char [OutBufLen]);
GetAdaptersInfo (AdapterInfo, & amp; OutBufLen);
if (((BYTE) AdapterInfo- & gt; Address [0== 0x00) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [1== 0x1c) & amp; & amp;
        ((BYTE) AdapterInfo- & gt; Address [2== 0x42))
        {
        delete (AdapterInfo);
        return true;
        }
else
        {
        delete (AdapterInfo);
        return false;
        }
}
// ------------------------------------------------ ----------------------
bool VirtualMachineIDDiskDetect (char * IDDisk)
{
HKEY rKey;
char RegKey [4096];
DWORD RegPath = sizeof (RegKey);
DWORD Type = REG_SZ;
 
RegOpenKeyExA (HKEY_LOCAL_MACHINE,
                         "SYSTEM \\ CurrentControlSet \\ Services \\ Disk \\ Enum",
                         0
                         KEY_QUERY_VALUE,
                         & Amp; rKey);
 
RegQueryValueExA (rKey,
                                "0"
                                NULL,
                                & Amp; Type,
                                (LPBYTE) RegKey,
                                & Amp; RegPath);
 
RegCloseKey (rKey);
 
if (strstr (RegKey, IDDisk)! = 0)
        {
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool ParallelsVideoCardDetect ()
{
HKEY rKey;
 
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                                L "SYSTEM \\ CurrentControlSet \\ Enum \\ PCI \\ VEN_1AB8 & amp; DEV_4005 & amp; SUBSYS_04001AB8 & amp; REV_00",
                                0
                                KEY_QUERY_VALUE,
                                & Amp; rKey) == ERROR_SUCCESS)
        {
        RegCloseKey (rKey);
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualBoxVideoCardDetect ()
{
HKEY rKey;
 
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                                L "SYSTEM \\ CurrentControlSet \\ Enum \\ PCI \\ VEN_80EE & amp; DEV_BEEF & amp; SUBSYS_00000000 & amp; REV_00",
                                0
                                KEY_QUERY_VALUE,
                                & Amp; rKey) == ERROR_SUCCESS)
        {
        RegCloseKey (rKey);
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------
bool VirtualPCVideoCardDetect ()
{
HKEY rKey;
 
if (RegOpenKeyEx (HKEY_LOCAL_MACHINE,
                                L "SYSTEM \\ CurrentControlSet \\ Enum \\ PCI \\ VEN_5333 & amp; DEV_8811 & amp; SUBSYS_00000000 & amp; REV_00",
                                0
                                KEY_QUERY_VALUE,
                                & Amp; rKey) == ERROR_SUCCESS)
        {
        RegCloseKey (rKey);
        return true;
        }
return false;
}
// ------------------------------------------------ ----------------------

 

 

 

REF. :

damagelab.org/lofiversion/index.php?t=24538

 

www.anti-reversing.com/category/the-a-r-f-project/

 

Comments