]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
eve-metadata: eve metadata test
authorJason Ish <ish@unx.ca>
Wed, 24 Jan 2018 22:49:56 +0000 (16:49 -0600)
committerJason Ish <ish@unx.ca>
Wed, 24 Jan 2018 22:49:56 +0000 (16:49 -0600)
tests/eve-metadata/check.sh [new file with mode: 0755]
tests/eve-metadata/suricata.yaml [new file with mode: 0644]
tests/eve-metadata/test.rules [new file with mode: 0644]
tests/eve-metadata/test.yaml [new file with mode: 0644]
tests/eve-metadata/testmyids.pcap [new file with mode: 0644]

diff --git a/tests/eve-metadata/check.sh b/tests/eve-metadata/check.sh
new file mode 100755 (executable)
index 0000000..32df158
--- /dev/null
@@ -0,0 +1,19 @@
+#! /bin/sh
+
+# Test the flow record metadata.
+test $(cat ./eve.json | \
+    jq -c 'select(.event_type == "flow")' | \
+    jq -c .metadata.flowbits[0]) == \"traffic/label/cli-http\"
+
+# Test the alert record metadata.
+test $(cat ./eve.json | \
+    jq -c 'select(.event_type == "alert")' | \
+    jq -c .metadata.flowbits[0]) == \"traffic/label/cli-http\"
+
+# Test the netflow records. We should have 2 of those, so do a line
+# count on netflow records with the required flowbit.
+test $(cat ./eve.json | \
+    jq -c 'select(.event_type == "netflow")' | \
+    jq -c 'select(.metadata.flowbits[0] == "traffic/label/cli-http")' |\
+    wc -l | xargs) -eq 2
+
diff --git a/tests/eve-metadata/suricata.yaml b/tests/eve-metadata/suricata.yaml
new file mode 100644 (file)
index 0000000..cc0fcad
--- /dev/null
@@ -0,0 +1,35 @@
+%YAML 1.1
+---
+
+include: ../../etc/suricata-4.0.3.yaml
+
+# Configure the type of alert (and other) logging you would like.
+outputs:
+  - eve-log:
+      enabled: yes
+      filetype: regular
+      filename: eve.json
+
+      # Enable to disable top-level metadata logging. Default: yes.
+      #metadata: no
+
+      types:
+        - alert
+        - http:
+            extended: yes
+        - dns:
+            query: yes     # enable logging of DNS queries
+            answer: yes    # enable logging of DNS answers
+        - tls:
+            extended: yes     # enable this for extended logging information
+        - files:
+            force-magic: no   # force logging magic on all logged files
+        - smtp:
+        - ssh
+        - stats:
+            totals: yes       # stats for all threads merged together
+            threads: no       # per thread stats
+            deltas: no        # include delta values
+        - flow
+        - netflow
+        - metadata
diff --git a/tests/eve-metadata/test.rules b/tests/eve-metadata/test.rules
new file mode 100644 (file)
index 0000000..7af6749
--- /dev/null
@@ -0,0 +1,9 @@
+# Silly rule to set the flowbit "traffic/label/cli-http" on
+# the curl user-agent.
+alert http any any -> any any (content:"curl"; http_user_agent; flowbits:set,traffic/label/cli-http; sid:1; rev:1;)
+
+# Capture the UID as a pktvar.
+alert http any any -> any any (pcre:"/uid=(\d+)/, pkt:uid";  noalert; sid:2; rev:1;)
+
+# Capture the GID as a flowvar.
+alert http any any -> any any (pcre:"/gid=(\d+)/, flow:gid"; noalert; sid:3; rev:1;)
diff --git a/tests/eve-metadata/test.yaml b/tests/eve-metadata/test.yaml
new file mode 100644 (file)
index 0000000..fdf622a
--- /dev/null
@@ -0,0 +1,34 @@
+requires:
+
+  # Require that we have metadata support, checked by looking for a
+  # function.
+  script:
+    - grep JsonAddMetadata src/output-json.h > /dev/null
+
+checks:
+
+  - filter:
+      count: 1
+      match:
+        event_type: flow
+        metadata.flowbits[0]: traffic/label/cli-http
+        metadata.flowvars.gid: "0"
+
+  - filter:
+      count: 1
+      match:
+        event_type: alert
+        metadata.flowbits[0]: traffic/label/cli-http
+
+  - filter:
+      count: 2
+      match:
+        event_type: netflow
+        metadata.flowbits[0]: traffic/label/cli-http
+        
+  - filter:
+      count: 1
+      match:
+        event_type: metadata
+        metadata.pktvars[0].uid: "0"
+        metadata.flowvars.gid: "0"
diff --git a/tests/eve-metadata/testmyids.pcap b/tests/eve-metadata/testmyids.pcap
new file mode 100644 (file)
index 0000000..868c57e
Binary files /dev/null and b/tests/eve-metadata/testmyids.pcap differ