]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
doc/lua-detection: fix example script; remove most buffers
authorJason Ish <jason.ish@oisf.net>
Mon, 28 Jul 2025 22:23:41 +0000 (16:23 -0600)
committerJason Ish <jason.ish@oisf.net>
Fri, 1 Aug 2025 16:54:18 +0000 (10:54 -0600)
- Reference rule hooks instead

Ticket: #7728

doc/userguide/rules/lua-detection.rst

index 5f58e5b0658b65cec580f9ec440d1c364ff7a48f..633476b0a330aea6f643e821a2805bfafba47d77 100644 (file)
@@ -33,66 +33,37 @@ Init function
 .. code-block:: lua
 
   function init (args)
-      local needs = {}
-      needs["http.request_line"] = tostring(true)
-      return needs
+      return {}
   end
 
-The init function registers the buffer(s) that need
-inspection. Currently the following are available:
+Most Lua rule scripts can simply return an empty table in their init
+method. To hook into specific protocols states, :ref:`rule-hooks` may
+be used. However, some buffers do require explicit initialization::
 
-* packet -- entire packet, including headers
-* payload -- packet payload (not stream)
-* buffer -- the current sticky buffer
+* ja3
+* ja3s
+* packet
+* payload
 * stream
-* dnp3
-* ssh
-* smtp
-* tls
-* http.uri
-* http.uri.raw
-* http.request_line
-* http.request_headers
-* http.request_headers.raw
-* http.request_body
-* http.response_headers
-* http.response_headers.raw
-* http.response_body
-
-All the HTTP buffers have a limitation: only one can be inspected by a
-script at a time.
 
-Match function
-^^^^^^^^^^^^^^
+To request these buffers, use an ``init`` method like:
 
 .. code-block:: lua
 
-  function match(args)
-      a = tostring(args["http.request_line"])
-      if #a > 0 then
-          if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
-              return 1
-          end
-      end
-
-      return 0
+  function init (args)
+    return {packet = true}
   end
 
-The script can return 1 or 0. It should return 1 if the condition(s)
-it checks for match, 0 if not.
-
-Entire script:
+Match function
+^^^^^^^^^^^^^^
 
 .. code-block:: lua
 
-  function init (args)
-      local needs = {}
-      needs["http.request_line"] = tostring(true)
-      return needs
-  end
+  local http = require("suricata.http")
 
   function match(args)
-      a = tostring(args["http.request_line"])
+      local tx = http.get_tx()
+      a = tx:request_line()
       if #a > 0 then
           if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
               return 1
@@ -102,7 +73,8 @@ Entire script:
       return 0
   end
 
-  return 0
+The script can return 1 or 0. It should return 1 if the condition(s)
+it checks for match, 0 if not.
 
 Lua Transform: ``luaxform``
 ---------------------------