]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
ja3: adjust and add tests
authorSascha Steinbiss <satta@debian.org>
Mon, 4 Mar 2024 18:22:16 +0000 (19:22 +0100)
committerVictor Julien <victor@inliniac.net>
Tue, 16 Apr 2024 06:00:38 +0000 (08:00 +0200)
tests/tls/tls-ja3s-requires-off/suricata.yaml [new file with mode: 0644]
tests/tls/tls-ja3s-requires-off/test-ja3s-hash.lua [new file with mode: 0644]
tests/tls/tls-ja3s-requires-off/test-ja3s-string.lua [new file with mode: 0644]
tests/tls/tls-ja3s-requires-off/test.rules [new file with mode: 0644]
tests/tls/tls-ja3s-requires-off/test.yaml [new file with mode: 0644]
tests/tls/tls-ja3s-requires/suricata.yaml [new file with mode: 0644]
tests/tls/tls-ja3s-requires/test-ja3s-hash.lua [new file with mode: 0644]
tests/tls/tls-ja3s-requires/test-ja3s-string.lua [new file with mode: 0644]
tests/tls/tls-ja3s-requires/test.rules [new file with mode: 0644]
tests/tls/tls-ja3s-requires/test.yaml [new file with mode: 0644]
tests/tls/tls-ja3s/test.yaml

