vincevi1375/sigma2kql

GitHub: vincevi1375/sigma2kql

将厂商中立的 Sigma 检测规则(YAML)自动编译为 Microsoft Sentinel/Defender 的 KQL 查询,让安全团队以「检测即代码」方式统一管理和发布规则。

Stars: 0 | Forks: 0

# sigma2kql 将 [Sigma](https://github.com/SigmaHQ/sigma) 检测规则编译为 Microsoft Sentinel / Defender **KQL** 查询。 检测即代码团队只需用 Sigma 厂商中立的 YAML 编写一次规则; `sigma2kql` 会将限定的子集转换为可运行的 KQL,以便你可以通过 CI 对检测进行 lint、 测试和发布,而无需手动移植。 ## 安装 ``` pip install -e ".[dev]" ``` ## 用法 ``` sigma2kql tests/fixtures/powershell_download.yml # -> SecurityEvent # | where (Image endswith "\powershell.exe" and ...) sigma2kql rule.yml --table DeviceProcessEvents ``` 作为库使用: ``` from sigma2kql import parse_rule, compile_rule rule = parse_rule(yaml_text) print(compile_rule(rule, table="DeviceProcessEvents")) ``` ## 支持范围 (v0.1) - 命名的 `selection` 映射;字段在一个 selection 中进行 AND 运算 - 标量相等 (`field == value`) - 列表值 (`field in~ (a, b)`) - 修饰符:`contains`, `startswith`, `endswith` (列表值进行 OR 运算) - 扁平条件:`sel`, `sel1 and sel2`, `sel1 or sel2` ## 路线图 (尚不支持) - 带括号/嵌套的条件,`not`,`1 of them`,`all of *` - 聚合 (`| count`),`near`,数值比较修饰符 (`gt`, `lt`) - 每个 logsource 的字段映射 (例如 Sigma `Image` → Defender `FolderPath`) - 多个目标后端 不支持的结构会抛出带有明确信息的 `NotImplementedError`, 而不是生成错误的 KQL —— 静默的错误编译是 检测工具绝对不能做的事情。 ## 开发 ``` ruff check . pytest -v ```
标签:KQL, Microsoft Sentinel, Sigma规则, 代码库, 安全规则引擎, 检测规则转换, 目标导入, 逆向工具