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 - v1 #8318

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
55 changes: 41 additions & 14 deletions doc/userguide/output/eve/eve-json-format.rst
Expand Up @@ -89,23 +89,17 @@ generated the event.
Event type: Alert
-----------------

Field action
~~~~~~~~~~~~

Possible values: "allowed" and "blocked"

Example:
This field contains data about a signature that matched, such as
``signature_id`` (``sid`` in the rule) and the ``signature`` (``msg`` in the
rule).

::


"action":"allowed"

Action is set to "allowed" unless a rule used the "drop" action and Suricata is in IPS mode, or when the rule used the "reject" action.

It can also contain information about Source and Target of the attack in the alert.source and alert.target field if target keyword is used in
It can also contain information about Source and Target of the attack in the
``alert.source`` and ``alert.target`` field if target keyword is used in
the signature.

This event will also have the ``pcap_cnt`` field, when running in pcap mode, to
indicate which packet triggered the signature.

::

"alert": {
Expand Down Expand Up @@ -147,6 +141,39 @@ the signature.
}
},

Field action
~~~~~~~~~~~~

Possible values: "allowed" and "blocked".

Example:

::


"action":"allowed"

Action is set to "allowed" unless a rule used the "drop" action and Suricata is
in IPS mode, or when the rule used the "reject" action. It is important to note
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
~~~~~~~~~~~~~

Possible values are "accept", "drop" or "reject".

Example:

::


"verdict":"drop"

Verdict is the final action that will be applied to a given packet, based on all
the signatures triggered by it. In IPS mode, all values are possible. In IDS
mode, verdict is only present if its value is "reject".

Pcap Field
~~~~~~~~~~

Expand Down
13 changes: 13 additions & 0 deletions doc/userguide/output/eve/eve-json-output.rst
Expand Up @@ -264,6 +264,19 @@ enabled, then the log gets more verbose.

By using ``custom`` it is possible to select which TLS fields to log.

Drops
~~~~~

Drops are event types logged when the engine drops a packet.

Config::

#- drop:
# alerts: yes # log alerts that caused drops
# flows: all # start or all: 'start' logs only a single drop
# # per flow direction. All logs each dropped pkt.


Date modifiers in filename
~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
3 changes: 3 additions & 0 deletions etc/schema.json
Expand Up @@ -100,6 +100,9 @@
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d+[+\\-]\\d+$",
"optional": false
},
"verdict": {
"type": "string"
},
"direction": {
"type": "string",
"optional": true
Expand Down
18 changes: 18 additions & 0 deletions src/decode.c
Expand Up @@ -819,6 +819,24 @@ const char *PacketDropReasonToString(enum PacketDropReason r)
return NULL;
}

/** \brief Decide Packet's final verdict based on packet action, return it as a string */
const char *PacketActionVerdictToString(const Packet *p)
{
/* Reject is valid in both IDS and IPS */
if (PacketCheckAction(p, ACTION_REJECT_ANY)) {
return "reject";
} else if (EngineModeIsIPS()) {
/* Verdicts will be reject, drop, or accept */
if (PacketCheckAction(p, ACTION_DROP)) {
return "drop";
}
return "accept";
}

/* If we're in IDS mode and action isn't reject, we won't log verdict */
return NULL;
}

/* TODO drop reason stats! */
void CaptureStatsUpdate(ThreadVars *tv, CaptureStats *s, const Packet *p)
{
Expand Down
1 change: 1 addition & 0 deletions src/decode.h
Expand Up @@ -838,6 +838,7 @@ void DecodeThreadVarsFree(ThreadVars *, DecodeThreadVars *);
void DecodeUpdatePacketCounters(ThreadVars *tv,
const DecodeThreadVars *dtv, const Packet *p);
const char *PacketDropReasonToString(enum PacketDropReason r);
const char *PacketActionVerdictToString(const Packet *p);

/* decoder functions */
int DecodeEthernet(ThreadVars *, DecodeThreadVars *, Packet *, const uint8_t *, uint32_t);
Expand Down
8 changes: 6 additions & 2 deletions src/output-json-alert.c
Expand Up @@ -826,12 +826,16 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
jb_set_string(jb, "capture_file", pcap_filename);
}

if (PacketActionVerdictToString(p) != NULL) {
const char *verdict = PacketActionVerdictToString(p);
jb_set_string(jb, "verdict", verdict);
}

OutputJsonBuilderBuffer(jb, aft->ctx);
jb_free(jb);
}

if ((p->flags & PKT_HAS_TAG) && (json_output_ctx->flags &
LOG_JSON_TAGGED_PACKETS)) {
if ((p->flags & PKT_HAS_TAG) && (json_output_ctx->flags & LOG_JSON_TAGGED_PACKETS)) {
JsonBuilder *packetjs =
CreateEveHeader(p, LOG_DIR_PACKET, "packet", NULL, json_output_ctx->eve_ctx);
if (unlikely(packetjs != NULL)) {
Expand Down
3 changes: 3 additions & 0 deletions src/output-json-drop.c
Expand Up @@ -158,6 +158,9 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p)
/* Close drop. */
jb_close(js);

const char *verdict = PacketActionVerdictToString(p);
jb_set_string(js, "verdict", verdict);

Comment on lines +161 to +163
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 felt a bit redundant when I was documenting it...

if (aft->drop_ctx->flags & LOG_DROP_ALERTS) {
int logged = 0;
int i;
Expand Down
3 changes: 3 additions & 0 deletions src/output-json.c
Expand Up @@ -52,6 +52,9 @@
#include "output.h"
#include "output-json.h"

#include "packet.h"
#include "action-globals.h"

#include "util-byte.h"
#include "util-privs.h"
#include "util-print.h"
Expand Down
3 changes: 3 additions & 0 deletions suricata.yaml.in
Expand Up @@ -168,6 +168,9 @@ outputs:
# Enable the logging of tagged packets for rules using the
# "tag" keyword.
tagged-packets: yes
# Enable logging the final verdict on a packet (e.g. "blocked",
Copy link
Member

Choose a reason for hiding this comment

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

these don't match the actual logged values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shame on me >____<'

# "allowed", "rejected")
verdict: yes
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should make the action field optional instead. That is the confusing one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then verdict becomes mandatory, and action optional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Making action optional becomes a bit annoying for the drop events, with our current way of handling optional fields in the alerts (the context flags). Should we keep this field mandatory, there?

# app layer frames
- frame:
# disabled by default as this is very verbose.
Expand Down