Windows 父进程欺骗技术,其实就是创建一个进程,指定其他进程为这个新创建进程的父进程。
通过CreateProcessA进行欺骗
对父进程进行欺骗有许多方法,本文中着重介绍通过调用CreateProcessA函数进行实现,该方法最简单也最常用。
CreateProcessA函数允许用户创建新进程,默认情况下,会通过其继承的父进程完成创建。该函数有一个名为“lpStartupInfo”的参数,该参数允许使用者自定义要使用的父进程。该功能最初用于Windows Vista中设置UAC。
lpStartupInfo参数指向一个名为“STARTUPINFOEX”的结构体,该结构包含变量“lpAttributeList”,这个变量在初始化时可以调用“UpdateProcThreadAttribute”回调函数进行属性添加,你可以通过“PROC_THREAD_ATTRIBUTE_PARENT_PROCESS”属性从而对父进程进行设置。
一下为C++实现代码
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
#include <winternl.h>
#include <psapi.h>
#include <processthreadsapi.h>
int main(int argc, char* argv[])
{
if (argc != 3)
return 0;
PROCESS_INFORMATION pi = { 0 };
STARTUPINFOEXA si = { 0 };
SIZE_T sizeToAllocate;
char* pEnd = NULL;
DWORD dwParentID = strtol(argv[1], &pEnd, 10);
char* pszPath = argv[2];
// Get a handle on the parent process to use
HANDLE processHandle = OpenProcess(PROCESS_ALL_ACCESS, false, dwParentID);
if (processHandle == NULL)
{
fprintf(stderr, "OpenProcess failed\n");
return 1;
}
// Initialize the process start attributes
InitializeProcThreadAttributeList(NULL, 1, 0, &sizeToAllocate);
// Allocate the size needed for the attribute list
si.lpAttributeList = (LPPROC_THREAD_ATTRIBUTE_LIST)HeapAlloc(GetProcessHeap(), 0, sizeToAllocate);
InitializeProcThreadAttributeList(si.lpAttributeList, 1, 0, &sizeToAllocate);
// Set the PROC_THREAD_ATTRIBUTE_PARENT_PROCESS option to specify the parent process to use
if (!UpdateProcThreadAttribute(si.lpAttributeList, 0, PROC_THREAD_ATTRIBUTE_PARENT_PROCESS,
&processHandle, sizeof(HANDLE), NULL, NULL))
{
fprintf(stderr, "UpdateProcThreadAttribute failed");
return 1;
}
si.StartupInfo.cb = sizeof(STARTUPINFOEXA);
printf("Creating process...\n");
BOOL success = CreateProcessA(
NULL, // App name
pszPath, // Command line
NULL, // Process attributes
NULL, // Thread attributes
true, // Inherits handles?
EXTENDED_STARTUPINFO_PRESENT | CREATE_NEW_CONSOLE, // Creation flags
NULL, // Env
NULL, // Current dir
(LPSTARTUPINFOA)&si,
&pi
);
if (!success)
{
printf("Error %d\n", GetLastError());
}
return 0;
}
测试一下效果吧,
参考文献: