diff --git a/etc/schema.json b/etc/schema.json index 32510a6198fa..285ba3068759 100644 --- a/etc/schema.json +++ b/etc/schema.json @@ -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" }, @@ -5393,6 +5396,32 @@ "$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", + "oneOf": [ + { + "properties": { + "icmp-proihib": { + "type": "string" + }, + "tcp-reset": { + "type": "string" + } + } + } + ] + }, + "reject_target": { + "type": "string" + } + } } } } diff --git a/src/output-json-alert.c b/src/output-json-alert.c index b494d4d19568..95bd3ff4848c 100644 --- a/src/output-json-alert.c +++ b/src/output-json-alert.c @@ -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 | \ @@ -665,6 +666,56 @@ 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 GetVerdictJson(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", "source"); + } else if (PacketCheckAction(p, ACTION_REJECT_DST)) { + JB_SET_STRING(jb, "reject_target", "destination"); + } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) { + JB_SET_STRING(jb, "reject_target", "both"); + } + jb_open_array(jb, "reject"); + switch (p->proto) { + 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; @@ -828,6 +879,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) { + GetVerdictJson(jb, p); + } + OutputJsonBuilderBuffer(jb, aft->ctx); jb_free(jb); } @@ -1016,6 +1071,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", diff --git a/src/output-json-alert.h b/src/output-json-alert.h index 5aaa034953f1..dcf4921c442b 100644 --- a/src/output-json-alert.h +++ b/src/output-json-alert.h @@ -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 GetVerdictJson(JsonBuilder *jb, const Packet *p); #endif /* __OUTPUT_JSON_ALERT_H__ */ diff --git a/suricata.yaml.in b/suricata.yaml.in index af7ad5344b72..c926b4b1107e 100644 --- a/suricata.yaml.in +++ b/suricata.yaml.in @@ -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.