yara icon indicating copy to clipboard operation
yara copied to clipboard

yara-rule: 2 of(IDENTIFIER)

Open kongo86 opened this issue 9 years ago • 1 comments

It will be great to be able to do the following with yara modules:

2 of (pe.exports("myex1") , pe.exports("myex2") . pe.exports("myex3"), pe.exports("myex4")) Currently Yara only does this with string identifiers.

Thanks advance!

kongo86 avatar Feb 19 '16 05:02 kongo86

Since 4.1.0, this can be done with the help of math.to_number:

math.to_number(pe.exports("myex1")) +
math.to_number(pe.exports("myex2")) +
math.to_number(pe.exports("myex3")) +
math.to_number(pe.exports("myex4")) >= 2

Be aware though that boolean and numeric operators behave differently with regard to undefined values. Example:

The rule filesize == 0 or pe.is_pe works as expected – it matches empty files and PE files: if the file is empty, filesize == 0 is true, pe.is_pe is undefinedtrue or undefined is true. 😊

The rule math.to_number(filesize == 0) + math.to_number(pe.is_pe) > 0 looks like it should match the same files (at least one of the conditions must be true, which is equivalent to logical OR), but it doesn't: if the file is empty, filesize == 0 is true, but pe.is_pe is undefinedmath.to_number(filesize == 0) is 1, math.to_number(pe.is_pe) is undefined1 + undefined is undefinedundefined > 0 is undefined → the rule doesn't match. 😕

jcsahnwaldt avatar May 08 '21 15:05 jcsahnwaldt