]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
output-json-alert: output source and target
authorEric Leblond <eric@regit.org>
Sat, 17 Dec 2016 09:40:11 +0000 (10:40 +0100)
committerVictor Julien <victor@inliniac.net>
Mon, 12 Jun 2017 17:21:52 +0000 (19:21 +0200)
Use metadata provided information to output the Source and Target
in the definition of IDMEF.

The output is now the following:

  "alert": {
    "action": "allowed",
    "gid": 1,
    "signature_id": 1,
    "rev": 1,
    "signature": "connection to home",
    "category": "",
    "severity": 3,
    "source": {
      "ip": "2001:31d0:000a:f68a:0000:0000:0000:0001",
      "port": 80
    },
    "target": {
      "ip": "2a01:0e34:ee97:b130:c685:08ff:dab3:c9c8",
      "port": 48390
    }

src/output-json-alert.c

index 2a5a752e41bc921c1c44e9593a4509ae817c78de..7526c96029ee1cb4fb7d18d72c22b18c36c9b97b 100644 (file)
@@ -174,6 +174,54 @@ static void AlertJsonDnp3(const Flow *f, json_t *js)
     return;
 }
 
+static void AlertJsonSourceTarget(const Packet *p, const PacketAlert *pa,
+                                  json_t *js, json_t* ajs)
+{
+    json_t *sjs = json_object();
+    if (sjs == NULL) {
+        return;
+    }
+
+    json_t *tjs = json_object();
+    if (tjs == NULL) {
+        json_decref(sjs);
+        return;
+    }
+
+    if (pa->s->flags & SIG_FLAG_DEST_IS_TARGET) {
+        json_object_set(sjs, "ip", json_object_get(js, "src_ip"));
+        json_object_set(tjs, "ip", json_object_get(js, "dest_ip"));
+        switch (p->proto) {
+            case IPPROTO_ICMP:
+            case IPPROTO_ICMPV6:
+                break;
+            case IPPROTO_UDP:
+            case IPPROTO_TCP:
+            case IPPROTO_SCTP:
+                json_object_set(sjs, "port", json_object_get(js, "src_port"));
+                json_object_set(tjs, "port", json_object_get(js, "dest_port"));
+                break;
+        }
+    } else if (pa->s->flags & SIG_FLAG_SRC_IS_TARGET) {
+        json_object_set(sjs, "ip", json_object_get(js, "dest_ip"));
+        json_object_set(tjs, "ip", json_object_get(js, "src_ip"));
+        switch (p->proto) {
+            case IPPROTO_ICMP:
+            case IPPROTO_ICMPV6:
+                break;
+            case IPPROTO_UDP:
+            case IPPROTO_TCP:
+            case IPPROTO_SCTP:
+                json_object_set(sjs, "port", json_object_get(js, "dest_port"));
+                json_object_set(tjs, "port", json_object_get(js, "src_port"));
+                break;
+        }
+    }
+    json_object_set_new(ajs, "source", sjs);
+    json_object_set_new(ajs, "target", tjs);
+}
+
+
 void AlertJsonHeader(const Packet *p, const PacketAlert *pa, json_t *js)
 {
     const char *action = "allowed";
@@ -215,6 +263,10 @@ void AlertJsonHeader(const Packet *p, const PacketAlert *pa, json_t *js)
     if (p->tenant_id > 0)
         json_object_set_new(ajs, "tenant_id", json_integer(p->tenant_id));
 
+    if (pa->s->flags & SIG_FLAG_HAS_TARGET) {
+        AlertJsonSourceTarget(p, pa, js, ajs);
+    }
+
     /* alert */
     json_object_set_new(js, "alert", ajs);
 }