Skip to content

Conversation

@catenacyber
Copy link
Contributor

@catenacyber catenacyber commented Sep 2, 2025

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

Describe changes:

  • detect: count keywords for multi-buffer

SV_BRANCH=OISF/suricata-verify#2634

Draft :

Feedback about design is welcome

"FtpDataStateValues",
"HTTP2TransactionState",
"DataRepType",
"DETECT_COUNT_INDEX",
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 hack is to reuse InspectionMultiBufferGetDataPtr function prototype, with passing special index 0xFFFFFFFF


/// Intermediary function used in detect-email.c to access data from the MimeStateSMTP structure
/// for array header fields.
/// The hname parameter determines which data will be returned.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO: remove this comment

}

sm_list = s->init_data->list;
// TODO check it is a multi buffer and not a single buffer
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And add tests about impossible rules like http.uri; count:1; and raw tcp content: "abc"; count: 1;

return false;
}

if (idx == DETECT_COUNT_INDEX) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need to do that for all the keywords listed in #13752

SCDetectHelperKeywordRegister(&kw);
g_mime_email_received_buffer_id = SCDetectHelperMultiBufferMpmRegister("email.received",
"MIME EMAIL RECEIVED", ALPROTO_SMTP, STREAM_TOSERVER, GetMimeEmailReceivedData);
g_mime_email_received_buffer_id = SCDetectHelperMultiBufferProgressMpmRegister("email.received",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That is an interesting point :

  • now we run detection on email.received multi-buffer even if the progress is not complete yet, that allows early detection
  • But with count, I think we only want the final count once the progress is far enough

Copy link
Member

Choose a reason for hiding this comment

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

now we run detection on email.received multi-buffer even if the progress is not complete yet, that allows early detection

If the progress is not complete, do we still have the entire buffer needed to match?

Copy link
Member

Choose a reason for hiding this comment

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

once the progress is far enough

how do we know that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

do we still have the entire buffer needed to match?

Depending on the packets, we have some of the instances of the multi-buffer.

You can have

  • 1 packet with 0 email.received
  • another packet after with 1 email.received
  • a final packet with 3 email.received

Does that reply to your question ?

how do we know that?

We can access the tx progress if we need...

Copy link
Member

Choose a reason for hiding this comment

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

Depending on the packets, we have some of the instances of the multi-buffer.

So, will the inspection be run every time a packet comes?

We can access the tx progress if we need

yes, but, could you please tell how do we define that the progress is "far enough"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For example, let's take HTTP which has the progress

  • request_line = 0
  • headers = 1
  • body = 2

And we want to count the number of http headers

We have the following packets

  • half of request line : progress is request_line = 0
  • end of request line : progress is now headers = 1, headers count is 0
  • first header : progress is headers = 1, headers count is 1
  • 2 last headers : progress is now body = 2, headers count is 3
  • end of request with its body

In this case, progress is "far enough" when it is 2

So, will the inspection be run every time a packet comes?

inspection does not run on first packet (progress not far enough) and neither on last packet (once progress is above, we only run once)

but it runs on the 3 packets in the middle

Copy link
Member

Choose a reason for hiding this comment

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

Thanks a lot for explaining! 🙇🏽‍♀️ This sounds very good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we can rely on the tx hooks...

DEBUG_VALIDATE_BUG_ON(1);
return false;
}
DetectU32Data *du32 = (DetectU32Data *)ctx;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we need to check the tx progress and allow only du32 modes "greater than" if progress means we still can get the count to grow

@codecov
Copy link

codecov bot commented Sep 2, 2025

Codecov Report

❌ Patch coverage is 82.53968% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.71%. Comparing base (be605ba) to head (895ac9b).
⚠️ Report is 117 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #13783      +/-   ##
==========================================
- Coverage   83.72%   83.71%   -0.01%     
==========================================
  Files        1011     1012       +1     
  Lines      275117   275178      +61     
==========================================
+ Hits       230328   230379      +51     
- Misses      44789    44799      +10     
Flag Coverage Δ
fuzzcorpus 62.96% <31.74%> (-0.02%) ⬇️
livemode 19.11% <14.28%> (+0.11%) ⬆️
pcap 44.72% <30.15%> (+0.02%) ⬆️
suricata-verify 65.10% <82.53%> (+<0.01%) ⬆️
unittests 59.16% <28.57%> (-0.02%) ⬇️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa
Copy link

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.uptime 648 624 96.3%

Pipeline = 27325

@catenacyber catenacyber added this to the 9.0 milestone Sep 9, 2025
@catenacyber
Copy link
Contributor Author

I would also like to support syntax email.received: count=3;

@catenacyber
Copy link
Contributor Author

Status : first make progress on #13823

@catenacyber
Copy link
Contributor Author

Replaced by #13902

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

Labels

needs rebase Needs rebase to main

Development

Successfully merging this pull request may close these issues.

3 participants