The differences on how the `need` key works, depending on script
usage (output or detection) confuses users, sometimes (cf doc#4725).
While we don't fix that, just explain this behavior.
pull/6642/head
Juliana Fajardini4 years agocommitted byVictor Julien
Currently, the ``needs`` key initialization varies, depending on what is the goal of the script: output or detection.
If the script is for detection, the ``needs`` initialization should be as seen in the example below (see :ref:`lua-scripting` for a complete example for a detect script):
::
function init (args)
local needs = {}
needs["packet"] = tostring(true)
return needs
end
For output logs, follow the pattern below. (The complete script structure can be seen at :ref:`lua-output`:)
::
function init (args)
local needs = {}
needs["protocol"] = "http"
return needs
end
Do notice that the functions and protocols available for ``log`` and ``match`` may also vary. DNP3, for instance, is not
available for logging.
packet
------
@ -159,7 +188,7 @@ notation. To avoid that, simply do:
http
----
Init with:
For output, init with:
::
@ -169,6 +198,16 @@ Init with:
return needs
end
For detection, use the specific buffer (cf :ref:`lua-detection` for a complete list), as with:
::
function init (args)
local needs = {}
needs["http.uri"] = tostring(true)
return needs
end
HttpGetRequestBody and HttpGetResponseBody.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -297,6 +336,27 @@ HttpGetResponseHeaders
DNS
---
If your purpose is to create a logging script, initialize the buffer as:
::
function init (args)
local needs = {}
needs["protocol"] = "dns"
return needs
end
If you are going to use the script for rule matching, choose one of the available DNS buffers listed in
:ref:`lua-detection` and follow the pattern:
::
function init (args)
local needs = {}
needs["dns.rrname"] = tostring(true)
return needs
end
DnsGetQueries
~~~~~~~~~~~~~
@ -383,7 +443,7 @@ returns a bool
TLS
---
Initialize with:
For log output, initialize with:
::
@ -393,6 +453,16 @@ Initialize with:
return needs
end
For detection, initialization is as follows:
::
function init (args)
local needs = {}
needs["tls"] = tostring(true)
return needs
end
TlsGetVersion
~~~~~~~~~~~~~
@ -519,7 +589,7 @@ JA3
JA3 must be enabled in the Suricata config file (set 'app-layer.protocols.tls.ja3-fingerprints' to 'yes').
Initialize with:
For log output, initialize with:
::
@ -529,6 +599,16 @@ Initialize with:
return needs
end
For detection, initialization is as follows:
::
function init (args)
local needs = {}
needs["tls"] = tostring(true)
return needs
end
Ja3GetHash
~~~~~~~~~~
@ -566,7 +646,7 @@ Ja3SGetHash
Get the JA3S hash (md5sum of JA3S string) through JA3SGetHash.
Lua scripting can be used in two components of Suricata. The first is in
output and the second one in rules in the detection engine.
Both features are using a list of functions to access to data extracted by
Both features are using a list of functions to access the data extracted by
Suricata. You can get the list of functions in the :ref:`lua-functions` page.
..note:: Currently, there is a difference in the ``needs`` key in the ``init`` function, depending on what is the usage: ``output`` or ``detection``. The list of available functions may also differ.