I am trying to write YARA rules to match simple IP Addresses (eg: 127.0.0.1 or 192.168.1.1). I understand that I can do it using Regular Expressions based on this open-source Github example.
However, YARA performance guidelines recommends us to avoid Regular Expressions whenever possible and use Hexadecimal Jumps/Wildcard matching instead, as stated in this Github Readme. I am using it on a large number of examples so I was keeping performance in mind.
I was wondering, does YARA need to get the IP in a hex format, or can I directly match it in the normal IP format (x.x.x.x
)?
I was trying something like:
rule url_localhost
{
strings:
$hex_test = { [1-3] 2E [1-3] 2E [1-3] 2E [1-3] ?? ?? }
condition:
any of them
}
My logic was something like 3 numbers to start, then a dot (2E in ASCII), and repeating the same, and having wildcards in the end for a potential 'path' in the IP address (eg: 127.0.0.1/p
)
It does not seem to directly work. Is this kind of use-case possible, or is Regex the only way to approach this?