Windows应急响应/36-自动化IR工具-KAPE与Velociraptor 本篇覆盖两大IR自动化工具:KAPE (离线取证采集)和 Velociraptor (远程agent响应)
以及 Eric Zimmerman Tools 完整工具链
关联:31-自动化排查脚本 、04-取证制品分析
一、KAPE (Kroll Artifact Parser and Extractor) 1.1 概述 KAPE由Eric Zimmerman开发,现归Kroll所有
核心理念:Targets (收集什么)+ Modules (如何解析)
下载:https://www.kroll.com/en/services/cyber-risk/incident-response-litigation-support/kroll-artifact-parser-extractor-kape
两个阶段:
Target收集 :从活动系统或磁盘镜像中提取取证制品文件
Module解析 :用各种解析工具处理收集到的文件,生成可读结果
1.2 Target(采集目标) Target定义了要收集的文件路径和模式
Target文件格式(.tkape):
1 2 3 4 5 6 7 8 9 10 11 12 Description: 收集Windows事件日志Author: Eric ZimmermanVersion: 1.0 Id: 1234567 8-123 4-123 4-123 4-123456789012 RecreateDirectories: true Targets: - Name: EventLogs Category: EventLogs Path: C:\Windows\System32\winevt\Logs\ FileMask: '* .evtx' Recursive: false
常用内置Target:
1 2 3 4 5 6 7 8 9 10 11 12 13 !BasicCollection → 事件日志 + 注册表hive + 预取 + 浏览器 + 基本系统文件 !SANS_Triage → SANS推荐的全量取证制品集 !EvidenceOfExecution → Prefetch + Amcache + ShimCache + BAM/DAM !FileSystem → $MFT + $J (USN Journal) + $LogFile !RegistryHives → SAM + SYSTEM + SOFTWARE + SECURITY + NTUSER.DAT + UsrClass.dat !EventLogs → 所有Windows事件日志(.evtx) !WebBrowsers → Chrome + Firefox + Edge 历史/缓存/Cookie !Antivirus → Windows Defender + 主流AV日志 !RecycleBin → 回收站文件和元数据 !PowerShellConsole → PowerShell ConsoleHost_history !RemoteAccess → RDP/TeamViewer/AnyDesk 等日志 !ScheduledTasks → 计划任务XML文件 !SRUM → 系统资源使用监视器数据库
1.3 Module(解析模块) Module定义了使用什么工具解析Target收集到的文件
Module文件格式(.mkape):
1 2 3 4 5 6 7 8 9 10 11 12 Description: 使用EvtxECmd解析Windows事件日志Category: EventLogsAuthor: Eric ZimmermanVersion: 1.0 Id: 87654321 -1234 -1234 -1234 -123456789012 BinaryUrl: https:ExportFormat: csvProcessors: - Executable: EvtxECmd\EvtxECmd.exe CommandLine: -d %sourceDirectory% --csv %destinationDirectory% ExportFormat: csv
常用内置Module:
1 2 3 4 5 6 7 8 9 10 !EZParser → 调用所有Eric Zimmerman工具集中解析 MFTECmd → $MFT 解析 PECmd → Prefetch 解析 AmcacheParser → Amcache.hve 解析 AppCompatCacheParser → ShimCache 解析 RECmd → 注册表批量查询 EvtxECmd → Windows事件日志解析 SrumECmd → SRUM数据库解析 JLECmd → Jump Lists 解析LECmd → LNK文件解析
1.4 KAPE使用示例 基础采集 (活动系统):
1 2 kape.exe --tsource C: --tdest C:\IR\Collection --target !BasicCollection
SANS Triage全量采集 :
1 2 kape.exe --tsource C: --tdest C:\IR\Collection --target !SANS_Triage --zip KAPECollection
采集+解析一步完成 :
1 2 kape.exe --tsource C: --tdest C:\IR\Collection --target !BasicCollection --mdest C:\IR\Parsed --module !EZParser
仅对已采集数据进行解析 :
1 2 kape.exe --msource C:\IR\Collection --mdest C:\IR\Parsed --module !EZParser
远程采集(UNC路径) :
1 2 kape.exe --tsource C: --tdest \\IR-Server \Cases\Host01 --target !SANS_Triage --zip Host01_Collection
1.5 自定义Target示例 创建自定义Target收集特定APT制品:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 Description : APT专项取证采集 Author : IR Team Version : 1.0 Id : aabbccdd-1234-5678-9012-abcdef123456 RecreateDirectories : true Targets : - Name : Sysmon Logs Category : EventLogs Path : C:\Windows\System32\winevt\Logs\ FileMask : 'Microsoft-Windows-Sysmon%4Operational.evtx' - Name : PowerShell Logs Category : EventLogs Path : C:\Windows\System32\winevt\Logs\ FileMask : 'Microsoft-Windows-PowerShell%4Operational.evtx' - Name : Prefetch Category : Execution Path : C:\Windows\Prefetch\ FileMask : '*.pf' - Name : Amcache Category : Execution Path : C:\Windows\AppCompat\Programs\ FileMask : 'Amcache.hve' - Name : SRUM Category : Execution Path : C:\Windows\System32\sru\ FileMask : 'SRUDB.dat' - Name : Hosts File Category : Network Path : C:\Windows\System32\drivers\etc\ FileMask : 'hosts' - Name : WMI Repository Category : Persistence Path : C:\Windows\System32\wbem\Repository\ Recursive : true
1.6 自定义Module示例 创建Hayabusa日志分析模块:
1 2 3 4 5 6 7 8 9 10 11 Description : 使用Hayabusa分析Windows事件日志 Category : EventLogs Author : IR Team Version : 1.0 Id : 11223344-5566-7788-9900-aabbccddeeff Processors : - Executable : hayabusa\hayabusa.exe CommandLine : csv-timeline -d %sourceDirectory% -o %destinationDirectory%\hayabusa_timeline.csv -p super-verbose ExportFormat : csv
二、Velociraptor 2.1 概述 Velociraptor是基于agent的数字取证和IR平台
由Rapid7维护,开源:https://github.com/Velocidex/velociraptor
架构:Server + Client Agent(支持Windows/Linux/macOS)
核心特性:
VQL (Velociraptor Query Language) —— 类SQL的查询语言
Artifacts —— 预定义的取证查询包
Hunts —— 在多台主机上同时执行查询
Offline Collector —— 不需要server也能采集
2.2 部署方式 快速部署 (单机测试):
1 2 3 4 5 6 7 8 9 velociraptor.exe config generate -i velociraptor.exe gui
生产部署 :
1 2 3 4 5 6 7 8 9 10 velociraptor.exe config generate velociraptor.exe --config server.config.yaml frontend velociraptor.exe --config server.config.yaml debian client velociraptor.exe --config client.config.yaml service install
2.3 VQL 查询语言 VQL语法类似SQL,用于查询系统制品
基本语法:
1 2 3 4 5 SELECT Column1, Column2FROM plugin(arg1= value1, arg2= value2)WHERE condition ORDER BY Column1LIMIT 100
常用查询示例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 SELECT Pid, Name, Exe, CommandLine, UsernameFROM pslist()SELECT Pid, Name, Status, Laddr, RaddrFROM netstat()WHERE Status = "ESTABLISHED"SELECT Name, FullPath, Data.value AS Value FROM glob(globs= "HKLM/SOFTWARE/Microsoft/Windows/CurrentVersion/Run/*", accessor= "registry")SELECT FullPath, Size, Mtime, BtimeFROM glob(globs= "C:/Users/*/AppData/**/*.exe")WHERE Size < 1000000 SELECT * FROM Artifact.Windows.System.TaskScheduler()WHERE Command = ~ "powershell|cmd|wscript|cscript"SELECT * FROM Artifact.Windows.Persistence.PermanentWMIEvents()SELECT FullPath, hash(path= FullPath) AS HashFROM glob(globs= "C:/Windows/Temp/*.exe")
2.4 内置 Artifacts Velociraptor自带数百个Artifact,覆盖常见IR场景:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 === 取证制品 === Windows.Forensics.Prefetch → Prefetch文件解析 Windows.Forensics.Amcache → Amcache解析 Windows.Forensics.ShimCache → ShimCache解析 Windows.Forensics.SRUM → SRUM数据库解析 Windows.Forensics.Timeline → 文件系统时间线 Windows.Forensics.MFT → $MFT解析 Windows.Forensics.Usn → USN Journal解析 Windows.Forensics.Lnk → LNK快捷方式解析 Windows.Forensics.RecycleBin → 回收站解析 === 持久化 === Windows.Persistence.PermanentWMIEvents → WMI事件订阅 Windows.Sys.StartupItems → 启动项 Windows.System.TaskScheduler → 计划任务 Windows.System.Services → 服务列表 === 检测 === Windows.Detection.Yara.Process → 进程内存YARA扫描 Windows.Detection.Yara.NTFS → 文件系统YARA扫描 Windows.Detection.HiddenProcesses → 隐藏进程检测 Windows.Detection.Mutants → 互斥量检测 === 日志 === Windows.EventLogs.Hayabusa → Hayabusa日志分析 Windows.EventLogs.PowerShell → PowerShell日志 Windows.EventLogs.RDPAuth → RDP认证日志 Windows.EventLogs.Sysmon → Sysmon日志
2.5 Hunt 创建(多主机查询) Hunt允许在所有已连接的agent上同时执行Artifact
Web UI操作:
顶部菜单 → Hunt Manager → New Hunt
选择Artifact(如 Windows.Persistence.PermanentWMIEvents)
配置参数和条件
选择目标主机(All / Label / 特定主机)
Launch Hunt
VQL示例 —— 自定义Hunt查找恶意计划任务:
1 2 3 4 SELECT ClientId, Fqdn, TaskName, Command, ArgumentsFROM Artifact.Windows.System.TaskScheduler()WHERE Command = ~ "(?i)powershell|cmd\.exe|wscript|mshta|certutil"
2.6 Offline Collector 不需要Server,生成独立的采集器exe:
1 2 3 4 5 6 velociraptor.exe --config server.config.yaml artifacts collect --output Collection.zip Windows.Forensics.Prefetch Windows.System.TaskScheduler Windows.Persistence.PermanentWMIEvents
适用场景:
无法安装agent的孤立系统
通过USB启动采集
临时响应,不需要持久agent
采集结果:ZIP文件,可导入到Server中分析或用VQL离线查询
3.1 工具清单与用途 下载地址:https://ericzimmerman.github.io/#!index.md
批量下载:
1 2 3 Invoke-WebRequest -Uri "https://raw.githubusercontent.com/EricZimmerman/Get-ZimmermanTools/master/Get-ZimmermanTools.ps1" -OutFile Get-ZimmermanTools .ps1.\Get-ZimmermanTools .ps1 -Dest C:\Tools\EZTools
工具
用途
输入
关键参数
MFTECmd
解析$MFT
$MFT文件
--csv 输出CSV
PECmd
解析Prefetch
.pf文件/目录
-d 目录 --csv
AmcacheParser
解析Amcache
Amcache.hve
--csv
AppCompatCacheParser
解析ShimCache
SYSTEM hive
--csv
RECmd
注册表批量查询
注册表hive
-d --bn batch文件
ShellBags Explorer
解析ShellBags
NTUSER.DAT/UsrClass.dat
GUI工具
JLECmd
解析Jump Lists
AutomaticDestinations
--csv
LECmd
解析LNK文件
.lnk文件
--csv
SrumECmd
解析SRUM
SRUDB.dat
--csv
EvtxECmd
解析事件日志
.evtx文件
-d --csv
Timeline Explorer
浏览CSV时间线
CSV文件
GUI工具
bstrings
高级字符串搜索
任意文件
-s --ls
WxTCmd
解析Windows 10 Timeline
ActivitiesCache.db
--csv
SBECmd
ShellBags命令行版
注册表hive
--csv
RBCmd
解析回收站
$I文件
--csv
3.2 MFTECmd 用法 解析$MFT(Master File Table)获取完整文件系统时间线:
1 2 3 4 5 6 7 8 MFTECmd.exe -f C:\IR\Collection\C\$MFT --csv C:\IR\Parsed\MFT
时间戳篡改(timestomping)检测:
1 2 3 4 5 6 7 8 Import-Csv "C:\IR\Parsed\MFT\*.csv" | Where-Object { $si = [datetime ]$_ .'Created0x10' $fn = [datetime ]$_ .'Created0x30' [Math ]::Abs(($si - $fn ).TotalHours) -gt 1 } | Select-Object ParentPath, FileName, 'Created0x10' , 'Created0x30' | Format-Table -AutoSize
3.3 PECmd 用法 解析Prefetch文件获取程序执行记录:
1 2 3 4 5 6 7 8 9 10 PECmd.exe -d C:\IR\Collection\C\Windows\Prefetch --csv C:\IR\Parsed\Prefetch PECmd.exe -f "C:\IR\Collection\C\Windows\Prefetch\CMD.EXE-89305D47.pf" --json C:\IR\Parsed
3.4 EvtxECmd 用法 解析Windows事件日志到CSV/JSON:
1 2 3 4 5 6 7 8 EvtxECmd.exe -d C:\IR\Collection\C\Windows\System32\winevt\Logs --csv C:\IR\Parsed\EventLogs EvtxECmd.exe -f C:\IR\Collection\Security.evtx --csv C:\IR\Parsed\EventLogs EvtxECmd.exe -d C:\IR\Logs --csv C:\IR\Parsed --maps C:\Tools\EZTools\EvtxECmd\Maps
配合 Timeline Explorer 进行可视化分析:
打开生成的CSV文件
按时间排序,筛选特定事件ID
支持列过滤、搜索、高亮
3.5 RECmd 注册表批量查询 使用Batch文件批量查询注册表制品:
1 2 3 4 RECmd.exe -d C:\IR\Collection\RegistryHives --bn C:\Tools\EZTools\RECmd\BatchExamples\RECmd_Batch_MC.reb --csv C:\IR\Parsed\Registry
3.6 AmcacheParser / AppCompatCacheParser 程序执行证据:
1 2 3 4 5 AmcacheParser.exe -f C:\IR\Collection\C\Windows\AppCompat\Programs\Amcache.hve --csv C:\IR\Parsed\Amcache AppCompatCacheParser.exe -f C:\IR\Collection\C\Windows\System32\config\SYSTEM --csv C:\IR\Parsed\ShimCache
3.7 SrumECmd 解析SRUM(System Resource Usage Monitor)数据库:
1 2 3 4 5 6 7 SrumECmd.exe -f C:\IR\Collection\C\Windows\System32\sru\SRUDB.dat -r C:\IR\Collection\C\Windows\System32\config\SOFTWARE --csv C:\IR\Parsed\SRUM
四、工具对比 4.1 KAPE vs Velociraptor vs 手动
特性
KAPE
Velociraptor
手动采集
部署方式
独立exe,无需安装
Agent + Server
无需工具
采集速度
快(文件复制)
快(VQL查询)
慢
远程支持
有限(UNC路径)
原生支持(Agent)
需要远程工具
多主机
需脚本分发
Hunt功能原生支持
逐台操作
实时查询
不支持
支持(VQL)
手动
解析能力
Module调用EZ Tools
内置Artifact
手动运行工具
学习曲线
低
中(需学VQL)
高
离线分析
支持
Offline Collector
支持
定制化
Target/Module文件
VQL + Artifact YAML
完全自定义
适用场景
单机深度取证
企业级多主机响应
特定需求
4.2 推荐使用策略 单机IR :KAPE !SANS_Triage 采集 → EZ Tools解析 → Timeline Explorer分析
企业级IR :Velociraptor Hunt → 筛选可疑主机 → KAPE深度采集
无工具环境 :手动PowerShell采集 → 带回分析(参考:31-自动化排查脚本 )
离线分析 :KAPE Module-only模式处理已采集数据
五、实战工作流示例 5.1 场景:发现可疑横向移动 Step 1:Velociraptor Hunt
1 2 3 4 5 SELECT * FROM Artifact.Windows.EventLogs.Sysmon()WHERE EventID = 1 AND (CommandLine = ~ "(?i)psexec" OR ParentImage = ~ "(?i)psexesvc")
Step 2:确定受影响主机,用KAPE深度采集
1 kape.exe --tsource C: --tdest \\IR-Server \Cases\Host-Compromised --target !SANS_Triage --zip CompromisedHost
Step 3:EZ Tools解析
1 2 kape.exe --msource \\IR-Server \Cases\Host-Compromised --mdest \\IR-Server \Parsed\Host-Compromised --module !EZParser
Step 4:Timeline Explorer分析
打开解析结果CSV
构建时间线,追踪攻击者活动
5.2 场景:勒索软件应急 Step 1:Velociraptor快速排查
1 2 3 4 5 6 7 8 SELECT FullPath, Mtime, SizeFROM glob(globs= "C:/Users/**/{README,DECRYPT,RESTORE,HOW_TO}*")SELECT FullPath, MtimeFROM glob(globs= "C:/Users/**/*.{encrypted,locked,crypto,crypt}")LIMIT 50
Step 2:KAPE采集关键证据
1 kape.exe --tsource C: --tdest E:\IR\RansomCase --target !SANS_Triage,!EventLogs --zip Ransomware_Evidence
Step 3:分析执行证据
1 2 3 4 5 6 7 8 PECmd.exe -d E:\IR\Parsed\Prefetch --csv E:\IR\Analysis AmcacheParser.exe -f E:\IR\Collection\Amcache.hve --csv E:\IR\Analysis hayabusa.exe csv-timeline -d E:\IR\Collection\EventLogs -o E:\IR\Analysis\hayabusa.csv -p super-verbose
关联参考:
04-取证制品分析 — 取证制品详解
31-自动化排查脚本 — Linux端自动化采集
35-恶意软件基础分析 — 采集到的恶意文件分析