Ana içeriğe geç
Kategoriye Dön

CrowdSec Kurulumu: Topluluk Destekli Güvenlik Motoru

CrowdSec kurulumu, bouncer yapılandırması, saldırı algılama, IP engelleme, dashboard, koleksiyon ve senaryo yönetimi.

Okuma süresi: 15 dk Monitoring
crowdsecgüvenlikidssaldırı algılamafirewalldockertopluluk

İçindekiler

CrowdSec Kurulumu: Topluluk Destekli Güvenlik Motoru

CrowdSec, topluluk destekli açık kaynaklı bir güvenlik motorudur. Log analizi yaparak saldırıları tespit eder ve topluluk tarafından paylaşılan tehdit istihbaratı ile proaktif koruma sağlar. Fail2ban'ın modern ve ölçeklenebilir alternatifi olarak düşünülebilir.

CrowdSec Nedir?

CrowdSec'in temel özellikleri:

  • Log Analizi: Sistem loglarını gerçek zamanlı analiz etme
  • Topluluk İstihbaratı: Küresel tehdit veritabanı paylaşımı
  • Bouncer Sistemi: Farklı katmanlarda engelleme (firewall, Nginx, Cloudflare)
  • Senaryo Tabanlı: YAML tabanlı saldırı senaryoları
  • Koleksiyonlar: Hazır güvenlik kural paketleri
  • Dashboard: Web tabanlı yönetim paneli
  • API Tabanlı: REST API ile entegrasyon
  • Hafif: Düşük kaynak tüketimi

Kurulum

Paket Yöneticisi ile Kurulum

hljs bash
# CrowdSec repository ekle
curl -s https://install.crowdsec.net | sudo sh

# CrowdSec kurulumu
sudo apt install crowdsec -y

# Firewall bouncer kurulumu
sudo apt install crowdsec-firewall-bouncer-iptables -y

# Servis durumu
sudo systemctl status crowdsec
sudo systemctl status crowdsec-firewall-bouncer

Docker ile Kurulum

hljs yaml
# docker-compose.yml
version: '3.8'
services:
  crowdsec:
    image: crowdsecurity/crowdsec:latest
    container_name: crowdsec
    restart: unless-stopped
    ports:
      - "8080:8080"    # API
      - "6060:6060"    # Prometheus metrics
    volumes:
      - crowdsec_config:/etc/crowdsec
      - crowdsec_data:/var/lib/crowdsec/data
      - /var/log:/var/log:ro
      - /var/log/nginx:/var/log/nginx:ro
    environment:
      - COLLECTIONS=crowdsecurity/linux crowdsecurity/nginx crowdsecurity/sshd
      - GID=${GID-1000}

volumes:
  crowdsec_config:
  crowdsec_data:
hljs bash
docker compose up -d

Temel Yapılandırma

Koleksiyon Yönetimi

Koleksiyonlar, belirli bir servis için parser, senaryo ve postoverflow kurallarını içeren paketlerdir:

hljs bash
# Mevcut koleksiyonları listele
sudo cscli collections list

# Koleksiyon kur
sudo cscli collections install crowdsecurity/linux
sudo cscli collections install crowdsecurity/nginx
sudo cscli collections install crowdsecurity/sshd
sudo cscli collections install crowdsecurity/apache2
sudo cscli collections install crowdsecurity/wordpress
sudo cscli collections install crowdsecurity/http-cve

# Koleksiyon güncelle
sudo cscli collections upgrade crowdsecurity/linux

# Tüm hub öğelerini güncelle
sudo cscli hub update
sudo cscli hub upgrade

Senaryo Yönetimi

Senaryolar, belirli saldırı kalıplarını tanımlayan YAML dosyalarıdır:

hljs bash
# Senaryoları listele
sudo cscli scenarios list

# Senaryo kur
sudo cscli scenarios install crowdsecurity/ssh-bf
sudo cscli scenarios install crowdsecurity/http-crawl-non_statics
sudo cscli scenarios install crowdsecurity/http-bad-user-agent
sudo cscli scenarios install crowdsecurity/http-probing

# Senaryo detayı
sudo cscli scenarios inspect crowdsecurity/ssh-bf

Parser Yönetimi

hljs bash
# Parser listele
sudo cscli parsers list

# Parser kur
sudo cscli parsers install crowdsecurity/sshd-logs
sudo cscli parsers install crowdsecurity/nginx-logs

Bouncer Yapılandırması

Firewall Bouncer (iptables/nftables)

hljs bash
# Firewall bouncer kur
sudo apt install crowdsec-firewall-bouncer-iptables -y

# Yapılandırma dosyası
sudo nano /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
hljs yaml
# /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
mode: iptables
pid_dir: /var/run/
update_frequency: 10s
daemonize: true
log_mode: file
log_dir: /var/log/
log_level: info
log_compression: true
log_max_size: 100
log_max_backups: 3
log_max_age: 30
api_url: http://localhost:8080/
api_key: YOUR_API_KEY
disable_ipv6: false
deny_action: DROP
deny_log: true
deny_log_prefix: "crowdsec: "
blacklists_ipv4: crowdsec-blacklists
blacklists_ipv6: crowdsec6-blacklists

