利用映像劫持轻松替换系统程序

  Image File Execution Options (其实应该称为“Image Hijack”)就是映像劫持技术,通过此种方式替换记事本,非常地绿色环保。

  Image File Execution Options 是 CreateProcess 函数中的一个功能,即在可执行程序运行时,Windows会先检测对应IFEO中的Debugger值,如果 存在这个参数的话,就运行这个参数中指定的程序,好像是程序调试之用,具体可以见这里

  原理:以替换记事本为例,通过修改 Image File Execution Options 键值后,在有 notepad.exe 运行请求的时候,欺骗系统运行指定的程序 notepad2.exe,为了更好地理解这个过程,我画了一幅图:

  根据上图我们可以得出两种更改文件打开方式的方法:

    • 使注册表定位到其它程序
    • 用其它程序替换原程序

这里两种方法各有优劣,第二种方法无疑更彻底,但问题也不少,下面我介绍的是第一种方法。

替换 notepad.exe

手工方法(所有方法的原理):

  1. 创建如下注册表项:HKLMSOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options otepad.exe,如果无法修改,需要先右键取得权限;
  2. 在notepad.exe 注册表项中,创建名为 Debugger 的字符串值(REG_SZ);
  3. 修改字符串值 Debugger 的数据为Notepad2.exe 的完整路径,最后以 /z参数结尾。
  4. 如:"D:Program FilesNotepad2Notepad2.exe" /z

 注册表方法:

1 Windows Registry Editor Version 5.00
2 
3 [HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe]
4 "Debugger"=""D:\Program Files\Notepad2\Notepad2.exe" /z"

批处理方法:

 1 @echo off
 2 cd /d "%~dp0"
 3 echo.
 4 echo.
 5 pause
 6 cd /d "%~dp0"
 7 reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe" /v "Debugger" /d ""%~dp0Notepad2.exe" /z" /f
 8 cls
 9 echo.
10 echo.
11 pause

批处理升级版:

  此版本在原版的基础上加入了管理员权限测试、劫持检测、反劫持。

 1 @echo off
 2 set regkey=HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe
 3 reg add "%regkey%" /v "test" /f 1>nul 2>nul && (reg delete "%regkey%" /v "test" /f) || (echo.&echo.&echo 缺少权限,请右键点击此脚本,选择“以管理员身份运行”。&pause>nul&exit)
 4 
 5 :begin
 6 cls
 7 for /L %%i in (1,1,5) do echo.
 8 set num=0
 9 reg query "%regkey%" /v "Debugger" 1>nul 2>nul && goto undo || goto done
10 
11 :done
12 set /P num=记事本[未劫持],是否开启劫持?( 1--是,其他--否 ) :
13 echo %num%
14 if %num% equ 1 reg add "%regkey%" /v "Debugger" /d ""%~dp0Notepad2.exe" /z" /f
15 goto begin
16 
17 :undo
18 set /P num=记事本[已劫持],是否取消劫持?( 1--是,其他--否 ) :
19 echo %num%
20 if %num% equ 1 reg delete "%regkey%" /f
21 goto begin

inf 方法:

  安装版:

 1 [Version]
 2 
 3 Signature="$WINDOWS NT$"
 4 
 5 [DefaultInstall]
 6 AddReg=an
 7 [an]
 8 HKLM,"SOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe","Debugger",0,"""%01%Notepad2.exe"" /z"
 9 HKCR,"*shellNotePad2",,,"用 &NotePad2 编辑"
10 HKCR,"*shellNotePad2command",,,"%01%Notepad2.exe ""%1"""

  反安装版:

1 [Version]
2 
3 Signature="$WINDOWS NT$"
4 
5 [DefaultInstall]
6 delReg=hf
7 [hf]
8 HKLM,"SOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options
otepad.exe"
9 HKCR,"*shellNotePad2

替换 explorer.exe

手工方法:(以 TC 为例)

  1. 打开注册表,HKEY_CLASSES_ROOTFoldershell
  2. 点开 open,opennewprocess,opennewwindow,修改里面的 command 键值
  3. 将 command 键值 "%SystemRoot%Explorer.exe" 修改为TC目录 "E: otalcmdTOTALCMD64.EXE""%1",删掉后面的 DelegateExecute {11dbb47c-a525-400b-9e80-a54615a090c0}.

  注意:该方法会导致无法打开 控制面板、个性化 等控制窗口!

还原(另存为*.reg):

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOTFoldershell] 

 
[HKEY_CLASSES_ROOTFoldershellexplore] 

"MultiSelectModel"="Document" 

"ProgrammaticAccessOnly"="" 

"LaunchExplorerFlags"=dword:00000018 

 
[HKEY_CLASSES_ROOTFoldershellexplorecommand] 

"DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}" 

 
[HKEY_CLASSES_ROOTFoldershellopen] 

"MultiSelectModel"="Document" 

 
[HKEY_CLASSES_ROOTFoldershellopencommand] 

"DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}" 

@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25, 
00,5c,00,45,00,78,00,70,00,6c,00,6f,00,72,00,65,00,72,00,2e,00,65,00,78,00, 
65,00,00,00 

 
[HKEY_CLASSES_ROOTFoldershellopennewprocess] 

"MUIVerb"="@shell32.dll,-8518" 

"MultiSelectModel"="Document" 

"Extended"="" 

"LaunchExplorerFlags"=dword:00000003 

"ExplorerHost"="{ceff45ee-c862-41de-aee2-a022c81eda92}" 

 
[HKEY_CLASSES_ROOTFoldershellopennewprocesscommand] 

"DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}" 

 
[HKEY_CLASSES_ROOTFoldershellopennewwindow] 

"MUIVerb"="@shell32.dll,-8517" 

"MultiSelectModel"="Document" 

"OnlyInBrowserWindow"="" 

"LaunchExplorerFlags"=dword:00000001 

 
[HKEY_CLASSES_ROOTFoldershellopennewwindowcommand] 

"DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}"  
原文地址:https://www.cnblogs.com/RhinoC/p/3772313.html