Skip to content

refactor(filter): Builtin field arguments grammar #425

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

Merged
merged 3 commits into from
Jan 24, 2025
Merged

Conversation

rabbitstack
Copy link
Owner

@rabbitstack rabbitstack commented Jan 24, 2025

What is the purpose of this PR / why it is needed?

This changeset brings a significant refactoring in the field arguments area. Previously, the field arguments were parsed on the fly, when extracting the value in the accessor. A regular expression-based approach would decide if the field could have an argument.
This was undermining the correctness of the rule grammar.

The parser is now extended to support field literals with arguments. Arguments can be optional or required. When provided the argument value must conform to the allowed pattern. All this information is stored within the field information and utilized in the
parser to produce the field literal or return an error, when, for example, a field with a required argument is not given.

As a side effect of this refactoring, new literals are introduced to better convey different rule language elements: bare bound variable and bound segment literals.

Finally, all accessors are reworked to adapt to the new field structure. The end result is a more efficient, cleaner, and concise code base.

Some examples:

kevt.arg contains 'svchost.exe'

Is semantically incorrect because the kevt.arg field requires an argument.

ps.envs in ('winroot:C:\\WINDOWS')
ps.envs[winroot] = 'C:\\WINDOWS`

Both expressions are correct. ps.envs accepts an optional argument (environment variable name), but if not given all env variables are returned as a string slice.

What type of change does this PR introduce?


Uncomment one or more /kind <> lines:

/kind feature (non-breaking change which adds functionality)

/kind bug-fix (non-breaking change which fixes an issue)

/kind refactor (non-breaking change that restructures the code, while not changing the original functionality)

/kind breaking (fix or feature that would cause existing functionality to not work as expected

/kind cleanup

/kind improvement

/kind design

/kind documentation

/kind other (change that doesn't pertain to any of the above categories)

Any specific area of the project related to this PR?


Uncomment one or more /area <> lines:

/area instrumentation

/area telemetry

/area rule-engine

/area filters

/area yara

/area event

/area captures

/area alertsenders

/area outputs

/area rules

/area filaments

/area config

/area cli

/area tests

/area ci

/area build

/area docs

/area deps

/area other

The parser got the ability to produce field literals with optional arguments. New bare
bound variable and segment bound variable literals
are added for a cleaner and more accurate representation of bare bounded variables, bound segments and bound fields respectively.
Most functions now support bare and segment bound
argument types.
Rework the value accessors to operate with the new field type that encapsulates the field argument. Additionally, bound segments are propagated to all accessors and currently used in the PE accessor to determine if the section entropy needs to be calculated.
@rabbitstack rabbitstack added the scope: filters Anything related to filters label Jan 24, 2025
@rabbitstack rabbitstack merged commit c493415 into master Jan 24, 2025
6 checks passed
@rabbitstack rabbitstack deleted the field-argument branch January 24, 2025 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: filters Anything related to filters
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant