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/entropy: Add entropy keyword #12385

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Conversation

jlucovsky
Copy link
Contributor

This PR adds the entropy keyword. See the documentation and commit commits for more information.
(tbd -- details left out for draft PR)

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

Describe changes:

Provide values to any of the below to override the defaults.

  • To use an LibHTP, Suricata-Verify or Suricata-Update pull request,
    link to the pull request in the respective _BRANCH variable.
  • Leave unused overrides blank or remove.

SV_REPO=
SV_BRANCH=OISF/suricata-verify#2232
SU_REPO=
SU_BRANCH=
LIBHTP_REPO=
LIBHTP_BRANCH=


#[repr(u8)]
#[derive(PartialEq, Debug)]
// operators: ==, <, <=, >, >=, !=
Copy link
Member

Choose a reason for hiding this comment

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

Q: Could we use DetectUintData and its syntax w bytes and offset options here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not directly as the entropy value is a floating point value.

Copy link
Member

Choose a reason for hiding this comment

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

Would be nice to add a DetectFloatData facility then?

Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 87.71930% with 42 lines in your changes missing coverage. Please review.

Project coverage is 80.61%. Comparing base (ad7ff1c) to head (aa5e2ab).
Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12385      +/-   ##
==========================================
- Coverage   82.49%   80.61%   -1.88%     
==========================================
  Files         912      917       +5     
  Lines      258220   258782     +562     
==========================================
- Hits       213006   208618    -4388     
- Misses      45214    50164    +4950     
Flag Coverage Δ
fuzzcorpus 56.79% <4.57%> (-3.63%) ⬇️
livemode 19.38% <4.57%> (-0.03%) ⬇️
pcap 44.26% <4.57%> (-0.09%) ⬇️
suricata-verify 63.18% <66.47%> (-0.07%) ⬇️
unittests 58.54% <75.43%> (+0.46%) ⬆️

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

@suricata-qa
Copy link

WARNING:

field baseline test %
SURI_TLPR1_stats_chk
.uptime 651 627 96.31%

Pipeline 24194

This commit adds
- Parser for the entropy keyword
- Calculation of content the Shannon entropy value

The entropy keyword syntax is the keyword entropy followed by options
and the entropy value for comparison.

The minimum entropy keyword specification is:
entropy: value <entropy-val>

This results in the calculated entropy value being compared with
<entropy-val> with the equality operator.

A match occurs when the values and operator agree. This example matches
if the calculated and entropy value are the same.

When entropy keyword options are specified, all options and "value" must
be comma-separated. Options and value may be specified in any order.

Options have default values:
- bytes is equal to the current content length
- offset is 0
- oper is equality "=="

entropy: [bytes <byteval>] [offset <offsetval>] [oper <operval>] value <entropy-val>

Using default values:
entropy: bytes 0, offset 0, oper ==, value <entropy-val>

The following operators are available:
    - == (default): Match when calculated value equals entropy value
    - < Match when calculated value is strictly less than entropy value
    - <=  Match when calculated value is less than or equal to entropy value
    - > Match when calculated value is strictly greater than entropy value
    - >= Match when calculated value is greater than or equal to entropy value
    - !=  Match when calculated value is not equal to entropy value
This commit adds keyword/build support for the entropy keyword. The
entropy keyword compares an entropy value with a value calculated
according to the Shannon entropy on the available content.
This commmit causes the content inspection engine to recognize and
invoke the entropy "match" function when the entropy keyword is used.
This commit updates the
- Upgrade notes for 7 to 8
- Payload keyword section

Both are update to document the new entropy keyword.
@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 24215

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.

4 participants