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

Detect bidir 5665 v13 #11323

Closed
wants to merge 4 commits into from
Closed

Conversation

catenacyber
Copy link
Contributor

Link to redmine ticket:
https://redmine.openinfosecfoundation.org/issues/5665

Describe changes:

  • allows bidirectional signature matching !

SV_BRANCH=OISF/suricata-verify#1922

Draft again because of second commit
General feedback expected :-)

TODO :

  • Give me better names
  • Where should I document these new keywords bidir.toclient ?

#11293 rebased with some new test in SV

Ticket: 5665

This is done with `alert ip any any => any any`
The => operator means that we will need both directions
By using keywords bidir.toclient and bidir.toserver, the following
keywords are forced to the direction even if they can match
on both directions.

Ticket: 5665
Do not require a rule to use bidir.toserver after the usage of
bidir.toclient for unambiguous keywords, where the rule writer
does not want to explicit the redundant direction.
Copy link

codecov bot commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 89.80583% with 21 lines in your changes missing coverage. Please review.

Project coverage is 82.49%. Comparing base (d59c604) to head (1c4cd67).

Additional details and impacted files
@@           Coverage Diff            @@
##           master   #11323    +/-   ##
========================================
  Coverage   82.48%   82.49%            
========================================
  Files         934      934            
  Lines      252239   252386   +147     
========================================
+ Hits       208070   208208   +138     
- Misses      44169    44178     +9     
Flag Coverage Δ
fuzzcorpus 60.23% <56.31%> (-0.02%) ⬇️
livemode 18.73% <9.22%> (-0.01%) ⬇️
pcap 43.79% <45.63%> (+0.04%) ⬆️
suricata-verify 61.34% <85.92%> (+<0.01%) ⬆️
unittests 59.90% <52.42%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 21126

@victorjulien
Copy link
Member

Comment w/o having reviewed yet: I think we should be extremely restrictive in our parsing. Just accept only the explicitly accepted combinations, and block anything else. Then we can slowly expand support.

@victorjulien
Copy link
Member

Comment w/o having reviewed yet: I think we should be extremely restrictive in our parsing. Just accept only the explicitly accepted combinations, and block anything else. Then we can slowly expand support.

What I tried, but apparently failed, to do for frames.

@catenacyber
Copy link
Contributor Author

Comment w/o having reviewed yet: I think we should be extremely restrictive in our parsing. Just accept only the explicitly accepted combinations, and block anything else. Then we can slowly expand support.

What I tried, but apparently failed, to do for frames.

:-p I have been doing that since the first version see detect-bidir-impossible SV test with its signatures

Let me know if I missed some

@victorjulien victorjulien self-assigned this Jun 19, 2024
@@ -252,6 +257,25 @@ as the direction specifies that we do not want to evaluate the response packet.

There is no 'reverse' style direction, i.e. there is no ``<-``.

Here is an example of a bidirectional rule:
Copy link
Member

Choose a reason for hiding this comment

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

This is very confusing to me. bidirectional and both dir seem to be interchangeably used throughout the code.
The pre-existing <> operator uses flags like SIG_FLAG_INIT_BIDIREC.. I'm unable to decipher the difference. Could you please explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The existing <> is just duplicating the signature in both directions specified by the header
alert tcp 1.2.3.4 any <> 5.6.7.8 80 (sid: 1; etc...)
becomes

alert tcp 1.2.3.4 any -> 5.6.7.8 80 (sid: 1; etc...)
alert tcp 5.6.7.8 80 -> 1.2.3.4 any (sid: 1; etc...)

I do not know the use case for it...

This PR with => allows to match on both sides of a transaction like
alert http any any => any any (msg:"matching both uri and status"; sid: 1; http.uri; content: "/download"; http.stat_code; content: "200";)
matching the URI from the client, and the status from the server

Let me know if you have a better wording...

Copy link
Member

Choose a reason for hiding this comment

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

Thank you very much!
After reading up what bidirectional means, I think it makes more sense for the <> operator as we use the same rule in both the directions.
Suggestions for your work:

  1. transaction scoped rule (flags and varnames could be like *tx_scope*)
  2. full transaction match rule (flags and varnames could be like *full_tx_match*)
  3. transaction span rule (flags and varnames could be like *tx_span*)

