File: //etc/nginx/modsec/crs-setup-wordpress-context7.conf
# ------------------------------------------------------------------------
# CONFIGURAÇÃO CRS PARA WORDPRESS RATE LIMITING
# Baseado na documentação oficial OWASP Core Rule Set
# Versão Context7 - Configuração Assertiva
# ------------------------------------------------------------------------
#
# -- [[ CONFIGURAÇÕES BÁSICAS DO MODSECURITY ]] --
#
# Configurar engine do ModSecurity
SecRuleEngine On
SecRequestBodyAccess On
SecResponseBodyAccess On
SecResponseBodyMimeType text/plain text/html text/xml application/json
#
# -- [[ CONFIGURAÇÕES DE PARANOIA LEVEL ]] --
#
# Definir nível de paranoia (1-4, onde 4 é mais restritivo)
SecAction \
"id:900000,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.blocking_paranoia_level=2,\
setvar:tx.detection_paranoia_level=2"
#
# -- [[ CONFIGURAÇÕES DE ANOMALY SCORING ]] --
#
# Definir pontuações de anomalia
SecAction \
"id:900001,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.critical_anomaly_score=5,\
setvar:tx.error_anomaly_score=4,\
setvar:tx.warning_anomaly_score=3,\
setvar:tx.notice_anomaly_score=2"
# Limites de bloqueio por anomalia
SecAction \
"id:900002,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.inbound_anomaly_score_threshold=5,\
setvar:tx.outbound_anomaly_score_threshold=4"
#
# -- [[ CONFIGURAÇÕES ESPECÍFICAS WORDPRESS ]] --
#
# Configurações para WordPress
SecAction \
"id:900010,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.wordpress_rate_limit_enabled=1,\
setvar:tx.wordpress_login_attempts_limit=5,\
setvar:tx.wordpress_login_block_time=300,\
setvar:tx.wordpress_xmlrpc_attempts_limit=3,\
setvar:tx.wordpress_xmlrpc_block_time=600,\
setvar:tx.wordpress_ajax_requests_limit=50"
#
# -- [[ CONFIGURAÇÕES DE VARIÁVEIS GLOBAIS ]] --
#
# Inicializar variáveis globais de transação
SecAction \
"id:900020,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.inbound_anomaly_score_pl1=0,\
setvar:tx.inbound_anomaly_score_pl2=0,\
setvar:tx.inbound_anomaly_score_pl3=0,\
setvar:tx.inbound_anomaly_score_pl4=0"
#
# -- [[ CONFIGURAÇÕES DE AUDITORIA ]] --
#
# Configurar auditoria
SecAuditEngine RelevantOnly
SecAuditLogRelevantStatus "^(?:5|4(?!04))"
SecAuditLogType Serial
SecAuditLog /var/log/modsec_audit.log
# Partes do log de auditoria
SecAuditLogParts ABDEFHIJZ
#
# -- [[ CONFIGURAÇÕES DE DETECÇÃO DE EVASÃO ]] --
#
# Detectar tentativas de evasão
SecAction \
"id:900030,\
phase:1,\
nolog,\
pass,\
t:none,\
setvar:tx.crs_validate_utf8_encoding=1,\
setvar:tx.arg_name_length=100,\
setvar:tx.arg_length=400,\
setvar:tx.total_arg_length=64000,\
setvar:tx.max_num_args=255,\
setvar:tx.max_file_size=1048576,\
setvar:tx.combined_file_sizes=1048576"
#
# -- [[ WHITELIST DE IPs (OPCIONAL) ]] --
#
# Whitelist de IPs confiáveis (descomente e configure conforme necessário)
# SecRule REMOTE_ADDR "@ipMatch 192.168.1.0/24,127.0.0.1" \
# "id:900040,\
# phase:1,\
# nolog,\
# pass,\
# t:none,\
# setvar:tx.wordpress_whitelist_ip=1"
#
# -- [[ CONFIGURAÇÕES DE EXCLUSÃO ]] --
#
# Exclusões para WordPress (reduzir falsos positivos)
SecRuleUpdateActionById 920230 "pass" # Multipart/form-data
SecRuleUpdateActionById 920300 "pass" # Missing Accept Header
SecRuleUpdateActionById 920440 "pass" # URL file extension
#
# -- [[ CONFIGURAÇÕES DE RESPOSTA ]] --
#
# Configurar página de erro customizada
SecRule TX:INBOUND_ANOMALY_SCORE "@ge %{tx.inbound_anomaly_score_threshold}" \
"id:900050,\
phase:2,\
block,\
status:403,\
log,\
logdata:'Anomaly Score Exceeded: %{TX.INBOUND_ANOMALY_SCORE}',\
msg:'Inbound Anomaly Score Exceeded (Total Score: %{TX.INBOUND_ANOMALY_SCORE})',\
tag:'application-multi',\
tag:'language-multi',\
tag:'platform-multi',\
tag:'attack-generic'"
# Marca de fim da configuração
SecMarker "END-CRS-SETUP-WORDPRESS"