0x00 前言
站在滲透的角度,當獲得了一台Windows主機的權限后,需要全面了解這台Windows主機的信息,文件執行記錄是重要的部分。
而站在防御的角度,文件執行記錄包含系統的重要信息,對其進行針對性的清除很有必要。
所以本文將嘗試對Windows主機(Win7及以上系統)常見文件執行記錄的位置進行整理,嘗試獲取並清除單條記錄,分析利用思路,總結防御方法。
參考鏈接:
· 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系統可記錄的內容,分析了部分記錄的清除方法。