elastic/detection-rules

GitHub: elastic/detection-rules

Elastic Security 官方检测规则仓库,提供检测规则开发、测试、验证和发布的完整工具链。

Stars: 2510 | Forks: 628

[![支持的 Python 版本](https://img.shields.io/badge/python-3.12+-yellow.svg)](https://www.python.org/downloads/) [![单元测试](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/80d819917f094426.svg)](https://github.com/elastic/detection-rules/actions) [![聊天](https://img.shields.io/badge/chat-%23security--detection--rules-blueviolet)](https://ela.st/slack) [![ATT&CK navigator 覆盖范围](https://img.shields.io/badge/ATT&CK-Navigator-red.svg)](https://ela.st/detection-rules-navigator-trade) # Detection 规则 Detection Rules 是 Elastic Security 所使用的规则的大本营。该仓库用于 Elastic Security 的 Detection Engine 规则的开发、维护、测试、验证和发布。 该仓库最初是在 Elastic 的博文 [Elastic Security opens public detection rules repo](https://elastic.co/blog/elastic-security-opens-public-detection-rules-repo) 中宣布的。有关更多内容,请参阅随附的网络研讨会 [Elastic Security: Introducing the public repository for detection rules](https://www.elastic.co/webinars/introducing-the-public-repository-for-detection-rules)。 ## 目录 - [Detection Rules](#detection-rules) - [目录](#table-of-contents) - [仓库概述](#overview-of-this-repository) - [入门指南](#getting-started) - [如何贡献](#how-to-contribute) - [Detections as Code (DaC)](#detections-as-code-dac) - [RTAs](#rtas) - [许可说明](#licensing) - [有问题?遇到困难?建议?](#questions-problems-suggestions) ## 仓库概述 Detection Rules 包含的内容不仅仅是静态规则文件。该仓库还包含用于构建 Detections-as-code 流水线、Python 单元测试以及与 Kibana 中的 Detection Engine 集成的代码。 | 文件夹 | 描述 | |------------------------------------------------ |------------------------------------------------------------------------------------ | | [`detection_rules/`](detection_rules) | 用于规则解析、验证和打包的 Python 模块 | | [`etc/`](detection_rules/etc) | 杂项文件,例如 ECS 和 Beats 架构及配置文件 | | [`hunting/`](./hunting/) | 存储威胁狩猎包和查询的根目录 | | [`kibana/`](lib/kibana) | 用于处理对 Kibana 和 Detection Engine API 调用的 Python 库 | | [`kql/`](lib/kql) | 用于解析和验证 Kibana Query Language 的 Python 库 | | [`rules/`](rules) | 存储规则的根目录 | | [`rules_building_block/`](rules_building_block) | 存储构建块规则的根目录 | | [`tests/`](tests) | 用于规则单元测试的 Python 代码 | ## 入门指南 虽然可以通过手动创建 `.toml` 文件来添加规则,但我们不建议这样做。该仓库还包含一个辅助规则创建和单元测试的 Python 模块。假设您使用的是 Python 3.12+,请运行以下命令以使用 makefile 安装依赖项: ``` ✗ make python3.12 -m pip install --upgrade pip setuptools Looking in indexes: https://pypi.org/simple Requirement already satisfied: pip in /opt/homebrew/lib/python3.12/site-packages (24.0) Requirement already satisfied: setuptools in /opt/homebrew/lib/python3.12/site-packages (69.1.1) python3.12 -m venv ./env/detection-rules-build ./env/detection-rules-build/bin/pip install --upgrade pip setuptools Looking in indexes: https://pypi.org/simple Requirement already satisfied: pip in ./env/detection-rules-build/lib/python3.12/site-packages (24.0) Collecting setuptools Using cached setuptools-69.1.1-py3-none-any.whl.metadata (6.2 kB) Using cached setuptools-69.1.1-py3-none-any.whl (819 kB) Installing collected packages: setuptools Successfully installed setuptools-69.1.1 Installing kql and kibana packages... ... ``` 或者使用以下命令安装依赖项: ``` $ pip3 install ".[dev]" Collecting jsl==0.2.4 Downloading jsl-0.2.4.tar.gz (21 kB) Collecting jsonschema==3.2.0 Downloading jsonschema-3.2.0-py2.py3-none-any.whl (56 kB) |████████████████████████████████| 56 kB 318 kB/s Collecting requests==2.22.0 Downloading requests-2.22.0-py2.py3-none-any.whl (57 kB) |████████████████████████████████| 57 kB 1.2 MB/s Collecting Click==7.0 Downloading Click-7.0-py2.py3-none-any.whl (81 kB) |████████████████████████████████| 81 kB 2.6 MB/s ... ``` 注意:`kibana` 和 `kql` 包在 PyPI 上不可用,必须从 `lib` 目录安装。`hunting` 包有可选依赖项,需通过 `pip3 install ".[hunting]` 安装。 ``` # 从 repository 安装 pip3 install git+https://github.com/elastic/detection-rules.git#subdirectory=lib/kibana pip3 install git+https://github.com/elastic/detection-rules.git#subdirectory=lib/kql # 或本地进行 development pip3 install lib/kibana lib/kql ``` 请记住,如果您使用的是虚拟环境,请确保将其激活。如果是通过 `make` 安装的,相关的虚拟环境将创建在 `env/detection-rules-build/` 中。 如果您在使用 Python 3.12 环境时遇到问题,请参阅我们[故障排除指南](./Troubleshooting.md)中的相关部分。 要确认所有内容均已正确安装,请使用 `--help` 标志运行 ``` $ python -m detection_rules --help Usage: detection_rules [OPTIONS] COMMAND [ARGS]... Commands for detection-rules repository. Options: -D, --debug / -N, --no-debug Print full exception stacktrace on errors -h, --help Show this message and exit. Commands: build-limited-rules Import rules from json, toml, or Kibana exported rule file(s), filter out unsupported ones, and write to output NDJSON file. build-threat-map-entry Build a threat map entry. create-rule Create a detection rule. custom-rules Commands for supporting custom rules. dev Commands related to the Elastic Stack rules release lifecycle. es Commands for integrating with Elasticsearch. export-rules-from-repo Export rule(s) and exception(s) into an importable ndjson file. generate-rules-index Generate enriched indexes of rules, based on a KQL search, for indexing/importing into elasticsearch/kibana. import-rules-to-repo Import rules from json, toml, or yaml files containing Kibana exported rule(s). kibana Commands for integrating with Kibana. mass-update Update multiple rules based on eql results. normalize-data Normalize Elasticsearch data timestamps and sort. rule-search Use KQL or EQL to find matching rules. test Run unit tests over all of the rules. toml-lint Cleanup files with some simple toml formatting. typosquat Commands for generating typosquat detections. validate-all Check if all rules validates against a schema. validate-rule Check if a rule staged in rules dir validates against a schema. view-rule View an internal rule or specified rule file. ``` 注意: - 如果您使用的是虚拟环境,请确保在运行上述命令之前将其激活。 - 如果使用 Windows,根据您的 Python 版本,您可能还需要运行 `\Scripts\pywin32_postinstall.py -install`。 [贡献指南](CONTRIBUTING.md)介绍了在为 Detection Rules 做贡献时,如何使用 `create-rule` 和 `test` 命令来创建和测试新规则。 有关更高级的命令行界面 (CLI) 用法,请参阅 [CLI 指南](CLI.md)。 ## 如何贡献 我们欢迎您对 Detection Rules 做出贡献!在贡献之前,请先熟悉该仓库、其[目录结构](#overview-of-this-repository)以及我们关于规则创建的[理念](PHILOSOPHY.md)。当您准备好做出贡献时,请阅读[贡献指南](CONTRIBUTING.md),了解我们如何将检测想法转化为生产规则并通过测试进行验证。 ## Detections as Code (DaC) Detection Rules 仓库包含许多命令,可帮助用户以“as code”的理念管理规则。我们建议先阅读我们的 [DaC 特定文档](https://dac-reference.readthedocs.io/en/latest/),了解策略和推荐的设置信息。但是,如果您更愿意直接开始,请参阅我们的本地[ detections as code 文档](docs-dev/detections-as-code.md)和[自定义规则文档](docs-dev/custom-rules-management.md),了解如何配置此仓库以使用自定义规则,然后参阅我们的 [CLI 文档](CLI.md),了解有关导入和导出规则的命令信息。 ## RTAs 用于模拟攻击者技术并验证规则的 Red Team Automations (RTAs) 可在专用 仓库 - [Cortado](https://github.com/elastic/cortado) 中找到。 ## 许可说明 本仓库中的所有内容 — 规则、代码等 — 均根据 [Elastic License v2](LICENSE.txt) 授权。这些规则旨在用于 Elastic Security 应用程序中的 Detection Engine 上下文中。如果您使用的是我们的 [Elastic Cloud 托管服务](https://www.elastic.co/cloud/)或包含[全套免费功能](https://www.elastic.co/subscriptions)的 Elastic Stack 默认发行版,首次导航到检测引擎时您将获得最新的规则。 有时,我们可能希望从另一个已经拥有许可证(例如 MIT 或 Apache 2.0)的仓库导入规则。这是受欢迎的,只要许可证允许根据 Elastic License v2 进行再许可即可。我们将这些许可证声明保留在 `NOTICE.txt` 中,并与所有其他规则一起以 Elastic License v2 进行再许可。我们还要求贡献者在向任何 Elastic 仓库贡献代码之前签署[贡献者许可协议](https://www.elastic.co/contributor-agreement)。 ## 有问题?遇到困难?建议? - 想了解更多关于 Detection Engine 的信息?请查看 Kibana 中的[概述](https://www.elastic.co/guide/en/security/current/detection-engine-overview.html)。 - 此仓库包含尚未发布的新规则和更新规则。要查看随 Stack 发布的最新规则集,请参阅[预置规则参考](https://www.elastic.co/guide/en/security/current/prebuilt-rules-downloadable-updates.html)。 - 如果您想报告误报或其他类型的错误,请创建一个 GitHub issue 并先检查是否已存在相关 issue。 - 需要 Detection Rules 方面的帮助?请在我们的[安全讨论论坛](https://discuss.elastic.co/c/security/)发帖提问,或者在 [Slack workspace](https://www.elastic.co/blog/join-our-elastic-stack-workspace-on-slack) 的 **#security-detection-rules** 频道中提问。 - 有关 DaC 的具体情况,请参阅我们的[支持和范围文档](docs-dev/detections-as-code.md#support-and-scope)以获取更多信息。
标签:AMSI绕过, API接口, Cloudflare, CSV导出, DaC, Detections-as-Code, DevSecOps, EDR, Elastic Security, GitHub, HTTP工具, IP 地址批量处理, MITRE ATT&CK, Modbus, PE 加载器, Python, Python安全, StruQ, YAML, 上游代理, 动态调用, 域名收集, 威胁检测, 子域名变形, 安全工程, 安全库, 安全检测规则, 实时处理, 密码管理, 提示词注入, 数据包嗅探, 无后门, 模拟器, 端点检测, 网络信息收集, 网络安全, 网络安全审计, 脆弱性评估, 误配置预防, 越狱测试, 逆向工具, 配置审计, 隐私保护