分析雅拉规则。
plyara的Python项目详细描述
将YARA规则解析为字典表示。
plyara是一个脚本和库,它解析一个由多个yara规则组成的文件。 变成一个python字典表示。此工具的目标是使其更易于执行 大量操作或大型yara规则集的转换,例如提取指标, 更新属性,分析语料库。其他应用程序包括linter和dependency 跳棋。
Pyra利用Python模块PLY来标注YARA规则。
这是由8u1a维护的original plyara的社区分支。“plyara”商标 经允许使用。
安装
plyara需要python 3.6+。
使用pip安装:
pip3 install plyara
用法
在自己的应用程序中使用plyara python库:
>>>importplyara>>>parser=plyara.Plyara()>>>mylist=parser.parse_string('rule MyRule { strings: $a="1" \n condition: false }')>>>>>>importpprint>>>pprint.pprint(mylist)[{'condition_terms':['false'],'raw_condition':'condition: false ','raw_strings':'strings: $a="1" \n ','rule_name':'MyRule','start_line':1,'stop_line':2,'strings':[{'name':'$a','type':'text','value':'1'}]}]>>>
或者,使用命令行中包含的plyara脚本:
$ plyara -h usage: plyara [-h] [--log] FILE Parse YARA rules into a dictionary representation. positional arguments: FILE File containing YARA rules to parse. optional arguments: -h, --help show this help message and exit --log Enable debug logging to the console.
解析规则时,命令行工具将打印有效的json输出:
$ cat example.yar rule silent_banker : banker { meta: description = "This is just an example" thread_level = 3 in_the_wild = true strings: $a = {6A 40 68 00 30 00 00 6A 14 8D 91} $b = {8D 4D B0 2B C1 83 C0 27 99 6A 4E 59 F7 F9} $c = "UVODFRYSIHLNWPEJXQZAKCBGMT" condition: $a or $b or $c } $ plyara example.yar [ { "condition_terms": [ "$a", "or", "$b", "or", "$c" ], "metadata": [ { "description": "This is just an example" }, { "thread_level": 3 }, { "in_the_wild": true } ], "raw_condition": "condition:\n $a or $b or $c\n", "raw_meta": "meta:\n description = \"This is just an example\"\n thread_level = 3\n in_the_wild = true\n ", "raw_strings": "strings:\n $a = {6A 40 68 00 30 00 00 6A 14 8D 91}\n $b = {8D 4D B0 2B C1 83 C0 27 99 6A 4E 59 F7 F9}\n $c = \"UVODFRYSIHLNWPEJXQZAKCBGMT\"\n ", "rule_name": "silent_banker", "start_line": 1, "stop_line": 13, "strings": [ { "name": "$a", "type": "byte", "value": "{6A 40 68 00 30 00 00 6A 14 8D 91}" }, { "name": "$b", "type": "byte", "value": "{8D 4D B0 2B C1 83 C0 27 99 6A 4E 59 F7 F9}" }, { "name": "$c", "type": "text", "value": "UVODFRYSIHLNWPEJXQZAKCBGMT" } ], "tags": [ "banker" ] } ]
迁移
如果您使用的是旧版本的plyara,并且希望迁移到此版本, 需要做一些更改。最重要的是,解析器对象 实例化已更改。它是:
# Old style - don't do this!importplyara.interpasinterprules_list=interp.parseString(open('myfile.yar').read())
但现在是:
# New style - do this instead!importplyaraparser=plyara.Plyara()rules_list=parser.parse_string(open('myfile.yar').read())
现有解析的密钥保持不变,添加了新的密钥。
在为多个规则和/或文件重用parser时,请注意 导入现在在所有规则之间共享-如果一个规则具有导入,则 导入将添加到解析器对象中的所有规则。
贡献
讨论
- 您可以在irc.freenode.net上加入我们的irc频道plyara