HTTP ---- HTTP事务的详细信息通过 ``suricata.http`` 库暴露给Lua脚本。例如:: local http = require("suricata.http") 初始化设置 ^^^^^ 如果目的是创建日志脚本,按如下方式初始化缓冲区:: function init (args) local needs = {} needs["protocol"] = "http" return needs end 如果脚本将用于规则匹配,请选择 :ref:`lua-detection` 中列出的可用HTTP缓冲区之一,并按以下模式操作:: function init (args) local needs = {} needs["http.request_line"] = tostring(true) return needs end 事务处理 ~~~~~~~~~~~ HTTP基于事务,使用前必须获取当前事务:: local tx, err = http.get_tx() if tx == err then print(err) end 其他所有函数都是事务表的方法。 事务方法 ~~~~~~~~~~~~~~~~~~~ ``request_header()`` ^^^^^^^^^^^^^^^^^^^^ 通过键名获取HTTP请求头值。 示例:: local tx = http.get_tx() local ua = tx:request_header("User-Agent") if ua ~= nil then print(ua) end ``response_header()`` ^^^^^^^^^^^^^^^^^^^^^ 通过键名获取HTTP响应头值。 示例:: local tx = http.get_tx() local content_type = tx:response_header("Content-Type") if content_type ~= nil then print(content_type) end ``request_line`` ^^^^^^^^^^^^^^^^ 以字符串形式获取HTTP请求行。 示例:: local tx = http.get_tx() local http_request_line = tx:request_line(); if #http_request_line > 0 then if http_request_line:find("^GET") then print(http_request_line) end end ``response_line`` ^^^^^^^^^^^^^^^^^ 以字符串形式获取HTTP响应行。 示例:: local tx = http.get_tx() local http_response_line = tx:response_line(); if #http_response_line > 0 then print(http_response_line) end ``request_headers_raw()`` ^^^^^^^^^^^^^^^^^^^^^^^^^ 获取原始HTTP请求头。 示例:: http_request_headers_raw = tx:request_headers_raw() if #http_request_headers_raw > 0 then if http_request_headers_raw:find("User%-Agent: curl") then print(http_request_headers_raw) end end ``response_headers_raw()`` ^^^^^^^^^^^^^^^^^^^^^^^^^^ 获取原始HTTP响应头。 示例:: http_response_headers_raw = tx:response_headers_raw() if #http_response_headers_raw > 0 then print(http_response_headers_raw) end ``request_uri_raw()`` ^^^^^^^^^^^^^^^^^^^^^ 获取原始HTTP请求URI。 示例:: local tx = http.get_tx() http_request_uri_raw = tx:request_uri_raw() print(http_request_uri_raw) ``request_uri_normalized()`` ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 获取标准化后的HTTP请求URI。 示例:: local tx = http.get_tx() http_request_uri_normalized = tx:request_uri_normalized() print(http_request_uri_normalized) ``request_headers()`` ^^^^^^^^^^^^^^^^^^^^^ 获取HTTP请求头。 示例:: local tx = http.get_tx() http_request_headers = tx:request_headers() print(http_request_headers) ``response_headers()`` ^^^^^^^^^^^^^^^^^^^^^^ 获取HTTP响应头。 示例:: local tx = http.get_tx() http_response_headers = tx:response_headers() print(http_response_headers) ``request_body()`` ^^^^^^^^^^^^^^^^^^ 获取HTTP请求体。 示例:: local tx = http.get_tx() http_request_body = tx:request_body() print(http_request_body) ``response_body()`` ^^^^^^^^^^^^^^^^^^^ 获取HTTP响应体。 示例:: local tx = http.get_tx() http_response_body = tx:response_body() print(http_response_body) ``request_host()`` ^^^^^^^^^^^^^^^^^^ 获取HTTP请求主机名。 示例:: local tx = http.get_tx() http_host = tx:request_host() print(http_host)