--- /dev/null
+Test Lua detection of HTTP methods via library.
--- /dev/null
+alert http any any -> any any (msg: "Test HTTP Lua request.line"; lua: test-request-line.lua; sid:1;)
+alert http any any -> any any (msg: "Test HTTP Lua request.headers.raw"; lua: test-request-headers-raw.lua; flow:to_server; sid:2;)
+alert http any any -> any any (msg: "Test HTTP Lua response.body"; lua: test-response-body.lua; sid:3;)
+alert http any any -> any any (msg: "Test HTTP Lua response-headers-raw"; lua: test-response-headers-raw.lua; flow:to_client; sid:4;)
--- /dev/null
+%YAML 1.1
+---
+
+include: ../../etc/suricata-4.0.3.yaml
--- /dev/null
+-- simple http match on request_headers_raw module
+local packet = require "suricata.packet"
+local http = require("suricata.http")
+
+function init (args)
+ local needs = {}
+ needs["http.request_headers.raw"] = tostring(true)
+ return needs
+end
+
+function match(args)
+ local tx = http.get_tx()
+ http_request_headers_raw, err = tx:request_headers_raw()
+
+ if #http_request_headers_raw > 0 then
+ if http_request_headers_raw:find("User%-Agent: curl") then
+ return 1
+ end
+ end
+
+ return 0
+end
--- /dev/null
+-- simple http match on request_line module
+local http = require("suricata.http")
+
+function init (args)
+ local needs = {}
+ needs["http.request_line"] = tostring(true)
+ return needs
+end
+
+function match(args)
+ local tx, err = http.get_tx()
+ http_request_line, err = tx:request_line()
+
+ if #http_request_line > 0 then
+ --GET /base64-hello-world.txt HTTP/1.1
+ if http_request_line:find("^GET") then
+ return 1
+ end
+ end
+
+ return 0
+end
--- /dev/null
+-- simple http match on response_body module
+local http = require("suricata.http")
+
+function init (args)
+ local needs = {}
+ needs["http.response_body"] = tostring(true)
+ return needs
+end
+
+function match(args)
+ local tx, err = http.get_tx()
+ http_response_body, err = tx:response_body()
+ if http_response_body ~= nil then
+ for i = 1,#http_response_body,1
+ do
+ if http_response_body[i]:find("^SGVsbG8gV29ybGQu") then
+ return 1
+ end
+ end
+ end
+
+ return 0
+end
--- /dev/null
+-- simple http match on response_headers_raw module
+local packet = require "suricata.packet"
+local http = require("suricata.http")
+
+function init (args)
+ local needs = {}
+ needs["http.response_headers.raw"] = tostring(true)
+ return needs
+end
+
+function match(args)
+ local tx = http.get_tx()
+ http_response_headers_raw, err = tx:response_headers_raw()
+
+ if #http_response_headers_raw > 0 then
+ if http_response_headers_raw:find("^Server: nginx/1.6.3") then
+ return 1
+ end
+ end
+
+ return 0
+end
--- /dev/null
+requires:
+ features:
+ - HAVE_LUA
+ min-version: 8
+
+pcap: ../lua-output-http/input.pcap
+
+args:
+ - --set security.lua.allow-rules=true
+
+checks:
+ - filter:
+ count: 1
+ match:
+ alert.signature_id: 1
+ - filter:
+ count: 1
+ match:
+ alert.signature_id: 2
+ - filter:
+ count: 1
+ match:
+ alert.signature_id: 3
+ - filter:
+ count: 1
+ match:
+ alert.signature_id: 4
+