【应急响应工具教程】Windows日志快速分析工具——Chainsaw

admin 2025年5月15日17:49:18评论1 views字数 8559阅读28分31秒阅读模式

Chainsaw 提供强大的“第一响应”功能,可快速识别 Windows 取证工件(如事件日志和 MFT 文件)中的威胁。Chainsaw 提供了一种通用且快速的方法,可以在事件日志中搜索关键字,并使用对 Sigma 检测规则的内置支持和自定义 Chainsaw 检测规则来识别威胁。

【应急响应工具教程】Windows日志快速分析工具——Chainsaw

特征

  • 🎯 使用 Sigma 检测规则和自定义 Chainsaw 检测规则搜寻威胁
  • 🔍 通过字符串匹配和正则表达式模式搜索和提取法医伪影
  • 📅 通过分析 Shimcache 工件并使用 Amcache 数据丰富它们来创建执行时间表
  • 💡 分析 SRUM 数据库并提供有关它的见解
  • ⬇️ 转储取证伪影的原始内容(MFT、注册表配置单元、ESE 数据库)
  • ⚡ 快如闪电,用 Rust 编写,通过 @OBenamram 包装 EVTX 解析器库
  • 🪶 干净轻量级的执行和输出格式,没有不必要的膨胀
  • 🔥 TAU Engine Library 提供的文档标记(检测逻辑匹配)
  • 📑 以多种格式输出结果,例如 ASCII 表格式、CSV 格式和 JSON 格式
  • 💻 可以在 MacOS、Linux 和 Windows 上运行

github链接:

 https://github.com/WithSecureLabs/chainsaw

Windows 事件日志的搜寻逻辑

Sigma 规则匹配

使用 --sigma 和 --mapping 参数,您可以指定一个包含 SIGMA 检测规则子集(或仅整个 SIGMA git 存储库)的目录,chainsaw 将根据提供的事件日志自动加载、转换和运行这些规则。映射文件告诉 chainsaw 事件日志中的哪些字段用于规则匹配。默认情况下,Chainsaw 支持多种 Event Log 类型,包括但不限于:

事件类型
事件 ID
进程创建 (Sysmon)
1
网络连接 (Sysmon)
3
映像加载 (Sysmon)
7
文件创建 (Sysmon)
11
注册表事件 (Sysmon)
13
Powershell 脚本块
4104
进程创建
4688
计划任务创建
4698
服务创建
7045

电锯检测规则

除了支持 sigma 规则外,Chainsaw 还支持自定义规则格式。在存储库中,您将找到一个 rules 目录,其中包含各种 Chainsaw 规则,允许用户:

1.提取和解析 Windows Defender、F-Secure、Sophos 和 Kaspersky AV 警报

2.检测正在清除的关键事件日志或正在停止的事件日志服务

3.正在创建或添加到敏感用户组的用户

4.远程登录(服务、RDP、网络等)事件。这有助于猎人识别横向移动的来源

5.本地用户帐户的暴力破解

下载和运行

Chainsaw v2 以及不在将 Sigma Rules 和 EVTX-Attack-Samples 存储库作为 Chainsaw 子模块包含在内。

如果你想自己编译 Chainsaw,你可以克隆 Chainsaw 仓库:

git clone ``https://github.com/WithSecureLabs/chainsaw.git

然后通过运行 cargo build --release 自行编译代码。构建完成后,您将在 target/release 文件夹中找到已编译二进制文件的副本。

确保使用 --release 标志进行构建,因为这将确保显著加快执行时间。

如果你想快速查看 Chainsaw 运行时的样子,你可以克隆 Sigma Rules 和 EVTX-Attack-Samples 存储库:

git clone https://github.com/SigmaHQ/sigmagit clone https://github.com/sbousseaden/EVTX-ATTACK-SAMPLES.git

然后使用以下参数运行 Chainsaw:

./chainsaw hunt EVTX-ATTACK-SAMPLES/ -s sigma/ --mapping mappings/sigma-event-logs-all.yml

使用 Nix 进行安装/构建

├───devShells│   └───x86_64-linux│       └───default: development environment 'nix-shell'├───formatter│   └───x86_64-linux: package 'alejandra-3.1.0'└───packages    └───x86_64-linux        ├───chainsaw: package 'chainsaw-2.10.1'        └───default: package 'chainsaw-2.10.1'

Chainsaw 作为一个包,可以通过 nixpkgs 获得。如果你使用的是 NixOS,只需在你的系统配置文件中添加 chainsaw 即可。

