Image File Execution Options (其實應該稱爲「Image Hijack」)就是映像劫持技術,經過此種方式替換記事本,很是地綠色環保。shell
Image File Execution Options 是 CreateProcess 函數中的一個功能,即在可執行程序運行時,Windows會先檢測對應IFEO中的Debugger值,若是 存在這個參數的話,就運行這個參數中指定的程序,好像是程序調試之用,具體能夠見這裏。ide
原理:以替換記事本爲例,經過修改 Image File Execution Options 鍵值後,在有 notepad.exe 運行請求的時候,欺騙系統運行指定的程序 notepad2.exe,爲了更好地理解這個過程,我畫了一幅圖:函數
根據上圖咱們能夠得出兩種更改文件打開方式的方法:測試
這裏兩種方法各有優劣,第二種方法無疑更完全,但問題也很多,下面我介紹的是第一種方法。spa
手工方法(全部方法的原理):debug
註冊表方法:調試
1 Windows Registry Editor Version 5.00 2 3 [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe] 4 "Debugger"="\"D:\\Program Files\\Notepad2\\Notepad2.exe\" /z"
批處理方法:code
1 @echo off 2 cd /d "%~dp0" 3 echo. 4 echo. 5 pause 6 cd /d "%~dp0" 7 reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" /v "Debugger" /d "\"%~dp0Notepad2.exe\" /z" /f 8 cls 9 echo. 10 echo. 11 pause
批處理升級版:blog
此版本在原版的基礎上加入了管理員權限測試、劫持檢測、反劫持。字符串
1 @echo off 2 set regkey=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.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,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe","Debugger",0,"""%01%\Notepad2.exe"" /z" 9 HKCR,"*\shell\NotePad2",,,"用 &NotePad2 編輯" 10 HKCR,"*\shell\NotePad2\command",,,"%01%\Notepad2.exe ""%1"""
反安裝版:
1 [Version] 2 3 Signature="$WINDOWS NT$" 4 5 [DefaultInstall] 6 delReg=hf 7 [hf] 8 HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\notepad.exe" 9 HKCR,"*\shell\NotePad2
手工方法:(以 TC 爲例)
注意:該方法會致使沒法打開 控制面板、個性化 等控制窗口!
還原(另存爲*.reg):
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Folder\shell] [HKEY_CLASSES_ROOT\Folder\shell\explore] "MultiSelectModel"="Document" "ProgrammaticAccessOnly"="" "LaunchExplorerFlags"=dword:00000018 [HKEY_CLASSES_ROOT\Folder\shell\explore\command] "DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}" [HKEY_CLASSES_ROOT\Folder\shell\open] "MultiSelectModel"="Document" [HKEY_CLASSES_ROOT\Folder\shell\open\command] "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_ROOT\Folder\shell\opennewprocess] "MUIVerb"="@shell32.dll,-8518" "MultiSelectModel"="Document" "Extended"="" "LaunchExplorerFlags"=dword:00000003 "ExplorerHost"="{ceff45ee-c862-41de-aee2-a022c81eda92}" [HKEY_CLASSES_ROOT\Folder\shell\opennewprocess\command] "DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}" [HKEY_CLASSES_ROOT\Folder\shell\opennewwindow] "MUIVerb"="@shell32.dll,-8517" "MultiSelectModel"="Document" "OnlyInBrowserWindow"="" "LaunchExplorerFlags"=dword:00000001 [HKEY_CLASSES_ROOT\Folder\shell\opennewwindow\command] "DelegateExecute"="{11dbb47c-a525-400b-9e80-a54615a090c0}"