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

output/eve: add 'verdict' field to 'alert' and 'drop' events - v8 #9162

Closed
wants to merge 6 commits into from

Conversation

jufajardini
Copy link
Contributor

@jufajardini jufajardini commented Jul 6, 2023

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

Previous PR: #8596

Sharing this now to clarify one aspect, and check if this is going on the right direction.

Describe changes from previous PR:

  • add verdict as a new output event
  • use flags to set configuration options for drop event (haven't touched the flows all/start one, as this was leading to failures, but can make it a TODO
  • drop idea of having alert.action as optional
  • incorporate verdict format suggestions from previous PR

TODOs:

  • add more examples in the documentation
  • document the json schema
  • document verdict configs for suricata.yaml (userguide)

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

SV_BRANCH=pr/1293

OISF/suricata-verify#1293

Outputs examples:

# ids mode, reject, verdict event:
{
  "timestamp": "2004-05-13T10:17:08.993643+0000",
  "flow_id": 1055224944964893,
  "pcap_cnt": 6,
  "event_type": "verdict",
  "src_ip": "65.208.228.223",
  "src_port": 80,
  "dest_ip": "145.254.160.237",
  "dest_port": 3372,
  "proto": "TCP",
  "pkt_src": "wire/pcap",
  "verdict": {
    "action": "alert",
    "reject-target": "source",
    "reject": "[tcp-reset, icmp-prohib, user defined]"
  }
}

# ids mode, reject, alert event (non-interesting portions removed):
{
  "timestamp": "2004-05-13T10:17:08.993643+0000",
  "flow_id": 1055224944964893,
  "pcap_cnt": 6,
  "event_type": "alert",
  "src_ip": "65.208.228.223",
  "src_port": 80,
  "dest_ip": "145.254.160.237",
  "dest_port": 3372,
  "proto": "TCP",
  "pkt_src": "wire/pcap",
  "alert": {
    "action": "blocked",
    "gid": 1,
    "signature_id": 1000001,
    "rev": 0,
    "signature": "",
    "category": "",
    "severity": 3
  },
...
  "verdict": {
    "action": "alert",
    "reject-target": "source",
    "reject": "[tcp-reset, icmp-prohib, user defined]"
  }
}
# ids mode, alert:
{
  "timestamp": "2004-05-13T10:17:08.783340+0000",
  "flow_id": 1055224944964893,
  "pcap_cnt": 5,
  "event_type": "verdict",
  "src_ip": "65.208.228.223",
  "src_port": 80,
  "dest_ip": "145.254.160.237",
  "dest_port": 3372,
  "proto": "TCP",
  "pkt_src": "wire/pcap",
  "verdict": {
    "action": "alert"
  }
}
# ips mode, drop event:
{
  "timestamp": "2016-07-13T22:42:07.388277+0000",
  "flow_id": 2019293786341530,
  "pcap_cnt": 8,
  "event_type": "drop",
  "src_ip": "10.16.1.11",
  "src_port": 54186,
  "dest_ip": "82.165.177.154",
  "dest_port": 80,
  "proto": "TCP",
  "pkt_src": "wire/pcap",
  "direction": "to_server",
  "drop": {
    "len": 40,
    "tos": 0,
    "ttl": 64,
    "ipid": 36762,
    "tcpseq": 2059970575,
    "tcpack": 2548486954,
    "tcpwin": 237,
    "syn": false,
    "ack": true,
    "psh": false,
    "rst": false,
    "urg": false,
    "fin": true,
    "tcpres": 0,
    "tcpurgp": 0,
    "reason": "flow drop"
  },
  "verdict": {
    "action": "drop"
  }
}
# ips mode, alert event, drop rule:
{
  "timestamp": "2016-07-13T22:42:07.199844+0000",
  "flow_id": 2019293786341530,
  "pcap_cnt": 4,
  "event_type": "alert",
  "src_ip": "10.16.1.11",
  "src_port": 54186,
  "dest_ip": "82.165.177.154",
  "dest_port": 80,
  "proto": "TCP",
  "pkt_src": "wire/pcap",
  "alert": {
    "action": "blocked",
    "gid": 1,
    "signature_id": 2,
    "rev": 1,
    "signature": "",
    "category": "",
    "severity": 3
  },
...
  "verdict": {
    "action": "drop"
  }
}

Besides having the alert's verdict as a part of the alert event, also
offer the ability to have it as an independent event type.

Related to
Task OISF#5464
The `field action` portion seemed to be comprised of a more generic
section that followed it. Also formatted the section for lines to be
within the character limit.
Comment on lines -63 to +65
#define LOG_DROP_ALERTS 1
#define LOG_DROP_ALERTS BIT_U8(1)
#define LOG_DROP_VERDICT BIT_U8(2)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed this, tried adding the flows start/all option here, but led to failures. Can make this a TODO.

} else if (p->action & ACTION_REJECT_BOTH) {
JB_SET_STRING(jb, "reject-target", "both");
}
JB_SET_STRING(jb, "reject", "[tcp-reset, icmp-prohib, user defined]");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the bit I wasn't sure about the approach, @victorjulien . The examples from #8596 (comment) show all options. If that's the case, would this work? Or do we want to check what is actually being done by Suri, and output only that option? If so, I'm done sure how to figure out when will it be user defined...

