背景
在某个规则中需要在suricata中对部分IP和域名进行白名单过滤,减少告警噪音和落盘数据大小。
配置
suricata配置
在suricata.yaml
添加如下配置,以启用lua规则检测功能
security:
lua:
allow-rules: yes
规则配置
新增如下规则
alert tcp $HOME_NET any -> $EXTERNAL_NET any (msg:"Outbound TCP connection from internal network to external network";flow:to_server,established;lua:lua_scripts/outbound_tls_conn.lua;sid:910010002; rev:1;)
需要在lua:lua_scripts/outbound_tls_conn.lua
指定lua脚本的地址, 相对于suricata配置中default-rule-path:
路劲进行配置。 该配置表示该lua文件位于[default-rule-path]/lua_scripts/outbound_tls_conn.lua
注意,这个flag在一条规则里面只能配置一个
lua规则编写
规则示例
function init (args)
local needs = {}
needs["http.request_line"] = tostring(true)
return needs
end
-- 白名单匹配, 0表示不进行告警, 1表示正常告警
function match(args)
a = tostring(args["http.request_line"])
if #a > 0 then
if a:find("^POST%s+/.*%.php%s+HTTP/1.0$") then
return 1
end
end
return 0
end
- 支持初始化的函数有
packet -- entire packet, including headers
payload -- packet payload (not stream)
buffer -- the current sticky buffer
http.uri
http.uri.raw
http.request_line
http.request_headers
http.request_headers.raw
http.request_cookie
http.request_user_agent
http.request_body
http.response_headers
http.response_headers.raw
http.response_body
http.response_cookie
注意当要使用http相关数据的时候, 初始化函数中只能初始化http这一个缓冲区。
如:
function init (args)
local needs = {}
needs["http.request_line"] = tostring(true)
-- 你就不能再初始化packet了
-- needs["packet"] = tostrng(true)
return needs
end
扩展
基于luarocks安装
yum install luarocks
# 安装一些基础库
yum install gcc gcc-c++ openssl-devel
- 安全request包
luarocks install lua-requests