muchdogesec/yara2stix
GitHub: muchdogesec/yara2stix
一个将 YARA 规则转换为 STIX 2.1 对象的命令行工具,支持从社区仓库批量拉取或处理本地规则文件。
Stars: 2 | Forks: 0
# yarastix
一个将 YARA 规则转换为 STIX 2.1 对象的命令行工具。
## 开始之前
如果您不想自行回填、维护或支持您的 YARA STIX 对象,请查看 CTI Butler,它提供了一个完全托管这些对象及更多内容的数据库!
https://www.ctibutler.com/
## 概述
[YARA 文档](https://yara.readthedocs.io/en/stable/index.html)
YARA 规则易于编写和理解,其语法类似于 C 语言。
公开规则(经 YARA 团队批准)存储在主 YARA 仓库中:https://github.com/Yara-Rules/rules 。每条规则都以 `.yar` 文件的形式分发。
您可以在此处查看 YARA 规则示例:https://github.com/Yara-Rules/rules/blob/master/antidebug_antivm/antidebug_antivm.yar
在 Signals Corps,我们处理的大多数数据都采用 STIX 2.1 格式。这是因为下游的威胁情报工具能够理解 STIX。
因此,yara2stix 的工作原理是将 YARA 规则转换为 STIX 2.1 对象。
yara2stix 提供两种模式:
1. 从 [Yara-Rules/rules 仓库](https://github.com/Yara-Rules/rules)下载最新规则,并将每条规则转换为一系列 STIX 对象
2. 接受 `.yar` 文件中的 YARA 规则,并将其转换为 STIX indicator 对象
## 安装脚本
要安装 yara2stix;
```
# 克隆最新代码
git clone https://github.com/muchdogesec/yara2stix
# 创建 venv
cd yara2stix
python3 -m venv yara2stix-venv
source yara2stix-venv/bin/activate
# 安装 requirements
pip3 install -r requirements.txt
```
## 运行脚本
### 模式 1:Yara-Rules/rules 仓库 -> STIX
```
python3 yara2stix.py \
--mode yararules-repo
```
其中;
* `mode`(必填):如果您想从 [Yara-Rules/rules](https://github.com/Yara-Rules/rules) 下载最新规则,此项应始终为 `yararules-repo`。将始终使用 master 分支上的最新提交。
每次运行时,所有对象都会在 `stix2_objects` 目录中重新生成。
请注意,[您可以轻松地从我们的 cti_knowledge_base 仓库下载历史 YARA 数据,这样就无需运行此脚本](https://github.com/muchdogesec/cti_knowledge_base_store)。
### 模式 2:YARA YAR 文件 -> STIX
```
python3 yara2stix.py \
--mode yara-yar \
--file PATH/TO/FILE.yar
```
其中;
* `mode`(必填):如果您想转换本地的 YAR 文件,此项应始终为 `yara-yar`
* `file`(必填):是仅包含 YARA 规则的 YAR 文件的路径
例如
```
python3 yara2stix.py \
--mode yara-yar \
--file tests/demo_rules.yar
```
每次运行时,所有对象都会在 `stix2_objects` 目录中重新生成
## 映射信息
公开规则(经 YARA 仓库维护者批准)存储在主 YARA 仓库中,以 `.yar` 形式嵌套在以下目录中;
* `antidebug_antivm`
* `capabilities`
* `crypto`
* `cve_rules`
* `deprecated`
* `email`
* `exploit_kits`
* `maldocs`
* `malware`
* `mobile_malware`
* `packers`
* `webshells`
此脚本不考虑仓库中的任何其他目录。
### Marking Definition / Identity
这些是硬编码的,并从我们的 [stix4doge 仓库](https://github.com/muchdogesec/stix4doge)中导入。具体是这些对象;
* Marking Definition:https://raw.githubusercontent.com/muchdogesec/stix4doge/main/objects/marking-definition/yara2stix.json
* Identity:https://raw.githubusercontent.com/muchdogesec/stix4doge/main/objects/identity/yara2stix.json
### Indicators
在上述每个目录中,可能包含一个或多个 `.yar` 文件。
每个 `.yar` 文件可能包含一条或多条规则。
文件中的每条规则都以以下内容开头;
`private rule`(例如:https://github.com/Yara-Rules/rules/blob/master/antidebug_antivm/antidebug_antivm.yar#L7),或者
`rule`(例如:https://github.com/Yara-Rules/rules/blob/master/antidebug_antivm/antidebug_antivm.yar#L24)
`yar` 文件中的每条 YARA 规则都会被转换为一个 Indicator,如下所示;
```
{
"type": "indicator",
"spec_version": "2.1",
"id": "indicator--",
"created_by_ref": "",
"created": "",
"modified": "",
"indicator_types": [
"malicious-activity",
"anomalous-activity"
],
"name": "",
"description": "",
"pattern": "",
"pattern_type": "yara",
"valid_from": "",
"external_references": [
{
"source_name": "rule",
"url": ""
},
{
"source_name": "reference",
"url": ""
},
{
"source_name": "author",
"url": ""
}
],
"object_marking_refs": [
"marking-definition--94868c89-83c2-464b-929b-a1a8aa3c8487",
""
]
}
```
规则的 UUID 部分是使用命名空间 `2c741473-e0f1-5f0a-a044-ae2a368ad0c6` 和 YARA 规则的 `GITHUB LINK+name+pattern_type`(来自 STIX 对象)生成的。
例如:`https://github.com/Yara-Rules/rules/blob/master/crypto/crypto_signatures.yar+Big_Numbers0+yara` = `907116cb-0e98-5aa2-bbf2-741f3477f3d4` = `indicator--907116cb-0e98-5aa2-bbf2-741f3477f3d4`
#### 关于 `created` 和 `modified` 属性的简短说明
如果可能,我们会使用规则中找到的 `date` 字段作为 STIX 对象的 `created` 和 `modified` 属性。
如果规则中没有找到日期(或日期格式无法识别),脚本将使用提交时间(如果是 `yararules-repo`)或脚本执行时间(如果是 `yara-yar`)。
### Grouping
为了表示找到所有规则的文件,使用了一个 STIX grouping 对象...
```
{
"type": "grouping",
"spec_version": "2.1",
"id": "grouping--",
"created_by_ref": "",
"created": "",
"modified": "",
"name": "",
"context": "suspicious-activity",
"object_refs": [
"indicator--",
"indicator--"
],
"object_marking_refs": [
"marking-definition--94868c89-83c2-464b-929b-a1a8aa3c8487",
""
]
}
```
为了生成 SRO 的 id,使用命名空间 `2c741473-e0f1-5f0a-a044-ae2a368ad0c6` 和 `name` 属性生成一个 UUIDv5。
例如:`rules/antidebug_antivm` = `1c303523-b8ff-57aa-990f-c1cc43b43a25` = `grouping--1c303523-b8ff-57aa-990f-c1cc43b43a25`
作为一个真实示例,此目录路径包含 14 条规则:https://github.com/Yara-Rules/rules/tree/master/cve_rules,因此表示它的 grouping 对象中将存在 14 个 `object_refs`。
### Bundle
yara2stix 还会创建一个 STIX 2.1 Bundle JSON 对象,其中包含每次运行时创建的所有 STIX 2.1 对象。Bundle 采用以下格式;
```
{
"type": "bundle",
"id": "bundle--",
"objects": [
""
]
}
```
为了生成 SRO 的 id,使用命名空间 `2c741473-e0f1-5f0a-a044-ae2a368ad0c6` 和 `` 生成一个 UUIDv5。
该 bundle 名为:yara-rule-bundle.json
## 有用的支持工具
* 用于生成 STIX 2.1 对象:[stix2 Python 库](https://stix2.readthedocs.io/en/latest/)
* STIX 2.1 规范:[STIX 2.1 文档](https://docs.oasis-open.org/cti/stix/v2.1/stix-v2.1.html)
* [GitHub 上的 Yara-Rules](https://github.com/Yara-Rules/rules)
## 支持
[通过 DOGESEC 社区提供最低限度的支持](https://community.dogesec.com/)。
## 许可证
[Apache 2.0](/LICENSE)。
标签:STIX, YARA, 云资产可视化, 威胁情报, 开发者工具, 数据转换, 逆向工具