Skip to content

Commit 4aa7200

Browse files
committed
doc/lua-detection: fix example script; remove most buffers
- Reference rule hooks instead Ticket: OISF#7728
1 parent 9513fca commit 4aa7200

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
@@ -33,66 +33,37 @@ Init function
3333
.. code-block:: lua
3434
3535
function init (args)
36-
local needs = {}
37-
needs["http.request_line"] = tostring(true)
38-
return needs
36+
return {}
3937
end
4038
41-
The init function registers the buffer(s) that need
42-
inspection. Currently the following are available:
39+
Most Lua rule scripts can simply return an empty table in their init
40+
method. To hook into specific protocols states, :ref:`rule-hooks` may
41+
be used. However, some buffers do require explicit initialization::
4342

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

65-
Match function
66-
^^^^^^^^^^^^^^
49+
To request these buffers, use an ``init`` method like:
6750

6851
.. code-block:: lua
6952
70-
function match(args)
71-
a = tostring(args["http.request_line"])
72-
if #a > 0 then
73-
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
74-
return 1
75-
end
76-
end
77-
78-
return 0
53+
function init (args)
54+
return {packet = true}
7955
end
8056
81-
The script can return 1 or 0. It should return 1 if the condition(s)
82-
it checks for match, 0 if not.
83-
84-
Entire script:
57+
Match function
58+
^^^^^^^^^^^^^^
8559

8660
.. code-block:: lua
8761
88-
function init (args)
89-
local needs = {}
90-
needs["http.request_line"] = tostring(true)
91-
return needs
92-
end
62+
local http = require("suricata.http")
9363
9464
function match(args)
95-
a = tostring(args["http.request_line"])
65+
local tx = http.get_tx()
66+
a = tx:request_line()
9667
if #a > 0 then
9768
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
9869
return 1
@@ -102,7 +73,8 @@ Entire script:
10273
return 0
10374
end
10475
105-
return 0
76+
The script can return 1 or 0. It should return 1 if the condition(s)
77+
it checks for match, 0 if not.
10678

10779
Lua Transform: ``luaxform``
10880
---------------------------

0 commit comments

Comments
 (0)