但是,如果你没有使用 NixOS,你仍然可以通过 Nix 安装 Chainsaw。推荐的方法是通过 nix-shell,它会暂时修改你的 $PATH 环境变量。为此,请运行以下命令:

nix-shell -p chainsaw

您还可以利用此 repo 是 flake 这一事实,您可以运行以下内容:

nix profile install github:WithSecureLabs/chainsaw

但是,如果您想使用 Nix 自己构建 chainsaw,您可以再次使用此存储库中提供的 flake.nix。要构建二进制文件,请在克隆的 repo 的根目录中运行以下命令

nix build .#

这将创建 ./result 目录,其中 chainsaw 二进制文件位于 ./result/bin/chainsaw 下。

EDR 和 AV 警告

下载和运行 Chainsaw 时,您可能会发现本地 EDR / AntiVirus 引擎将 Chainsaw 检测为恶意。您可以在以下 GitHub 问题中看到相关示例:Example1、Example2。

这些警告通常是由于示例事件日志和/或 Sigma 规则包含对恶意字符串(例如“mimikatz”)的引用。我们还看到过 Chainsaw 二进制文件被一小部分反病毒引擎检测到的情况,这可能是由于某种形式的启发式检测。

简单使用

Searching

=  USAGE:      chainsaw search [FLAGS] [OPTIONS] <pattern> [--] [path]...  FLAGS:      -h, --help            Prints help information      -i, --ignore-case     Ignore the case when searching patterns          --json            Print the output in json format          --load-unknown    Allow chainsaw to try and load files it cannot identify          --local           Output the timestamp using the local machine's timestamp      -q                    Suppress informational output          --skip-errors     Continue to search when an error is encountered      -V, --version         Prints version information  OPTIONS:          --extension <extension>...    Only search through files with the provided extension          --from <from>                 The timestamp to search from. Drops any documents older than the value provided      -o, --output <output>             The path to output results to      -e, --regex <pattern>...          A string or regular expression pattern to search for      -t, --tau <tau>...                Tau expressions to search with. e.g. 'Event.System.EventID: =4104'          --timestamp <timestamp>       The field that contains the timestamp          --timezone <timezone>         Output the timestamp using the timezone provided          --to <to>                     The timestamp to search up to. Drops any documents newer than the value provided  ARGS:<pattern>    A string or regular expression pattern to search for. Not used when -e or -t is specified<path>...    The paths containing event logs to load and hunt through

命令示例

在所有 .evtx 文件中搜索不区分大小写的字符串 “mimikatz”

./chainsaw search mimikatz -i evtx_attack_samples/
【应急响应工具教程】Windows日志快速分析工具——Chainsaw

在所有 .evtx 文件中搜索 powershell 脚本块事件(事件 ID 4014)

./chainsaw search -t 'Event.System.EventID: =4104' evtx_attack_samples/
【应急响应工具教程】Windows日志快速分析工具——Chainsaw

在特定的 evtx 日志中搜索登录事件,具有匹配的正则表达式模式,输出为JSON格式

./chainsaw search -e "DC[0-9].insecurebank.local" evtx_attack_samples --json
【应急响应工具教程】Windows日志快速分析工具——Chainsaw

Hunting

  USAGE:      chainsaw hunt [FLAGS] [OPTIONS] [--] [path]...  FLAGS:--csv             Print the output in csv format--full            Print the full values for the tabular output      -h, --help            Prints help information--json            Print the output in json format--load-unknown    Allow chainsaw to try and load files it cannot identify--local           Output the timestamp using the local machine's timestamp--log             Print the output in log like format--metadata        Display additional metadata in the tablar output      -q                    Suppress informational output--skip-errors     Continue to hunt when an error is encountered      -V, --version         Prints version information  OPTIONS:--column-width <column-width>    Set the column width for the tabular output--extension <extension>...       Only hunt through files with the provided extension--from <from>                    The timestamp to hunt from. Drops any documents older than the value provided--kind <kind>...                 Restrict loaded rules to specified kinds--level <level>...               Restrict loaded rules to specified levels      -m, --mapping <mapping>...           A mapping file to tell Chainsaw how to use third-party rules      -o, --output <output>                A path to output results to      -r, --rule <rule>...                 A path containing additional rules to hunt with      -s, --sigma <sigma>...               A path containing Sigma rules to hunt with--status <status>...             Restrict loaded rules to specified statuses--timezone <timezone>            Output the timestamp using the timezone provided--to <to>                        The timestamp to hunt up to. Drops any documents newer than the value provided  ARGS:      <rules>      The path to a collection of rules to usefor hunting      <path>...    The paths containing eventlogstoloadand hunt through

命令示例

