这是我之前写的一份远程线程注入的代码,用VC6编译在XP下测试通过,今天我试图在win10下用vs编译出来使用却失败了。字符串成功注了进去(用CE可以看到),但是LoadLibrary的返回值是0
我把用VC6编译的程序拖到WIN10下测试,发现可以成功注入,但同样的代码用VS编译注入就会失败
我以为是ASLR的问题,但是关闭了VS项目的ASLR之后还是没法注入到任何进程中。
我注的目标进程是用户态的,跟session隔离没关系,,不知道为什么VS生成的代码就是没法注进去,想请教一下大家。
以下是我远程线程注入的代码
#include "StdAfx.h"
// EnumProcessAndModules.cpp : Defines the entry point for the console application.
//
#include "windows.h"
#include "stdio.h"
#include "iostream"
// #include "head.h"
using namespace std;
#define MY_ASSERT(x) \
do \
{ \
if (!(x)) \
EXIT_ERROR("ASSERTION failed!"); \
} while (0)
#define EXIT_ERROR(x) \
do \
{ \
cout << "error in line " << __LINE__ << endl; \
printf("errcode = %d\n", GetLastError()); \
cout << x; \
system("pause"); \
exit(EXIT_FAILURE); \
} while (0)
char string_inject[] = "injectdll.dll";
#define MY_DEBUG
int main()
{
int pid = 0;
cout << "请输入要注入的进程的PID:";
cin >> pid;
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, pid);
if (hProcess == NULL)
EXIT_ERROR("hProcess == NULL!");
// else cout << hex << hProcess;
// 在进程中分配内存
LPVOID baseAddr = ::VirtualAllocEx(hProcess, NULL, sizeof(string_inject), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
if (baseAddr == NULL)
EXIT_ERROR("VirtualAllocEx failure");
#ifdef MY_DEBUG
printf("base address that VirtualAllocEx returns is 0x%x\n", (DWORD)baseAddr);
#endif
// 写入内存
DWORD NumberOfBytesWritten = 0;
if (!WriteProcessMemory(hProcess, baseAddr, string_inject, sizeof(string_inject), &NumberOfBytesWritten))
EXIT_ERROR("WriteProcessMemory failure");
#ifdef MY_DEBUG
printf("NumberOfBytesWritten = 0x%x\n", NumberOfBytesWritten);
#endif
// 创建远程线程
HANDLE hRemoteThread = ::CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibrary, /*TODO: */ baseAddr, 0, NULL);
MY_ASSERT(hRemoteThread);
// 3、等待线程函数结束, 获取线程退出码,即LoadLibrary的返回值,即dll的首地址
WaitForSingleObject(hRemoteThread, -1);
DWORD exitCode = 0;
if (!GetExitCodeThread(hRemoteThread, &exitCode))
EXIT_ERROR("GetExitCodeThread error!");
#ifdef MY_DEBUG
printf("thread exitcode = 0x%x\n", exitCode);
printf("errcode = %d\n", GetLastError());
#endif
system("pause");
}
|