From: Sascha Steinbiss Date: Mon, 4 Mar 2024 18:22:16 +0000 (+0100) Subject: ja3: adjust and add tests X-Git-Tag: suricata-6.0.19~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d693d8672c10c2f01289d00b0e8c88f7889b0477;p=thirdparty%2Fsuricata-verify.git ja3: adjust and add tests --- diff --git a/tests/tls/tls-ja3s-requires-off/suricata.yaml b/tests/tls/tls-ja3s-requires-off/suricata.yaml new file mode 100644 index 000000000..282e8ae60 --- /dev/null +++ b/tests/tls/tls-ja3s-requires-off/suricata.yaml @@ -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 index 000000000..791afa779 --- /dev/null +++ b/tests/tls/tls-ja3s-requires-off/test-ja3s-hash.lua @@ -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 index 000000000..2ea8b0d80 --- /dev/null +++ b/tests/tls/tls-ja3s-requires-off/test-ja3s-string.lua @@ -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 index 000000000..87f4f5a63 --- /dev/null +++ b/tests/tls/tls-ja3s-requires-off/test.rules @@ -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 index 000000000..13baeddde --- /dev/null +++ b/tests/tls/tls-ja3s-requires-off/test.yaml @@ -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 index 000000000..c471b56cf --- /dev/null +++ b/tests/tls/tls-ja3s-requires/suricata.yaml @@ -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 index 000000000..791afa779 --- /dev/null +++ b/tests/tls/tls-ja3s-requires/test-ja3s-hash.lua @@ -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 index 000000000..2ea8b0d80 --- /dev/null +++ b/tests/tls/tls-ja3s-requires/test-ja3s-string.lua @@ -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 index 000000000..87f4f5a63 --- /dev/null +++ b/tests/tls/tls-ja3s-requires/test.rules @@ -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 index 000000000..f418b2aa5 --- /dev/null +++ b/tests/tls/tls-ja3s-requires/test.yaml @@ -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 diff --git a/tests/tls/tls-ja3s/test.yaml b/tests/tls/tls-ja3s/test.yaml index c7a9719db..e65e7122c 100644 --- a/tests/tls/tls-ja3s/test.yaml +++ b/tests/tls/tls-ja3s/test.yaml @@ -6,6 +6,7 @@ requires: - HAVE_LIBJANSSON - HAVE_NSS - HAVE_LUA + - HAVE_JA3 args: - -k none