使用检测逻辑的 Sigma 规则搜寻所有 evtx 文件

./chainsaw hunt evtx_attack_samples/ -s sigma/ --mapping mappings/sigma-event-logs-all.yml

sigma规则下载链接:https://github.com/SigmaHQ/sigma

【应急响应工具教程】Windows日志快速分析工具——Chainsaw

使用 Sigma 规则和 Chainsaw 规则搜寻所有 evtx 文件,以获取检测逻辑,并以 CSV 格式输出到结果文件夹

./chainsaw hunt evtx_attack_samples/ -s sigma/ --mapping mappings/sigma-event-logs-all.yml -r rules/ --csv --output results

使用 Sigma 检测逻辑规则搜寻所有 evtx 文件,仅在特定时间戳之间搜索,并以JSON格式输出结果

 ./chainsaw hunt evtx_attack_samples/ -s sigma/ --mapping mappings/sigma-event-logs-all.yml --from "2019-03-17T19:09:39" --to "2019-03-17T19:09:50" --json

Analysing

COMMAND:    analyse shimcache                 Create an execution timeline from the shimcache with optional amcache enrichmentsUSAGE:    chainsaw analyse shimcache [OPTIONS] <SHIMCACHE>ARGUMENTS:    <SHIMCACHE>                       The pathto the shimcache artefact (SYSTEM registry file)OPTIONS:    -e, --regex <pattern>             A string or regular expression for detecting shimcache entries whose timestamp matches their insertion time    -r, --regexfile <REGEX_FILE>      The path to a newline delimited file containing regex patterns for detecting shimcache entries whose timestamp matches their insertion time    -o, --output <OUTPUT>             The path to output the result csv file    -a, --amcache <AMCACHE>           The path to the amcache artefact (Amcache.hve) for timeline enrichment    -p, --tspair                      Enable near timestamp pair detection between shimcache and amcache for finding additional insertion timestamps for shimcache entries    -h, --help                        Print help
  • --regexfile 参数的示例模式文件包含在 analysis/shimcache_patterns.txt 中。
  • 正则表达式模式在转换为小写的 shimcache 条目中的路径上匹配。
命令示例

使用提供的正则表达式模式分析 shimcache 工件,并在启用时间戳接近对检测的情况下使用 amcache 扩充。输出到 csv 文件。

./chainsaw analyse shimcache ./SYSTEM --regexfile ./analysis/shimcache_patterns.txt --amcache ./Amcache.hve --tspair --output ./output.csv

使用提供的正则表达式模式分析 shimcache 工件(无需 amcache 扩充)。输出到终端。

./chainsaw analyse shimcache ./SYSTEM --regexfile ./analysis/shimcache_patterns.txt

SRUM (系统资源使用情况监视器)

在 Chainsaw 中实现的 SRUM 数据库解析器与其他解析器不同,因为它不依赖于有关表的硬编码值。该信息直接从 SOFTWARE 配置单元中提取,这是一个必需参数。目标是避免与未知表相关的错误。

COMMAND:    analyse srum                             Analyse the SRUM databaseUSAGE:    chainsaw analyse srum [OPTIONS] --software <SOFTWARE_HIVE_PATH> <SRUM_PATH>ARGUMENTS:    <SRUM_PATH>                              The path to the SRUM databaseOPTIONS:    -s, --software <SOFTWARE_HIVE_PATH>      The path to the SOFTWARE hive--stats-only                         Only output details about the SRUM database    -q                                       Suppress informational output    -o, --output <OUTPUT>                    Save the output to a file    -h, --help                               Print help
命令示例

分析 SRUM 数据库(SOFTWARE 配置单元)

./chainsaw analyse srum --software ./SOFTWARE ./SRUDB.dat --output ./output.json

Dumping

USAGE:    chainsaw dump [OPTIONS] <PATH>ARGUMENTS:    <PATH>                  The path to an artefact to dumpOPTIONS:    -j, --json              Dump in json format--jsonl             Print the output in jsonl format--load-unknown      Allow chainsaw to try and load files it cannot identify    -o, --output <OUTPUT>   A path to output results to    -q                      Suppress informational output--skip-errors       Continue to hunt when an error is encountered    -h, --help              Print help

转储 SOFTWARE 配置单元

命令示例
./chainsaw dump ./SOFTWARE.hve --json --output ./output.json

原文始发于微信公众号(solar应急响应团队):【应急响应工具教程】Windows日志快速分析工具——Chainsaw

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2025年5月15日17:49:18
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【应急响应工具教程】Windows日志快速分析工具——Chainsawhttps://cn-sec.com/archives/4068280.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息