HAProxy Crowdsec Workshop: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 57: Zeile 57:
  
 
= Installation der WAF mit CrowdSec für HAProxy =
 
= Installation der WAF mit CrowdSec für HAProxy =
==CrowdSec installieren==
+
 
 +
==Vorherige Version entfernen und aktuelle installieren==
 +
*curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | bash
 
*apt install crowdsec
 
*apt install crowdsec
 +
 +
==CrowdSec Hub aktualisieren==
 +
*cscli hub update
  
 
==HAProxy Collection und Parser aktivieren==
 
==HAProxy Collection und Parser aktivieren==
 
*cscli collections install crowdsecurity/haproxy
 
*cscli collections install crowdsecurity/haproxy
 
*cscli parsers install crowdsecurity/haproxy-logs
 
*cscli parsers install crowdsecurity/haproxy-logs
 +
 +
==Journald-Logverarbeitung aktivieren==
 +
*cscli collections install crowdsecurity/linux-journal-logs
  
 
==Logging in HAProxy aktivieren==
 
==Logging in HAProxy aktivieren==
Zeile 75: Zeile 83:
 
*systemctl restart crowdsec
 
*systemctl restart crowdsec
  
==HAProxy-Logs im Journal prüfen==
+
==Verarbeitung prüfen==
*journalctl -u haproxy -f
+
*cscli metrics | grep haproxy
  
 
==Angriff simulieren==
 
==Angriff simulieren==

Version vom 27. März 2025, 18:16 Uhr

Vorbereitung

Nameserver

Wildcard Record anlegen
*.art113.int.		300	IN	A	10.88.113.61

Rechner aufsetzen

  • Hostname: star.art113.int
  • Address: 10.88.113.61/24
  • Nameserver: 10.88.113.21
  • Netz: DMZ

Wildcard Certifikat für *.art113.int

Request erstellen
  • openssl req -new -newkey rsa:4096 -nodes -keyout star.art113.int.key -out star.art113.int.csr -subj "/CN=*.art113.int"
Zu CA schicken dort wird signiert
  • openssl x509 -req -days 730 -in star.art113.int.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out star.art113.int.crt -extfile <(echo "subjectAltName=DNS:*.art113.int")
Empfang des star.art113.int Zertifikat
star.art113.int.crt

HAProxy

Installation

  • apt install -y haproxy

Minimales Szenario

  • HAProxy unter mail.art113.int erreichbar zu machen
  • Anfragen an einen internen Server mailit113.int per HTTPS weiterzuleiten (Reverse Proxy)
  • Das Wildcard-Zertifikat zu verwenden (star.art113.int.pem)

Konfiguration

  • mkdir /etc/haproxy/ssl
  • sudo sh -c 'cat star.art113.int.crt star.art113.int.key > /etc/haproxy/ssl/star.art113.int.pem'

Konfigurations Datei

  • vi /etc/haproxy/haproxy.cfg
global
    daemon

defaults
    mode http
    timeout connect 10s
    timeout client  30s
    timeout server  30s

frontend https-in
    bind *:443 ssl crt /etc/haproxy/star.art113.int.pem
    mode http
    acl host_mail hdr(host) -i mail.art113.int
    use_backend mailit113_backend if host_mail

backend mailit113_backend
    mode http
    server mailit113 mail.it113.int:443 ssl verify none

Check

  • haproxy -c -f /etc/haproxy/haproxy.cfg
Configuration file is valid

Starten, Enablen und Checken

  • systemctl restart haproxy.service
  • systemctl enable haproxy.service
  • ss -lntp | grep 443
LISTEN 0      4096         0.0.0.0:443       0.0.0.0:*    users: (("haproxy",pid=993,fd=6))

Installation der WAF mit CrowdSec für HAProxy

Vorherige Version entfernen und aktuelle installieren

CrowdSec Hub aktualisieren

  • cscli hub update

HAProxy Collection und Parser aktivieren

  • cscli collections install crowdsecurity/haproxy
  • cscli parsers install crowdsecurity/haproxy-logs

Journald-Logverarbeitung aktivieren

  • cscli collections install crowdsecurity/linux-journal-logs

Logging in HAProxy aktivieren

In der Datei /etc/haproxy/haproxy.cfg im defaults-Block ergänzen:

log stdout format raw local0
option httplog

Dienste neu starten

  • systemctl restart haproxy
  • systemctl restart crowdsec

Verarbeitung prüfen

  • cscli metrics | grep haproxy

Angriff simulieren

Bann prüfen

  • cscli decisions list