Skip to main content
Solved

Use string length in YARA-L rule

  • Dec 7, 2023 11:16 AM UTC
  • 2 replies
  • 113 views

Hi everyone,

Is there a way to get the length of a string in YARA-L? For example, I'd like to alert on DNS queries longer than a certain threshold.

Best answer by Anonymous

Lunch break helped, I found a workaround with regex, at least for my case:

events: $dns.metadata.event_type = "NETWORK_DNS" $dns.network.dns.questions.name = $dns_query // DNS Query at least 100 characters long $dns_query = /\\S{100,}/
View original

2 replies

  • Answer
  • Dec 7, 2023 12:17 PM UTC

Lunch break helped, I found a workaround with regex, at least for my case:

events: $dns.metadata.event_type = "NETWORK_DNS" $dns.network.dns.questions.name = $dns_query // DNS Query at least 100 characters long $dns_query = /\\S{100,}/

jstoner
Community Manager
Forum|alt.badge.img+24
  • Community Manager
  • Dec 7, 2023 2:37 PM UTC

Great call out! I will add that if someone wanted to do this in search they could use the same technique.

metadata.event_type = "NETWORK_DNS" and network.dns.questions.name = /\\S{100,}/