Skip to main content

Python libary to normalize Yara signatures

Project description

# 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.condition:
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.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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yaratool-0.0.6.tar.gz (6.2 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

yaratool-0.0.6-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

yaratool-0.0.6-py2-none-any.whl (8.2 kB view details)

Uploaded Python 2

File details

Details for the file yaratool-0.0.6.tar.gz.

File metadata

  • Download URL: yaratool-0.0.6.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for yaratool-0.0.6.tar.gz
Algorithm Hash digest
SHA256 6b8f30f109f771605759039a1e97617782ddb374692b530be4133de87e51b0cf
MD5 e3555ed2922c75b5cddaa323945d1151
BLAKE2b-256 771e8632950fe832eef5febeb9fad0930524d3d863c1c8b94a18b5b18bb9decb

See more details on using hashes here.

File details

Details for the file yaratool-0.0.6-py3-none-any.whl.

File metadata

File hashes

Hashes for yaratool-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 36967298fc5c74cb9f6f8ff0ee4f84bb0a8390a92f23fe220542d40be1e72cf2
MD5 17b7d3a481b7ca744e2495f2924164b8
BLAKE2b-256 2cca040953ba0c094159de7e0f9115a0b17c042fc1bb7f6e6286ea57078edf7d

See more details on using hashes here.

File details

Details for the file yaratool-0.0.6-py2-none-any.whl.

File metadata

File hashes

Hashes for yaratool-0.0.6-py2-none-any.whl
Algorithm Hash digest
SHA256 32b355ad71f723b48795f906f92c66e17048bcd0a954032f969e23c805723e45
MD5 7841b206d8a263703f661303f3bfbabe
BLAKE2b-256 7cd27d16ed93d5f2cc350bb810aaad1a6aa0361037ab6ec39a13e8383ea912d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page