forked from INotGreen/Check-SandBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCheckParentProcess.cpp
66 lines (56 loc) · 1.8 KB
/
CheckParentProcess.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
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <string>
#include <psapi.h>
#pragma comment(lib, "psapi.lib")
bool CheckParentProcess()
{
// 获取当前进程的父进程ID
DWORD parentPID = 0;
HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 pe32 = { sizeof(PROCESSENTRY32) };
if (Process32First(hSnapshot, &pe32))
{
do {
if (pe32.th32ProcessID == GetCurrentProcessId())
{
parentPID = pe32.th32ParentProcessID;
break;
}
} while (Process32Next(hSnapshot, &pe32));
}
CloseHandle(hSnapshot);
// 检查父进程是否为沙箱进程
if (parentPID == 0)
return false;
HANDLE hParentProcess = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, parentPID);
if (hParentProcess == NULL)
return false;
std::wstring parentName(MAX_PATH, L'\0');
DWORD len = GetProcessImageFileNameW(hParentProcess, &parentName[0], MAX_PATH);
parentName.resize(len);
bool isSandbox = false;
// 以下示例代码用于检测VMware、VirtualBox等虚拟机软件的特征
if (parentName.find(L"vmware") != std::wstring::npos ||
parentName.find(L"vbox") != std::wstring::npos ||
parentName.find(L"qemu") != std::wstring::npos ||
parentName.find(L"vmsrvc") != std::wstring::npos)
{
isSandbox = true;
}
CloseHandle(hParentProcess);
return isSandbox;
}
int main()
{
if (CheckParentProcess())
{
std::cout << "Current process is running in sandbox environment." << std::endl;
}
else
{
std::cout << "Current process is not running in sandbox environment." << std::endl;
}
return 0;
}