diff --git a/tests/tls/tls-ja3s-requires-off/suricata.yaml b/tests/tls/tls-ja3s-requires-off/suricata.yaml
new file mode 100644 (file)
index 0000000..282e8ae
--- /dev/null
@@ -0,0 +1,26 @@
+%YAML 1.1
+---
+
+outputs:
+  - eve-log:
+      enabled: yes
+      filetype: regular #regular|syslog|unix_dgram|unix_stream|redis
+      filename: eve.json
+      types:
+        - alert:
+            payload: no
+            payload-buffer-size: 4kb
+            payload-printable: no
+            packet: no
+            metadata: no
+        - tls:
+            extended: yes
+
+app-layer:
+  protocols:
+    tls:
+      enabled: yes
+      detection-ports:
+        dp: 443
+
+      ja3-fingerprints: yes
diff --git a/tests/tls/tls-ja3s-requires-off/test-ja3s-hash.lua b/tests/tls/tls-ja3s-requires-off/test-ja3s-hash.lua
new file mode 100644 (file)
index 0000000..791afa7
--- /dev/null
@@ -0,0 +1,18 @@
+function init(args)
+    local needs = {}
+    needs["tls"] = tostring(true)
+    return needs
+end
+
+function match(args)
+    hash = Ja3SGetHash()
+    if hash == nil then
+        return 0
+    end
+
+    if hash == "5d79edf64e03689ff559a54e9d9487bc" then
+        return 1
+    end
+
+    return 0
+end
diff --git a/tests/tls/tls-ja3s-requires-off/test-ja3s-string.lua b/tests/tls/tls-ja3s-requires-off/test-ja3s-string.lua
new file mode 100644 (file)
index 0000000..2ea8b0d
--- /dev/null
@@ -0,0 +1,18 @@
+function init(args)
+    local needs = {}
+    needs["tls"] = tostring(true)
+    return needs
+end
+
+function match(args)
+    str = Ja3SGetString()
+    if str == nil then
+        return 0
+    end
+
+    if str == "771,49199,65281-0-11-16-23" then
+        return 1
+    end
+
+    return 0
+end
diff --git a/tests/tls/tls-ja3s-requires-off/test.rules b/tests/tls/tls-ja3s-requires-off/test.rules
new file mode 100644 (file)
index 0000000..87f4f5a
--- /dev/null
@@ -0,0 +1,4 @@
+alert tls any any -> any any (msg:"ja3s.hash test"; requires: feature ja3; flow:established,to_client; ja3s.hash; content:"5d79edf64e03689ff559a54e9d9487bc"; sid:1;)
+alert tls any any -> any any (msg:"ja3s.string test"; requires: feature ja3; flow:established,to_client; ja3s.string; content:"771,49199,65281-0-11-16-23"; sid:2;)
+alert tls any any -> any any (msg:"ja3s.hash Lua test"; requires: feature ja3; flow:established,to_client; lua:test-ja3s-hash.lua; sid:3;)
+alert tls any any -> any any (msg:"ja3s.string Lua test"; requires: feature ja3; flow:established,to_client; lua:test-ja3s-string.lua; sid:4;)
diff --git a/tests/tls/tls-ja3s-requires-off/test.yaml b/tests/tls/tls-ja3s-requires-off/test.yaml
new file mode 100644 (file)
index 0000000..13baedd
--- /dev/null
@@ -0,0 +1,21 @@
+pcap: ../../tls/tls-certs-alert/input.pcap
+
+requires:
+  min-version: 7.0.3
+  features:
+    - HAVE_LUA
+  script:
+    - ./src/suricata --build-info | grep "JA3 support" | grep no > /dev/null
+
+args:
+ - -k none
+ - --set security.lua.allow-rules=true
+
+checks:
+  - filter:
+      count: 0
+      match:
+        event_type: alert
+  - shell:
+      args: "grep -c 'missing a required feature: feature ja3' stdout"
+      expect: 4
diff --git a/tests/tls/tls-ja3s-requires/suricata.yaml b/tests/tls/tls-ja3s-requires/suricata.yaml
new file mode 100644 (file)
index 0000000..c471b56
--- /dev/null
@@ -0,0 +1,25 @@
+%YAML 1.1
+---
+
+outputs:
+  - eve-log:
+      enabled: yes
+      filetype: regular #regular|syslog|unix_dgram|unix_stream|redis
+      filename: eve.json
+      types:
+        - alert:
+            payload: no
+            payload-buffer-size: 4kb
+            payload-printable: no
+            packet: no
+            metadata: no
+        - tls:
+            extended: yes
+
+app-layer:
+  protocols:
+    tls:
+      enabled: yes
+      detection-ports:
+        dp: 443
+      ja3-fingerprints: no
diff --git a/tests/tls/tls-ja3s-requires/test-ja3s-hash.lua b/tests/tls/tls-ja3s-requires/test-ja3s-hash.lua
new file mode 100644 (file)
index 0000000..791afa7
--- /dev/null
@@ -0,0 +1,18 @@
+function init(args)
+    local needs = {}
+    needs["tls"] = tostring(true)
+    return needs
+end
+
+function match(args)
+    hash = Ja3SGetHash()
+    if hash == nil then
+        return 0
+    end
+
+    if hash == "5d79edf64e03689ff559a54e9d9487bc" then
+        return 1
+    end
+
+    return 0
+end
diff --git a/tests/tls/tls-ja3s-requires/test-ja3s-string.lua b/tests/tls/tls-ja3s-requires/test-ja3s-string.lua
new file mode 100644 (file)
index 0000000..2ea8b0d
--- /dev/null
@@ -0,0 +1,18 @@
+function init(args)
+    local needs = {}
+    needs["tls"] = tostring(true)
+    return needs
+end
+
+function match(args)
+    str = Ja3SGetString()
+    if str == nil then
+        return 0
+    end
+
+    if str == "771,49199,65281-0-11-16-23" then
+        return 1
+    end
+
+    return 0
+end
diff --git a/tests/tls/tls-ja3s-requires/test.rules b/tests/tls/tls-ja3s-requires/test.rules
new file mode 100644 (file)
index 0000000..87f4f5a
--- /dev/null
@@ -0,0 +1,4 @@
+alert tls any any -> any any (msg:"ja3s.hash test"; requires: feature ja3; flow:established,to_client; ja3s.hash; content:"5d79edf64e03689ff559a54e9d9487bc"; sid:1;)
+alert tls any any -> any any (msg:"ja3s.string test"; requires: feature ja3; flow:established,to_client; ja3s.string; content:"771,49199,65281-0-11-16-23"; sid:2;)
+alert tls any any -> any any (msg:"ja3s.hash Lua test"; requires: feature ja3; flow:established,to_client; lua:test-ja3s-hash.lua; sid:3;)
+alert tls any any -> any any (msg:"ja3s.string Lua test"; requires: feature ja3; flow:established,to_client; lua:test-ja3s-string.lua; sid:4;)
diff --git a/tests/tls/tls-ja3s-requires/test.yaml b/tests/tls/tls-ja3s-requires/test.yaml
new file mode 100644 (file)
index 0000000..f418b2a
--- /dev/null
@@ -0,0 +1,22 @@
+pcap: ../../tls/tls-certs-alert/input.pcap
+
+requires:
+  min-version: 7.0.3
+  features:
+    - HAVE_LUA
+    - HAVE_JA3
+  script:
+    - grep 'ProvidesFeature(FEATURE_JA3);' src/app-layer-ssl.c > /dev/null
+
+args:
+ - -k none
+ - --set security.lua.allow-rules=true
+
+checks:
+  - filter:
+      count: 0
+      match:
+        event_type: alert
+  - shell:
+      args: "grep -c 'missing a required feature: feature ja3' stdout"
+      expect: 4
index c7a9719db26514452007b6ac3774453cceefbd69..e65e7122c24c6328c05e2c2bf3bb823ba1ad9133 100644 (file)
@@ -6,6 +6,7 @@ requires:
     - HAVE_LIBJANSSON
     - HAVE_NSS
     - HAVE_LUA
+    - HAVE_JA3
 
 args:
  - -k none