]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
eve/alert: add support for logging frame
authorVictor Julien <vjulien@oisf.net>
Fri, 3 Dec 2021 06:47:29 +0000 (07:47 +0100)
committerVictor Julien <vjulien@oisf.net>
Tue, 18 Jan 2022 11:21:50 +0000 (12:21 +0100)
If detection was done in a frame, the frame will be added to the
eve.alert output.

src/decode.h
src/detect-engine-alert.c
src/detect.h
src/output-json-alert.c

index 0673a66b81fdaadf54bd27c7289859aea47a7085..9ac8ca1b6dc61171dce8f25b30aa00aafea0376c 100644 (file)
@@ -283,6 +283,7 @@ typedef struct PacketAlert_ {
     uint8_t flags;
     const struct Signature_ *s;
     uint64_t tx_id;
+    int64_t frame_id;
 } PacketAlert;
 
 /* flag to indicate the rule action (drop/pass) needs to be applied to the flow */
@@ -295,6 +296,8 @@ typedef struct PacketAlert_ {
 #define PACKET_ALERT_FLAG_TX            0x08
 /** action was changed by rate_filter */
 #define PACKET_ALERT_RATE_FILTER_MODIFIED   0x10
+/** alert is in a frame, frame_id set */
+#define PACKET_ALERT_FLAG_FRAME 0x20
 
 #define PACKET_ALERT_MAX 15
 
index cdfcb527ada7f1838678874fc6931a5407543dcd..ff72724fcae28fedb050198f9865e61785ddf4fb 100644 (file)
@@ -204,6 +204,8 @@ int PacketAlertAppend(DetectEngineThreadCtx *det_ctx, const Signature *s,
         p->alerts.alerts[p->alerts.cnt].flags = flags;
         p->alerts.alerts[p->alerts.cnt].s = s;
         p->alerts.alerts[p->alerts.cnt].tx_id = tx_id;
+        p->alerts.alerts[p->alerts.cnt].frame_id =
+                (flags & PACKET_ALERT_FLAG_FRAME) ? det_ctx->frame_id : 0;
     } else {
         /* We need to make room for this s->num
          (a bit ugly with memcpy but we are planning changes here)*/
@@ -218,6 +220,7 @@ int PacketAlertAppend(DetectEngineThreadCtx *det_ctx, const Signature *s,
         p->alerts.alerts[i].flags = flags;
         p->alerts.alerts[i].s = s;
         p->alerts.alerts[i].tx_id = tx_id;
+        p->alerts.alerts[i].frame_id = (flags & PACKET_ALERT_FLAG_FRAME) ? det_ctx->frame_id : 0;
     }
 
     /* Update the count */
index b85c65adaad1e952666cf0fdf32f79f6d26134d8..3a3758a35d4abbdea0c31fa98858e79bfa632901 100644 (file)
@@ -1071,12 +1071,13 @@ typedef struct DetectEngineThreadCtx_ {
 
     /* used to discontinue any more matching */
     uint16_t discontinue_matching;
-    uint16_t flags;
+    uint16_t flags; /**< DETECT_ENGINE_THREAD_CTX_* flags */
 
     /* true if tx_id is set */
     bool tx_id_set;
     /** ID of the transaction currently being inspected. */
     uint64_t tx_id;
+    int64_t frame_id;
     Packet *p;
 
     SC_ATOMIC_DECLARE(int, so_far_used_by_detect);
index bd4957f1e4fa59e4d8d8c1721e69720d6f98db95..dac4e3ff27380c3374c50d8cedc3cb1c2a1720a9 100644 (file)
@@ -50,6 +50,7 @@
 #include "app-layer-htp.h"
 #include "app-layer-htp-xff.h"
 #include "app-layer-ftp.h"
+#include "app-layer-frames.h"
 #include "util-classification-config.h"
 #include "util-syslog.h"
 #include "util-logopenfile.h"
@@ -73,6 +74,7 @@
 #include "output-json-mqtt.h"
 #include "output-json-ike.h"
 #include "output-json-modbus.h"
+#include "output-json-frame.h"
 
 #include "util-byte.h"
 #include "util-privs.h"
@@ -581,6 +583,32 @@ static void AlertAddFiles(const Packet *p, JsonBuilder *jb, const uint64_t tx_id
     }
 }
 
+static void AlertAddFrame(const Packet *p, JsonBuilder *jb, const int64_t frame_id)
+{
+    if (p->flow == NULL || p->flow->protoctx == NULL)
+        return;
+
+    FramesContainer *frames_container = AppLayerFramesGetContainer(p->flow);
+    if (frames_container == NULL)
+        return;
+
+    Frames *frames;
+    TcpSession *ssn = p->flow->protoctx;
+    TcpStream *stream;
+    if (PKT_IS_TOSERVER(p)) {
+        stream = &ssn->client;
+        frames = &frames_container->toserver;
+    } else {
+        stream = &ssn->server;
+        frames = &frames_container->toclient;
+    }
+
+    Frame *frame = FrameGetById(frames, frame_id);
+    if (frame != NULL) {
+        FrameJsonLogOneFrame(frame, p->flow, stream, p, jb);
+    }
+}
+
 static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
 {
     MemBuffer *payload = aft->payload_buffer;
@@ -704,6 +732,10 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
             jb_set_uint(jb, "stream", stream);
         }
 
+        if (pa->flags & PACKET_ALERT_FLAG_FRAME) {
+            AlertAddFrame(p, jb, pa->frame_id);
+        }
+
         /* base64-encoded full packet */
         if (json_output_ctx->flags & LOG_JSON_PACKET) {
             EvePacket(p, jb, 0);