Overview
YaraTool was created to normalize yara signatures to format the signatures nicely, detect duplicates, and express a specific signature by hash (similar to how we express malware). The hashing method in this tool is the same as the Ruby Yara-Normalize module.
Normalizing a signature
The following snippet takes a signature, normalizes it, prints out the pieces of the rule, and provides the "Yara Normalized" hash. The YNHash is designed to identify yara signatures.
import yaratool
if __name__ == "__main__":
ruletext = """rule DebuggerCheck__API : AntiDebug DebuggerCheck {
meta:
author="Some dude or dudette"
weight = 1
strings:
$ ="IsDebuggerPresent"
condition:
any of them
}"""
yr = yaratool.YaraRule(ruletext)
print(yr.normalize())
print("Name: %s, Tags: %s, Author: %s" % (yr.name, "&".join(yr.tags), yr.metas['author']))
print("Strings: ")
for string in yr.strings:
print(" %s" % (string))
print("Condition: ")
for condition in yr.conditions:
print(" %s" % (condition))
print(yr.hash())
Outputs
rule DebuggerCheck__API : AntiDebug DebuggerCheck {
meta:
author = "Some dude or dudette"
weight = 1
strings:
$ = "IsDebuggerPresent"
condition:
any of them
}
Name: DebuggerCheck__API, Tags: AntiDebug&DebuggerCheck, Author: "Some dude or dudette"
Strings:
$ = "IsDebuggerPresent"
Condition:
any of them
yn01:d28d649e24c37244:d936fceffe
Detecting Duplicate Rules
The following code iterates through all the files specified on the command line and counts the number of rules and duplicate rules. It will display the normalized versions of any duplicate rules.
import yaratool
import sys
if __name__ == "__main__":
count = 0
duplicates = 0
drf = yaratool.DuplicateDetector()
for filename in sys.argv[1:]:
fh = open(filename, 'r')
sigrules = fh.read()
fh.close()
rules = yaratool.YaraRule.split(sigrules)
for rule in rules:
ynhash = rule.hash()
res = drf.check(rule)
if res:
duplicates += 1
for r in res:
print(r.normalize())
pass
print(rule.normalize())
print()
count += len(rules)
print("Count: %d, Duplicates: %d" % (count, duplicates))
Command line
Installing the package provides two console scripts (also reachable via python -m yaratool):
yaranormalize [-i in_file]... [-o out_file] [-h | -H] # python -m yaratool normalize ...
yara_uniq [-i in_file]... [-o out_file] [-u | -d] # python -m yaratool uniq ...
Development
python -m venv .venv && . .venv/bin/activate
pip install -e '.[dev,docs]'
pytest
ruff check . && black --check . && flake8 && pylint yaratool
sphinx-build -W docs docs/_build/html
Metadata
Release files for yaratool 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| yaratool-0.2.0.tar.gz | 11.5 kB | Without provenance | Details for yaratool-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| yaratool-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for yaratool-0.2.0-py3-none-any.whl |
Total release size: 21.4 kB
Release files / yaratool-0.2.0.tar.gz
| Download URL | yaratool-0.2.0.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1ead6ce9f4a5d161cb5ee693322ae1a43752880ad347fd79a03f0403afe17361
|
|
BLAKE2b-256 checksum How to use checksums |
618871c7ff6e05c6280da858f2c0aaf8b4af34fe80d63887efac362677c8f1f1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.2
|
Release files / yaratool-0.2.0-py3-none-any.whl
| Download URL | yaratool-0.2.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0f4cc4bb25d734e909ce53cab539b7c1fa22987a338548fcaa0b35694aa3fb59
|
|
BLAKE2b-256 checksum How to use checksums |
d0868a1ac0d405182bbdda57ff0a3a5794b5c21dd25c6546c5c782acb3c7c3a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.2
|
Security for yaratool 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.