idaholab/ATIS
GitHub: idaholab/ATIS
ATIS 是一款将 VirusTotal 等开源威胁情报自动转换为 STIX 标准化图谱并进行比较与丰富的威胁情报处理工具。
Stars: 3 | Forks: 0
# 任意威胁情报到 STIX (ATIS)
本项目的目的是从 VirusTotal 报告中包含的信息生成 STIX 图。
该程序接收一个单独的 sha-256 哈希值或一个包含多个 sha-256 哈希值的文本文件,并根据与哈希值关联的 VirusTotal 报告生成 STIX 图。如果哈希值没有关联的 VirusTotal 报告,程序将跳过该文件。
注意:如果使用 campaign 或 generate many 功能,文本文件必须每行包含一个 sha-256 哈希值,并且哈希值的首尾必须没有空白字符。未来,我们将研究如何处理空白字符以及哪种格式最适合此功能。
- [任意威胁情报到 STIX](#any-threat-intelligence-to-stix)
- [安装](#installation)
- [Anaconda 安装](#anaconda-installation)
- [变量与 API Key 设置](#variables--api-key-setup)
- [用法](#usage)
- [STIX 图生成](#stix-graph-generation)
- [单个恶意软件样本生成图](#graph-from-single-malware-sample)
- [多个恶意软件样本生成图](#graph-from-multiple-malware-samples)
- [生成 Campaign 图](#generate-campaign-graph)
- [生成 Family 图](#generate-family-graph)
- [比较 STIX 图](#compare-stix-graphs)
- [生成 STIX 图比较的热力图](#generate-heatmap-of-stix-graph-comparison)
- [丰富现有的 STIX 图](#enrich-existing-stix-graph)
- [丰富多个现有的 STIX 图](#enrich-multiple-existing-stix-graphs)
- [故障排除](#troubleshooting)
- [同行评审](#peer-reviews)
## 安装
本项目使用 Python 编程语言开发,目标版本为 Python3.8。本项目的开发使用了 Anaconda 虚拟环境系统,但也可以使用 Poetry/pyenv 来创建虚拟环境。
### Anaconda 安装
```
conda create -n atis python=3.8
conda activate atis
pip install -r requirements.txt
```
### 变量与 API Key 设置
将 variables.TEMPLATE 文件的名称更改为 variables.py
将 API_KEY 变量更改为您的个人 VirusTotal API key。如果您还没有 key,请阅读[此指南](https://developers.virustotal.com/reference/getting-started) 了解如何免费获取一个。
通过将 API_PREMIUM 变量更改为 True(如果使用 premium API)或 False(如果使用 public API)来指定 API key 是 public 还是 premium。这将告诉 VTAGS 在请求之间进行等待,以避免触发 public API 施加的 4 次请求/分钟的限制。
## 用法
```
Any Threat Intelligence to STIX
Usage:
main.py generate single
main.py generate many
main.py generate campaign
main.py generate family
main.py compare
main.py heatmap
main.py weights
main.py clean
main.py configure (yara|ma) (yes|no)
main.py enrich single [cve]
main.py enrich many [cve]
main.py (-h | --help)
main.py --version
Options:
yara|noYara Generate the graphs with or without YARA indicators. Comparison functionality will fail if trying to compare YARA indicators with each other.
file_hash SHA256 Hash of file being translated.
report_file Path to a text file that contains SHA256 hashes of files to be translated.
campaign_name Name of the campaign that connects the samples together.
output_directory Path to location where STIX graphs will be saved. If directory doesn't exist, then it will be created.
title Title of the heatmap generated.
json_path* Path to json file containing the STIX bundle you wish to interact with.
bundle_directory_path* Path to a directory containing multiple JSON bundles to be compared.
weights Generates a STIX weight comparison dictionary based off the given bundle
clean Grabs objects that are a 100% match from a generated comparison .json file
configure Configure the generator to generate graphs with or without certain objects
yara|ma Used in conjuction with the configure command. Determines whether you are configuring the generator to include or leave out YARA Indicators(yara) or Malware Analysis(ma) objects
yes|no Yes configures the selected option to generate graphs with the feature, no turns the feature off **NOTE** Default state is off for both YARA and MA
cve If included, tells the enrichment script to include CVEs. Warning: this will potentially add thousands of CVEs to the bundle and take a while. The default is False.
-h --help Show this screen.
--version Show version.
```
## STIX 图生成
### 单个恶意软件样本生成图
场景:您有一个单独的恶意软件样本需要进行分析,并将结果存储在 STIX 图中。
1. 要为单个恶意软件对象生成 STIX 图包,请运行以下命令。这里作为输入使用的 754fa... 哈希示例是一个 [永恒之蓝](https://www.virustotal.com/gui/file/754fa28e342c991d11404cde13845f8737994ef06652997f08eb0fa74cb6f71b) 样本的 **sha256 哈希**。`python main.py generate single 754fa28e342c991d11404cde13845f8737994ef06652997f08eb0fa74cb6f71b output_tests/`(更改哈希值和输出目录以满足您的需求)
2. 在输出文件夹中查找诸如 "stix_754fa28e342c991d11404cde13845f8737994ef06652997f08eb0fa74cb6f71b.json" 名称的文件。这是程序生成的 STIX 文件。
3. 在您[首选的 STIX 查看器应用程序](https://github.com/idaholab/STIG/releases/tag/2.0.1.alpha)中打开此文件,以查看为该单个恶意软件样本生成的不同 indicator、report、file 和 malware 对象。
可选参数:包含 YARA indicator 和/或包含 malware indicator 对象。在命令中添加 `--YARA` 标志将添加包含由 VirusTotal 报告定义的任何 YARA 规则的 indicator 对象。在命令中添加 `--MA` 标志将向图中添加一个 Malware Analysis 对象。
### 多个恶意软件样本生成图
场景:您有多个需要进行分析并组合成单个 STIX 图的恶意软件样本。
1. 创建一个包含多个恶意软件样本 **SHA256 哈希**的文件,每行一个哈希。
2. 运行命令以生成包含多个恶意软件样本的 STIX 文件:`python main.py generate many hash_file.txt output_tests/`(替换文件名和输出目录的值以符合您的需求)。
3. 输出目录中将存在三个新的 json 文件,每一个都是格式正确的 STIX 图,在相应的 indicator 对象中包含来自 VirusTotal 的信息。
可选参数:包含 YARA indicator 和/或包含 malware indicator 对象。在命令中添加 `--YARA` 标志将添加包含由 VirusTotal 报告定义的任何 YARA 规则的 indicator 对象。在命令中添加 `--MA` 标志将向图中添加一个 Malware Analysis 对象。
### 生成 Campaign 图
场景:您有多个在同一 campaign 中使用的恶意软件样本,并希望创建一个代表该 campaign 的 STIX 图,其中包含所有恶意软件样本的信息。
1. 创建一个包含多个恶意软件样本 **SHA256 哈希**的文件,每行一个哈希。
2. 运行 `python main.py generate campaign test_campaign1 hash_file.txt output_tests/ --YARA --MA`
可选参数:包含 YARA indicator 和/或包含 malware indicator 对象。在命令中添加 `--YARA` 标志将添加包含由 VirusTotal 报告定义的任何 YARA 规则的 indicator 对象。在命令中添加 `--MA` 标志将向图中添加一个 Malware Analysis 对象。
### 生成 Family 图
场景:您想为某个恶意软件家族生成一个图,但没有该家族标签下所有样本的哈希列表。此功能将查询 Malware Bazaar 中以家族名称标签(例如 TrickBot)分组的所有恶意软件样本,并为每个恶意软件样本生成一个 STIX 图,其中包含来自 VirusTotal 和 Malware Bazaar 的相关信息。
可选参数:包含 YARA indicator 和/或包含 malware indicator 对象。在命令中添加 `--YARA` 标志将添加包含由 VirusTotal 报告定义的任何 YARA 规则的 indicator 对象。在命令中添加 `--MA` 标志将向图中添加一个 Malware Analysis 对象。
1. 运行 `python main.py generate family test_family1 output_tests/`
2. 将使用来自 MalwareBazaar 的信息为与给定家族关联的每个样本生成一个图,并保存在指定的输出目录中。
注意:目前的工作原理是查询 [MalBazaar signatures](https://bazaar.abuse.ch/api/#siginfo) 而不是 [MalBazaar tags](https://bazaar.abuse.ch/api/#taginfo)。
### 比较 STIX 图
场景:您想比较两个不同的 STIX 图,以确定图之间的相似度得分。
1. 运行 `python main.py compare stix1.json stix2.json output_tests/`
1. 例如:`python main.py compare output_tests/old/withMA/wannacry_individuals/stix_1be0b96d502c268cb40da97a16952d89674a9329cb60bac81a96e01cf7356830.json output_tests/old/withMA/wannacry_individuals/stix_2ca2d550e603d74dedda03156023135b38da3630cb014e3d00b1263358c5f00d.json output_tests/`
2. 结果将存储在输出目录中的一个文件中,其命名格式如下:`{file1}V{file2}.json`
1. 此文件包含图的整体相似度得分、图中每个对象的比较得分,以及图中相似节点的百分比得分
- 注意:如果尝试将 YARA indicator 相互比较,比较功能将会失败。
- 注意:如果您收到类似 `'file' type has no 'weights' dict specified` 的错误消息,则说明正在比较的其中一个 STIX 图中存在一个对象(即 file 对象),该对象在 variables.py:WEIGHTS 字典中没有定义如何进行比较的规则。
### 生成 STIX 图比较的热力图
场景:您有两个目录,每个目录都包含多个 STIX 图,您希望可视化每个目录中各个图之间的比较得分。例如,这两个目录中的每一个都是使用“Family Generation”功能填充的。
1. 运行 `python main.py heatmap TestTitle graphdir1/ graphdir2/ output_tests/`
2. 将生成并显示一个 matplotlib 热力图,并带有允许将热力图保存为图像文件的默认控件。同时,包含热力图原始数据的矩阵文件也将保存到指定的输出目录中。
- 注意:被比较的两个目录必须是不同的目录,目前无法对单个图目录生成热力图比较。
- 注意:此过程可能需要很长时间,因为它是一个 O^2 操作。
### 丰富现有的 STIX 图
场景:您有一个包含恶意软件对象的单个 STIX 图,您希望用附加信息丰富该图,可能包括来自[国家漏洞数据库](https://nvd.nist.gov/developers/vulnerabilities)的 CVE 信息。
可选参数:在命令中添加 `--CVE` 标志将查询 NVD NIST API endpoint
1. 运行 `python main.py enrich single graph1.json output_tests/`
2. 如果在原始图中找到了攻击模式 (attack pattern) 对象,并且它包含指向 MITRE ATT&CK 列表的链接,那么将从 NVD 下载与此列表关联的所有 CWE 和缓解措施 (Mitigations),并作为适当的对象和关系添加到新图中。
1. 生成的图文件可以在指定的输出目录中找到,并命名为 `{filename}__enriched.json`
3. 否则,程序将打印未找到攻击模式 (attack pattern) 的信息,并且不会进行丰富 (enrichment) 操作。
4. 此外,如果定义了 `--CVE` 标志,则将下载找到的每个 CWE 的所有 CVE 信息并进行适当的链接。
- 注意:每个 CWE 可能与数千个 CVE 相关,这可能会使图严重膨胀。这些 CVE 中可能只有一小部分与该恶意软件相关。
### 丰富多个现有的 STIX 图
场景:您有多个 STIX 图,每个图都包含至少一个恶意软件对象,您希望用附加信息丰富所有这些图,可能包括来自[国家漏洞数据库](https://nvd.nist.gov/developers/vulnerabilities)的 CVE 信息。
可选参数:在命令中添加 `--CVE` 标志将查询 NVD NIST API endpoint
1. 运行 `python main.py enrich many samples_directory output_tests`
2. 在 `samples_directory` 中找到的每个文件将被输入到 `enrich single` 命令所使用的相同流程中,丰富后的文件可以在指定的输出目录中找到,并命名为 `{filename}__enriched.json`。
## 故障排除
检查您的 API key 以及与您的账户相关的限制。您请求的次数是否超过了最大每日限制?程序会自动进行速率限制,确保每秒发送 4 个请求,这符合最大每分钟速率限制,但不考虑每日限制。
检查任一图中是否存在 YARA 对象。程序无法比较这些对象。如果出现消息提示在 weights 字典中未找到某个对象的条目,则说明该对象没有比较方法,但可以在必要时自定义。
这是一个奇怪的现象,原因在于网站上的常规查询 `tag:Sandworm` 将按标签名称进行搜索,但输入到我们程序中的 `sandworm` 将按 signature 进行搜索。正如 MalwareBazaar API 文档中 [标签搜索](https://bazaar.abuse.ch/api/#taginfo) 和 [signature 搜索](https://bazaar.abuse.ch/api/#siginfo) 所确定的,这两个术语之间的区别目前尚未明确界定。
## 同行评审
- 安全代码审查于 2021 年 10 月 25 日完成,所有问题均已解决。
- 安全代码审查于 2022 年 8 月 5 日完成
- 完整的功能测试于 2022 年 8 月 30 日完成
标签:Python, STIX, 威胁情报, 安全, 开发者工具, 无后门, 超时处理, 逆向工具