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/analyzer: add more details for the tcp ack keyword - v2 #9608

Closed
wants to merge 1 commit into from

Conversation

0xEniola
Copy link
Contributor

@0xEniola 0xEniola commented Oct 12, 2023

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

Previous PR: #9605

Describe changes:

  • Added the detect-tcp-ack.h header to the file.
  • Modified the code to properly handle the DETECT_ACK case; pass the int value of ack to the JsonBuilder.
  • Corrected the test.rules signature.

test.rules:

alert tcp any any -> any any (msg:"SURICATA STREAM 3way handshake ACK"; ack:0; sid:1;)
alert tcp any any -> any any (msg:"SURICATA STREAM 3way handshake ACK"; ack:1; sid:2;)
alert tcp any any -> any any (msg:"SURICATA STREAM 3way handshake ACK"; ack:2; sid:3;)

test.yaml:

requires:
    min-version: 7.0.0
args:
    - --engine-analysis

checks:
- filter:
    filename: rules.json
    count: 1
    match:
      id: 1
      lists.packet.matches[0].name: "tcp.ack"

output:

{
  "raw":"alert tcp any any -> any any (msg:\"SURICATA STREAM 3way handshake ACK\"; ack:0; sid:1;)",
  "id":1,
  "gid":1,
  "rev":0,
  "msg":"SURICATA STREAM 3way handshake ACK",
  "app_proto":"unknown",
  "requirements": [],
  "type":"pkt",
  "flags": [
    "src_any",
    "dst_any",
    "sp_any",
    "dp_any",
    "need_packet",
    "toserver",
    "toclient"
  ],
  "pkt_engines": [
    {
      "name":"packet",
      "is_mpm":false
    }
  ],
  "frame_engines":[],
  "lists": {
    "packet":{
      "matches": [
        {
          "name":"tcp.ack"
        }
      ]
    }
  }
}

SV_BRANCH=OISF/suricata-verify#1423

Issue: OISF#6354

Added the DETECT_ACK case to detect-engine-analyzer.c
@inashivb inashivb added the outreachy Contributions made by Outreachy applicants label Oct 13, 2023
@github-actions
Copy link

NOTE: This PR may contain new authors:

Daniel Olatunji <[email protected]>

@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

Merging #9608 (b7849c2) into master (1a132f4) will increase coverage by 0.08%.
The diff coverage is 100.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9608      +/-   ##
==========================================
+ Coverage   82.28%   82.37%   +0.08%     
==========================================
  Files         968      968              
  Lines      274275   274281       +6     
==========================================
+ Hits       225700   225946     +246     
+ Misses      48575    48335     -240     
Flag Coverage Δ
fuzzcorpus 64.64% <0.00%> (+0.30%) ⬆️
suricata-verify 60.93% <100.00%> (+<0.01%) ⬆️
unittests 62.87% <0.00%> (-0.01%) ⬇️

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

@jufajardini jufajardini added the needs verify Needs (a) Suricata-verify test(s) label Oct 13, 2023
Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

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

Looking much better, as I indicated in the previous PR, we may need some discussion to define how will we settle on the output itself - but that's minor.

For this PR, it would be good to have an accompanying suricata-verify PR with a test similar to the ipopts one (see OISF/suricata-verify#1387).

Could you work on that, too? This will help us visualize that the changes you're adding here are the way we expect them to be.

If you do, make sure to add a check on the test.yaml for the actual values the ack flag has, in each rule ;)

@jufajardini
Copy link
Contributor

Edited PR description to include link to SV PR, to see if CI checks run against it.

const DetectAckData *cd = (const DetectAckData *)smd->ctx;

jb_open_object(js, "ack");
jb_set_uint(js, "ack", cd->ack);
Copy link
Contributor

Choose a reason for hiding this comment

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

After considering our documentation, let's go with number for this inner field.

So the expectation is that for the output, we will see not only the keyword name, but also what was set in the rule for the ack number.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK.

I'll check it out—you mean, I should do cd->number right?

Copy link
Member

Choose a reason for hiding this comment

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

No. There is no cd->number. Your current object would look like ack.ack: 4, you should instead make it ack.number: 4 as per Juliana's comments. Does this make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohhh! Yes it makes sense.

I understand now.

@jufajardini jufajardini removed the needs verify Needs (a) Suricata-verify test(s) label Oct 17, 2023
Copy link
Contributor

@jufajardini jufajardini left a comment

Choose a reason for hiding this comment

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

Please see the inline comment for a suggestion on how to name the ack integer value we want to log out :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
outreachy Contributions made by Outreachy applicants
Development

Successfully merging this pull request may close these issues.

3 participants