═══════════════════════════════════════════════════════════════════════════
  PCI DSS PREGUNTA 43 — PAQUETE DE EVIDENCIA
  Web Application Firewall (WAF) — Coraza + OWASP CRS v4
═══════════════════════════════════════════════════════════════════════════

PCI DSS Q43 (PCI v4 Req 6.4.1 + 6.4.2) requiere:
  - Solución técnica automatizada para detectar/prevenir ataques web
  - Solución mantenida actualizada
  - Configuración de alertas
  - Alertas de eventos de seguridad de ejemplo recientes
  - Seguimiento a las alertas

QSA solicitó: Pantallazos que evidencien la implementación del WAF
              e incluir configuración, reglas definidas, alertas
              y seguimiento a las alertas.

═══════════════════════════════════════════════════════════════════════════
SOLUCIÓN DESPLEGADA (2026-05-27)
═══════════════════════════════════════════════════════════════════════════

Coraza WAF (open-source ModSecurity v3) en cluster K8s producción:

Imagen:        owasp/modsecurity-crs:nginx (oficial OWASP)
Componentes:   ModSecurity v3.0.15 + nginx + OWASP CRS v4.25.0
Rules count:   673 reglas activas
Paranoia:      2 (de 4)
Anomaly:       Inbound 5 / Outbound 4
Mode:          BLOCKING (SecRuleEngine: On)
Custom rules:  5 reglas Fintrixs (ID 1001-1005)

URL pública:   http://138.197.228.148/  (DO LoadBalancer)
Namespace:     waf (cluster fintrix-production-k8s)
Backend:       kong-kong-proxy.default.svc.cluster.local:443

═══════════════════════════════════════════════════════════════════════════
ARQUITECTURA DEFENSE-IN-DEPTH
═══════════════════════════════════════════════════════════════════════════

Internet
   │
   ▼
DO Load Balancer (138.197.228.148)
   │
   ▼
Coraza WAF (waf ns) — bloquea ataques antes de llegar al backend
   │ (tráfico limpio)
   ▼
Kong API Gateway (rate limiting, JWT, CORS)
   │
   ▼
Microservicios PCI (payments-api, card-vault, tokenization)

═══════════════════════════════════════════════════════════════════════════
TESTS DE ATAQUE EJECUTADOS
═══════════════════════════════════════════════════════════════════════════

Attack type           Test payload                              Result
──────────────────────────────────────────────────────────────────────────
SQL Injection         ?id=1 OR 1=1--                            ✓ 403 Forbidden
SQL Injection (UNION) ?q=UNION SELECT username FROM users        ✓ 403 Forbidden
XSS                   ?x=<script>alert(1)</script>              ✓ 403 Forbidden
Path Traversal        /api/../../../../etc/passwd               ✓ Normalized → 404
Command Injection     ?cmd=;cat /etc/passwd                     ✓ 403 Forbidden
Scanner detection     User-Agent: sqlmap/1.0                    ✓ 403 Forbidden
Legitimate traffic    GET /api/v1/health                        ✓ Passed to Kong

═══════════════════════════════════════════════════════════════════════════
EVENTOS REALES CAPTURADOS (audit log)
═══════════════════════════════════════════════════════════════════════════

Top rules disparadas (en 5 minutos de testing):
    5x  rule 920350    Host header is numeric IP
    5x  rule 949110    BLOCKING - anomaly score exceeded
    2x  rule 942100    SQL injection - boolean-based blind
    1x  rule 942130    SQL injection - boolean condition
    1x  rule 942390    SQL injection - comment sequence
    1x  rule 942440    SQL injection - comment sequence (alt)
    1x  rule 942190    SQL injection - '1=1' pattern
    1x  rule 942270    SQL injection - UNION SELECT
    1x  rule 942200    SQL injection - SQL keywords
    1x  rule 942260    SQL injection - SQL comment with quote

Top attack categories blocked:
   11x  attack-sqli
    5x  attack-protocol
    5x  attack-xss
    2x  attack-rce
    1x  attack-lfi
    1x  attack-reputation-scanner

═══════════════════════════════════════════════════════════════════════════
ALERT TRACKING (PCI Req 6.4.2 + 10.4)
═══════════════════════════════════════════════════════════════════════════

Pipeline:
  Coraza JSON log → stdout
                ↓
  Fluent Bit DaemonSet (ns logging)
                ↓
  Wazuh manager (TCP 5141)
                ↓
  Wazuh analysisd correlation
                ↓
  Alert dashboard + email/Slack notification al CISO

Wazuh rules para WAF events:
  - Rule 81203: High-severity (HTTP 403 blocked)
  - Rule 81204: Multiple blocks from same IP (correlation)

Retention de logs:
  - 90 días online en Wazuh indexer (cross-ref Q32)
  - 270 días offline en DO Spaces

═══════════════════════════════════════════════════════════════════════════
CONTENIDO DEL PAQUETE
═══════════════════════════════════════════════════════════════════════════

  00-README.txt              (este archivo)
  coraza-waf-deploy.yaml     K8s manifest deployment + service
  10-attack-tests.txt        7 ataques de prueba con respuestas HTTP
  11-modsec-audit-log.json   Eventos audit JSON (cada bloqueo)
  12-nginx-blocked-events.txt nginx access log con 403s
  13-modsec-detailed-events.txt nginx error log con detalle ModSec
  14-attacks-summary.txt     Resumen contado por rule y categoría
  15-waf-state.txt           OWASP CRS version + rules count + env

═══════════════════════════════════════════════════════════════════════════
MANTENIMIENTO DEL WAF
═══════════════════════════════════════════════════════════════════════════

Versión actual:  OWASP CRS v4.25.0 (incluida en imagen owasp/modsecurity-crs:nginx)
Update process:  Dependabot Docker scan semanal monitorea la imagen base
                 (ver Q33). Cuando OWASP publica nuevo CRS, Dependabot
                 abre PR para bump.
Revisión rules:  CISO revisa logs Wazuh mensualmente + ajusta exclusions
                 si hay false positives.
SLA patch:       Bug crítico en CRS = P0 24h (POL-006)

═══════════════════════════════════════════════════════════════════════════
Fecha de extracción: 2026-05-27
Extraído por: Gabriel Ureña (CTO Fintrixs SAS)
═══════════════════════════════════════════════════════════════════════════
