-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to have optional strings in the rule as "0 of" behavior changed in v4.2.3 #1937
Comments
Can you elaborate more on the concept of "staged matching"? I understand you are interested in those unreferenced strings in the rule, but is not clear to me whether you are interested in them only when the rest of the rule matches, or when it doesn't match, or in both cases. |
Yes, we're interested in them only when the rest of the rule matches. By "staged matching" I mean:
In some cases we decided that it would be great to get complete information from single rule in one pass, that's why |
To give a more concrete example: we write "normal" yara rules first, with the goal of hunting for the specific malware family. We don't have use for Then we put the yara rules in our malware extraction system (built using https://github.com/CERT-Polska/malduck, our framework used by a few other orgs). The system runs a callback for every string matched by yara rule. And now, sometimes it's useful to add a "non-detecting" string that will only be used in the malware extraction (for example, string that detects encryption function, that we use in our module toextract the encryption key). We don't want to mess with detections at this point, since the rule is already tested, we just want to have another optional string. Sometimes it's possible to do this in other way, sometimes the This is probably not the only use case we had, but the one that we stumbled upon first. |
Interesting, I never thought that someone would be using I'm not sure what's the better solution here, I don't dislike the option of going back to the original meaning for |
I like the idea of marking a string as intentionally unreferenced. Seems like an elegant solution to this problem while keeping the semantics of |
+1 for the string modifier idea! |
I modified my rules to use |
In my rules where I want to compute some strings but not have them influence the condition, i use the Another point in favor of the string modifier, or against changing back the
The issue with the |
As briefly discussed in VirusTotal#1937, this change will make it so that any string identifier that starts with '_' can be unreferenced. Any anonymous strings must still be referenced. While testing this out I realized that an unreferenced string still had the STRING_FLAG_FIXED_OFFSET set, which meant any unreferenced string would have a fixed_offset of YR_UNDEFINED. To deal with this when we are reducing the rule we unset STRING_FLAG_FIXED_OFFSET if the string is unreferenced.
I put together a PR that would allow for unreferenced strings if they are prefixed with This shouldn't break anyone who is already using |
As briefly discussed in #1937, this change will make it so that any string identifier that starts with '_' can be unreferenced. Any anonymous strings must still be referenced. While testing this out I realized that an unreferenced string still had the STRING_FLAG_FIXED_OFFSET set, which meant any unreferenced string would have a fixed_offset of YR_UNDEFINED. To deal with this when we are reducing the rule we unset STRING_FLAG_FIXED_OFFSET if the string is unreferenced.
#1941 has been merged. So we can have optional strings by prefixing the identifier with an underscore (e.g: |
Is your feature request related to a problem? Please describe.
We spotted that commit 7a99e6d released in v4.2.3 changed
0 of (...)
behavior, so it broke some of our Yara rules:0 of
was used in our rules to overcome the fact that Yara doesn't allow matching strings that are not referenced in the condition. In our case we wanted to have "optional" strings that don't affect the match result, but are still looked up so we can get their offsets and extract additional information.Previous meaning of
x of (...)
was "match if there are at least x occurrences" of the specified string, so0 of
still matched the original semantics well.I understand that it started to be confusing when
none
keyword arrived sonone of (...)
behaved the same like0 of (...)
as noted in #1695Describe the solution you'd like
It would be nice to have another way to indicate that some strings are intentionally unreferenced in the condition, but should still be matched. Right now we're doing "staged matching" in multiple places, spawning another Yara match with optional strings and
any of them
condition.Possible solutions I would like are:
none of
and0 of
, leaving the original0 of
meaningLet me know what do you think about it!
The text was updated successfully, but these errors were encountered: