-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: test lua require with builtin lib for output scripts
- Loading branch information
Showing
5 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
A rather simple test to make sure that out built-in libraries can be | ||
loaded by a Lua output script. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
%YAML 1.1 | ||
--- | ||
|
||
include: ../../../etc/suricata-3.1.2.yaml | ||
|
||
rule-files: | ||
|
||
outputs: | ||
- lua: | ||
enabled: yes | ||
scripts-dir: . | ||
scripts: | ||
- test.lua |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
local hashlib = require("suricata.hashlib") | ||
|
||
-- We don't actually use, but the script will fail to run if it fails | ||
-- to "require". | ||
local dataset = require("suricata.dataset") | ||
|
||
-- www.suricata-ids.org | ||
local expected_md5 = "27170ec0609347c6a158bb5b694822a5" | ||
|
||
filename = "results.log" | ||
|
||
function init (args) | ||
local needs = {} | ||
needs["protocol"] = "dns" | ||
return needs | ||
end | ||
|
||
function setup (args) | ||
SCLogNotice("lua: setup()") | ||
file = assert(io.open(SCLogPath() .. "/" .. filename, "w")) | ||
end | ||
|
||
function log(args) | ||
queries = DnsGetQueries() | ||
if queries ~= nil then | ||
for n, t in pairs(queries) do | ||
if hashlib.md5_hexdigest(t["rrname"]) == expected_md5 then | ||
msg = "OK" | ||
else | ||
msg = "FAIL" | ||
end | ||
write(msg) | ||
end | ||
end | ||
end | ||
|
||
function deinit(args) | ||
file:close(file) | ||
end | ||
|
||
function write(msg) | ||
file:write(msg .. "\n") | ||
end |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
requires: | ||
min-version: 8 | ||
|
||
pcap: ../../cond-log-dns-dig/input.pcap | ||
|
||
checks: | ||
- shell: | ||
args: grep "OK" results.log | wc -l | ||
expect: 2 | ||
|