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 to check for tcp_mss - v1 #1433

Closed
wants to merge 1 commit into from

Conversation

0xEniola
Copy link
Contributor

@0xEniola 0xEniola commented Oct 21, 2023

Test for rule type for tcp-mss keyword

Related to
Issue: #6355

Redmine ticket: https://redmine.openinfosecfoundation.org/issues/6355

Suricata PR: OISF/suricata#9673

Related to
Issue: #6355
@jufajardini jufajardini added outreachy Contributions made by Outreachy applicants requires suricata pr Depends on a PR in Suricata labels Oct 22, 2023
Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

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

Right path, but two adjustments needed ;)

filename: rules.json
count: 1
match:
# list.packet.matches[0].name: "tcp.mss"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this should be commented out.

count: 1
match:
# list.packet.matches[0].name: "tcp.mss"
list.packet.matches[0].mss.size: 536
Copy link
Contributor

Choose a reason for hiding this comment

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

This check will fail with the rule you've provided ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I have tried with other working tests, I don't necessarily have to test for name, and the check still passes.

But for this tcp-mss.
Even testing for name doesn't work.

That's where the issue is, I don't get the reason why it does not even recognise tcp.mss as the name, that's why I did that.

Because normally, it will pass even without checking for name matches.

So I feel there's an issue with my code.

Copy link
Contributor

Choose a reason for hiding this comment

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

I got it. It's not with the code.
The check should be for lists, not list ;)
Also, as I pointed out, the size check won't work with the rule you've added for this test.

Copy link
Contributor

Choose a reason for hiding this comment

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

When such failures occur, what I do is open and compare my changes with a similar test, and carefully look for possible differences. That's what I did for this case. ;)

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 got it. It's not with the code.
The check should be for lists, not list ;)
Also, as I pointed out, the size check won't work with the rule you've added for this test.

Wiiiiiiii!

Thank you for catching that 😂.
It's really funny how the issues always be right in my face but still subtle.

But, why isn't the size check working though? I've looked through it as well; it says Rule matches on packets rules_analysis.txt but still fails.

Copy link
Contributor Author

@0xEniola 0xEniola Oct 23, 2023

Choose a reason for hiding this comment

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

OK! I was tinkering around, and figured I'd have to include a test for all the options before the test could pass, which means a test for the mode, arg1 and arg2.

Which means, for each option, the code to log them must be present.

So I did jb_set_uint for each of them.

And found out mode: 1 = <, mode: 3 = >, and mode: 5 is used for min-max.

I'm not sure if arg2 is used for tcp.mss, but if it is, it is indeed better that you add a test to showcase that.
Great catch about the mode bit. As I am not familiar with this type of keyword, I wondered how the >/</ and similar was being represented, but didn't investigate further. This should definitely be present, thanks for pointing out! It also means there's more work to be done on the Suricata side of this task, as you will have to first log these fields, if you want to test the output here. I'll update my review there! :)

Yes! I have added the tests locally here.

But then, about adding the function that will relate the mode bits to their corresponding characters for setting up a proper configuration file, I would like to suggest;

  • lt for Less than (< value).
  • gt for Greater than (> value).
  • rg or range for Range (min_value - max_value).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for asking this.
Any reason not to add the full sentence? It feels to me that this makes it slightly harder to understand, in a situation where I'm not sure there's a need for concision - since this mode is only used for testing, so output size isn't so critical, I think 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

We probably have also >= and <=, besides exact value too, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We probably have also >= and <=, besides exact value too, right?

Yes, there are these and even !, but the format provided for tcp.mss in the userguide for header keyword rules, only those three were given.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for asking this.
Any reason not to add the full sentence? It feels to me that this makes it slightly harder to understand, in a situation where I'm not sure there's a need for concision - since this mode is only used for testing, so output size isn't so critical, I think 🤔

Oh yes! Actually, understanding is paramount.

I'll change it to full sentences then.

  • less than
  • greater than
  • range

@0xEniola
Copy link
Contributor Author

When suricata-verify is done running, it says “FAILED”, but shows that “Rule matches on packet” in the rules_analysis.txt file.

@jufajardini
Copy link
Contributor

When suricata-verify is done running, it says “FAILED”, but shows that “Rule matches on packet” in the rules_analysis.txt file.

Can you share the complete output for that, please? I'll double check your code and see if I can figure out what's going on.

@0xEniola
Copy link
Contributor Author

When suricata-verify is done running, it says “FAILED”, but shows that “Rule matches on packet” in the rules_analysis.txt file.

Can you share the complete output for that, please? I'll double check your code and see if I can figure out what's going on.

Which of the output? rules. json or rules_analysis.txt?

@jufajardini
Copy link
Contributor

When suricata-verify is done running, it says “FAILED”, but shows that “Rule matches on packet” in the rules_analysis.txt file.

Can you share the complete output for that, please? I'll double check your code and see if I can figure out what's going on.

Which of the output? rules. json or rules_analysis.txt?

The one you mentioned ;)

But I think at least we've figured why the test was failing.

@0xEniola 0xEniola closed this Oct 23, 2023
@0xEniola 0xEniola deleted the sv-task-6355-v1 branch January 31, 2024 15:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
outreachy Contributions made by Outreachy applicants requires suricata pr Depends on a PR in Suricata
Development

Successfully merging this pull request may close these issues.

2 participants