Nginx Bouncer

hljs bash
# Nginx bouncer kur
sudo apt install crowdsec-nginx-bouncer -y

# API key oluştur
sudo cscli bouncers add nginx-bouncer

# Yapılandırma
sudo nano /etc/crowdsec/bouncers/crowdsec-nginx-bouncer.conf
hljs ini
API_URL=http://localhost:8080/
API_KEY=YOUR_BOUNCER_API_KEY
CACHE_EXPIRATION=1
UPDATE_FREQUENCY=10
BAN_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/ban.html
CAPTCHA_TEMPLATE_PATH=/var/lib/crowdsec/lua/templates/captcha.html

Docker Bouncer

hljs yaml
# docker-compose.yml'e ekle
services:
  bouncer-firewall:
    image: crowdsecurity/crowdsec-firewall-bouncer-nftables:latest
    container_name: crowdsec-firewall-bouncer
    restart: unless-stopped
    network_mode: host
    cap_add:
      - NET_ADMIN
      - NET_RAW
    volumes:
      - ./crowdsec-firewall-bouncer.yaml:/etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
    depends_on:
      - crowdsec

Karar Yönetimi (Decisions)

hljs bash
# Aktif kararları listele
sudo cscli decisions list

# Manuel IP engelle
sudo cscli decisions add --ip 1.2.3.4 --reason "Manuel engelleme" --type ban --duration 24h

# IP aralığı engelle
sudo cscli decisions add --range 1.2.3.0/24 --reason "Subnet engelleme" --type ban

# Karar kaldır
sudo cscli decisions delete --ip 1.2.3.4

# Tüm kararları temizle
sudo cscli decisions delete --all

Alert Yönetimi

hljs bash
# Alertleri listele
sudo cscli alerts list

# Alert detayı
sudo cscli alerts inspect ALERT_ID

# Alertleri temizle
sudo cscli alerts delete --all

CrowdSec Console (Dashboard)

CrowdSec Console, web tabanlı yönetim panelidir:

hljs bash
# Console'a kayıt ol
sudo cscli console enroll YOUR_ENROLLMENT_KEY

# Kayıt sonrası servisi yeniden başlat
sudo systemctl restart crowdsec

Dashboard'a erişim: https://app.crowdsec.net

Dashboard özellikleri:

  • Gerçek zamanlı saldırı haritası
  • Engellenen IP'ler ve istatistikler
  • Senaryo ve koleksiyon yönetimi
  • Bouncer durumu izleme
  • Alert geçmişi

Özel Senaryo Oluşturma

hljs yaml
# /etc/crowdsec/scenarios/custom-brute-force.yaml
type: leaky
name: custom/brute-force
description: "Özel brute force algılama"
filter: "evt.Meta.log_type == 'ssh_failed-auth'"
groupby: evt.Meta.source_ip
capacity: 5
leakspeed: 10m
blackholeduration: 4h
labels:
  service: ssh
  type: brute_force
  remediation: true
hljs bash
# Yapılandırmayı yeniden yükle
sudo systemctl reload crowdsec

Whitelist Yapılandırması

hljs yaml
# /etc/crowdsec/parsers/s02-enrich/whitelist.yaml
name: custom/whitelist
description: "Güvenilir IP'ler"
whitelist:
  reason: "Güvenilir IP adresleri"
  ip:
    - "192.168.1.0/24"
    - "10.0.0.0/8"
    - "1.2.3.4"
  expression:
    - evt.Meta.source_ip startsWith '172.16.'

Prometheus Metrikleri

CrowdSec Prometheus metrikleri sunar:

hljs bash
# Metrikleri görüntüle
sudo cscli metrics

# Prometheus endpoint
curl http://localhost:6060/metrics

Grafana dashboard'u için: Dashboard ID 15620

Güncelleme

hljs bash
# CrowdSec güncelle
sudo apt update
sudo apt upgrade crowdsec crowdsec-firewall-bouncer-iptables

# Hub güncelle
sudo cscli hub update
sudo cscli hub upgrade

# Docker güncelleme
docker compose pull
docker compose up -d

Log ve Debug

hljs bash
# CrowdSec logları
sudo tail -f /var/log/crowdsec.log

# Bouncer logları
sudo tail -f /var/log/crowdsec-firewall-bouncer.log

# Debug modu
sudo cscli config show
sudo cscli explain --file /var/log/auth.log --type syslog

REXE sunucularınızda CrowdSec kurarak topluluk destekli güvenlik koruması sağlayabilirsiniz. Fail2ban'dan farklı olarak CrowdSec, küresel tehdit istihbaratı paylaşımı sayesinde henüz sunucunuza saldırmamış IP'leri bile proaktif olarak engelleyebilir.