12

渗透技巧——Windows系统文件执行记录的获取与清除

 3 years ago
source link: https://3gstudent.github.io/3gstudent.github.io/%E6%B8%97%E9%80%8F%E6%8A%80%E5%B7%A7-Windows%E7%B3%BB%E7%BB%9F%E6%96%87%E4%BB%B6%E6%89%A7%E8%A1%8C%E8%AE%B0%E5%BD%95%E7%9A%84%E8%8E%B7%E5%8F%96%E4%B8%8E%E6%B8%85%E9%99%A4/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

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

源代码开源(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

源代码开源(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加密(解密比较简单)

记录实时更新

命令行解析

https://www.nirsoft.net/utils/userassist_view.html

用法示例:

UserAssistView.exe  /stext out.txt

源代码开源(c#)

https://blog.didierstevens.com/programs/userassist/

清除记录的方法

清除对应的注册表键值

3、MUICache

参考资料:

http://what-when-how.com/windows-forensic-analysis/registry-analysis-windows-forensic-analysis-part-8/

用来记录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

数据未加密

记录实时更新

命令行解析

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

命令行解析

源代码开源(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)

源代码开源(c#)

https://github.com/jwhwan9/dumpBCF

源代码开源(python)

https://github.com/prolsen/recentfilecache-parser

用法示例:

rfcparse.py -f C:\Windows\AppCompat\Programs\RecentFileCache.bcf

解析工具(Amcache.hve)

命令行解析

源代码开源(c#)

https://github.com/EricZimmerman/AmcacheParser

用法示例:

AmcacheParser.exe -f C:\Windows\AppCompat\Programs\Amcache.hve --csv c:\test

注:

某些情况下会无法导出,提示系统正在占用文件Amcache.hve

源代码开源(python)

https://github.com/williballenthin/python-registry/blob/master/samples/amcache.py

源代码开源(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

数据未加密

记录实时更新

直接查询文件夹

dir %APPDATA%\Microsoft\Windows\Recent

清除记录的方法

清除路径下的文件

4、SRUM

Win8及以上系统支持

参考资料:

https://www.sans.org/cyber-security-summit/archives/file/summit-archive-1492184583.pdf

包括多种信息,其中包括程序执行时间

记录实时更新

命令行解析

源代码开源(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 防御建议


不同系统支持不同方法,如下图:

Alt text

图片截取自https://1234n6-my.sharepoint.com/:x:/p/adam/EU3Fk3ec6NdPsSQx1eA1sfwB_R_fRa4tJ4c1FR6WJlWIEA?e=GRyu7r

站在防御的角度,可以选择定期清理系统中的文件执行记录

站在取证的角度,攻击者能够对文件执行记录进行修改和删除,所以对这些记录不能盲目相信

0x06 小结


本文对Windows主机(Win7及以上系统)常见文件执行记录的位置进行整理,通过实际测试验证了Windows系统可记录的内容,分析了部分记录的清除方法。


LEAVE A REPLY


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK