Replies: 1 comment 1 reply
-
There seems to be a slight, yet important, misunderstanding: The term Here are two ideas, that hopefully might help you find a solution to your problem. The first one uses a sliding-window: rule search_for_lines_sliding_window
{
strings:
$ = "line1 from list" ascii
$ = "line2 from list" ascii
$ = "line3 from list" ascii
$ = "line4 from list" ascii
$ = "line5 from list" ascii
$ = "line6 from list" ascii
$ = "line7 from list" ascii
$ = "line8 from list" ascii
$ = "line9 from list" ascii
$ = "line10 from list" ascii
condition:
// make sure we have at least 2 distinct strings
2 of them and
// now search within a sliding window, assume window size of 100 bytes
for any i in (1 .. filesize-100) : (
2 of them in (i .. i+100)
)
} Please note that this a slow approach and may take a lot of time for large files. In order to avoid wasting time, the condition first checks for the presence of two strings, regardless of the distance constraint. The second approach uses a regex to find all relevant lines. In this simple example, import "hash"
rule search_for_lines_regex
{
strings:
$line = /line\d+ from list/ ascii
condition:
#line >= 2 and
for any i in (2 .. #line) : (
// ensure matches are nearby
@line[i] - @line[i-1] <= 100 and
// ensure matches are different strings
hash.sha256(@line[i-1], !line[i-1]) != hash.sha256(@line[i], !line[i])
)
} This rule checks for two consecutive matches that are at most 100 bytes apart, measured from start to start. Of course, this would also match on two consecutive instances of the same string. But as I understand your problem, these have to be different strings. I wish I could just compare the two matches, e.g. As said before, this might not be the exact solution to your problem, but hopefully will get you started. |
Beta Was this translation helpful? Give feedback.
-
Please help with compilation error yara rule. Rule logic: find 2 different strings from the list and at the same time they were nearby in the file. Code:
An error occurs while compiling: 'undefined string "$line"' at string: ( ($line[i] - 50) < $line[j] < ($line[i] + 50) )
Beta Was this translation helpful? Give feedback.
All reactions