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

Flow bytes pkts either support/v4 #11897

Closed
wants to merge 2 commits into from

Conversation

inashivb
Copy link
Member

@inashivb inashivb commented Oct 8, 2024

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

SV_BRANCH=OISF/suricata-verify#2082

Previous PR: #11889

Changes since v3:

  • Kept the old syntax as that is more in line w schema as per internal discussion
  • rebased on top of latest master

Add an extension to keywords flow.bytes.. and flow.pkts.. to allow
matching on bytes or pkts in either direction. The syntax for this
operation would look like the following:

flow.bytes_either:1000
flow.pkts_either:20

These are implemented as generic uint types and thus allow all basic ops
in the syntax like greater than, less than, etc alongwith the exact
match.

Feature 5646
@inashivb inashivb requested review from catenacyber and removed request for jufajardini and victorjulien October 8, 2024 07:18
Copy link

codecov bot commented Oct 8, 2024

Codecov Report

Attention: Patch coverage is 69.33333% with 23 lines in your changes missing coverage. Please review.

Project coverage is 82.61%. Comparing base (6ae5ae7) to head (f4bc8c7).
Report is 120 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #11897   +/-   ##
=======================================
  Coverage   82.60%   82.61%           
=======================================
  Files         912      912           
  Lines      249342   249417   +75     
=======================================
+ Hits       205968   206046   +78     
+ Misses      43374    43371    -3     
Flag Coverage Δ
fuzzcorpus 60.66% <25.33%> (+0.02%) ⬆️
livemode 18.72% <25.33%> (+<0.01%) ⬆️
pcap 44.08% <25.33%> (+0.01%) ⬆️
suricata-verify 62.01% <69.33%> (-0.02%) ⬇️
unittests 58.93% <25.33%> (-0.01%) ⬇️

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

---- 🚨 Try these New Features:

@inashivb inashivb changed the title Flow bytes pkts syntax/v4 Flow bytes pkts either support/v4 Oct 8, 2024
@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 23041

if (p->flow == NULL) {
return 0;
}
uint32_t nb = p->flow->tosrcpktcnt;
Copy link
Member

Choose a reason for hiding this comment

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

can avoid using nb and just use p->flow->tosrcpkt_cnt directly?

if (p->flow == NULL) {
return 0;
}
uint64_t nb = p->flow->tosrcbytecnt;
Copy link
Member

Choose a reason for hiding this comment

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

same as with pkts

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

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

See inline comments.

@victorjulien
Copy link
Member

Still not entirely fan of the keyword itself, as I feel it is better to have it as an option somehow. But since the existing keywords map to eve, and adding the option there doesn't make sense, I don't know a better way right now.

Or we'd have change eve to do something like:

flow.pkts.toserver
flow.pkts.toclient

then keywords could be

flow.pkts:toserver
flow.pkts:toclient
flow.pkts:either

Hmmm... not a perfect match either. So, I remain undecided...

@jufajardini
Copy link
Contributor

Still not entirely fan of the keyword itself, as I feel it is better to have it as an option somehow. But since the existing keywords map to eve, and adding the option there doesn't make sense, I don't know a better way right now.

Or we'd have change eve to do something like:

flow.pkts.toserver
flow.pkts.toclient

then keywords could be

flow.pkts:toserver
flow.pkts:toclient
flow.pkts:either

Hmmm... not a perfect match either. So, I remain undecided...

Imho, this alternative seems easier to correlate and understand.

flow.pkts_either
------------------

Flow number of packets in either direction (integer)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
Flow number of packets in either direction (integer)
Flow number of packets in either direction (integer).

Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if it is needed to add that it is either, but not the some of both - or if it is clear enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think mathematically either is different than both or/and sum. But, if it seems like it can confuse new people, sure. Do you have suggestions on incorporating it in the sentence?

Comment on lines +357 to +359
flow.pkts_either:3 # exactly 3
flow.pkts_either:<3 # smaller than 3
flow.pkts_either:>=2 # greater than or equal to 2
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this list non-exhaustive? Should we somehow indicate the other possible operations (even if by just adding a "for example", at the end of the sentence?

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, we do link to all the possible ops in the ref tag above. It leads to this elaborate doc: https://docs.suricata.io/en/latest/rules/integer-keywords.html#rules-integer-keywords.
Lmk if this does not seem enough


Signature example::

alert ip any any -> any any (msg:"Flow has greater than 3000 bytes in either dir"; flow.bytes_either:>3000; 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.

nit:

Suggested change
alert ip any any -> any any (msg:"Flow has greater than 3000 bytes in either dir"; flow.bytes_either:>3000; sid:1;)
alert ip any any -> any any (msg:"Flow is greater than 3000 bytes in either dir"; flow.bytes_either:>3000; sid:1;)

@inashivb
Copy link
Member Author

Still not entirely fan of the keyword itself, as I feel it is better to have it as an option somehow. But since the existing keywords map to eve, and adding the option there doesn't make sense, I don't know a better way right now.

Or we'd have change eve to do something like:

flow.pkts.toserver
flow.pkts.toclient

then keywords could be

flow.pkts:toserver
flow.pkts:toclient
flow.pkts:either

Just adding that the previous version of this PR had exactly this syntax for rule keywords to have direction as an option. eve was unchanged though

@victorjulien victorjulien added the decision-required Waiting on deliberation from the team label Oct 24, 2024
@inashivb
Copy link
Member Author

As discussed internally, we'll keep the syntax of previous PR

@inashivb inashivb closed this Nov 22, 2024
@victorjulien
Copy link
Member

As discussed internally, we'll keep the syntax of previous PR

But, also keep flow.pkts_toserver and flow.pkts_toclient for now. Same for bytes.

@inashivb inashivb deleted the flow-bytes-pkts-syntax/v4 branch November 25, 2024 06:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
decision-required Waiting on deliberation from the team
Development

Successfully merging this pull request may close these issues.

4 participants