【问题标题】:Writing yara rules in Python用 Python 编写 yara 规则
【发布时间】:2016-05-09 14:44:38
【问题描述】:

我一直在阅读文档,但我一直很难弄清楚这一点。翻译会有很大帮助。

我在网上看到了 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 malware yara


    【解决方案1】:

    从python你首先需要import yara

    直接来自文档:

    那么你需要在将它们应用到你的数据之前编译你的 YARA 规则,这些规则可以从文件路径编译:

    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)'
                          }'})
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多