CrowdSec setup
Architecture Overview
Section titled “Architecture Overview”flowchart LR A[System / App Logs] --> B[CrowdSec Agent / LAPI] B -->|Analyzes Patterns| C[Scenario Engine] C -->|Trigger Decision| D[Local Remediation Bouncer] D -->|Block / Captcha| E[Iptables / Nginx / Cloudflare] B <-->|Federated Blocklists| F[CrowdSec Central API / CAPI]- CrowdSec Agent & Local API (LAPI): Parses logs, correlates events, matches scenarios, and issues remediation decisions.
- Bouncers (Remediation Components): Standalone plugins that enforce decisions at the firewall (nftables/iptables), reverse proxy (Nginx/Traefik), or CDN level (Cloudflare).
- Central API (CAPI): Synchronizes global community blocklists and pushes verified threat telemetry.
Installation & Setup
Section titled “Installation & Setup”-
Add Repository and Install Agent
Terminal window curl -s https://install.crowdsec.net | sudo bashsudo apt-get install crowdsec -yTerminal window curl -s https://install.crowdsec.net | sudo bashsudo dnf install crowdsec -y -
Verify Acquired Log Sources CrowdSec automatically discovers local services (Nginx, SSH, systemd):
Terminal window sudo cscli collections listsudo cscli metrics -
Install Firewall Remediation Bouncer Install the kernel firewall bouncer (nftables or iptables):
Terminal window sudo apt-get install crowdsec-firewall-bouncer-iptables -yThe bouncer registers with LAPI and creates an automated kernel drop rule for blocked IPs.
Installing Essential Collections
Section titled “Installing Essential Collections”Collections bundle parsers and behavioral attack scenarios:
# SSH brute force protectionsudo cscli collections install crowdsecurity/sshd
# Web application protection (Nginx, HTTP crawl, bad user agents, CVE scanners)sudo cscli collections install crowdsecurity/nginxsudo cscli collections install crowdsecurity/http-cvesudo cscli collections install crowdsecurity/base-http-scenarios
# Reload crowdsec to activatesudo systemctl reload crowdsecCLI Management & Inspection
Section titled “CLI Management & Inspection”Common administrative commands with cscli:
# View active ban decisionssudo cscli decisions list
# Manually ban an abusive IP for 24 hourssudo cscli decisions add --ip 198.51.100.42 --duration 24h --reason "targeted scanning"
# Remove a bansudo cscli decisions delete --ip 198.51.100.42
# Check alerts and telemetrysudo cscli alerts listIntegrating with Reverse Proxies (Nginx Bouncer)
Section titled “Integrating with Reverse Proxies (Nginx Bouncer)”To return custom 403 or challenge pages rather than dropping TCP connections at the firewall:
sudo apt-get install crowdsec-nginx-bouncer -yThis installs Lua-based integration directly into /etc/nginx/conf.d/crowdsec.conf, intercepting HTTP requests before they reach application upstreams.
