Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

transform/base64: Add "set_error" to detect if buffer is valid base64 encoded content #12085

Closed
wants to merge 2 commits into from

Conversation

jlucovsky
Copy link
Contributor

This PR adds to the from_base64 decode and provides an indication of whether the input buffer is properly encoded as a base64 buffer. Use set_error and if the buffer cannot be decoded, the output buffer will be set to BASE64_ECODE_BUF

Use this rule snippet to test whether the input is not properly encoded:

      content:"Unencoded content"; from_base64: set_error;  content:"BASE64_ECODE_BUF";

Use this rule snippet to test if the input is base64 encoded:

       content:"/?arg=Zm 9v Ym Fy"; from_base64: set_error;  content:!"BASE64_ECODE_BUF"; content: "foobar";

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

Describe changes:

  • Add set_error to the transform's available option list
  • Update the transform to set the output buffer when set_error is used
  • Document new behavior

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#2117
SU_REPO=
SU_BRANCH=
LIBHTP_REPO=
LIBHTP_BRANCH=

Issue: 7114

Extend the `from_base64` transform with the `set_error` keyword. This
can be used to detect whether the input buffer is base64-encoded or not.

When `set_error` is used and the content is not encoded, the output
will be a buffer with fixed contents: `"BASE64_ECODE_BUF"`

Rule writers can use this with a following `content: "BASE64_ECODE_BUF"` to check
if the input buffer is not base64-encoded.

Add the content negation symbol `!` to ensure the content is
base64-encoded: `content: !"BASE64_ECODE_BUF"`
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.39%. Comparing base (b1e7917) to head (43ff582).

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #12085      +/-   ##
==========================================
+ Coverage   83.37%   83.39%   +0.01%     
==========================================
  Files         910      910              
  Lines      257556   257582      +26     
==========================================
+ Hits       214748   214802      +54     
+ Misses      42808    42780      -28     
Flag Coverage Δ
fuzzcorpus 61.54% <20.00%> (+<0.01%) ⬆️
livemode 19.41% <0.00%> (-0.01%) ⬇️
pcap 44.47% <0.00%> (-0.04%) ⬇️
suricata-verify 62.77% <90.00%> (+0.02%) ⬆️
unittests 59.36% <84.61%> (+<0.01%) ⬆️

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 23248

@jlucovsky
Copy link
Contributor Author

Closing as we're going in a different direction for signaling failure cases.

@jlucovsky jlucovsky closed this Nov 5, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants