Skip to content
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

tests: add rule type check for flowbits #1438

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/rules/flowbits/test.rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
alert ip any any -> any any (msg:"isset rule need an option"; flowbits:isset; sid:1;)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As seen in the flowbits documentation, this keyword needs two values, so all the rules written here will result in a parse error due to the lack of the second field.

(cf https://docs.suricata.io/en/latest/rules/flow-keywords.html#flowbits)

Tip: when an SV test fails with FAILED: got exit code 1, expected 0 this indicates that Suricata finished with an error state, so to debug such cases you should check the output directory in the test folder and see what's in stderr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to pass as the second value? I have changed the code for DETECT-FLOWBITS case so that the name is being stored in ored_variables array, should I pass this array as the second value?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second value is a variable name, and as such it's not predefined. Just like a code variable, it is user-defined. Does this clear up?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, okay, that makes sense. Thanks!

alert ip any any -> any any (msg:"isnotset rule need an option"; flowbits:isnotset; sid:2)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the lack of a name for the flowbits variable, this rule would also result in a parse error because it lacks the ; after the rule sid. Each field within the parenthesis must be followed by those. ;)

alert ip any any -> any any (msg:"set rule need an option"; flowbits:set; sid:3;)
alert ip any any -> any any (msg:"unset rule need an option"; flowbits:unset; sid:4;)
alert ip any any -> any any (msg:"toggle rule need an option"; flowbits:toggle; sid:5;)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's also have a rule for the flowbits:noalert option, please :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

43 changes: 43 additions & 0 deletions tests/rules/flowbits/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
requires:
min-version: 7.0.0
pcap: false

args:
- --engine-analysis

checks:
- filter:
filename: rules.json
count: 1
match:
id: 1
lists.packet.matches[0].name: "flowbits"
lists.packet.matches[0].flowbits.option: "isset"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checks use flowbits.option, but the Suri code change has flowbits.cmd, which results in a check failure with SV.

- filter:
filename: rules.json
count: 1
match:
id: 2
lists.packet.matches[0].name: "flowbits"
lists.packet.matches[0].flowbits.option: "isnotset"
- filter:
filename: rules.json
count: 1
match:
id: 3
lists.packet.matches[0].name: "flowbits"
lists.packet.matches[0].flowbits.option: "set"
- filter:
filename: rules.json
count: 1
match:
id: 4
lists.packet.matches[0].name: "flowbits"
lists.packet.matches[0].flowbits.option: "unset"
- filter:
filename: rules.json
count: 1
match:
id: 5
lists.packet.matches[0].name: "flowbits"
lists.packet.matches[0].flowbits.option: "toggle"
Loading