Parse YARA rules
Low maintenance activity. Last release 22 months ago, commits in 0 of the last 26 weeks. Weaker on commit activity and recent releases.
pip install plyaraplyara
Parse YARA rules into a dictionary representation.
Plyara is a script and library that lexes and parses a file consisting of one more YARA rules into a python dictionary representation. The goal of this tool is to make it easier to perform bulk operations or transformations of large sets of YARA rules, such as extracting indicators, updating attributes, and analyzing a corpus. Other applications include linters and dependency checkers.
Plyara leverages the Python module PLY for lexing YARA rules.
This is a community-maintained fork of the original plyara by 8u1a. The "plyara" trademark is used with permission.
Installation
Plyara requires Python 3.10+.
Install with pip:
pip install plyara
Usage
Use the plyara Python library in your own applications:
>>> import plyara
>>> parser = plyara.Plyara()
>>> mylist = parser.parse_string('rule MyRule { strings: $a="1" \n condition: false }')
>>>
>>> import pprint
>>> 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'}]}]
>>>
Or, use the included plyara script from the command line:
$ 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.
The command-line tool will print valid JSON output when parsing rules:
rule silent_banker : banker
{
meta:
description = "This is just an example"
threat_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
}
Command-line tool: