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

verdict eve field - 6.0.x backports - v3 #9311

Closed
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 58 additions & 14 deletions doc/userguide/output/eve/eve-json-format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -73,23 +73,17 @@ generated the event.
Event type: Alert
-----------------

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

Possible values: "allowed" and "blocked"

Example:

::


"action":"allowed"
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 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 it 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 All @@ -109,6 +103,56 @@ the signature.
"port": 80
},

Action field
~~~~~~~~~~~~

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-alert:

Verdict
~~~~~~~

An object containning info on the final action that will be applied to a given
packet, based on all the signatures triggered by it and other possible events
(e.g., a flow drop). For that reason, it is possible for an alert with
an action ``allowed`` to have a verdict ``drop``, in IPS mode, for instance, if
that packet was dropped due to a different alert.

* Action: ``alert``, ``pass``, ``drop`` (this latter only occurs in IPS mode)
* Reject-target: ``to_server``, ``to_client``, ``both`` (only occurs for 'reject' rules)
* Reject: an array of strings with possible reject types: ``tcp-reset``,
``icmp-prohib`` (only occurs for 'reject' rules)

Example:

::

"verdict": {
"action": "drop",
"reject-target": "to_client",
"reject": "[icmp-prohib]"
}


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

If pcap log capture is active in `multi` mode, a `capture_file` key will be added to the event
with value being the full path of the pcap file where the corresponding packets
have been extracted.

Event type: Anomaly
-------------------

Expand Down
16 changes: 16 additions & 0 deletions doc/userguide/output/eve/eve-json-output.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,22 @@ 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.
# Enable logging the final action taken on a packet by the engine
# (will show more information in case of a drop caused by 'reject')
verdict: yes


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

Expand Down
70 changes: 69 additions & 1 deletion src/output-json-alert.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2013-2020 Open Information Security Foundation
/* Copyright (C) 2013-2023 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -94,6 +94,7 @@
#define LOG_JSON_HTTP_BODY_BASE64 BIT_U16(7)
#define LOG_JSON_RULE_METADATA BIT_U16(8)
#define LOG_JSON_RULE BIT_U16(9)
#define LOG_JSON_VERDICT BIT_U16(10)

#define METADATA_DEFAULTS ( LOG_JSON_FLOW | \
LOG_JSON_APP_LAYER | \
Expand Down Expand Up @@ -572,6 +573,68 @@ static void AlertAddFiles(const Packet *p, JsonBuilder *jb, const uint64_t tx_id
}
}

bool PacketCheckAction(const Packet *p, const uint8_t a)
{
Copy link
Member

Choose a reason for hiding this comment

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

in master 6 we have been fixing things differently, I think you should use PACKET_TEST_ACTION instead

if (likely(p->root == NULL)) {
return (p->action & a) != 0;
} else {
/* check against both */
const uint8_t actions = p->action | p->root->action;
return (actions & a) != 0;
}
}

/**
* \brief Build verdict object
*
* \param p Pointer to Packet current being logged
*
*/
void EveAddVerdict(JsonBuilder *jb, const Packet *p)
{
jb_open_object(jb, "verdict");

/* add verdict info */
if (PacketCheckAction(p, ACTION_REJECT_ANY)) {
// check rule to define type of reject packet sent
if (EngineModeIsIPS()) {
JB_SET_STRING(jb, "action", "drop");
} else {
JB_SET_STRING(jb, "action", "alert");
}
if (PacketCheckAction(p, ACTION_REJECT)) {
JB_SET_STRING(jb, "reject-target", "to_client");
} else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
JB_SET_STRING(jb, "reject-target", "to_server");
} else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
JB_SET_STRING(jb, "reject-target", "both");
}
jb_open_array(jb, "reject");
switch (p->proto) {
case IPPROTO_UDP:
case IPPROTO_ICMP:
case IPPROTO_ICMPV6:
jb_append_string(jb, "icmp-prohib");
break;
case IPPROTO_TCP:
jb_append_string(jb, "tcp-reset");
break;
}
jb_close(jb);

} else if (PacketCheckAction(p, ACTION_DROP) && EngineModeIsIPS()) {
JB_SET_STRING(jb, "action", "drop");
} else if (p->alerts.alerts[p->alerts.cnt].action & ACTION_PASS) {
JB_SET_STRING(jb, "action", "pass");
} else {
// TODO make sure we don't have a situation where this wouldn't work
JB_SET_STRING(jb, "action", "alert");
}

/* Close verdict */
jb_close(jb);
}

