Skip to content

Commit

Permalink
output/alert: add verdict field
Browse files Browse the repository at this point in the history
Related to
Bug OISF#5464
  • Loading branch information
jufajardini authored and victorjulien committed Jul 13, 2023
1 parent d9c430d commit 53b8def
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
37 changes: 37 additions & 0 deletions etc/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@
"type": "string",
"pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d+[+\\-]\\d+$"
},
"verdict": {
"$ref": "#/$defs/verdict_type"
},
"direction": {
"type": "string"
},
Expand Down Expand Up @@ -5393,6 +5396,40 @@
"$comment": "Definition for TLS date formats",
"type": "string",
"pattern": "^[1-2]\\d{3}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}$"
},
"verdict_type": {
"type": "object",
"properties": {
"action": {
"type": "string"
},
"reject": {
"type": "array",
"items": {
"type": "string",
"oneOf": [
{
"enum": [
"icmp-prohib",
"tcp-reset"
]
}
]
}
},
"reject-target": {
"type": "string",
"oneOf": [
{
"enum": [
"to_client",
"to_server",
"both"
]
}
]
}
}
}
}
}
57 changes: 57 additions & 0 deletions src/output-json-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,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 @@ -665,6 +666,57 @@ static void AlertAddFrame(const Packet *p, JsonBuilder *jb, const int64_t frame_
}
}

/**
* \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 @@ -828,6 +880,10 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
jb_set_string(jb, "capture_file", pcap_filename);
}

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

OutputJsonBuilderBuffer(jb, aft->ctx);
jb_free(jb);
}
Expand Down Expand Up @@ -1016,6 +1072,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 flags and warn that they have no effect. */
static const char *deprecated_flags[] = { "http", "tls", "ssh", "smtp", "dnp3", "app-layer",
Expand Down
1 change: 1 addition & 0 deletions src/output-json-alert.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
void JsonAlertLogRegister(void);
void AlertJsonHeader(void *ctx, const Packet *p, const PacketAlert *pa, JsonBuilder *js,
uint16_t flags, JsonAddrInfo *addr, char *xff_buffer);
void EveAddVerdict(JsonBuilder *jb, const Packet *p);

#endif /* __OUTPUT_JSON_ALERT_H__ */

4 changes: 4 additions & 0 deletions suricata.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,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
# app layer frames
- frame:
# disabled by default as this is very verbose.
Expand Down

0 comments on commit 53b8def

Please sign in to comment.