将Stix2模式转换为其他搜索平台(如ElasticSearch)和数据模型(如CIM)的转换器
stix-pattern-translator的Python项目详细描述
此存储库包含转换STIX2 Patterning的原型分析转换器 查询到其他查询语言,目前是ElasticSearch和Splunk除了翻译 查询语法,转换器还将从Stix 2的数据模型转换到其他目标数据模型, 现在是斜接的Cyber Analytic Repository (CAR)和splunk的Common Information Model (CIM)。 查询语言翻译和数据模型翻译都是松耦合实现的 通过实现新的模块来生成模块和其他目标,可以简单地添加模块和其他目标。
这个功能最初是为mitre的CASCADE项目开发的。 这个存储库作为一个独立的特性提供了cascade的翻译功能, 并用STIX 2.0模式替换CASCADE自己的领域特定语言(DSL)
要求
- Python3.5或3.6
- antlr语法运行时(4.7或更新版本):
- antlr4-python3-runtime (Python3)
- python-dateutil(python 3.3)
或者,web api需要:
- Flask(Python3.3)
安装
使用pip安装:
$ pip install stix-pattern-translator
(可选)要使用web api,请使用pip:
$ pip install stix-pattern-translator[web]
注意:如果您正在进行开发,请确保使用以下命令安装开发依赖项:
$ pip install stix-pattern-translator[dev]
用法
stix分析转换器提供一个可执行脚本(translate pattern)、一个作为flask应用程序提供的简单web api和python翻译。 方法(stix2patterns_translator.translate)
从python代码
fromstix2patterns_translator.translatorimport*translate("[file:hashes.MD5 = '79054025255fb1a26e4bc422aef54eb4']",SearchPlatforms.ELASTIC,DataModels.CAR)
命令行
使用命令translate stix pattern,传入所需的输出语言、数据分类法和STIX2模式:
$ translate-stix-pattern --output-language=elastic --output-data-model=car "[file:hashes.MD5 = '79054025255fb1a26e4bc422aef54eb4']"
网络api
web api作为flask服务器提供,它接受stix模式作为输入并返回转换的模式。路径决定输出 搜索平台和数据分类。要运行web服务器,请安装“web”附加组件(烧瓶)
$ pip install stix-pattern-translator[web]
服务器可以直接从源代码、通过命令行脚本运行,或者通过将代码导入到现有的应用程序中。最简单的方法 通过命令行脚本进行测试:
$ pattern-translator-server
在服务器运行时,使用命令行在本地或通过网络从Flask实例发送和接收。 如下例所示,使用curl发送带有json的post会将结果返回到调用shell:
$ curl -X POST -H "Content-Type: text/plain" -d "[process:pid <= 5]" http://localhost:5000/car-elastic
结果是:
data_model.object:"process" AND data_model.action:"*" AND ( data_model.fields.pid:<=5)
测试
pytest集成测试是根据从测试/输入文件中的文件中提取的输入模式自动生成的。输入文件按测试类型命名, 例如“md5_hash.json”,包含带有输入模式(key=stix input)和预期结果的json,其中key是<;datamodel>;-<;platform>; 值是预期结果:
{"stix-input":"[file:hashes.MD5 ='79054025255fb1a26e4bc422aef54eb4']","car-elastic":"data_model.object:\"file\" AND data_model.action:\"*\" AND (data_model.fields.md5_hash:\"79054025255fb1a26e4bc422aef54eb4\")","car-splunk":"match(tag, \"dm-file-.*\") md5_hash=\"79054025255fb1a26e4bc422aef54eb4\"","cim-elastic":null,"cim-splunk":null}
预期的结果可以是字符串,用于测试该字符串是否成功和匹配,也可以是null,用于测试错误。 像往常一样,可以通过运行pytest来运行测试:
pytest
也可以运行测试,将事件推到Splunk/Elastic,然后确保正确的事件匹配它们使用相同的输入文件,但需要一些 附加钥匙“matches”键应该包含一个字典,其中包含每个数据模型的一组键(当前只是“car”)。那本字典包含 应与模式匹配的事件列表“nonmatches”键是相同的,但显然将进行测试以确保它们不匹配。 运行实时集成测试需要启动Docker:
docker-compose -f test.docker-compose.yml up
然后可以通过pytest直接调用测试来运行它们:
pytest test/integration_tests.py