在 Python 中编写 yara 规则
Writing yara rules in Python
我一直在阅读文档,但我一直很难弄明白这一点。翻译会有很大帮助。
我在网上看到了这个 Yara 示例 Perl 规则:
rule BadBoy
{
strings:
$a = "win.exe"
$b = "http://foo.com/badfile1.exe"
$c = "http://bar.com/badfile2.exe"
condition:
$a and ($b or $c)
}
您将如何在 Python 中编写和编译此规则?
从python开始,您首先需要import yara
直接来自文档:
Then you will need to compile your YARA rules before applying them to your data, the rules can be compiled from a file path:
rules = yara.compile()
您可以为格式化规则传递一个文件名,或者插入一个字符串进行编译。
要传递字符串,必须使用字典结构,键是数据的命名空间,值是属性。
import yara
rules = yara.compile(sources={
'identifier_for_instance_of rule':'rule BadBoy {
'strings': [('$a', 'win.exe'),('$b', 'http://foo.com/badfile1.exe') , ('$c', 'http://bar.com/badfile2.exe')],
'condition': '$a and ($b or $c)'
}'})
我一直在阅读文档,但我一直很难弄明白这一点。翻译会有很大帮助。
我在网上看到了这个 Yara 示例 Perl 规则:
rule BadBoy
{
strings:
$a = "win.exe"
$b = "http://foo.com/badfile1.exe"
$c = "http://bar.com/badfile2.exe"
condition:
$a and ($b or $c)
}
您将如何在 Python 中编写和编译此规则?
从python开始,您首先需要import yara
直接来自文档:
Then you will need to compile your YARA rules before applying them to your data, the rules can be compiled from a file path:
rules = yara.compile()
您可以为格式化规则传递一个文件名,或者插入一个字符串进行编译。
要传递字符串,必须使用字典结构,键是数据的命名空间,值是属性。
import yara
rules = yara.compile(sources={
'identifier_for_instance_of rule':'rule BadBoy {
'strings': [('$a', 'win.exe'),('$b', 'http://foo.com/badfile1.exe') , ('$c', 'http://bar.com/badfile2.exe')],
'condition': '$a and ($b or $c)'
}'})