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: absent keyword to test absence of sticky buffer #11375

Conversation

catenacyber
Copy link
Contributor

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

Describe changes:

  • detect: adds absent keyword to match on absent buffer

SV_BRANCH=OISF/suricata-verify#1942

#11301 with use of SIGMATCH_OPTIONAL_OPT

Ticket: 2224

It takes an argument to match only if the buffer is absent,
or it can still match if the buffer is present, but we test
the absence of some content
@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 21274

if (sm->type == DETECT_CONTENT) {
const DetectContentData *cd = (DetectContentData *)sm->ctx;
if (has_absent && (cd->flags & DETECT_CONTENT_NEGATED) == 0) {
SCLogError("signature can't have a buffer both absent and with content");
Copy link
Member

Choose a reason for hiding this comment

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

I wondering if this limitation should be lifted. I could easily imagine ppl wanting to express something like
"if there is no user agent, or if it exists and is XYZ, then 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.

It looks possible, but I had to put in some more changes so that the positive content does not get picked as fast_pattern...

@victorjulien
Copy link
Member

The engine analysis output does not reflect the match_on_null state a engine can be in. Would also be good to add detail to the absent match:

{
  "raw": "alert http1 any any -> any any (http.referer; absent; sid:1;)",
  "id": 1,
  "gid": 1,
  "rev": 0,
  "app_proto": "http",
  "requirements": [
    "flow"
  ],
  "type": "app_tx",
  "flags": [
    "src_any",
    "dst_any",
    "sp_any",
    "dp_any",
    "applayer",
    "toserver"
  ],
  "pkt_engines": [],
  "frame_engines": [],
  "engines": [
    {
      "name": "http_referer",
      "direction": "toserver",
      "is_mpm": false,
      "app_proto": "http",
      "progress": 2,
      "matches": [
        {
          "name": "absent"
        }
      ]
    }
  ],
  "lists": {}
}
{
  "raw": "alert http1 any any -> any any (http.referer; absent:or_else; content:!\"ABC\"; sid:3;)",
  "id": 3,
  "gid": 1,
  "rev": 0,
  "app_proto": "http",
  "requirements": [
    "flow"
  ],
  "type": "app_tx",
  "flags": [
    "src_any",
    "dst_any",
    "sp_any",
    "dp_any",
    "applayer",
    "negated_mpm",
    "toserver",
    "prefilter"
  ],
  "pkt_engines": [],
  "frame_engines": [],
  "engines": [
    {
      "name": "http_referer",
      "direction": "toserver",
      "is_mpm": true,
      "app_proto": "http",
      "progress": 2,
      "matches": [
        {
          "name": "absent"
        },
        {
          "name": "content",
          "content": {
            "pattern": "ABC",
            "length": 3,
            "nocase": false,
            "negated": true,
            "starts_with": false,
            "ends_with": false,
            "is_mpm": true,
            "no_double_inspect": false,
            "fast_pattern": false,
            "relative_next": false
          }
        }
      ]
    }
  ],
  "lists": {},
  "mpm": {
    "buffer": "http_referer",
    "pattern": "ABC",
    "length": 3,
    "nocase": false,
    "negated": true,
    "starts_with": false,
    "ends_with": false,
    "is_mpm": true,
    "no_double_inspect": false,
    "fast_pattern": false,
    "relative_next": false
  }
}

@victorjulien
Copy link
Member

Plus a SV test for the engine analysis.

@victorjulien
Copy link
Member

Does it make sense to allow this for each sticky buffer? I wonder for example, if we can have http w/o a http.method, so this rule may nonsense: alert http1 any any -> any any (http.method; absent; sid:4;). I wonder if a buffer registration should include info about whether it makes sense for it to be "absent".

@inashivb inashivb self-requested a review July 2, 2024 04:55
@catenacyber
Copy link
Contributor Author

Does it make sense to allow this for each sticky buffer? I wonder for example, if we can have http w/o a http.method, so this rule may nonsense: alert http1 any any -> any any (http.method; absent; sid:4;). I wonder if a buffer registration should include info about whether it makes sense for it to be "absent".

I think it does make sense at first sight... Maybe it can be a later optimization...

@catenacyber
Copy link
Contributor Author

The engine analysis output does not reflect the match_on_null state a engine can be in.

It does because there is

      "matches": [
        {
          "name": "absent"
        }

Would also be good to add detail to the absent match:

Adding it and the SV test

@catenacyber
Copy link
Contributor Author

Continued in #11423

@catenacyber catenacyber closed this Jul 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs rebase Needs rebase to master
Development

Successfully merging this pull request may close these issues.

3 participants