static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
{
MemBuffer *payload = aft->payload_buffer;
Expand Down Expand Up @@ -708,6 +771,10 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
jb_set_string(jb, "xff", xff_buffer);
}

if (json_output_ctx->flags & LOG_JSON_VERDICT) {
EveAddVerdict(jb, p);
}

OutputJsonBuilderBuffer(jb, aft->file_ctx, &aft->json_buffer);
jb_free(jb);
}
Expand Down Expand Up @@ -938,6 +1005,7 @@ static void JsonAlertLogSetupMetadata(AlertJsonOutputCtx *json_output_ctx,
SetFlag(conf, "payload-printable", LOG_JSON_PAYLOAD, &flags);
SetFlag(conf, "http-body-printable", LOG_JSON_HTTP_BODY, &flags);
SetFlag(conf, "http-body", LOG_JSON_HTTP_BODY_BASE64, &flags);
SetFlag(conf, "verdict", LOG_JSON_VERDICT, &flags);

/* Check for obsolete configuration flags to enable specific
* protocols. These are now just aliases for enabling
Expand Down
4 changes: 3 additions & 1 deletion src/output-json-alert.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2013-2014 Open Information Security Foundation
/* Copyright (C) 2013-2023 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -30,6 +30,8 @@
void JsonAlertLogRegister(void);
void AlertJsonHeader(void *ctx, const Packet *p, const PacketAlert *pa, JsonBuilder *js,
uint16_t flags, JsonAddrInfo *addr);
bool PacketCheckAction(const Packet *p, const uint8_t a);
void EveAddVerdict(JsonBuilder *jb, const Packet *p);

#endif /* __OUTPUT_JSON_ALERT_H__ */

17 changes: 14 additions & 3 deletions src/output-json-drop.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (C) 2007-2020 Open Information Security Foundation
/* Copyright (C) 2007-2023 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
Expand Down Expand Up @@ -58,7 +58,8 @@

#define MODULE_NAME "JsonDropLog"

#define LOG_DROP_ALERTS 1
#define LOG_DROP_ALERTS BIT_U8(1)
#define LOG_DROP_VERDICT BIT_U8(2)

typedef struct JsonDropOutputCtx_ {
LogFileCtx *file_ctx;
Expand Down Expand Up @@ -155,6 +156,10 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p)
/* Close drop. */
jb_close(js);

if (aft->drop_ctx->flags & LOG_DROP_VERDICT) {
EveAddVerdict(js, p);
}

if (aft->drop_ctx->flags & LOG_DROP_ALERTS) {
int logged = 0;
int i;
Expand Down Expand Up @@ -280,7 +285,7 @@ static OutputInitResult JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_
const char *extended = ConfNodeLookupChildValue(conf, "alerts");
if (extended != NULL) {
if (ConfValIsTrue(extended)) {
drop_ctx->flags = LOG_DROP_ALERTS;
drop_ctx->flags |= LOG_DROP_ALERTS;
}
}
extended = ConfNodeLookupChildValue(conf, "flows");
Expand All @@ -294,6 +299,12 @@ static OutputInitResult JsonDropLogInitCtxSub(ConfNode *conf, OutputCtx *parent_
"'flow' are 'start' and 'all'");
}
}
extended = ConfNodeLookupChildValue(conf, "verdict");
if (extended != NULL) {
if (ConfValIsTrue(extended)) {
drop_ctx->flags |= LOG_DROP_VERDICT;
}
}
}

drop_ctx->file_ctx = ajt->file_ctx;
Expand Down
7 changes: 7 additions & 0 deletions suricata.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,10 @@ outputs:
# Enable the logging of tagged packets for rules using the
# "tag" keyword.
tagged-packets: yes
# Enable logging the final action taken on a packet by the engine
# (e.g: the alert may have action 'allowed' but the verdict be
# 'drop' due to another alert. That's the engine's verdict)
# verdict: yes
- anomaly:
# Anomaly log records describe unexpected conditions such
# as truncated packets, packets with invalid IP/UDP/TCP
Expand Down Expand Up @@ -250,6 +254,9 @@ outputs:
# 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.
# Enable logging the final action taken on a packet by the engine
Copy link
Member

Choose a reason for hiding this comment

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

in the github review view this looks odd wrt formatting

# (will show more information in case of a drop caused by 'reject')
# verdict: yes
- smtp:
#extended: yes # enable this for extended logging information
# this includes: bcc, message-id, subject, x_mailer, user-agent
Expand Down
Loading