Skip to content

Instantly share code, notes, and snippets.

@stvemillertime
Forked from tlansec/externals_example.py
Created February 21, 2022 14:28
Show Gist options
  • Save stvemillertime/d561236c58e3b16a6992501f7da3a531 to your computer and use it in GitHub Desktop.
Save stvemillertime/d561236c58e3b16a6992501f7da3a531 to your computer and use it in GitHub Desktop.
Simple script to demo use of yara-python + externals
# Simple script to demo use of yara-python + externals
# think of all the externals you could define!
import os
import sys
import yara
example_rule = '''
rule demo_externals
{
condition:
filename == "target.dat"
}
'''
target_file = sys.argv[1]
with open(target_file, 'rb') as infile:
data = infile.read()
externals_init = {
'filename' : ""
}
compiled_rules = yara.compile(source=example_rule, externals=externals_init)
match = compiled_rules.match(
data=data,
externals={
'filename': os.path.basename(sys.argv[1])
}
)
print(match)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment