aris1009/pySigma-backend-victorialogs

GitHub: aris1009/pySigma-backend-victorialogs

将 Sigma 安全检测规则转换为 VictoriaLogs 的 LogsQL 查询的 pySigma 后端,支持多日志源字段映射和 vmalert 告警规则直接输出。

Stars: 0 | Forks: 0

# pySigma VictoriaLogs 后端 (LogsQL) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/ba022bd64a080801.svg)](https://github.com/aris1009/pySigma-backend-victorialogs/actions/workflows/test.yml) [![PyPI](https://img.shields.io/pypi/v/pySigma-backend-victorialogs.svg)](https://pypi.org/project/pySigma-backend-victorialogs/) [![Python](https://img.shields.io/pypi/pyversions/pySigma-backend-victorialogs.svg)](https://pypi.org/project/pySigma-backend-victorialogs/) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) 将 [Sigma](https://github.com/SigmaHQ/sigma) 检测规则转换为 针对 [VictoriaLogs](https://docs.victoriametrics.com/victorialogs/) 运行的 [LogsQL](https://docs.victoriametrics.com/victorialogs/logsql/) 查询。 ``` Sigma rule (YAML) │ ▼ pySigma core │ ▼ VictoriaLogsBackend ──► field:="value" AND other:~"regex" ``` ## 安装 推荐的方式是通过 `sigma-cli` 的插件系统: ``` pip install sigma-cli sigma plugin install victorialogs ``` 或者直接作为库安装: ``` pip install pysigma-backend-victorialogs ``` ## 首次查询 ``` sigma convert -t victorialogs path/to/rule.yml ``` 编程式用法: ``` from sigma.collection import SigmaCollection from sigma.backends.victorialogs import VictoriaLogsBackend rule = SigmaCollection.from_yaml(""" title: SSH login failure logsource: product: linux service: auth detection: sel: program: sshd message|contains: "Failed password" condition: sel """) print(VictoriaLogsBackend().convert(rule)[0]) # program:="sshd" AND message:~"Failed password" ``` 请参阅 [docs/getting_started.md](docs/getting_started.md) 获取包含本地 VictoriaLogs 容器的完整演练。 ## 兼容性 | 组件 | 支持的版本 | |------------|------------------------| | Python | 3.10, 3.11, 3.12, 3.13, 3.14 | | pySigma | `^1.1.0` | | VictoriaLogs | `v1.50.0` (在 CI 中通过摘要固定) | 为了可重现性,CI 通过 sha256 摘要固定了 `victoriametrics/victoria-logs:v1.50.0`;版本升级遵循 [CONTRIBUTING.md](CONTRIBUTING.md#bumping-the-pinned-victorialogs-image) 中的流程。 未对较旧或较新的 VL 版本进行主动测试,但只要它们能解析 [docs/mapping.md](docs/mapping.md) 中列出的 LogsQL 结构,就应该可以正常工作。 ## 映射摘要 | Sigma 特性 | LogsQL 输出 | |-----------------------------|----------------------------------------------------------| | `field: value` | `field:="value"` | | `field\|contains: x` | `field:~"x"` (regex) | | `field\|startswith: x` | `field:="x"*` (native prefix) | | `field\|endswith: x` | `field:~"x$"` (regex anchor) | | `field\|re: pattern` | `field:~"pattern"` | | `field\|cidr: 10.0.0.0/8` | `field:ipv4_range("10.0.0.0/8")` | | `field\|cidr: ::1/128` | `field:ipv6_range("::1/128")` | | `field\|gte: 1024` | `field:>=1024` | | `field\|fieldref: other` | `field:eq_field(other)` | | `field\|exists: true` | `field:*` | | `field: null` | `field:""` | | field IN [a, b] | `field:in("a", "b")` | | event_count correlation | `_time:Xm \| stats by (g) count() as event_count \| filter event_count:>=N` | 完整参考:[docs/mapping.md](docs/mapping.md)。 ## 管道 Sigma 规则使用中立的字段分类法(`Image`、`CommandLine`、`EventID` 等),这与任何特定日志发送器写入记录的方式都不匹配。请选择与您的摄取路径相匹配的管道: | Pipeline | 目标 | 重命名 | |-----------------------------------|-----------------------------------------|------------------------------------------------| | `victorialogs` | (无操作占位符) | 无 | | `victorialogs_windows_eventlog` | Winlogbeat / Vector ECS Windows 摄取 | `EventID`→`winlog.event_id`, EventData→`winlog.event_data.*`, 通道选择器 | | `victorialogs_journald` | systemd-journal 原生字段 | `Image`→`_EXE`, `CommandLine`→`_CMDLINE`, `Message`→`MESSAGE`, … | | `victorialogs_caddy` | Caddy v2 JSON 访问日志 | `cs-method`→`request.method`, `cs-uri-*`→`request.uri`, `sc-status`→`status`, … | | `victorialogs_suricata` | Suricata EVE JSON | `dst_ip`→`dest_ip`, `QueryName`→`dns.rrname`, `TlsServerName`→`tls.sni`, … | | `victorialogs_podman` | podman/docker journald `CONTAINER_*` | `ContainerName`→`CONTAINER_NAME`, `ImageName`→`IMAGE_NAME`, … | ``` sigma convert -t victorialogs -p victorialogs_journald rule.yml sigma convert -t victorialogs -p victorialogs_windows_eventlog rule.yml sigma convert -t victorialogs -p victorialogs_caddy rule.yml ``` 每个管道仅适用于 `logsource` 与其目标匹配的规则(例如,`product: linux` 对应 journald,`category: webserver` 对应 Caddy,`category: network` 或 `product: zeek|suricata` 对应 EVE 管道);其他规则将原封不动地通过。例如,当 podman 容器通过 journald 发送日志时,可以使用多个 `-p` 标志堆叠管道。 ## 输出格式 | 格式 | 输出 | |-----------|------------------------------------------------------------| | `default` | 纯 LogsQL 查询字符串(每条规则一个) | | `vmalert` | 用于 VictoriaLogs 的 vmalert 规则组 YAML (`type: vlogs`) | ### vmalert (部署为告警规则) ``` sigma convert -t victorialogs -f vmalert -p victorialogs_journald \ rules/*.yml > sigma-rules.yaml ``` 输出的是一个单一的规则组,可直接提供给指向 VictoriaLogs 数据源的 [vmalert](https://docs.victoriametrics.com/victorialogs/vmalert/): ``` vmalert \ -datasource.url=http://victorialogs:9428 \ -rule.defaultRuleType=vlogs \ -rule=sigma-rules.yaml \ -notifier.url=http://alertmanager:9093 ``` 每个 Sigma 规则将成为一个告警,其 `expr` 被包装为 ` | stats count() as matches | filter matches:>0`(关联规则已经聚合,并原封不动地通过)。vmalert 会自动前置 `_time:`,因此生成的表达式在设计上是时间无关的——通过组的 `interval`(默认为 `5m`)更改评估窗口,而不是编辑每个查询。Sigma `level` 映射到 `labels.severity`,`id` 映射到 `labels.sigma_id`。需要 vmalert ≥ v1.93(即添加 `type: vlogs` 的版本)。有关完整映射,请参阅 [docs/mapping.md §14](docs/mapping.md#14-vmalert-output-format)。 ## 限制 - **时间关联** (`temporal`, `temporl_ordered`) 不受支持——LogsQL 没有原生的多事件窗口连接。 - **`-search.maxQueryLen`** 默认为 16 KiB;有七个 SigmaHQ 规则生成的查询超出此限制。如果您需要它们,请在 VL 启动时提高该标志:`victoria-logs -search.maxQueryLen=524288 ...` - **无原生单字符通配符** —— Sigma 的 `?` 会路由到 regex。 - **大小写敏感**是默认行为 (LogsQL `:=`)。 完整详情和解决方法:[docs/limitations.md](docs/limitations.md)。 ## 文档 - [入门指南](docs/getting_started.md) — 安装 → 首次查询 → 运行中的 VL。 - [映射参考](docs/mapping.md) — 详尽的 Sigma → LogsQL 规范。 - [架构](docs/architecture.md) — 后端如何工作(面向贡献者)。 - [限制](docs/limitations.md) — 我们无法做的事情及其原因。 - [安全政策](SECURITY.md) — 威胁模型 + 报告。 - [贡献](CONTRIBUTING.md) — 开发设置 + 约定式提交。 ## 许可证 [MIT](LICENSE) © aris1009
标签:AMSI绕过, LogsQL, PB级数据处理, pySigma, Sigma规则, URL发现, VictoriaLogs, VictoriaMetrics, YAML转换, 威胁检测, 安全检测, 安全运维, 日志查询, 目标导入, 网络安全, 规则转换, 逆向工具, 隐私保护