You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- cleanup usage and documentation around needs
- mentiond that rule hooks are used instead of "needs" keywords with
link with rule hooks (which is still in the firewall-design doc)
Copy file name to clipboardExpand all lines: doc/userguide/lua/lua-functions.rst
+48-16Lines changed: 48 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,32 +6,41 @@ Lua functions
6
6
Differences between `output` and `detect`:
7
7
------------------------------------------
8
8
9
-
Currently, the ``needs`` key initialization varies, depending on what is the goal of the script: output or detection.
10
-
The Lua script for the ``luaxform`` transform **does not use ``needs``**.
9
+
Currently the ``table`` returned from the ``init`` method varies,
10
+
depending on if the script is an output script or a detection script.
11
11
12
-
If the script is for detection, the ``needs`` initialization should be as seen in the example below (see :ref:`lua-detection` for a complete example of a detection script):
12
+
Lua scripts for ``luaxform`` do not require an ``init`` method.
13
13
14
-
::
14
+
If the script is for detection, the ``init`` method should return a
15
+
table, for example, if a packet is required:
16
+
17
+
.. code-block:: lua
15
18
16
19
function init (args)
17
-
local needs = {}
18
-
needs["packet"] = tostring(true)
19
-
return needs
20
+
local needs = {}
21
+
needs["packet"] = true
22
+
return needs
20
23
end
21
24
22
-
For output logs, follow the pattern below. (The complete script structure can be seen at :ref:`lua-output`:)
25
+
See :ref:`lua-detection` for more detection script examples.
23
26
24
-
::
27
+
For output scripts, follow the pattern below. (The complete script
28
+
structure can be seen at :ref:`lua-output`:)
29
+
30
+
.. code-block:: lua
25
31
26
32
function init (args)
27
33
local needs = {}
28
34
needs["protocol"] = "tls"
29
35
return needs
30
36
end
31
37
38
+
Do notice that the functions and protocols available for ``log`` and
39
+
``match`` may also vary. DNP3, for instance, is not available for
40
+
logging.
32
41
33
-
Do notice that the functions and protocols available for ``log`` and ``match`` may also vary. DNP3, for instance, is not
34
-
available for logging.
42
+
.. note:: By convention, many scripts use a variable name of ``needs``
43
+
for this table, however this is not a hard requirement.
35
44
36
45
packet
37
46
------
@@ -71,16 +80,39 @@ For output, init with:
71
80
return needs
72
81
end
73
82
74
-
For detection, use the specific buffer (cf :ref:`lua-detection` for a complete list), as with:
83
+
For detection, rule hooks are used are execute the Lua script at
84
+
specific protocol states, for example::
75
85
76
-
::
86
+
alert http1:request_line any any -> any any (
87
+
msg: "Test HTTP Lua request.line";
88
+
lua: test-request-line.lua; sid:1;)
89
+
90
+
where ``test-request-line.lua`` might look like:
91
+
92
+
.. code-block:: lua
93
+
94
+
local http = require("suricata.http")
77
95
78
96
function init (args)
79
-
local needs = {}
80
-
needs["http.uri"] = tostring(true)
81
-
return needs
97
+
return {}
98
+
end
99
+
100
+
function match(args)
101
+
local tx, err = http.get_tx()
102
+
http_request_line, err = tx:request_line()
103
+
104
+
if #http_request_line > 0 then
105
+
--GET /base64-hello-world.txt HTTP/1.1
106
+
if http_request_line:find("^GET") then
107
+
return 1
108
+
end
109
+
end
110
+
111
+
return 0
82
112
end
83
113
114
+
For more information on rule hooks, see :ref:`rule-hooks`.
0 commit comments