HAProxy Crowdsec Workshop: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(29 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 3: Zeile 3:
 
:Wildcard Record anlegen
 
:Wildcard Record anlegen
 
  *.art113.int. 300 IN A 10.88.113.61
 
  *.art113.int. 300 IN A 10.88.113.61
;Wildcard Request stellen
+
==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"
 
*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==
 +
;Haproxy und andere Dinge
 +
*apt install -y haproxy curl
 +
 +
==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
 +
<pre>
 +
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
 +
</pre>
 +
 +
==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))
 +
 +
= Integration von CrowdSec als WAF für HAProxy =
 +
 +
==CrowdSec installieren==
 +
*curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | bash
 +
*apt install crowdsec
 +
 +
==CrowdSec-Hub aktualisieren und Grundregeln laden==
 +
*cscli hub update
 +
*cscli collections install crowdsecurity/linux
 +
*cscli collections install crowdsecurity/base-http-scenarios
 +
*cscli collections install crowdsecurity/haproxy
 +
 +
==Logging in HAProxy aktivieren==
 +
 +
In der Datei /etc/haproxy/haproxy.cfg im defaults-Block ergänzen:
 +
 +
log stdout format raw local0
 +
option httplog
 +
==CrowdSec konfigurieren: journald-Zugriff auf HAProxy aktivieren==
 +
 +
;Datei /etc/crowdsec/acquis.yaml bearbeiten oder erstellen
 +
*nano /etc/crowdsec/acquis.yaml
 +
 +
;Inhalt ergänzen (neben ssh.service)
 +
<pre>
 +
journalctl_filter:
 +
  - _SYSTEMD_UNIT=ssh.service
 +
labels:
 +
  type: syslog
 +
 +
---
 +
 +
source: journalctl
 +
journalctl_filter:
 +
  - _SYSTEMD_UNIT=haproxy.service
 +
labels:
 +
  type: haproxy
 +
</pre>
 +
 +
==Dienste neu starten==
 +
*systemctl restart haproxy
 +
*systemctl restart crowdsec
 +
 +
==Angriff simulieren==
 +
*curl -k -H "Host: mail.art113.int"
 +
 +
*cscli metrics | grep haproxy
 +
<pre>
 +
| journalctl:journalctl-%s_SYSTEMD_UNIT=haproxy.service | 4          | 4            | -              | -                      | 4                |
 +
| crowdsecurity/haproxy-logs    | 4    | 4      | -        |
 +
</pre>
 +
 +
==Banns anzeigen==
 +
*cscli decisions list

Aktuelle Version vom 27. März 2025, 18:47 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

Haproxy und andere Dinge
  • apt install -y haproxy curl

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))

Integration von CrowdSec als WAF für HAProxy

CrowdSec installieren

CrowdSec-Hub aktualisieren und Grundregeln laden

  • cscli hub update
  • cscli collections install crowdsecurity/linux
  • cscli collections install crowdsecurity/base-http-scenarios
  • cscli collections install crowdsecurity/haproxy

Logging in HAProxy aktivieren

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

log stdout format raw local0
option httplog

CrowdSec konfigurieren: journald-Zugriff auf HAProxy aktivieren

Datei /etc/crowdsec/acquis.yaml bearbeiten oder erstellen
  • nano /etc/crowdsec/acquis.yaml
Inhalt ergänzen (neben ssh.service)
journalctl_filter:
  - _SYSTEMD_UNIT=ssh.service
labels:
  type: syslog

---

source: journalctl
journalctl_filter:
  - _SYSTEMD_UNIT=haproxy.service
labels:
  type: haproxy

Dienste neu starten

  • systemctl restart haproxy
  • systemctl restart crowdsec

Angriff simulieren

  • curl -k -H "Host: mail.art113.int"
  • cscli metrics | grep haproxy
| journalctl:journalctl-%s_SYSTEMD_UNIT=haproxy.service | 4          | 4            | -              | -                      | 4                 |
| crowdsecurity/haproxy-logs     | 4    | 4      | -        |

Banns anzeigen

  • cscli decisions list