Skip to content

Commit 3cbddc5

Browse files
committed
doc/lua-detection: fix example script; remove most buffers
- Reference rule hooks instead Ticket: OISF#7728
1 parent 97be33b commit 3cbddc5

1 file changed

Lines changed: 18 additions & 46 deletions

File tree

doc/userguide/rules/lua-detection.rst

Lines changed: 18 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -30,66 +30,37 @@ Init function
3030
.. code-block:: lua
3131
3232
function init (args)
33-
local needs = {}
34-
needs["http.request_line"] = tostring(true)
35-
return needs
33+
return {}
3634
end
3735
38-
The init function registers the buffer(s) that need
39-
inspection. Currently the following are available:
36+
Most Lua rule scripts can simply return an empty table in their init
37+
method. To hook into specific protocols states, :ref:`rule-hooks` may
38+
be used. However, some buffers do require explicit initialization::
4039

41-
* packet -- entire packet, including headers
42-
* payload -- packet payload (not stream)
43-
* buffer -- the current sticky buffer
40+
* ja3
41+
* ja3s
42+
* packet
43+
* payload
4444
* stream
45-
* dnp3
46-
* ssh
47-
* smtp
48-
* tls
49-
* http.uri
50-
* http.uri.raw
51-
* http.request_line
52-
* http.request_headers
53-
* http.request_headers.raw
54-
* http.request_body
55-
* http.response_headers
56-
* http.response_headers.raw
57-
* http.response_body
58-
59-
All the HTTP buffers have a limitation: only one can be inspected by a
60-
script at a time.
6145

62-
Match function
63-
^^^^^^^^^^^^^^
46+
To request these buffers, use an ``init`` method like:
6447

6548
.. code-block:: lua
6649
67-
function match(args)
68-
a = tostring(args["http.request_line"])
69-
if #a > 0 then
70-
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
71-
return 1
72-
end
73-
end
74-
75-
return 0
50+
function init (args)
51+
return {packet = true}
7652
end
7753
78-
The script can return 1 or 0. It should return 1 if the condition(s)
79-
it checks for match, 0 if not.
80-
81-
Entire script:
54+
Match function
55+
^^^^^^^^^^^^^^
8256

8357
.. code-block:: lua
8458
85-
function init (args)
86-
local needs = {}
87-
needs["http.request_line"] = tostring(true)
88-
return needs
89-
end
59+
local http = require("suricata.http")
9060
9161
function match(args)
92-
a = tostring(args["http.request_line"])
62+
local tx = http:get_tx()
63+
a = tx:request_line()
9364
if #a > 0 then
9465
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
9566
return 1
@@ -99,7 +70,8 @@ Entire script:
9970
return 0
10071
end
10172
102-
return 0
73+
The script can return 1 or 0. It should return 1 if the condition(s)
74+
it checks for match, 0 if not.
10375

10476
Lua Transform: ``luaxform``
10577
---------------------------

0 commit comments

Comments
 (0)