The other two I figured I could decide by checking the packet proto.

Copy link
Member

Choose a reason for hiding this comment

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

this shouldn't be a single string, but a json array of strings

Copy link
Member

Choose a reason for hiding this comment

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

"user defined" can be ignored, it was a place holder for some future ideas

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, thanks.

@codecov
Copy link

codecov bot commented Jul 6, 2023

Codecov Report

Merging #9162 (24c9bf8) into master (9b09b29) will decrease coverage by 0.01%.
The diff coverage is 81.25%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #9162      +/-   ##
==========================================
- Coverage   82.34%   82.33%   -0.01%     
==========================================
  Files         968      969       +1     
  Lines      273546   273656     +110     
==========================================
+ Hits       225247   225317      +70     
- Misses      48299    48339      +40     
Flag Coverage Δ
fuzzcorpus 64.54% <8.03%> (-0.06%) ⬇️
suricata-verify 60.74% <81.25%> (-0.01%) ⬇️
unittests 62.88% <5.35%> (-0.03%) ⬇️

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
.flow.memuse 592373632 511756848 86.39%

Pipeline 15018

that this does not necessarily indicate the final verdict for a given packet or
flow, since one packet may match on several rules.

Verdict Field
Copy link
Member

Choose a reason for hiding this comment

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

this is not a field, but an object containing other fields, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, I was seeing it as a field because it's part of 'alert', but... that's indeed wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also: update description, there are more fields in verdict now.

"verdict": {
"action": "alert"
"reject-target": "both"
"reject": [ "tcp-reset", "icmp-prohib", "user defined" ]
Copy link
Member

Choose a reason for hiding this comment

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

the value here should be a json array of strings

JsonVerdictLogThread *vlt = thread_data;

int r = VerdictJson(vlt, p);

Copy link
Member

Choose a reason for hiding this comment

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

remove newline


static int JsonVerdictLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
{
if (p->alerts.cnt > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

so verdict records are only written for alerts... this excludes drops from outside the detect engine (e.g. exception policy), also "pass" would be excluded, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right on cue for both aspects, I hadn't considered them >__<'

@@ -168,6 +168,10 @@ outputs:
# Enable the logging of tagged packets for rules using the
# "tag" keyword.
tagged-packets: yes
# Enable logging the final verdict for packets with the alert
verdict: yes
- verdict:
Copy link
Member

Choose a reason for hiding this comment

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

add a comment to explain on a high level what this is

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

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

see inline comments

@jufajardini
Copy link
Contributor Author

Replaced by: #9216

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.

3 participants