Interested in hearing your and others' thoughts.
Also, we should make sure that if we make changes, the <> varnames and flags are all named alike as should be the new ones, I think.

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 Shivani for the proposals.
I think it is still good to use somehow the word direction to indicate that these rules do not have a direction like others...

@catenacyber
Copy link
Contributor Author

@jufajardini could you please review the documentation ?
Any idea where should I document these new keywords bidir.toclient ?

@jufajardini
Copy link
Contributor

@jufajardini could you please review the documentation ? Any idea where should I document these new keywords bidir.toclient ?

Do we see more bidirectional keywords coming? If yes, maybe we could have a separate section, like we have for Flow, Meta keywords, etc. If not, then maybe a subsection of the Direction section could do.

I think that to help illustrate the difference between <> and =>, adding an example for <>, like you did in the explanation to Shivani, would be quite helpful :)

directionality for adresses and ports is used,
but such a rule can match a bidirectional transaction, using keywords
matching in each direction.
However, it is also possible to have a rule match both directions (``<>``)::
Copy link
Contributor

Choose a reason for hiding this comment

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

Considering Shivani's comments, Philippe's answers, and just this last sentence that we have in our docs, I'm thinking that maybe changing this to:

Suggested change
However, it is also possible to have a rule match both directions (``<>``)::
However, it is also possible to have a rule match either directions (``<>``)::

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if maybe we can't come up with a different name for this new feature, as maybe bidirectional is already too known for the interchangeability of source and destination? Or would this be too disruptive for us?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you find a good name, let me know ;-)

Comment on lines 271 to 278
Bidirectional rules have some limitations :
- They are only meant to work on transactions with first a request to the server,
and then a response to the client, and not the other way around.
- They cannot have ``fast_pattern`` or ``prefilter`` on a keyword which is on
the direction to client.
- They will not work with ambiguous keywords, which work for both directions.
- They will refuse to load if a single directional rule is enough.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this could become a note, or a subsection, as it's something specific to bidirectional rules?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@@ -278,8 +278,9 @@ Bidirectional rules can use direction-abmibuous keywords, by first using
Bidirectional rules have some limitations :
- They are only meant to work on transactions with first a request to the server,
and then a response to the client, and not the other way around.
- They cannot have ``fast_pattern`` or ``prefilter`` on a keyword which is on
the direction to client.
- They cann have ``fast_pattern`` or ``prefilter`` on a keyword which is on
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/cann/can

Copy link
Contributor Author

Choose a reason for hiding this comment

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

cannot ;-)

Comment on lines +232 to +235
It is also possible to have a double arrow (``=>``) which means that the
directionality for adresses and ports is used,
but such a rule can match a bidirectional transaction, using keywords
matching in each direction.
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion of alternative text: "There is also the double arrow (=>), which respects the directionality as ->, but allows matching on bidirectional transactions, used with keywords matching each direction."

Question: would it be possible to say that using => has a similar effect as having two rules (one for each side of the bidir transaction) and setting flowbits to only have an alert in case both match?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

would it be possible to say that using => has a similar effect as having two rules (one for each side of the bidir transaction) and setting flowbits to only have an alert in case both match?

It is the goal indeed cf tests/detect-bidir-flowbits/ in OISF/suricata-verify#1922

The goal is to be better as these are txbits, not flowbits ;-)

- They are only meant to work on transactions with first a request to the server,
and then a response to the client, and not the other way around.
- They cann have ``fast_pattern`` or ``prefilter`` on a keyword which is on
the direction to client only if they do not have any have streaming buffers
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
the direction to client only if they do not have any have streaming buffers
the direction to client only if they do not have any streaming buffers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if they do have ;-)

@catenacyber
Copy link
Contributor Author

@jufajardini could you please review the documentation ? Any idea where should I document these new keywords bidir.toclient ?

Do we see more bidirectional keywords coming? If yes, maybe we could have a separate section, like we have for Flow, Meta keywords, etc. If not, then maybe a subsection of the Direction section could do.

I do not see anymore coming.
So subsection of Direction sounds good :-)

I think that to help illustrate the difference between <> and =>, adding an example for <>, like you did in the explanation to Shivani, would be quite helpful :)

Adding something

@catenacyber
Copy link
Contributor Author

Thanks for the tips, continued in #11497

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants