CybercentreCanada / CCCS-Yara

YARA rule metadata specification and validation utility / Spécification et validation pour les règles YARA
MIT License
98 stars 19 forks source link

Metadata Parsing Errors #61

Open malvidin opened 1 year ago

malvidin commented 1 year ago

In a few situations, a valid rule fails to be written (using -c or -i) with the following error:

./CCCS-Yara/yara-validator/yara_file_processor.py", line 184, in strings_of_rules_to_original_file
    changed_rule_string = rule.rule_return.validated_rule.splitlines()
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'splitlines'

These regular expressions appear to the cause of the issue: https://github.com/CybercentreCanada/CCCS-Yara/blob/4cca67453bee31e5cc4a2522b5aa9b1f6a488268/yara-validator/yara_validator.py#L246-L247

Based on these expressions:

This breaks otherwise valid rules:

rule testing 
{ meta:
    key = "value"
  condition:
    true
}
rule testing {
  meta:
    key = "value"
  strings: $re = /test/
  condition: $re
}
rule testing 
{ meta:
    key = "value"
  condition: true
}

And on the most extreme end:

rule testing { meta: key = "value" condition: true }
cccs-rs commented 1 year ago

I think in this case, plyara would come in handy. I have to take a look at this more in-depth to see what the original author was doing.