VC++檢測VM、VPC虛擬機器程式碼 .
C++檢測VM、VPC虛擬機器程式碼,新增後只需要呼叫IsVirtualMachine即可判斷是否在虛擬機器執行!
AntiVM.h
01.#ifndef __DETECT_VM__02222005__
02.#define __DETECT_VM__02222005__
03.
04.bool IsVirtualMachine();
05.bool IsInsideVPC();
06.bool IsInsideVMWare();
07.
08.#endif
AntiVM.cpp
/* -----------------------------------------------------------------------------
* Created by * lallous <lallousx86@yahoo.com> *
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* -----------------------------------------------------------------------------
History
---------
09/09/2004 - added IsInsideVPC()
02/22/2005 - added IsInsideVMWare()
03/26/2005 - . added C++ friendy version of IsInsideVPC() and renamed old IsInsideVPC()
. rewritten IsInsideVmWare()
Special thanks to Ken Kato <chitchat-lj@infoseek.jp> for his VMWare Backdoor information
(http://chitchat.at.infoseek.co.jp/vmware/vmtools.html)
*/
#include "AntiVM.h"
#include <windows.h>
bool IsVirtualMachine()
{
if(IsInsideVPC())
return true;
if(IsInsideVMWare())
return true;
return false;
}
// IsInsideVPC's exception filter
DWORD __forceinline IsInsideVPC_exceptionFilter(LPEXCEPTION_POINTERS ep)
{
PCONTEXT ctx = ep->ContextRecord;
ctx->Ebx = -1; // Not running VPC
ctx->Eip += 4; // skip past the "call VPC" opcodes
return EXCEPTION_CONTINUE_EXECUTION; // we can safely resume execution since we skipped faulty instruction
}
// high level language friendly version of IsInsideVPC()
bool IsInsideVPC()
{
bool rc = false;
__try
{
_asm push ebx
_asm mov ebx, 0 // Flag
_asm mov eax, 1 // VPC function number
// call VPC
_asm __emit 0Fh
_asm __emit 3Fh
_asm __emit 07h
_asm __emit 0Bh
_asm test ebx, ebx
_asm setz [rc]
_asm pop ebx
}
// The except block shouldn't get triggered if VPC is running!!
__except(IsInsideVPC_exceptionFilter(GetExceptionInformation()))
{
}
return rc;
}
bool IsInsideVMWare()
{
bool rc = true;
__try
{
__asm
{
push edx
push ecx
push ebx
mov eax, 'VMXh'
mov ebx, 0 // any value but not the MAGIC VALUE
mov ecx, 10 // get VMWare version
mov edx, 'VX' // port number
in eax, dx // read port
// on return EAX returns the VERSION
cmp ebx, 'VMXh' // is it a reply from VMWare?
setz [rc] // set return value
pop ebx
pop ecx
pop edx
}
}
__except(EXCEPTION_EXECUTE_HANDLER)
{
rc = false;
}
return rc;
}
/*
// pure ASM version of IsInsideVPC()
__declspec(naked) bool IsInsideVPC_asm()
{
__asm
{
push ebp
mov ebp, esp
mov ecx, offset exception_handler
push ebx
push ecx
push dword ptr fs:[0]
mov dword ptr fs:[0], esp
mov ebx, 0 // Flag
mov eax, 1 // VPC function number
}
// call VPC
_asm __emit 0Fh
_asm __emit 3Fh
_asm __emit 07h
_asm __emit 0Bh
_asm
{
mov eax, dword ptr ss:[esp]
mov dword ptr fs:[0], eax
add esp, 8
test ebx, ebx
setz al
lea esp, dword ptr ss:[ebp-4]
mov ebx, dword ptr ss:[esp]
mov ebp, dword ptr ss:[esp+4]
add esp, 8
jmp ret1
exception_handler:
mov ecx, [esp+0Ch]
mov dword ptr [ecx+0A4h], -1 // EBX = -1 -> not running, ebx = 0 -> running
add dword ptr [ecx+0B8h], 4 // -> skip past the call to VPC
xor eax, eax // exception is handled
ret
ret1:
ret
}
}
bool IsInsideVMWare_()
{
bool r;
_asm
{
push edx
push ecx
push ebx
mov eax, 'VMXh'
mov ebx, 0 // any value but MAGIC VALUE
mov ecx, 10 // get VMWare version
mov edx, 'VX' // port number
in eax, dx // read port
// on return EAX returns the VERSION
cmp ebx, 'VMXh' // is it a reply from VMWare?
setz [r] // set return value
pop ebx
pop ecx
pop edx
}
return r;
}
bool IsInsideVMWare()
{
__try
{
return IsInsideVMWare_();
}
__except(1) // 1 = EXCEPTION_EXECUTE_HANDLER
{
return false;
}
}
*/
相關文章
- VC++檢測VM、VPC虛擬機器程式碼C++虛擬機
- 親測好用的虛擬機器軟體:vm虛擬機器 mac中文版虛擬機Mac
- 虛擬機器 VM virtualBox && VMware虛擬機
- Esxi下vm虛擬機器命令虛擬機
- 虛擬機器VM跨版本使用虛擬機
- 虛擬機器檢測技術攻防虛擬機
- VM虛擬機器 VMware Fusion Pro for Mac虛擬機Mac
- VMware Fusion 13 for Mac(VM虛擬機器)Mac虛擬機
- vm虛擬機器改變硬碟大小虛擬機硬碟
- VM和Container 虛擬機器和容器AI虛擬機
- VMware Fusion Pro 13(VM虛擬機器) 中文虛擬機
- VMware Fusion Pro for mac(vm虛擬機器13.0.2)Mac虛擬機
- 安裝VM虛擬機器 centos7虛擬機CentOS
- VM虛擬機器Ubuntu下安裝VMTools虛擬機Ubuntu
- 超好用的mac虛擬機器軟體:VM虛擬機器 mac中文版Mac虛擬機
- VM 虛擬機器linux從主機複製檔案到虛擬機器錯誤虛擬機Linux
- 華為matebook14vm虛擬機器錯誤虛擬機
- VirtureBox如何執行VM的虛擬機器虛擬機
- VM虛擬機器 linux系統新增磁碟虛擬機Linux
- VM虛擬機器下載及安裝教程虛擬機
- 關於虛擬機器VM聯網問題虛擬機
- VMware Fusion Pro 13 for Mac,VM虛擬機器工具Mac虛擬機
- 搭建測試環境exadata一體機 (vm虛擬機器redhat上配置)虛擬機Redhat
- 怎樣檢視虛擬機器裡面的程式!虛擬機
- vm虛擬機器專業版:VMware Fusion Pro中文虛擬機
- 在VM虛擬機器中安裝centos7虛擬機CentOS
- vm虛擬機器啟動 報511錯誤虛擬機
- 虛擬機器vm開機黑屏處理,簡單解決虛擬機
- VM NAT模式主機虛擬機器互聯注意事項模式虛擬機
- 虛擬機器快速搭建 Android 包分析檢測工具虛擬機Android
- 動手實現程式碼虛擬機器虛擬機
- VM VirtualBox 虛擬機器掛載共享資料夾虛擬機
- 使用VM虛擬機器安裝CentOS-stream系統虛擬機CentOS
- 支援Monterey 12.x VM虛擬機器 中文版虛擬機
- VM虛擬機器:VMware Fusion Pro 13 Mac中文版虛擬機Mac
- vm虛擬機器安裝CentOS8.2伺服器系統虛擬機CentOS伺服器
- Dalvik虛擬機器、Java虛擬機器與ART虛擬機器虛擬機Java
- VM VirtualBox 虛擬機器 Linux 安裝增強功能虛擬機Linux