CrowdSec: Collaborative Protection Against Attacks

CrowdSec is an open source security system that analyzes your server logs, detects malicious behavior and automatically blocks IPs. Unlike Fail2ban, it shares information about attackers with the entire community: if one IP attacks a CrowdSec server anywhere in the world, it gets preventively blocked on all others.

02

Installation

bash
# Add CrowdSec repository
curl -s https://packagecloud.io/install/repositories/crowdsec/crowdsec/script.deb.sh | bash

# Install CrowdSec
apt install crowdsec -y

# Check status
systemctl status crowdsec
cscli version
03

Bouncer (The Component That Actually Blocks IPs)

CrowdSec detects attacks but delegates blocking to a "bouncer". The most common is the firewall bouncer:

bash
# Install bouncer for iptables/nftables
apt install crowdsec-firewall-bouncer-iptables -y

# Verify it's active
systemctl status crowdsec-firewall-bouncer
04

Default Installed Scenarios

CrowdSec automatically installs scenarios to detect:

bash
# View active scenarios
cscli scenarios list

# Add additional scenarios
cscli scenarios install crowdsecurity/nginx-req-limit-exceeded
cscli scenarios install crowdsecurity/http-crawl-non_statics
cscli scenarios install crowdsecurity/http-bad-user-agent
  • SSH brute force
  • HTTP brute force
  • Port scan
  • Path traversal
  • WordPress exploit
05

Add Log Sources

bash
# View active collections (bundle of parser + scenarios)
cscli collections list

# Install collection for Nginx
cscli collections install crowdsecurity/nginx

# Install collection for Apache
cscli collections install crowdsecurity/apache2

# Install collection for WordPress
cscli collections install crowdsecurity/wordpress

# After adding collections, restart
systemctl restart crowdsec

Make sure log paths are configured in /etc/crowdsec/acquis.yaml:

yaml
# /etc/crowdsec/acquis.yaml
    - /var/log/nginx/access.log
    - /var/log/nginx/error.log
  labels:
    type: nginx

    - /var/log/auth.log
  labels:
    type: syslog
  • filenames:
  • filenames:
06

Daily Commands

bash
# View active bans
cscli decisions list

# View detected alerts (attacks)
cscli alerts list

# Manually ban an IP
cscli decisions add --ip 1.2.3.4 --reason "test" --duration 24h

# Remove a ban
cscli decisions delete --ip 1.2.3.4

# Permanent whitelist of an IP
cscli whitelists add --ip 1.2.3.4 --reason "Office IP"

# Statistics
cscli metrics
07

Community Blocklist (Known Malicious IPs)

By registering for free at app.crowdsec.net and linking your instance, you get access to the community's global blocklist:

bash
# Link your instance (generate key at app.crowdsec.net)
cscli console enroll ENROLLMENT_KEY

# Restart
systemctl restart crowdsec

The community blocklist includes millions of IPs known for malicious activity (scanners, botnets, bruteforcers). It's updated in real-time and free for personal use.

08

Local Web Dashboard

bash
# Install local web dashboard (optional)
docker run -d \
  --name crowdsec-dashboard \
  -e GIN_MODE=release \
  -e CROWDSEC_LAPI_KEY=$(cscli bouncers add dashboard -o raw) \
  -p 3000:3000 \
  --network host \
  crowdsecurity/crowdsec-dashboard
09

CrowdSec vs Fail2ban

CrowdSecFail2ban
Threat Intelligence✅ Global community❌ Local only
Performance✅ Much faster⚠️ Slow on large logs
Configuration✅ Simple YAML⚠️ Complex regex
Multi-server✅ Native❌ Not supported
False PositivesLowHigher
Project AgeRecent (2020)Mature (2004)

CrowdSec is the recommended replacement for new installations. If you already have Fail2ban configured, you can keep it: but start new servers with CrowdSec.

DeluxHost, fondata nel 2023, offre soluzioni di hosting di alta qualità per diverse esigenze digitali. Forniamo hosting condiviso, VPS e server dedicati con sicurezza avanzata e datacenter globali.

© DeluxHost, Tutti i diritti riservati. | Partita IVA: IT17734661006
Tutti i sistemi operativi