--- /dev/null
+%YAML 1.1
+---
+
+include: ../../etc/suricata-4.0.3.yaml
--- /dev/null
+function init (args)
+ local needs = {}
+ needs["dns.request"] = tostring(true)
+ return needs
+end
+
+function count(t)
+ local count = 0
+ for _ in pairs(t) do
+ count = count + 1
+ end
+ return count
+end
+
+function match(args)
+ if DnsGetTxid() ~= 36146 then
+ return 0
+ end
+
+ -- The requested name.
+ local rrname = DnsGetDnsRrname()
+ if rrname ~= "www.suricata-ids.org" then
+ return 0
+ end
+
+ -- Queries
+ local queries = DnsGetQueries()
+ if queries == nil then return 0 end
+
+ -- There should only be one query.
+ if count(queries) ~= 1 then return 0 end
+
+ local query = queries[0]
+
+ if query["type"] ~= "A" then
+ return 0
+ end
+
+ if query["rrname"] ~= "www.suricata-ids.org" then
+ return 0
+ end
+
+ local answers = DnsGetAnswers()
+ if answers == nil then return 0 end
+ if count(answers) ~= 0 then return 0 end
+
+ local authorities = DnsGetAuthorities()
+ if authorities == nil then return 0 end
+ if count(authorities) ~= 0 then return 0 end
+
+ return 1
+end
--- /dev/null
+function init (args)
+ local needs = {}
+ needs["dns.response"] = tostring(true)
+ return needs
+end
+
+function count(t)
+ local count = 0
+ for _ in pairs(t) do
+ count = count + 1
+ end
+ return count
+end
+
+function match(args)
+ if DnsGetTxid() ~= 36146 then
+ return 0
+ end
+
+ -- The requested name.
+ local rrname = DnsGetDnsRrname()
+ if rrname ~= "www.suricata-ids.org" then
+ return 0
+ end
+
+ -- Queries
+ local queries = DnsGetQueries()
+ if queries == nil then return 0 end
+
+ -- There should only be one query.
+ if count(queries) ~= 1 then return 0 end
+
+ local query = queries[0]
+
+ if query["type"] ~= "A" then
+ return 0
+ end
+
+ if query["rrname"] ~= "www.suricata-ids.org" then
+ return 0
+ end
+
+ local answers = DnsGetAnswers()
+ if answers == nil then return 0 end
+ if count(answers) ~= 3 then return 0 end
+
+ local authorities = DnsGetAuthorities()
+ if authorities == nil then return 0 end
+ if count(authorities) ~= 0 then return 0 end
+
+ -- TODO: Look at the answers.
+
+ return 1
+end
--- /dev/null
+function init (args)
+ local needs = {}
+ needs["dns.rrname"] = tostring(true)
+ return needs
+end
+
+function match(args)
+ rrname = tostring(args["dns.rrname"])
+ if rrname == "www.suricata-ids.org" then
+ return 1
+ end
+ return 0
+end
--- /dev/null
+alert dns any any -> any any (msg:"TEST DNS LUA dns.rrname"; \
+ lua:test-rrname.lua; sid:1; rev:1;)
+alert dns any any -> any any (msg:"TEST DNS LUA dns.request"; \
+ lua:test-request.lua; sid:2; rev:1;)
+alert dns any any -> any any (msg:"TEST DNS LUA dns.response"; \
+ lua:test-response.lua; sid:3; rev:1;)
+
\ No newline at end of file
--- /dev/null
+requires:
+ features:
+ - HAVE_LUA
+
+checks:
+ - signature-id: 1
+ - signature-id: 2
+ - signature-id: 3