]> git.ipfire.org Git - thirdparty/suricata-verify.git/commitdiff
tests: add dnp3 lua state 2374/head
authorJason Ish <jason.ish@oisf.net>
Thu, 27 Mar 2025 17:20:05 +0000 (11:20 -0600)
committerJason Ish <jason.ish@oisf.net>
Thu, 27 Mar 2025 17:20:05 +0000 (11:20 -0600)
This is very minimal, should be expanded on.

Ticket: #7601

tests/dnp3/dnp3-lua/README.md [new file with mode: 0644]
tests/dnp3/dnp3-lua/rule.lua [new file with mode: 0644]
tests/dnp3/dnp3-lua/suricata.yaml [new file with mode: 0644]
tests/dnp3/dnp3-lua/test.rules [new file with mode: 0644]
tests/dnp3/dnp3-lua/test.yaml [new file with mode: 0644]

diff --git a/tests/dnp3/dnp3-lua/README.md b/tests/dnp3/dnp3-lua/README.md
new file mode 100644 (file)
index 0000000..4d3199a
--- /dev/null
@@ -0,0 +1,8 @@
+# Description
+
+Test dnp3_func rule keyword.
+
+# PCAP
+
+The pcap comes from running the master-demo and outstation-demo from
+the OpenDNP3 project.
diff --git a/tests/dnp3/dnp3-lua/rule.lua b/tests/dnp3/dnp3-lua/rule.lua
new file mode 100644 (file)
index 0000000..7569cfe
--- /dev/null
@@ -0,0 +1,31 @@
+local dnp3 = require("suricata.dnp3")
+
+function init (args)
+   return {dnp3 = true}
+end
+
+function match(args)
+   -- No args for DNP3.
+   
+   -- Get transaction.
+   local tx = dnp3.get_tx()
+
+   if not tx["is_request"] then
+      return 0
+   end
+
+   local request = tx["request"]
+   if request == nil then
+      return 0
+   end
+
+   if not request["done"] then
+      return 0
+   end
+
+   if not request["complete"] then
+      return 0
+   end
+
+   return 1
+end
diff --git a/tests/dnp3/dnp3-lua/suricata.yaml b/tests/dnp3/dnp3-lua/suricata.yaml
new file mode 100644 (file)
index 0000000..83b7626
--- /dev/null
@@ -0,0 +1,18 @@
+%YAML 1.1
+---
+
+outputs:
+  - eve-log:
+      enabled: yes
+      filetype: regular
+      filename: eve.json
+      types:
+        - alert:
+        - dnp3:
+
+app-layer:
+  protocols:
+    dnp3:
+      enabled: yes
+      detection-ports:
+        dp: 20000
diff --git a/tests/dnp3/dnp3-lua/test.rules b/tests/dnp3/dnp3-lua/test.rules
new file mode 100644 (file)
index 0000000..77b2c45
--- /dev/null
@@ -0,0 +1 @@
+alert dnp3 any any -> any any (msg:"LUA"; dnp3_func:21; lua:rule.lua; sid:4; rev:1;)
diff --git a/tests/dnp3/dnp3-lua/test.yaml b/tests/dnp3/dnp3-lua/test.yaml
new file mode 100644 (file)
index 0000000..024dd7d
--- /dev/null
@@ -0,0 +1,13 @@
+requires:
+  min-version: 8
+
+args:
+  - --set security.lua.allow-rules=true
+
+pcap: ../dnp3-eve/input.pcap
+
+checks:
+  - filter:
+      count: 1
+      match:
+        alert.signature_id: 4