OpenWaf
O primeiro sistema de proteção de segurança da Web de código aberto, mais proteção do que outros.
Este documento descreve o OpenWAF v1.1 lançado em 8 de março de 2021.
As imagens Dockerfile e Docker foram atualizadas para a versão 1.1 em 8 de março de 2021.
#nginx.conf
lua_package_path '/twaf/?.lua;;' ;
init_by_lua_file /twaf/app/twaf_init.lua;
lua_shared_dict twaf_shm 50m ;
upstream test {
server 0.0.0.1 ; #just an invalid address as a place holder
balancer_by_lua_file twaf_balancer.lua;
}
server {
listen 443 ssl;
server_name _;
ssl_certificate_by_lua_file twaf_ssl_cert.lua;
rewrite_by_lua_file /twaf/app/twaf_rewrite.lua;
access_by_lua_file /twaf/app/twaf_access.lua;
header_filter_by_lua_file /twaf/app/twaf_header_filter.lua;
body_filter_by_lua_file /twaf/app/twaf_body_filter.lua
log_by_lua_file /twaf/app/twaf_log.lua;
set $twaf_https 1 ;
set $twaf_upstream_server "" ;
ssl_certificate nginx.crt;
ssl_certificate_key nginx.key;
location / {
lua_need_request_body on;
proxy_pass $twaf_upstream_server ;
}
}
server {
listen 80 ;
server_name _;
rewrite_by_lua_file /twaf/app/twaf_rewrite.lua;
access_by_lua_file /twaf/app/twaf_access.lua;
header_filter_by_lua_file /twaf/app/twaf_header_filter.lua;
body_filter_by_lua_file /twaf/app/twaf_body_filter.lua
log_by_lua_file /twaf/app/twaf_log.lua;
set $twaf_upstream_server "" ;
location / {
lua_need_request_body on;
proxy_pass $twaf_upstream_server ;
}
} #default_config-json
#main_safe_policy-jsonVoltar ao TOC
O OpenWaf é o primeiro sistema de proteção de aplicativos da Web de código aberto (WAF), com base na análise da API nginx_lua das informações de solicitação HTTP. O OpenWaf é composto por dois motores funcionais: mecanismo de análise de comportamento e mecanismo de regras. O mecanismo de regra analisa principalmente as solicitações individuais, e o mecanismo de análise de comportamento é principalmente responsável pelo rastreamento das informações de solicitação.
Motor de regra inspirado pela ModSecurity e Freewaf (Lua-Resty-WAF), as regras ModSecurity serão implementadas usando o Lua. O mecanismo de regra pode ser baseado na especificação do protocolo, ferramentas automáticas, ataques de injeção, ataques transversais, vazamentos de informações e outras solicitações de exceção de segurança, adicionando suporte a regras dinâmicas, vulnerabilidades oportunas de reparo.
Análise de comportamento Motor, incluindo identificação difusa com base na frequência, rastreador anti-malware, módulo anti-detecção de identificação humano-computador, anti-CSRF, anti CC, anti-direito, proteção contra o módulo de upload de arquivos de ataque, comprovante de adulteração de biscoitos, cadeia anti-roubo, cabeçalhos personalizados e módulo de revisão da página de resposta de resposta.
Além dos dois motores, mas também inclui estatísticas, log, página de resposta de ataque, regras de acesso e outros módulos básicos. Além dos módulos funcionais existentes, o OpenWaf também suporta modificação dinâmica da configuração, a adição dinâmica de módulos de terceiros, para que o motor não reinicie sob as condições da interrupção, a proteção de atualização.
O OpenWaf suporta os recursos acima como uma estratégia para diferentes aplicativos da Web com diferentes estratégias para proteger. O futuro criará uma plataforma em nuvem, a estratégia também pode ser compartilhada para outras pessoas.
Módulos básicos:
Módulos seguros:
Documentos e exemplos detalhados de configuração, consulte a documentação do módulo acima
Voltar ao TOC
请看 OpenWaf 安装文档
Voltar ao TOC
A lista de discussão OpenWaf-en é para falantes de inglês.
A lista de discussão OpenWaf-CN é para falantes chineses.
579790127
Voltar ao TOC
Envie relatórios de bugs, listas de desejos ou patches por
Voltar ao TOC
Voltar ao TOC
Changelog
Voltar ao TOC
Este módulo está licenciado sob a licença BSD.
Copyright (c) 2016-2016, por Jian "Miracle" Qi (齐健) [email protected], Titan Co.Ltd.
Todos os direitos reservados.
Redistribuição e uso em formulários de origem e binária, com ou sem modificação, são permitidos, desde que as seguintes condições sejam atendidas:
As redistribuições do código -fonte devem manter o aviso de direitos autorais acima, esta lista de condições e o seguinte aviso.
As redistribuições em formato binário devem reproduzir o aviso de direitos autorais acima, esta lista de condições e o seguinte aviso na documentação e/ou outros materiais fornecidos com a distribuição.
Este software é fornecido pelos detentores de direitos autorais e colaboradores "como está" e quaisquer garantias expressas ou implícitas, incluindo, entre outros, as garantias implícitas de comercialização e condicionamento físico para um determinado objetivo. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF Aconselhado sobre a possibilidade de tais danos.
Voltar ao TOC
Voltar ao TOC
{
"twaf_access_rule": {
"rules": [ -- 注意先后顺序
{
"user": "user_id", -- 用户名ID,非必填,默认值"-"
"ngx_ssl": false, -- nginx认证的开关,非必填,默认值false
"ngx_ssl_cert": "path", -- nginx认证所需PEM证书地址
"ngx_ssl_key": "path", -- nginx认证所需PEM私钥地址
"host": " ^ 1\.1\.1\.1 $ ", -- 域名,支持正则匹配,支持字符串或数组,同时支持IPv4/IPv6
"port": 80, -- 端口号。支持number或数组类型,非必填,默认值80或443
"path": "/", -- 路径,支持正则匹配,非必填,默认值"/"
"url_case_sensitive": false, -- 路径区分大小写,boolean类型,非必填,默认值 false
"server_ssl": false, -- 后端服务器ssl开关,boolean类型,非必填,默认值 false
"forward": "server_5", -- 后端服务器upstream名称,string类型
"forward_addr": "1.1.1.2", -- 后端服务器ip地址,string类型
"forward_port": "8080", -- 后端服务器端口号,非必填,默认值80或443
"uuid": "access_567b067ff2060", -- 用来标记此规则的uuid,非必填,默认16位随机字符串
"policy": "policy_uuid" -- 安全策略ID,string类型,非必填,默认值twaf_default_conf
}
]
}
}Sintaxe: "Regras": Tabela
Padrão: Nenhum
Contexto: twaf_access_rule
Tabela 类型 , 接入规则 , 顺序匹配
Sintaxe: "Usuário": String
padrão: -
Contexto: twaf_access_rule: regras
String 类型。用户名 id 。对应变量 %{userID}。
非必填 , 默认值 "-".
Sintaxe: "ngx_ssl": true | false
Padrão: false
Contexto: twaf_access_rule: regras
booleano 类型 , 服务器端 (nginx) 认证开关 , 可与 client_ssl 组成双向认证
非必填 , 默认值 Falso
Sintaxe: "NGX_SSL_CERT": "PATH"
Padrão: Nenhum
Contexto: twaf_access_rule: regras
String 类型 , 服务器端 (nginx) 认证所需 Pem 证书地址 , 目前仅支持绝对地址
Sintaxe: "NGX_SSL_KEY": "PATH"
Padrão: Nenhum
Contexto: twaf_access_rule: regras
String 类型 , 服务器端 (nginx) 认证所需 Pem 私钥地址 , 目前仅支持绝对地址
Sintaxe: "Host": "IP | Nome do domínio regex"
Padrão: Nenhum
Contexto: twaf_access_rule: regras
String 或数组类型。发布域名。 (从 v1.0.0β 版本开始支持数组)
支持正则表达式 (匹配时 , 自动忽略大小写)。
同时支持 ipv4/ipv6。 (从 v1.0.0β 版本开始支持 ipv6)
例如:
"host": "^1\.1\.1\.1$"
"host": "test\.com"
"host": "^.*\.com$"
"host": "www.baidu.com"
"host": ["www.baidu.com", "1.1.1.1", "8888::192.168.1.1"]
Sintaxe: "Port": Número
Padrão: 80 | 443
Contexto: twaf_access_rule: regras
Número 或数组类型 , 端口号。 (从 v1.0.0β 版本开始支持数组)
非必填 , 默认值 80 或 443
若 "host" 参数为数组时 , "porta" 也应为数组。例如:
"host": ["www.baidu.com", "1.1.1.1", "8888::192.168.1.1"]
"posrt": [80, 8088, 8099]
Sintaxe: "Path": "Regex"
Padrão: Nenhum
Contexto: twaf_access_rule: regras
String 类型 , 路径 , 支持正则匹配
非必填 , 默认值 "/"
例如:
"path": "/"
"path": "/images"
"path": "/[a|b]test"
Sintaxe: "url_case_sensitive": "true | false"
Padrão: false
Contexto: twaf_access_rule: regras
booleano 类型 , 路径区分大小写 (从 v1.0.0β 版本开始支持此参数)
非必填 , 默认值 Falso (不区分大小写)
Sintaxe: "Server_ssl": true | false
Padrão: false
Contexto: twaf_access_rule: regras
booleano 类型 , Openwaf 向后端服务器连接的 ssl 开关
非必填 , 默认值 Falso
例如:
upstream test {
server 1.1.1.1;
}
http {
server {
listen 80;
server_name _;
location / {
#server_ssl为true,相当于proxy_pass后为https
proxy_pass https://test;
#server_ssl为false,相当于proxy_pass后为http
#proxy_pass http://test;
}
}
}
Sintaxe: "Forward": "upstream_uuid"
Padrão: Nenhum
Contexto: twaf_access_rule: regras
String 类型 , para a frente 表示后端服务器的 uuid , 即 a montante 的名称
若不使用 OpenWaf 提供的 $ twaf_upstream_server 变量 , 则 "Forward", "Forward_addr", "Forward_port" 均非必填 (从 v1.0.0β 版本开始支持非必填)
#如:使用OpenWAF自带的$twaf_upstream_server变量,forward值为test
upstream test {
server 1.1.1.1;
}
server {
...
location / {
proxy_pass $twaf_upstream_server;
}
}
---------------------------------
#如:未使用OpenWAF自带的$twaf_upstream_server变量,forward非必填
server {
...
location / {
proxy_pass http://1.1.1.1;
}
}
---------------------------------
#如:未使用OpenWAF自带的$twaf_upstream_server变量,forward非必填
server {
...
location / {
root html;
index index.htm;
}
}
Sintaxe: "Forward_addr": "IP"
Padrão: Nenhum
Contexto: twaf_access_rule: regras
string 类型 , forward_addr 表示后端服务器的 ip 地址 (TODO: 支持域名))))))))))))
upstream test {
#如:forward_addr值为1.1.1.1
server 1.1.1.1;
}
Sintaxe: "Forward_port": Port
Padrão: 80 | 443
Contexto: twaf_access_rule: regras
número 类型 , forward_port 表示后端服务器端口号
非必填 , 默认值 80 或 443
upstream test {
#如:forward_port值为50001
server 1.1.1.1:50001;
}
Sintaxe: "uuid": "string"
Padrão: Random (16)
Contexto: twaf_access_rule: regras
String 类型 , 接入规则的唯一标识
非必填 , 默认 16 位随机字符串 (从 v1.0.0β 版本开始默认 16 位随机字符串)
Sintaxe: "Política": "Policy_uuid"
Padrão: twaf_default_conf
Contexto: twaf_access_rule: regras
String 类型 , 满足此接入规则的请求 , 所使用安全策略的 uuid
非必填 , 默认值 twaf_default_conf
Voltar para TWAF_ACCESS_RULE
Voltar ao TOC
{
"twaf_anti_hotlink" :{
"state" : false ,
"log_state" : true ,
"event_id" : " 110001 " ,
"event_severity" : " medium " ,
"ct_state" : false ,
"action_meta" : 403 ,
"action" : " DENY " ,
"mode" : " referer " ,
"allow_noreferer" : true ,
"cookie_name" : " TWAF_AH " ,
"uri_ext" :[ " javascript " , " css " , " html " , " " ]
}
}Sintaxe: "estado": true | false | "$ dynamic_state"
Padrão: false
Contexto: twaf_anti_hotlink
当前模块暂未开源
Sintaxe: "log_state": true | false | "$ dinâmico_state"
Padrão: true
Contexto: twaf_anti_hotlink
Sintaxe: "ct_state": true | false | "$ dinâmico_state"
Padrão: false
Contexto: twaf_anti_hotlink
Sintaxe: "Event_id": "String"
Padrão: "110001"
Contexto: twaf_anti_hotlink
Sintaxe: "Event_severity": "String"
Padrão: "Médio"
Contexto: twaf_anti_hotlink
Sintaxe: "Ação": "String"
padrão: "negar"
Contexto: twaf_anti_hotlink
Sintaxe: "Action_Meta": "String" | Número
Padrão: 403
Contexto: twaf_anti_hotlink
Sintaxe: "Mode": "String"
Padrão: "Refereiro"
Contexto: twaf_anti_hotlink
Sintaxe: "allow_noreferer": true | false
Padrão: true
Contexto: twaf_anti_hotlink
Sintaxe: "cookie_name": "string"
Padrão: TWAF_AH
Contexto: twaf_anti_hotlink
cookie_name 表示盗链模块发送 cookie 的名称 , 默认 "twaf_ah"
此配置只有 Modo 为 Cookie 模式下生效
Sintaxe: "Uri_ext": Array | Exten | "All"
Padrão: Nenhum
Contexto: twaf_anti_hotlink
uri_ext 表示对哪些资源进行盗链防护
#对html类型资源进行盗链防护
"uri_ext": "html"
#对未知类型资源进行盗链防护,nginx无法解析出资源类型时为空字符串
"uri_ext": ""
#对html、css及未知类型资源进行盗链防护
"uri_ext": ["html", "css", ""]
#对所有资源进行盗链防护
"uri_ext": "all"
Voltar para TWAF_ANTI_HOTLINK
Voltar ao TOC
{
"state": false, -- 模块开关,支持 true,false
"log_state":true, -- 日志开关
"dict_state": false, -- shared_dict 开关
"shared_dict_name":"twaf_anti_mal_crawler", -- shared_dict 名称,若为空,则值为 "twaf_global" 下的 "dict_name"
"shared_dict_key": "remote_addr", -- shared_dict 键值
"timeout":300, -- shared_dict 保存状态有效时长(单位秒)
"timer_flush_expired":200, -- shared_dict 清除过期信息的间隔时间(单位秒),若为空,则值为 "twaf_global" 下的 "timer_flush_expired"
"cookie_state":true, -- cookie机制开关
"crawler_cookie_name":"TWAF_crawler", -- 爬虫cookie名称
"mal_cookie_name":"TWAF_mcrawler", -- 恶意爬虫cookie名称
"force_scan_robots_state":true, -- 页面注入诱捕路径的开关
"force_scan_times": 3, -- 注入诱捕路径的页面个数
"trap_uri":"/abc/abc.html", -- 诱捕路径
"trap_args":"id=1", -- 诱捕参数
"action":"DENY", -- 执行动作,支持 "ALLOW", "DENY", "REDIRECT", "ROBOT", "RESET_CONNECTION", "PASS" 等
"action_meta": 403 -- 执行动作的附属信息,若 action 为 DENY,action_meta为响应码,若 action 为 REDIRECT,action_meta 为重定向 url
}Sintaxe: estado verdadeiro | false | $ dinâmico_state
Padrão: false
Contexto: twaf_anti_mal_crawler
模块开关 , 默认 Falso (关闭) , , 支持动态开关
De volta ao MCD
Sintaxe: log_state true | false | $ dynamic_state
Padrão: true
Contexto: twaf_anti_mal_crawler
安全日志开关 , 默认 TRUE (记录)) , 支持动态开关
De volta ao MCD
Sintaxe: dict_state true | false
Padrão: false
Contexto: twaf_anti_mal_crawler
shared_dict 开关。当 dict_state 为 true , 某 ip 被此模块拦截 , 会被记录在内存中 , 在 timeout 时间内访问会被拦截 (timeout)
De volta ao MCD
Sintaxe: shared_dict_name
Padrão: nil
Contexto: twaf_anti_mal_crawler
shared_dict 名称。对应 nginx 中的配置项 , 不可轻易修改
若为空 , 则值为 "twaf_global" 下的 "dict_name"
De volta ao MCD
Sintaxe: shared_dict_key |
Padrão: Remote_addr
Contexto: twaf_anti_mal_crawler
shared_dict 键值。支持数组
De volta ao MCD
Sintaxe: Tempo limite
Padrão: 300
Contexto: twaf_anti_mal_crawler
shared_dict 保存状态有效时长 (单位秒))
De volta ao MCD
Sintaxe: Tempo limite
Padrão: 200
Contexto: twaf_anti_mal_crawler
shared_dict 清除过期信息的间隔时间 (单位秒)), 若为空 , 则值为 "twaf_global" 下的 "timer_flush_expired"
De volta ao MCD
Sintaxe: cookie_state true | false | $ dynamic_state
Padrão: true
Contexto: twaf_anti_mal_crawler
是否发送 Cookie, 默认 True (发送)) , 支持动态开关
De volta ao MCD
Sintaxe: crawler_cookie_name
padrão: "twaf_crawler"
Contexto: twaf_anti_mal_crawler
爬虫 Cookie 名称
De volta ao MCD
Sintaxe: mal_cookie_name
Padrão: TWAF_MCRAWLER
Contexto: twaf_anti_mal_crawler
恶意爬虫 Cookie 名称
De volta ao MCD
Sintaxe: force_scan_robots_state true | false
Padrão: true
Contexto: twaf_anti_mal_crawler
页面注入诱捕路径的开关
某些扫描工具不会去访问 /robots.txt , 因此在他访问的页面中插入禁爬目录的暗链
De volta ao MCD
Sintaxe: force_scan_times
Padrão: 3
Contexto: twaf_anti_mal_crawler
注入诱捕路径的页面数
De volta ao MCD
Sintaxe: TRAP_URI
padrão: /abc/abc.html
Contexto: twaf_anti_mal_crawler
诱捕路径 , 访问此路径 , 被标识为恶意爬虫
De volta ao MCD
Sintaxe: trap_args
Padrão: id = 1
Contexto: twaf_anti_mal_crawler
诱捕参数。携带此参数访问诱捕路径 , 不会标识为攻击
De volta ao MCD
Voltar para TWAF_ANTI_MAL_CRAWLER
Voltar ao TOC
"twaf_reqstat": {
"state":true, -- 统计模块总开关
"safe_state":true, -- 安全信息统计开关
"access_state":true, -- 访问信息统计开关
"upstream_state":true, -- upstream信息统计开关
"shared_dict_name":"twaf_reqstat", -- shm名称
"shared_dict_key":"policy_id" -- shm键值。依据此值进行分类统计
}
PS: 当前统计模块是全局模块,仅支持在twaf_default_conf中进行全局配置,不支持在自定义策略中进行配置Sintaxe: estado verdadeiro | false | $ dinâmico_state
Padrão: true
Contexto: TWAF_REQSTAT
统计模块开关 , 支持动态开关 , 默认开启
Sintaxe: access_state true | false | $ dynamic_state
Padrão: true
Contexto: TWAF_REQSTAT
访问信息统计开关 , 支持动态开关 , 默认开启
Sintaxe: safe_state true | false | $ dynamic_state
Padrão: true
Contexto: TWAF_REQSTAT
安全信息统计开关 , 支持动态开关 , 默认开启
Sintaxe: upstream_state true | false | $ dynamic_state
Padrão: true
Contexto: TWAF_REQSTAT
转发信息统计开关 , 支持动态开关 , 默认开启
Sintaxe: string shared_dict_name
Padrão: twaf_reqstat
Contexto: TWAF_REQSTAT
指定 Shared_dict 名称 , 在这之前需在 nginx 配置文件中配置 lua_shared_dict
Sintaxe: string shared_dict_key
Padrão: PolicyId
Contexto: TWAF_REQSTAT
string 类型。指定 shm 键值。依据此值进行分类统计。
如 : 值设为 PolicyId , 则统计每一个策略相关的 Acesso 、 seguro 和 a montante 信息。
如 : 值设为 UserID , 则统计每一个用户相关的 Acesso 、 seguro 和 a montante 信息。
如 : 值设为 Access_id , 则统计每一个接入规则相关的 Acesso 、 seguro 和 a montante 信息。
Voltar para TWAF_REQSTAT
Voltar ao TOC
"twaf_log": {
"access_log_state":true, -- 访问日志总开关
"security_log_state":true, -- 安全日志总开关
"flush_limit":32768, -- 缓冲,当存储的日志大于阈值时发送日志
"size_limit": 200, -- 控制日志中每一项的字符上限,如'raw_header'或请求体响应体,可能会使udp日志报错
"drop_limit":65507, -- 缓冲上限,达到此值,丢弃当前日志,发送缓存并清空缓存,当sock_type为udp时,drop_limit值最大为65507(65508会报错message too long)
"periodic_flush": 2, -- flush间隔周期。单位:秒。日志会在达到flush_limit或periodic_flush时输出
"max_retry_times":5, -- 最大容错次数
-- -- 以下为socket输出日志配置
"socket_access_log_state": true, -- socket模式的访问日志开关
"socket_security_log_state": true, -- socket模式的安全日志开关
"sock_type":"udp", -- 支持tcp和udp两种协议
"content_type":"JSON", -- sock支持JSON和INFLUXDB两种日志格式
"host":"127.0.0.1", -- 日志服务器地址
"port":60055, -- 日志服务器端口号
"ssl":false, -- 是否开启ssl协议
"access_log":{}, -- 访问日志格式
"security_log":{}, -- 安全日志格式
-- -- 以下为file输出日志配置
"file_access_log_state": true, -- file模式的访问日志开关
"file_security_log_state": true, -- file模式的安全日志开关
"file_flush": false, -- 是否实时写入文件
"file_content_type": "W3C", -- file模式时日志格式,当前仅支持W3C
"file_access_log_path": "/var/log/openwaf_access.log", -- file模式的访问日志路径
"file_security_log_path": "/var/log/openwaf_security.log", -- file模式的安全日志路径
"access_log_w3c": "", -- file模式访问日志的w3c格式
"security_log_w3c": "" -- file模式安全日志的w3c格式
}Sintaxe: "Access_log_state": true | false
Padrão: false
Contexto: TWAF_LOG
booleano 类型 , 访问日志总开关 , 默认关闭。
Sintaxe: "Security_log_state": true | false
Padrão: true
Contexto: TWAF_LOG
booleano 类型 , 安全事件日志总开关 , 默认开启
Sintaxe: "Flush_limit": Número
Padrão: 32768
Contexto: TWAF_LOG
Número 类型。缓冲区大小 , 当存储的日志大于阈值才发送 , 默认值为 32768
v0.0.6 及之前版本默认值为 0 , 即立刻发送日志 , 不进行缓存。 不进行缓存。
v1.0.0β 版本开始 , 默认值为 32768。
日志输出控制条件 , 还与 periodic_flush 参数有关.
Sintaxe: "size_limit": número
Padrão: 200
Contexto: TWAF_LOG
Número 类型。控制日志中每一项的字符上限。单位: 字节。
若 'RAW_HEADER' 或请求体响应体过长 , 可能会使 UDP 日志报错
Sintaxe: "Drop_limit": Número
Padrão: 65507
Contexto: TWAF_LOG
Número 类型。缓冲上限 , 达到此值 , 丢弃当前日志 , 发送缓存并清空缓存 , 当 Sock_type 为 Udp 时 , Drop_limit 值最大为 65507 (65508 会报错 Mensagem muito longa)
Sintaxe: "periódico_flush": número
Padrão: 2
Contexto: TWAF_LOG
Número 类型。日志 Flush 间隔周期。单位: 秒。
日志会在满足 Flush_limit 或 periodic_flush 条件时输出
Sintaxe: "max_retry_times": número
Padrão: 5
Contexto: TWAF_LOG
Número 类型。最大容错次数
Sintaxe: "Socket_Access_Log_State": true | false
Padrão: true
Contexto: TWAF_LOG
BOOLEAN 类型 , SOCKET 模式的访问日志开关
Sintaxe: "Socket_Security_Log_State": true | false
Padrão: true
Contexto: TWAF_LOG
BOOLEAN 类型 , SOCKET 模式的安全日志开关
Sintaxe: "sock_type": tcp | udp
Padrão: UDP
Contexto: TWAF_LOG
日志传输协议 , 默认 udp
Sintaxe: "Content_type": JSON | InfluxDB
Padrão: JSON
Contexto: TWAF_LOG
日志格式 , JSON
Sintaxe: "host": string
Padrão: "127.0.0.1"
Contexto: TWAF_LOG
日志接收服务器的 IP 地址
Sintaxe: "Port": Número
Padrão: 60055
Contexto: TWAF_LOG
日志接收服务器的端口号
Sintaxe: "ssl": true | false
Padrão: false
Contexto: TWAF_LOG
是否开启 SSL 协议 , 默认 Falso
Sintaxe: "Access_log": Tabela
Padrão: false
Contexto: TWAF_LOG
Tabela 类型。访问日志格式。格式详见 Security_log 说明.
Sintaxe: "Security_log": Tabela
Padrão: false
Contexto: TWAF_LOG
安全事件日志格式
若 Content_Type 为 JSON , 则日志格式为
[
variable_key_1,
variable_key_2,
...
]
若 Content_Type 为 InfluxDB , 则日志格式为
{
"db":MEASUREMENT名称,
"tags":[variable_key_1, variable_key_2, ...],
"fileds"[variable_key_1, variable_key_2, ...],
"time":true|false
}
变量名称详见规则引擎模块 TWAF_SECRULES
#日志格式举例
#JSON格式
"security_log": [
"remote_addr",
"remote_port",
"userid",
"dev_uuid",
"original_dst_addr",
"original_dst_port",
"remote_user",
"time_local",
"msec",
"request_method",
"request_uri",
"request_protocol",
"status",
"bytes_sent",
"http_referer",
"http_user_agent",
"gzip_ratio",
"http_host",
"raw_header",
"%{request_headers.host}"
]
#INFLUXDB格式
"security_log": {
"db":"test", -- MEASUREMENT名称
"tags":[], -- tags keys
"fileds":[ -- fileds keys
"remote_addr",
"remote_port",
"userid",
"dev_uuid",
"original_dst_addr",
"original_dst_port",
"remote_user",
"time_local",
"msec",
"request_method",
"request_uri",
"request_protocol",
"status",
"bytes_sent",
"http_referer",
"http_user_agent",
"gzip_ratio",
"http_host",
"raw_header",
"%{request_headers.host}"
],
"time":true -- 日志是否携带时间戳
}
PS: JSON 和 INFLUXDB 格式的 access_log 和 security_log 支持自定义变量
如上述举例,为了获取到 request_headers 中的 host 值,因此配置 "%{request_headers.host}"
Sintaxe: "file_access_log_state": true | false
Padrão: true
Contexto: TWAF_LOG
BOOLEAN 类型。FILE 模式的访问日志开关
Sintaxe: "file_security_log_state": true | false
Padrão: true
Contexto: TWAF_LOG
BOOLEAN 类型。FILE 模式的安全日志开关
Sintaxe: "file_flush": true | false
Padrão: false
Contexto: TWAF_LOG
booleano 类型。是否实时写入文件
Sintaxe: "file_content_type": w3c
Padrão: W3C
Contexto: TWAF_LOG
String 类型。File 模式时日志格式 , 当前仅支持 W3C
Sintaxe: "FILE_ACCESS_LOG_PATH": PATH
Padrão: "/var/log/openwaf_access.log"
Contexto: TWAF_LOG
String 类型。File 模式的访问日志路径
Sintaxe: "file_security_log_path": path
Padrão: "/var/log/openwaf_security.log"
Contexto: TWAF_LOG
String 类型。File 模式的安全日志路径
Sintaxe: "Access_log_W3C": String
Padrão:详见说明
Contexto: TWAF_LOG
String 类型。File 模式访问日志的 W3C 格式
默认值为:"%{remote_addr} - %{remote_user} [%{time_local}] "%{request_method} %{request_uri} %{request_protocol}" %{response_status} %{bytes_sent} "%{http_referer}" "%{http_user_agent}" %{userid} %{server_addr}:%{server_port} "%{http_host}" %{request_time} %{policyid} %{unique_id} %{api_id}"
变量名称详见规则引擎模块 TWAF_SECRULES
Sintaxe: "Security_Log_W3C": String
Padrão:详见说明
Contexto: TWAF_LOG
String 类型。File 模式安全日志的 W3C 格式
默认值为:"%{remote_addr} - %{remote_user} [%{time_local}] "%{request_method} %{request_uri} %{request_protocol}" %{response_status} %{bytes_sent} "%{http_referer}" "%{http_user_agent}" %{userid} %{server_addr}:%{server_port} "%{http_host}" %{request_time} %{policyid} %{category} %{severity} %{action} %{id} %{rule_name} %{unique_id} %{api_id}"
变量名称详见规则引擎模块 TWAF_SECRULES
Voltar para TWAF_LOG
Voltar ao TOC
"twaf_secrules":{
"state": true, -- 总开关
"reqbody_state": true, -- 请求体检测开关
"header_filter_state": true, -- 响应头检测开关
"body_filter_state": true, -- 响应体检测开关
"system_rules_state": true, -- 系统规则集检测开关
"reqbody_limit":134217728, -- 请求体检测阈值,大于阈值不检测
"respbody_limit":524288, -- 响应体检测阈值,大于阈值不检测
"pre_path": "/opt/OpenWAF/", -- OpenWAF安装路径
"path": "lib/twaf/inc/knowledge_db/twrules", -- 特征规则库在OpenWAF中的路径
"user_defined_rules":[ ], -- 用户自定义规则,数组
"rules_id":{ -- 特征排除
"111112": [{"REMOTE_HOST":"a.com", "URI":" ^ /ab"}], -- 匹配中数组中信息则对应规则失效,数组中key为变量名称,值支持正则
"111113": {}, -- 特征未被排除
"111114": [{}] -- 特征被无条件排除
},
"ruleset_ids": [ -- 规则集引用。若 ruleset_ids 值为空,则默认所有的规则都生效(用于兼容无ruleset_ids的旧版本)
"set_123456789",
"set_987654321"
]
}Sintaxe: Estado Verdadeiro | Falso
Padrão: true
Contexto: TWAF_SECRULES
规则引擎总开关
Sintaxe: reqbody_state true | false
Padrão: true
Contexto: TWAF_SECRULES
请求体检测开关
Sintaxe: header_filter_state true | false
Padrão: true
Contexto: TWAF_SECRULES
响应头检测开关
Sintaxe: body_filter_state true | false
Padrão: false
Contexto: TWAF_SECRULES
响应体检测开关 , 默认关闭 , 若开启需添加第三方模块 [ngx_http_twaf_header_sent_filter_module 暂未开源]
Sintaxe: System_Rules_State True | False
Padrão: true
Contexto: TWAF_SECRULES
系统规则集检测开关
lib/twaf/inc/conhecimento_db/twrules 目录下的规则 , 都是系统规则
除了系统规则外 , 还有 twaf_secrules 模块下 user_defined_rules 的用户自定义规则
系统规则一般很少改动 , 而用户自定义规则却随着业务而增减 , 如动态配置缓存、压缩、时域控制和黑白名单等。
Sintaxe: número reqbody_limit
Padrão: 134217728
Contexto: TWAF_SECRULES
请求体检测大小上限 , 默认 134217728b (128 MB) , 若请求体超过设置上限 , 则不检测
Ps : reqbody_limit 值要小于 nginx 中 client_body_buffer_size 的值才会生效
Sintaxe: Número respbody_limit
Padrão: 134217728
Contexto: TWAF_SECRULES
响应体检测大小上限 , 默认 134217728b (128 MB) , 若响应体大小超过设置上限 , 则不检测
Sintaxe: string pre_path
padrão: /opt/openwaf/
Contexto: TWAF_SECRULES
OpenWaf 的安装路径
Sintaxe: string de caminho
Padrão: lib/twaf/inc/conhecimento_db/twrules
Contexto: TWAF_SECRULES
特征规则库在 OpenWaf 中的路径
Sintaxe: user_defined_rules
padrão: []
Contexto: TWAF_SECRULES
策略下的用户自定义特征规则
先执行用户自定义规则 , 再执行系统规则
系统特征规则适用于所有的策略 , 在引擎启动时通过加载特征库或通过 API 加载系统特征规则 , 系统特征规则一般不会动态更改
用户自定义特征在策略下生效 , 一般用于变动较大的特征规则 , 如 : : 时域控制 , 修改响应头等临时性规则
"user_defined_rules" :[
{
"id" : " 1000001 " ,
"release_version" : " 858 " ,
"charactor_version" : " 001 " ,
"disable" : false ,
"opts" : {
"nolog" : false
},
"phase" : " access " ,
"action" : " deny " ,
"meta" : 403 ,
"severity" : " high " ,
"rule_name" : " relative time " ,
"desc" : "周一至周五的8点至18点,禁止访问/test目录" ,
"match" : [{
"vars" : [{
"var" : " URI "
}],
"operator" : " begins_with " ,
"pattern" : " /test "
},
{
"vars" : [{
"var" : " TIME_WDAY "
}],
"operator" : " equal " ,
"pattern" : [ " 1 " , " 2 " , " 3 " , " 4 " , " 5 " ]
},
{
"vars" : [{
"var" : " TIME "
}],
"operator" : " str_range " ,
"pattern" : [ " 08:00:00-18:00:00 " ]
}]
},
{
"id" : " 1000002 " ,
"release_version" : " 858 " ,
"charactor_version" : " 001 " ,
"disable" : false ,
"opts" : {
"nolog" : false
},
"phase" : " access " ,
"action" : " deny " ,
"meta" : 403 ,
"severity" : " high " ,
"rule_name" : " iputil " ,
"desc" : "某ip段内不许访问" ,
"match" : [{
"vars" : [{
"var" : " REMOTE_ADDR "
}],
"operator" : " ip_utils " ,
"pattern" : [ " 1.1.1.0/24 " , " 2.2.2.2-2.2.20.2 " ]
}]
}
]Sintaxe: Regras_id Tabela
Padrão: Nenhum
Contexto: TWAF_SECRULES
用于排除特征
Sintaxe: Tabela RegrasLet_Ids
Padrão: Nenhum
Contexto: TWAF_SECRULES
Tabela 类型。规则集引用, 用于不同策略加载不同的规则进行防护。从 v1.0.0β 版本开始引入规则集。
若 Regraslet_ids 值为空 , 则默认引用所有加载的规则。
若 Regraslet_ids 值为空数组 , 则无任何规则生效。
"ruleset_ids": [ -- 有序引用 set_123456789 与 set_987654321 两个规则集。
"set_123456789",
"set_987654321"
]
PS: 当前规则集有关具体配置仅支持通过rule_set API进行配置
Voltar para TWAF_SECRULES
Voltar ao TOC
{
"twaf_limit_conn": {
"state":false, -- CC防护模块开关
"log_state":true, -- CC日志开关
"trigger_state":true, -- 触发开关
"clean_state":true, -- 清洗开关
"trigger_thr":{ -- 触发阈值(关系为“或”)
"req_flow_max":1073741824, -- 每秒请求流量,单位B
"req_count_max":10000 -- 每秒请求数
},
"clean_thr":{ -- 清洗阈值
"new_conn_max":40, -- 单一源ip每秒新建连接数
"conn_max":100, -- 单一源ip防护期间内连接总数
"req_max":50, -- 单一源ip每秒请求总数
"uri_frequency_max":3000 -- 单一路径每秒请求总数
},
"attacks": 1, -- 在一次CC攻击过程中,某ip触发清洗值的次数大于attacks,则此ip会一直被拦截,直到CC攻击结束
"timer_flush_expired":10, -- 清理shared_dict过期数据的时间间隔
"interval":10, -- 进入CC防护后发送日志的时间间隔,单位秒
"shared_dict_name":"twaf_limit_conn", -- 存放其他信息的shared_dict
"shared_dict_key": "remote_addr", -- shared_dict的键值
"action":"DENY", -- 触发CC防护执行的动作
"action_meta":403,
"timeout":30 -- 清洗时长(当再次触发清洗值时,重置)
}
}Sintaxe: "Estado": Verdadeiro | Falso
Padrão: false
Contexto: twaf_limit_conn
booleano 类型 , cc 防护模块总开关 , 默认关闭
Sintaxe: "log_state": true | false
Padrão: true
Contexto: twaf_limit_conn
booleano 类型 , cc 防护模块日志开关 , 默认开启
Sintaxe: "trigger_state": true | false
Padrão: true
Contexto: twaf_limit_conn
booleano 类型 , cc 防护模块的触发开关 , 默认开启
若关闭 , 则触发机制关闭 , 时刻进入 cc 清洗状态
Sintaxe: "Clean_state": true | false
Padrão: true
Contexto: twaf_limit_conn
booleano 类型 , cc 防护模块总开关 , 默认开启
若关闭 (仅用于测试) , 则清洗机制关闭 , cc 模块将无法拦截请求
Sintaxe: "trigger_thr": tabela
Padrão: {"req_flow_max": 1073741824, "req_count_max": 10000}
Contexto: twaf_limit_conn
Tabela 类型 , 触发阈值
当达到其中一个触发阈值 , 进入 cc 清洗状态
当前有两个触发阈值
"trigger_thr":{ -- 触发阈值(关系为“或”)
"req_flow_max":1073741824, -- 每秒请求流量,单位B,默认1GB/s
"req_count_max":10000 -- 每秒请求数,默认10000个/秒
}Sintaxe: "Clean_thr": Tabela
padrão: {"new_conn_max": 40, "conn_max": 100, "req_max": 50, "uri_frequency_max": 3000}
Contexto: twaf_limit_conn
Tabela 类型 , 清洗阈值
当进入 cc 清洗状态 , 达到其中一个清洗阈值 , 则执行相应动作
当前有四个清洗阈值
"clean_thr":{ -- 清洗阈值(关系为“或”)
"new_conn_max":40, -- 单一源ip每秒新建连接数,默认40个/秒
"conn_max":100, -- 单一源ip防护期间内连接总数,默认100个
"req_max":50, -- 单一源ip每秒请求总数,默认50个/秒
"uri_frequency_max":3000 -- 单一路径每秒请求总数,默认3000个/秒
}Sintaxe: "Ataques": Número
Padrão: 1
Contexto: twaf_limit_conn
在一次 cc 攻击过程中 , 某 ip 触发清洗阈值的次数大于 ataques , 则此 ip 会一直被拦截 , 直到 cc 攻击结束
此前 , 在一次 cc 攻击过程中 , 当达到清洗阈值时 , , , , , 也可正常访问后端服务器
正确设置此参数 , 可以大大提升 cc 防护性能
若想恢复以前的 cc 防护机制 , 只需 ataques 设为 0 即可
此参数出现在 OpenWaf-0.0.6 版本 , TWAF_ANTI_CC 的 0.0.3 版本
Sintaxe: "timer_flush_expired": número
Padrão: 10
Contexto: twaf_limit_conn
Número 类型 , 清理 Shared_dict 过期数据的时间间隔 , 默认 10 秒
Sintaxe: "intervalo": número
Padrão: 10
Contexto: twaf_limit_conn
número 类型 , 进入 cc 防护后发送日志的时间间隔 , 默认 10 秒
Sintaxe: "shared_dict_name": string
padrão: "twaf_limit_conn"
Contexto: twaf_limit_conn
String 类型 , 存放当前 cc 防护信息的 shared_dict 名称
Sintaxe: "shared_dict_key": string | tabela
Padrão: "Remote_addr"
Contexto: twaf_limit_conn
String 或 Tabela 类型 , Shared_dict 的键值 , 支持 nginx 变量
支持字符串类型和数组类型
"shared_dict_key": "remote_addr"
"shared_dict_key": ["remote_addr", "http_user_agent"]
Sintaxe: "Ação": String
padrão: "negar"
Contexto: twaf_limit_conn
string 类型 , 触发 cc 防护执行的动作 , 默认 "negar"
Sintaxe: "Action_meta": Número | String
Padrão: 403
Contexto: twaf_limit_conn
String 或 Número 类型 , 执行动作的附属信息 , 默认 403
Sintaxe: "Timeout": número
Padrão: 30
Contexto: twaf_limit_conn
Número 类型 , 清洗时长 , n 秒内不再达到触发阈值 , 则退出 cc 清洗状态
在清洗过程中 , 再次达到触发阈值 , 则时间重置为 30 秒
Voltar ao TOC
Sintaxe: set $ twaf_https 0 | 1
Padrão: 0
Contexto: servidor
用于标记请求是否通过 SSL 加密
"Definir $ twaf_https 1" , 则表示请求通过 ssl 加密
"Definir $ twaf_https 0" , 则表示请求未通过 ssl 加密
server {
listen 443 ssl;
set $twaf_https 1;
...
}
server {
listen 80;
set $twaf_https 0;
...
}
Sintaxe: defina $ twaf_upstream_server ""
Padrão: Nenhum
Contexto: servidor
用于指定后端服务器地址 , 只需初始化为空字符串即可 , 其值由 "Server_ssl" 和 "Forward" 确定
upstream server_1 {
...
}
upstream server_2 {
...
}
server {
...
set $twaf_upstream_server "";
location / {
...
proxy_pass $twaf_upstream_server;
}
}
若"server_ssl"值为true, "forward"值为"server_1"
等价于proxy_pass https://server_1;
若"server_ssl"值为false, "forward"值为"server_2"
等价于proxy_pass http://server_2;
Voltar ao TOC
Voltar para var
Voltar ao TOC
Tabela 类型 , 所有的请求参数 , 包含 args_get 和 args_post
例如:POST http://www.baidu.com?name=miracle&age=5
请求体为:time=123456&day=365
ARGS变量值为{"name": "miracle", "age": "5", "time": "123456", "day": "365"}
Voltar para var
Voltar ao TOC
número 类型 , 请求参数总长度 , 只包含 只包含 和 Valor 的长度 , 不包含 '&' '' = '等符号
例如:GET http://www.baidu.com?name=miracle&age=5
ARGS_COMBINED_SIZE变量值为15,而不是18
Voltar para var
Voltar ao TOC
Tabela 类型 , Querystring 参数
例如:GET http://www.baidu.com?name=miracle&age=5
ARGS_GET变量值为{"name": "miracle", "age": "5"}
Voltar para var
Voltar ao TOC
Tabela 类型 , Querystring 参数 Tecla 值
例如:GET http://www.baidu.com?name=miracle&age=5
ARGS_GET_NAMES变量值为["name", "age"]
Voltar para var
Voltar ao TOC
Tabela 类型 , Querystring 参数 chave 值及 Post 参数 参数 值 值
例如:POST http://www.baidu.com?name=miracle&age=5
请求体为:time=123456&day=365
ARGS_NAMES变量值为["name", "age", "time", "day"]
Voltar para var
Voltar ao TOC
Tabela 类型 , post 参数
例如:
POST http://www.baidu.com/login.html
请求体为:time=123456&day=365
ARGS_POST变量值为{"time": "123456", "day": "365"}
Voltar para var
Voltar ao TOC
Tabela 类型 , Post 参数 值 值
例如:
POST http://www.baidu.com/login.html
请求体为:time=123456&day=365
ARGS_POST_NAMES变量值为["time", "day"]
Voltar para var
Voltar ao TOC
Número 类型 , 接收信息字节数
Voltar para var
Voltar ao TOC
Número 类型 , 当前连接中的请求数
Voltar para var
Voltar ao TOC
String 类型 , 处理事务用时时间 , 单位: 微秒 (μs)
Voltar para var
Voltar ao TOC
Tabela 类型 , 从请求体中得到的原始文件名 (带有文件后缀名)
Voltar para var
Voltar ao TOC
Tabela 类型 , 上传文件名称 (不带有后缀名))
Voltar para var
Voltar ao TOC
Tabela 类型 , 包含 Code3, Código, ID, Continente, Nome 等字段信息
Voltar para var
Voltar ao TOC
String 类型 , 3 个字母长度的国家缩写
Voltar para var
Voltar ao TOC
String 类型 , 2 个字母长度的国家缩写
Voltar para var
Voltar ao TOC
número 类型 , 国家 id
Voltar para var
Voltar ao TOC
String 类型 , 国家所在大洲
Voltar para var
Voltar ao TOC
String 类型 , 国家全称
Voltar para var
Voltar ao TOC
String 类型 , 压缩比率
Voltar para var
Voltar ao TOC
String 类型 , 请求头中的 Cookie 字段
Voltar para var
Voltar ao TOC
String 类型 , 请求头中的 Host 字段值 , 既域名: 端口 (80 缺省)
Voltar para var
Voltar ao TOC
String 类型 , 请求头中的 referente 字段
Voltar para var
Voltar ao TOC
String 类型 , 请求头中的 agente de usuário 字段
Voltar para var
Voltar ao TOC
String 类型 , IPv4 ou IPv6
Voltar para var
Voltar ao TOC
类型不定 , 当前匹配中的变量
Voltar para var
Voltar ao TOC
Tabela 类型 , 单条规则匹配中的所有变量
Voltar para var
Voltar ao TOC
String 类型 , 当前匹配中的变量名称
Voltar para var
Voltar ao TOC
Tabela 类型 , 单条规则匹配中的所有变量名称
Voltar para var
Voltar ao TOC
String 类型 , 服务器地址 , 应用代理模式为 waf 地址 , 透明模式为后端服务器地址
Voltar para var
Voltar ao TOC
String 类型 , 服务器端口号 , 应用代理模式为 waf 端口号 , 透明模式为后端服务器端口号
Voltar para var
Voltar ao TOC
String 类型 , 策略 id
Voltar para var
Voltar ao TOC
String 类型 , 未解码的请求参数
Voltar para var
Voltar ao TOC
String 类型 , 请求头信息 , 带请求行
Voltar para var
Voltar ao TOC
String 类型 , 请求头信息 , 不带请求行
Voltar para var
Voltar ao TOC
String 类型 , 客户端地址
Voltar para var
Voltar ao TOC
String 类型 , 域名
Voltar para var
Voltar ao TOC
Número 类型 , 端口号
Voltar para var
Voltar ao TOC
String 类型 , 用于身份验证的用户名
Voltar para var
Voltar ao TOC
String 类型 , 请求的文件名
例如: GET http://www.baidu.com/test/login.php
REQUEST_BASENAME值为/login.php
Voltar para var
Voltar ao TOC
类型不定 , 请求体
Voltar para var
Voltar ao TOC
Tabela 类型 , 请求携带的 Cookie
Voltar para var
Voltar ao TOC
Tabela 类型 , 请求携带 Cookie 的名称
Voltar para var
Voltar ao TOC
String 类型 , URL de solicitação relativa (相对请求路径)
例如: GET http://www.baidu.com/test/login.php
REQUEST_FILENAME值为/test/login.php
Voltar para var
Voltar ao TOC
Tabela 类型 , 请求头信息
Voltar para var
Voltar ao TOC
Tabela 类型 , 请求头 Tecla 值
Voltar para var
Voltar ao TOC
String 类型 , 请求行
Voltar para var
Voltar ao TOC
String 类型 , 请求方法
Voltar para var
Voltar ao TOC
String 类型 , http 请求协议 , 如: http/1.1
Voltar para var
Voltar ao TOC
número 类型 , http 请求协议版本 , 如: 1, 1,1, 2
Voltar para var
Voltar ao TOC
String 类型 , 请求路径 , 既不带域名 , 也不带参数
例如: GET http://www.baid.com/test/login.php?name=miracle
URI变量值为/test/login.php
Voltar para var
Voltar ao TOC
String 类型 , 统一资源定位符 , Esquema 与 http_host 与 uri 的拼接
例如: GET http://www.baid.com/test/login.php?name=miracle
URL变量值为http://www.baid.com/test/login.php
Voltar para var
Voltar ao TOC
String 类型 , 请求路径 , 带参数 , 但不带有域名
例如: GET http://www.baid.com/test/login.php?name=miracle
REQUEST_URI变量值为/test/login.php?name=miracle
Voltar para var
Voltar ao TOC
String 类型 , 响应体
Voltar para var
Voltar ao TOC
Tabela 类型 , 响应头信息
Voltar para var
Voltar ao TOC
função 类型 , 响应状态码
Voltar para var
Voltar ao TOC
String 类型 , http ou https
例如:GET http://www.baidu.com/
SCHEME变量值为http
Voltar para var
Voltar ao TOC
String 类型 , 服务器地址
Voltar para var
Voltar ao TOC
String 类型 , 服务器名称
Voltar para var
Voltar ao TOC
Número 类型 , 服务器端口号
Voltar para var
Voltar ao TOC
Tabela 类型 , 第三方模块 lua-rony-session 提供的变量
Voltar para var
Voltar ao TOC
Tabela 类型 , Sessão 信息 , 第三方模块 lua-renetion-session 提供的变量
Voltar para var
Voltar ao TOC
String 类型 Hora: Minuto: Segundo
Voltar para var
Voltar ao TOC
Número 类型 , 天 (1-31)
Voltar para var
Voltar ao TOC
número 类型 , 时间戳 , segundos desde 1970
Voltar para var
Voltar ao TOC
Número 类型 , 小时 (0-23)
Voltar para var
Voltar ao TOC
Número 类型 , 分钟 (0-59)
Voltar para var
Voltar ao TOC
Número 类型 , 月份 (1-12)
Voltar para var
Voltar ao TOC
Número 类型 , 秒 (0-59)
Voltar para var
Voltar ao TOC
Número 类型 , 周 (0-6)
Voltar para var
Voltar ao TOC
Número 类型 , 年份 , , , , , ,: 1997
Voltar para var
Voltar ao TOC
String 类型 , 当前时间 , 例如: 26/agosto de 2016: 01: 32: 16 -0400
Voltar para var
Voltar ao TOC
Tabela 类型 , 用于存储当前请求信息的变量 , 作用域仅仅是当前请求
Voltar para var
Voltar ao TOC
String 类型 , id 标识 , 随机生成的字符串 , 可通过配置来控制随机字符串的长度
从 v1.0.0β 版本开始 , 默认 34 位自定义随机字符串 改为从 ngx.request_id 变量获取的 16/32 位随机字符串
Voltar para var
Voltar ao TOC
Mantém o status de acessar um cache de resposta (0,8.3). O status pode ser "Miss", "Bypass", "Expired", "Stale", "Atualizando", "revalidado" ou "Hit".
Voltar para var
Voltar ao TOC
String 类型 , 从接入规则配置得到的用于 id 标识
Voltar para var
Voltar ao TOC
De volta ao TFF
Voltar ao TOC
Decodifica uma corda baseada em Base64.
Nota: 注意 Transform 的执行顺序
例如:
{
"id": "xxxx",
...
"transform": ["base64_decode", "lowercase"],
...
}
先执行base64解码,然后字符串最小化,若顺序调换,会影响结果
De volta ao TFF
Voltar ao TOC
Decode dados Hex SQL.
De volta ao TFF
Voltar ao TOC
Codifica a sequência de entrada usando a codificação BASE64.
De volta ao TFF
Voltar ao TOC
计数 , 相当于 ModSecurity 中的 '&' 符号
De volta ao TFF
Voltar ao TOC
Converte qualquer um dos caracteres de espaço em branco (0x20, f, t, n, r, v, 0xa0) em espaços (ASCII 0x20), compactando vários caracteres de espaço consecutivos em um.
De volta ao TFF
Voltar ao TOC
Decodifica uma string que foi codificada usando o mesmo algoritmo que a usada no hexncode
De volta ao TFF
Voltar ao TOC
Codifica string (possivelmente contendo caracteres binários) substituindo cada byte de entrada por dois caracteres hexadecimais.
De volta ao TFF
Voltar ao TOC
Decodifica os caracteres codificados como entidades HTML.
De volta ao TFF
Voltar ao TOC
Olha o comprimento da sequência de entrada em bytes
De volta ao TFF
Voltar ao TOC
Converte todos os personagens em minúsculas
De volta ao TFF
Voltar ao TOC
Calcula um hash md5 a partir dos dados na entrada. O hash calculado está em uma forma binária bruta e pode precisar ser codificado no texto a ser impresso (ou registrado). As funções de hash são comumente usadas em combinação com Hex_Encode (por exemplo: "Transform": ["md5", "hex_encode").
De volta ao TFF
Voltar ao TOC
Remove várias barras, auto-referências de diretório e referências de retorno do diretório (exceto quando no início da entrada) da string de entrada.
De volta ao TFF
Voltar ao TOC
Remove todos os bytes nul da entrada
De volta ao TFF
Voltar ao TOC
Remove todos os caracteres de espaço em branco da entrada.
移除空白字符s,包含水平定位字符 ('t')、归位键('r')、换行('n')、垂直定位字符('v')或翻页('f')等
Back to TFF
Back to TOC
用一个空格代替/ ... /注释内容
Back to TFF
Back to TOC
Removes common comments chars (/*, */, --, #).
Back to TFF
Back to TOC
去掉/ ... /注释内容
Back to TFF
Back to TOC
Unescape str as an escaped URI component.
例如:
"b%20r56+7" 使用uri_decode转换后为 b r56 7
Back to TFF
Back to TOC
Escape str as a URI component.
Back to TFF
Back to TOC
Calculates a SHA1 hash from the input string. The computed hash is in a raw binary form and may need encoded into text to be printed (or logged). Hash functions are commonly used in combination with hex_encode (for example, "transform": ["sha1", "hex_encode"]).
Back to TFF
Back to TOC
Removes whitespace from the left side of the input string.
Back to TFF
Back to TOC
Removes whitespace from the right side of the input string.
Back to TFF
Back to TOC
Removes whitespace from both the left and right sides of the input string.
Back to TFF
Back to TOC
Back to OPERATORS
Back to TOC
Returns true if the parameter string is found at the beginning of the input.
Back to OPERATORS
Back to TOC
Returns true if the parameter string is found anywhere in the input.
operator 为 contains 且 pattern 为数组,等价于 modsecurity 的 pm
PS: modsecurity的pm忽略大小写,OpenWAF中contains不忽略大小写
例如:
{
"id": "xxx",
...
"operator": "contains",
"pattern": ["abc", "def"],
...
}
Back to OPERATORS
Back to TOC
Returns true if the parameter string (with word boundaries) is found anywhere in the input.
Back to OPERATORS
Back to TOC
This operator uses LibInjection to detect SQLi attacks.
Back to OPERATORS
Back to TOC
This operator uses LibInjection to detect XSS attacks.
Back to OPERATORS
Back to TOC
Returns true if the parameter string is found at the end of the input.
Back to OPERATORS
Back to TOC
Performs a string comparison and returns true if the parameter string is identical to the input string.
等价于 modsecurity 的 eq 和 streq
例如:
{
"id": "xxx",
...
"operator": "equal",
"pattern": [12345, "html", "23456"]
...
}
Back to OPERATORS
Back to TOC
Performs numerical comparison and returns true if the input value is greater than or equal to the provided parameter.
return false, if a value is provided that cannot be converted to a number.
Back to OPERATORS
Back to TOC
Performs numerical comparison and returns true if the input value is greater than the operator parameter.
return false, if a value is provided that cannot be converted to a number.
Back to OPERATORS
Back to TOC
Performs a fast ipv4 or ipv6 match of REMOTE_ADDR variable data. Can handle the following formats:
Full IPv4 Address: 192.168.1.100 Network Block/CIDR Address: 192.168.1.0/24 IPv4 Address Region: 1.1.1.1-2.2.2.2
从 v1.0.0β 版本开始支持 IPv6,如8888::192.168.1.1
ip_utils与pf的组合相当于modsecurity中的ipMatchF和ipMatchFromFile
例如:
规则如下:
{
"id": "xxxx",
...
"operator": "ip_utils",
"pf": "/tmp/ip_blacklist.txt",
...
}
"/tmp/ip_blacklist.txt"文件内容如下:
192.168.1.100
192.168.1.0/24
1.1.1.1-2.2.2.2
8888::192.168.1.1
8888::1:1
Back to OPERATORS
Back to TOC
Performs numerical comparison and returns true if the input value is less than or equal to the operator parameter.
return false, if a value is provided that cannot be converted to a number.
Back to OPERATORS
Back to TOC
Performs numerical comparison and returns true if the input value is less than to the operator parameter.
return false, if a value is provided that cannot be converted to a number.
Back to OPERATORS
[Back to TOC](#table-of-contents
判断是否在数字范围内
它与transform的length组合,相当于modsecurity的validateByteRange
{
"id": "xxx",
...
"operator": "num_range",
"pattern": [10, "13", "32-126"],
"transform": "length",
...
}
Back to OPERATORS
Back to TOC
Performs a regular expression match of the pattern provided as parameter.
regex 等于 rx + capture,即 regex 同时包含 modsecurity 的 rx 功能 和 capture 捕获功能
modsecurity有关capture的描述如下: When used together with the regular expression operator (@rx), the capture action will create copies of the regular expression captures and place them into the transaction variable collection.
OpenWAF 中无单独的 capture 指令,但使用 regex 默认开启 capture 功能
例如:
{
"id": "000031",
"release_version": "858",
"charactor_version": "001",
"opts": {
"nolog": false
},
"phase": "access",
"action": "deny",
"meta": 403,
"severity": "low",
"rule_name": "protocol.reqHeader.c",
"desc": "协议规范性约束,检测含有不合规Range或Request-Range值的HTTP请求",
"match": [
{
"vars": [
{
"var": "REQUEST_HEADERS",
"parse": {
"specific": "Range"
}
},
{
"var": "REQUEST_HEADERS",
"parse": {
"specific": "Request-Range"
}
}
],
"operator": "regex",
"pattern": "(\d+)\-(\d+)\,"
},
{
"vars": [{
"var": "TX",
"parse": {
"specific": "2"
}
}],
"operator": "greater_eq",
"pattern": "%{TX.1}",
"parse_pattern": true,
"op_negated": true
}
]
}
Back to OPERATORS
Back to TOC
等同于contains
Back to OPERATORS
Back to TOC
判断是否在字符串范围内
例如时间区间判断:
{
"id": "xxx",
...
"operator": "str_range",
"pattern": ["01:42:00-04:32:00"],
...
}
Back to OPERATORS
Back to TOC
Validates the URL-encoded characters in the provided input string.
Back to OPERATORS
Back to TOC
Back to OTHERS
Back to TOC
Stops processing of the current phase but also skipping over all other phases.
"action": "allow"
一旦执行此动作,则后面的防护规则及其他安全模块均不进行安全检测,此动作一般用于白名单
Back to OTHERS
Back to TOC
Stops processing of the current phase.
"action": "allow_phase"
Back to OTHERS
Back to TOC
Stops rule processing and intercepts transaction.
"action": "deny",
"meta": 403
Back to OTHERS
Back to TOC
Stops rule processing and intercepts transaction.
"id": "xxxxxxx"
Back to OTHERS
Back to TOC
不记录日志
"opts": {
"nolog": true
}
Back to OTHERS
Back to TOC
对operator结果的取反
"match": [{
"vars": [{
"var": "HTTP_USER_AGENT"
}],
"transform": "length",
"operator": "less_eq",
"pattern": 50,
"op_negated": true
}]
等价于
"match": [{
"vars": [{
"var": "HTTP_USER_AGENT"
}],
"transform": "length",
"operator": "greater",
"pattern": 50
}]
若请求头中user_agent字段长度大于50,则匹配中此条规则
Back to OTHERS
Back to TOC
对变量进一步解析
若请求GET http://www.baidu.com?name=miracle&age=5
"match": [{
"vars": [{
"var": "ARGS_GET"
}],
...
}]
得到的值为{"name": "miracle", "age": "5"}
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"specific": "name"
}
}]
}]
得到的值为["miracle"]
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"specific": ["name", "age"]
}
}]
}]
得到的值为["miracle", "5"]
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"ignore": "name"
}
}]
}]
得到的值为{"age": "5"}
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"ignore": ["name", "age"]
}
}]
}]
得到的值为[]
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"keys": true
}
}]
}]
得到的值为["name", "age"]
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"values": true
}
}]
}]
得到的值为["miracle", "5"]
"match": [{
"vars": [{
"var": "ARGS_GET",
"parse": {
"all": true
}
}]
}]
得到的值为["name", "age", "miracle", "5"]
Back to OTHERS
Back to TOC
Continues processing with the next rule in spite of a successful match.
"action": "pass"
Back to OTHERS
Back to TOC
like 'pass'
"action": "warn"
Back to OTHERS
Back to TOC
like 'pass'
"action": "audit"
Back to OTHERS
Back to TOC
规则执行的阶段,取值可为"access","header_filter","body_filter"的组合
{
"id": "xxx_01",
"phase": "access",
...
}
"xxx_01"规则在access阶段执行
{
"id": "xxx_02",
"phase": ["access", "header_filter"],
...
}
"xxx_02规则在access阶段和"header_filter"阶段各执行一次
Back to OTHERS
Back to TOC
{
...
phase = "header_filter", -- 缓存开关需在header_filter阶段配置
action = "pass", -- 无需拦截请求
opts = {
nolog = true, -- 不需记录日志
proxy_cache = {
state = true|false, -- 缓存开关
expired = 600 -- 缓存时长(单位秒),默认600秒
}
}
...
}
若state为true,且得到的缓存状态为"MISS"或"EXPIRED",则对响应内容进行缓存,同时设置缓存时长
若state为false,则清除对应缓存键的缓存(包含其缓存文件)
举例如下:
# nginx.conf 有关proxy cache 配置如下
http {
proxy_cache_path /opt/cache/OpenWAF-proxy levels=2:2 keys_zone=twaf_cache:101m max_size=100m use_temp_path=off;
proxy_cache_key $host$uri;
proxy_cache twaf_cache;
proxy_ignore_headers X-Accel-Expires Cache-Control Set-Cookie;
proxy_no_cache $twaf_cache_flag;
server {
set $twaf_cache_flag 1; #默认不缓存
}
}
# lua 格式 配置
{
id = "test_x01", -- id 全局唯一
opts = {
nolog = true,
proxy_cache = {
state = true,
expired = 300
}
},
phase = "header_filter",
action = "pass",
match = {{
vars = {{
var = "URI"
},{
var = "REQUEST_HEADERS",
parse = {
specific = "Referer"
}
}},
operator = "equal",
pattern = {"/xampp/", "%{SCHEME}://%{HTTP_HOST}/xampp/"},
parse_pattern = true
}}
}
此规则将缓存URI为'/xampp/'的页面,更新时间为300秒
若match中过滤条件为响应码,则相当于Nginx的proxy_cache_valid指令
若match中过滤条件为请求方法,则相当于Nginx的proxy_cache_methods指令
若macth中过滤条件为资源类型,则相当于Nginx的proxy_cache_content_type指令
PS: proxy_cache_content_type指令为官方指令,是miracle Qi修改Nginx源码扩展的功能
Back to OTHERS
Back to TOC
pattern是operator操作的参数
pf是指pattern from file,与pattern和pset互斥(三者不可同时出现),目前仅支持绝对路径
pf 与 contains 组合,相当于modsecurity的 pmf 或 pmFromFile
pf 与 ip_utils 组合,相当于modsecurity的 ipMatchF 或 ipMatchFromFile
Back to OTHERS
Back to TOC
集合。pattern、pf 和 pset 互斥(只能同时出现一个)。
暂不支持数组。
使用方法详见 https://github.com/titansec/openwaf_api#pset_post
Back to OTHERS
Back to TOC
"action": "redirect",
"meta": "/index.html"
Back to OTHERS
Back to TOC
指定此条规则的版本,同modsecurity中Action的rev功能
"charactor_version": "001"
Back to OTHERS
Back to TOC
Assigns severity to the rule in which it is used.
The data below is used by the OWASP ModSecurity Core Rule Set (CRS):
EMERGENCY: is generated from correlation of anomaly scoring data where there is an inbound attack and an outbound leakage. ALERT: is generated from correlation where there is an inbound attack and an outbound application level error. CRITICAL: Anomaly Score of 5. Is the highest severity level possible without correlation. It is normally generated by the web attack rules (40 level files). ERROR: Error - Anomaly Score of 4. Is generated mostly from outbound leakage rules (50 level files). WARNING: Anomaly Score of 3. Is generated by malicious client rules (35 level files). NOTICE: Anomaly Score of 2. Is generated by the Protocol policy and anomaly files. INFO DEBUG
也可自定义严重等级,如:low,medium,high,critical等
"severity": "high"
Back to OTHERS
Back to TOC
Creates, removes, or updates a variable.
{
"id": "xxx_01",
"opts":{
"nolog": false,
"setvar": [{
"column": "TX",
"key": "score",
"value": 5,
"incr": true
}]
},
...
}
"xxx_01"规则中,给变量TX中score成员的值加5,若TX中无score成员,则初始化为0,再加5
{
"id": "xxx_02",
"opts":{
"nolog": false,
"setvar": [{
"column": "TX",
"key": "score",
"value": 5
}]
},
...
}
"xxx_02"规则中,给变量TX中score成员的值赋为5
Back to OTHERS
Back to TOC
"action"的附属信息
若"action"为"deny",则"meta"为响应码
"action": "deny",
"meta": 403
若"action"为"redirect",则"meta"为重定向地址
"action": "redirect",
"meta": "/index.html"
Back to OTHERS
Back to TOC
为 nginx 变量赋值,支持赋值字符串
v1.0.0β版本之后支持赋值变量%{}
如在 nginx.conf 中 set $twaf_test "";
可在 secrules 中基于条件动态赋值
"opts": {
"ngx_var": {
"twaf_test": "1.1.1.1" -- 也可赋值变量,如 "twaf_test": "%{remote_addr}"
}
}
Back to OTHERS
Back to TOC
This action is used to specify the transformation pipeline to use to transform the value of each variable used in the rule before matching.
Back to OTHERS
Back to TOC
Assigns a tag (category) to a rule.
支持数组 "tag": ["xxx_1", "xxx_2"]
支持字符串 "tag": "xxx_3"
Back to OTHERS
Back to TOC
规则集版本,等同于modsecurity中Action的ver功能
"release_version": "858"
Back to OTHERS
Back to TOC
人机识别
需提前配置人机识别模块配置,此功能暂未放开
"action": "robot"
Back to OTHERS
Back to TOC
增删改响应头
例如隐藏server字段:
"opts": {
"add_resp_headers": {
"server": ""
}
}
Back to OTHERS
Back to TOC
通过 PayPal 来支持 OpenWAF
Back to TOC