滲透技巧——Windows系統檔案執行記錄的獲取與清除
0x00 前言
站在滲透的角度,當獲得了一臺Windows主機的許可權後,需要全面瞭解這臺Windows主機的資訊,檔案執行記錄是重要的部分。
而站在防禦的角度,檔案執行記錄包含系統的重要資訊,對其進行鍼對性的清除很有必要。
所以本文將嘗試對Windows主機(Win7及以上系統)常見檔案執行記錄的位置進行整理,嘗試獲取並清除單條記錄,分析利用思路,總結防禦方法。
參考連結:
· ofollow,noindex">https://blog.1234n6.com/2018/10/available-artifacts-evidence-of.html?m=1
· https://xz.aliyun.com/t/3067#toc-5
0x01 簡介
本文將要介紹以下內容:
·從日誌獲得檔案執行記錄
· 從登錄檔獲得檔案執行記錄
· 從檔案獲得檔案執行記錄
· 例項測試
· 利用和防禦思路
0x02 從日誌獲得檔案執行記錄
1、程序建立(ID:4688)
使用條件:
系統預設關閉該功能,需要手動設定開啟。
·Policy location: Computer Configuration -> Policies -> Windows Settings -> Security Settings -> Advanced Audit Configuration -> Detailed Tracking
·Policy Name: Audit Process Creation
命令列獲得日誌資訊:
wevtutil qe security /rd:true /f:text /q:"Event[System[(EventID=4688)]]"
清除記錄的方法:
單條日誌的清除,可參考之前的文章: 《滲透技巧——Windows單條日誌的刪除》
2、Microsoft-Windows-Application-Experience Program-Inventory
參考資料: http://journeyintoir.blogspot.com/2014/03/exploring-program-inventory-event-log.html
·800 (summary of software activities)
· 903 & 904 (new application installation)
· 905 & 906 (updated application)
· 907 & 908 (removed application).
命令列獲得日誌資訊:
wevtutil qe Microsoft-Windows-Application-Experience/Program-Inventory
3、Microsoft-Windows-Application-Experience Program-Telemetry
命令列獲得日誌資訊:
wevtutil qe Microsoft-Windows-Application-Experience/Program-Telemetry
0x03 從登錄檔獲得檔案執行記錄
1、ShimCache
參考資料: https://www.fireeye.com/blog/threat-research/2015/06/caching_out_the_val.html
用來記錄Windows系統程式執行時產生的相容性問題。
位置:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache
XP最多儲存96條記錄,Win7及以上最多儲存1024條記錄。
記錄以下內容:
· 檔案路徑
· 上次修改時間
· 是否被執行
注:ShimCache不僅會記錄exe檔案的執行,而且會對exe檔案同級目錄下的檔案進行記錄(如果檔案沒有執行,那麼Executed的屬性為no)。
資料以固定格式儲存,儲存結構可參考: https://www.fireeye.com/content/dam/fireeye-www/services/freeware/shimcache-whitepaper.pdf
解析工具
(1)原始碼開源(c#)
https://github.com/EricZimmerman/AppCompatCacheParser/
用法示例:
讀取當前系統的登錄檔並將結果輸出的到指定路徑:
AppCompatCacheParser.exe --csv c:\test
輸出結果按照上次修改的時間排序:
AppCompatCacheParser.exe --csv c:\test -t
讀取指定System檔案並將結果輸出的到指定路徑:
AppCompatCacheParser.exe --csv c:\test -h C:\Windows\System32\config\SYSTEM
(2)原始碼開源(python)
如果想要先匯出登錄檔檔案,然後在另一系統中獲得解析結果,可使用python實現的指令碼:
https://github.com/mandiant/ShimCacheParser
用法示例:
reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache" ShimCache.reg ShimCacheParser.py -o out.csv -r c:\test\ShimCache.reg -t
通過System檔案匯出結果:
ShimCacheParser.py -o out.csv -i C:\Windows\System32\config\SYSTEM -t
清除記錄的方法
ShimCache只會在系統重新啟動後更新(登出當前使用者不會更新)。
也就是說,想要清除本次系統從啟動至關機的ShimCache記錄,有兩種方法:
(1)修改登錄檔
備份當前登錄檔:
reg export "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\AppCompatCache" ShimCache.reg
系統重啟後,恢復登錄檔:
reg import ShimCache.reg
(2)非正常關機
跳過寫入登錄檔的操作,無法記錄本次系統自啟動至關機的記錄。
(3)修改記憶體
(理論上可行)
2、UserAssist
參考資料: https://www.4n6k.com/2013/05/userassist-forensics-timelines.html
可以用來記錄Windows系統程式執行的次數和最後一次執行時間。
位置:
當前使用者:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist
所有使用者:
HKEY_USERS\<sid>\Software\Microsoft\Windows\CurrentVersion\Explorer\UserAssist
子健的名稱使用ROT-13加密(解密比較簡單)。
記錄實時更新。
解析工具
(1)命令列解析
https://www.nirsoft.net/utils/userassist_view.html
用法示例:
UserAssistView.exe/stext out.txt
(2)原始碼開源(c#)
https://blog.didierstevens.com/programs/userassist/
清除記錄的方法
清除對應的登錄檔鍵值。
3、MUICache
用來記錄exe檔案的檔名稱,在登錄檔中儲存exe檔案的絕對路徑和對應exe檔案的檔名稱。
位置:
當前使用者:
HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache
所有使用者:
HKEY_USERS\<sid>\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache
資料未加密。
記錄實時更新。
解析工具
(1)命令列解析
http://www.nirsoft.net/utils/muicache_view.html
用法示例:
MUICacheView.exe/stext out.txt
(2)直接查詢登錄檔
reg query "HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache"
清除記錄的方法
清除對應的登錄檔鍵值
4、RunMRU
參考資料: http://www.forensicfocus.com/a-forensic-analysis-of-the-windows-registry
儲存輸入Win+U啟動程式的歷史記錄。
位置:
當前使用者:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU
所有使用者:
HKEY_USERS\<sid>\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU
資料未加密。
記錄實時更新。
解析工具
(1)直接查詢登錄檔
reg query "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\RunMRU"
清除記錄的方法
清除對應的登錄檔鍵值。
5、AppCompatFlags Registry Keys
參考資料: https://journeyintoir.blogspot.com/2013/12/revealing-program-compatibility.html
儲存程式執行記錄。
位置:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store
解析工具
(1)直接查詢登錄檔
reg query "HKLM\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Persisted" reg query "HKCU\Software\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Compatibility Assistant\Store"
清除記錄的方法
清除對應的登錄檔鍵值。
0x04 從檔案獲得檔案執行記錄
1、Prefetch
參考資料: https://www.forensicmag.com/article/2010/12/decoding-prefetch-files-forensic-purposes-part-1
預讀取資料夾,用來存放系統已訪問過檔案的預讀資訊,能夠加快系統的啟動速度。
記錄檔案執行次數、上次執行時間、Hash等。
檢視該功能是否開啟:
reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters" /v EnablePrefetcher
·0 = Disabled
· 1 = Only Application launch prefetching enabled
· 2 = Only Boot prefetching enabled
· 3 = Both Application launch and Boot prefetching enabled
位置:
C:\Windows\Prefetch
資料以固定格式儲存,副檔名為pf。
解析工具
(1)命令列解析
原始碼開源(c#)
https://github.com/EricZimmerman/PECmd
用法示例:
PECmd.exe -d C:\Windows\Prefetch --csv c:\temp
生成兩個檔案"time"_PECmd_Output.csv和"time"_PECmd_Output_Timeline.csv
"time"_PECmd_Output.csv儲存詳細資訊
"time"_PECmd_Output_Timeline.csv只儲存檔案的名稱列表
PECmd.exe -d C:\Windows\Prefetch --json c:\temp
生成多個json檔案,每個pf檔案對應一個json檔案。
清除記錄的方法
刪除對應檔名的pf檔案。
2、Amcache
參考資料:
· https://journeyintoir.blogspot.com/2013/12/revealing-recentfilecachebcf-file.html
· http://www.swiftforensics.com/2013/12/amcachehve-in-windows-8-goldmine-for.html
用來跟蹤應用程式與不同可執行檔案的相容性問題。
資料以固定格式儲存。
位置:
Win7:
C:\Windows\AppCompat\Programs\RecentFileCache.bcf
只記錄檔名稱。
Win8及以上:
C:\Windows\AppCompat\Programs\Amcache.hve
記錄建立時間、上次修改時間、SHA1和一些PE檔案頭資訊。
注:Win7系統安裝KB2952664後,也會支援Amcache.hve,也就是說,RecentFileCache.bcf和Amcache.hve都包含檔案執行記錄。
解析工具(RecentFileCache.bcf)
(1)原始碼開源(c#)
https://github.com/jwhwan9/dumpBCF
(2)原始碼開源(python)
https://github.com/prolsen/recentfilecache-parser
用法示例:
rfcparse.py -f C:\Windows\AppCompat\Programs\RecentFileCache.bcf
解析工具(Amcache.hve)
(1)命令列解析
原始碼開源(c#)
https://github.com/EricZimmerman/AmcacheParser
用法示例:
AmcacheParser.exe -f C:\Windows\AppCompat\Programs\Amcache.hve --csv c:\test
注:某些情況下會無法匯出,提示系統正在佔用檔案Amcache.hve
(2)原始碼開源(python)
https://github.com/williballenthin/python-registry/blob/master/samples/amcache.py
(3)原始碼開源(powershell)
https://github.com/yoda66/GetAmCache/blob/master/Get-Amcache.ps1
清除記錄的方法(RecentFileCache.bcf)
修改檔案。
詳細方法將在下篇文章《滲透技巧——RecentFileCache.bcf和Amcache.hve單條記錄的清除》介紹
清除記錄的方法(Amcache.hve)
修改檔案。
詳細方法將在下篇文章《滲透技巧——RecentFileCache.bcf和Amcache.hve單條記錄的清除》介紹
3、JumpLists
參考資料: https://articles.forensicfocus.com/2012/10/30/forensic-analysis-of-windows-7-jump-lists/
用來記錄使用者最近使用的文件和應用程式,通常顯示在工作列中
位置:
%APPDATA%\Microsoft\Windows\Recent
資料未加密。
記錄實時更新。
解析工具
(1)直接查詢資料夾。
dir %APPDATA%\Microsoft\Windows\Recent
清除記錄的方法
清除路徑下的檔案。
4、SRUM
Win8及以上系統支援。
參考資料: https://www.sans.org/cyber-security-summit/archives/file/summit-archive-1492184583.pdf
包括多種資訊,其中包括程式執行時間。
資料加密。
記錄實時更新。
解析工具
(1)命令列解析
原始碼開源(python)
https://github.com/MarkBaggett/srum-dump
用法示例:
需要模板檔案SRUM_TEMPLATE.xlsx
srum_dump.exe --SRUM_INFILE c:\Windows\system32\sru\SRUDB.dat
注:我在測試的過程中發現上面的命令有問題,執行失敗,提示ESE File Not found: C:\Windows\System32\sru\SRUDB.dat
需要將SRUDB.dat複製到另一目錄,再進行解析。
srum_dump.exe --SRUM_INFILE SRUDB.dat
清除記錄的方法
(留在以後介紹)
0x05 防禦建議
不同系統支援不同方法,如下圖:
圖片擷取自https://1234n6-my.sharepoint.com/:x:/p/adam/EU3Fk3ec6NdPsSQx1eA1sfwB_R_fRa4tJ4c1FR6WJlWIEA?e=GRyu7r
站在防禦的角度,可以選擇定期清理系統中的檔案執行記錄
站在取證的角度,攻擊者能夠對檔案執行記錄進行修改和刪除,所以對這些記錄不能盲目相信
0x06 小結
本文對Windows主機(Win7及以上系統)常見檔案執行記錄的位置進行整理,通過實際測試驗證了Windows系統可記錄的內容,分析了部分記錄的清除方法。