Skip to content

Intrusion Prevention: CrowdSec & nftables Threat Intelligence

Created: 2026-11-10 Updated: 2026-11-10

Management Summary: Traditional host-based intrusion prevention utilities such as Fail2ban evaluate log streams solely in isolation on a single machine and operate purely reactively after attacks have already begun. Modern distributed botnets bypass single-host tools with ease by coordinating tens of thousands of rotating IP addresses across prolonged time windows ("low and slow"). CrowdSec redefines this defensive paradigm through a high-performance Security Engine implemented in Go, pairing behavioral log parsing with worldwide collaborative threat intelligence: when a malicious IP address is flagged anywhere in the world, it is preemptively blocked across all participating infrastructure nodes. This guide details the engine and API architecture (LAPI/CAPI), leaky-bucket scenario design, atomic line-rate remediation via native nftables kernel sets, whitelisting, and the operational incident runbook.

  • Fail2ban vs. CrowdSec


    Why isolated rule evaluation fails against modern botnets and how collective threat intelligence neutralizes attacks at inception.

  • Engine & API Architecture


    Modular separation of concerns: local Security Engine (parsers & scenarios), Local API (LAPI), and Central API (CAPI).

  • Hub, Collections & Scenarios


    Installing verified detection rules for SSH brute-force, Nginx web requests, reverse proxies, and port scans using cscli.

  • Remediation with nftables Bouncer


    Automated, line-rate blocking of malicious IP addresses in the Linux kernel using native nftables sets with zero CPU penalty.

  • Multi-Server & SIEM Integration


    Centralized fleet detection: deploy lightweight agents across servers reporting telemetry to a single central LAPI instance.

  • Whitelisting & Alert Monitoring


    Prevent false positives with clean whitelists (parsers/s02-enrich/), inspect active bans with cscli alerts, and incident runbooks.


1. Fail2ban vs. CrowdSec: Limitations of Traditional Host-Only Prevention

For two decades, fail2ban served as the standard defensive tool against SSH brute-force attacks. In modern enterprise production environments, however, Fail2ban encounters fundamental architectural limits:

  1. Reactive Single-Host Isolation: Fail2ban learns of an attacker only after they have already initiated attacks. There is zero knowledge sharing between machines.
  2. CPU Exhaustion During Log Spikes: Fail2ban processes log lines sequentially using Python regular expressions. During high-throughput scans or HTTP floods, CPU usage spikes drastically.
  3. Powerless Against Distributed Botnets: An adversary controlling 5,000 distinct IP addresses executing a single authentication attempt per IP every two hours will never cross a threshold of maxretry = 5.
%%{init: {'flowchart': {'wrappingWidth': 350}}}%%
flowchart TB
    Logs["Server Log Streams<br/>(journald, auth.log, nginx)"] ==> Parser["CrowdSec Parser Engine<br/>(Grok / Go Streaming Pipeline)"]
    Parser --> Scenarios["Scenario Evaluation<br/>(Leaky Bucket Algorithm)"]
    Scenarios -->|"Threshold Exceeded"| LAPI["Local API (LAPI)<br/>Generates Alert & Decision"]
    LAPI --> Bouncer["nftables Bouncer<br/>(Atomic Kernel Set Drop)"]
    LAPI -.->|"Anonymized Telemetry"| CAPI["CrowdSec CAPI<br/>(Global Community Cloud)"]
    CAPI -.->|"Consensus Blocklist Updates"| LAPI

The Collaborative CrowdSec Advantage

CrowdSec reverses the attacker advantage: when a botnet scans a honeypot or production node in Tokyo, the Central API (CAPI) validates the malicious behavior through consensus algorithms and distributes the offending IP address within minutes to all participating CrowdSec instances globally. The incoming attack on your infrastructure is neutralized before the adversary's first packet touches your firewall.


2. CrowdSec Core Architecture: Security Engine, LAPI & CAPI

CrowdSec is architected into three distinct layers, cleanly decoupling detection, decision-making, and enforcement:

  1. Security Engine (Agent): Ingests raw logs, normalizes them into structured event objects via Grok-based parsers, and forwards them into active detection scenarios.
  2. Local API (LAPI): The local decision authority. LAPI persists alerts and enforcement decisions in a local SQLite or PostgreSQL database and serves remediation bouncers over an authenticated REST API.
  3. Central API (CAPI): The global cloud service. CAPI distributes verified community blocklists and aggregates anonymized attack telemetry (IP address, timestamp, and scenario name only—never log contents or sensitive payloads).

Configuring Log Data Sources in /etc/crowdsec/acquis.yaml

Configure which log sources the engine ingests:

# /etc/crowdsec/acquis.yaml
# Monitor traditional authentication logs for SSH events
filenames:
  - /var/log/auth.log
labels:
  type: syslog
---
# Monitor Nginx access logs
filenames:
  - /var/log/nginx/*.log
labels:
  type: nginx
---
# Ingest native systemd journal units (Debian 12+ / Bookworm)
source: journalctl
journalctl_filter:
  - _SYSTEMD_UNIT=ssh.service
labels:
  type: syslog

3. Installation & Hub Ecosystem: Collections, Parsers & Scenarios

On Debian and Ubuntu systems, CrowdSec is installed from its official package repository:

# Add official repository and install the security engine
curl -s https://packagecloud.io/install/repositories/crowdsecurity/crowdsec/script.deb.sh | sudo bash
sudo apt-get install crowdsec

# Verify installed components and hub status
sudo cscli hub list

Installing Hub Collections

A Collection bundles all required parsers, scenarios, and post-overflow rules for a particular application stack:

# Core collections for Linux base OS and OpenSSH
sudo cscli collections install crowdsecurity/linux
sudo cscli collections install crowdsecurity/sshd

# Protection rules for Nginx web servers and HTTP CVE exploits
sudo cscli collections install crowdsecurity/nginx

# Reload the daemon to compile and apply new rules
sudo systemctl reload crowdsec

Anatomy of a Scenario (The Leaky Bucket Algorithm)

Scenarios define the threshold criteria for malicious behavior using the leaky bucket algorithm:

# Example: /etc/crowdsec/scenarios/ssh-bf.yaml
type: leaky
name: crowdsecurity/ssh-bf
description: "Detects SSH brute-force attacks"
filter: "evt.Meta.log_type == 'ssh_failed-auth'"
groupby: evt.Meta.source_ip
capacity: 5        # Bucket holds 5 failed attempts
leakspeed: 10s     # 1 attempt leaks out every 10 seconds
blackhole: 1m      # Suppress secondary duplicate alerts for 1 minute
remediation: true  # Triggers an active remediation decision

If an IP exceeds 5 failed attempts before the bucket leaks out, the bucket overflows, prompting LAPI to issue an active enforcement decision.


4. High-Speed Remediation with the nftables Bouncer

The CrowdSec engine evaluates log streams; it does not block packets directly. Enforcing defensive blocks requires a Remediation Bouncer.

Legacy tools insert a separate firewall rule for every blocked IP (iptables -A INPUT -s ... -j DROP). With 10,000 banned addresses, packet processing degrades severely because every network packet must traverse 10,000 rules sequentially.

The nftables bouncer leverages native kernel sets providing $O(1)$ constant-time lookup performance. Whether 10 or 100,000 IPs are banned, CPU overhead remains virtually unmeasurable!

1. Installing the Bouncer

# Install the native nftables firewall bouncer
sudo apt-get install crowdsec-firewall-bouncer-nftables

# Verify bouncer registration with LAPI
sudo cscli bouncers list

2. Configuration in /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml

# /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml
api_url: http://127.0.0.1:8080/
api_key: <automatically_generated_api_key>
mode: nftables
update_frequency: 10s
blacklists_ipv4: crowdsec_blacklists
blacklists_ipv6: crowdsec6_blacklists
# Drop traffic silently without ICMP unreachable responses
deny_action: DROP

3. Inspecting Live Kernel Sets

# Inspect the active in-kernel nftables set containing banned IPs
sudo nft list set inet crowdsec crowdsec_blacklists

5. Decisions Management, Whitelisting & Metrics

The cscli utility provides complete operational command over active bans and alerts.

1. Querying Decisions and Alerts

# Review recent alerts triggered across the system
sudo cscli alerts list

# Inspect all currently enforced active IP bans
sudo cscli decisions list

# Manually ban a suspicious IP address for 24 hours
sudo cscli decisions add --ip 198.51.100.42 --duration 24h --reason "Manual triage ban"

# Unban an IP address immediately
sudo cscli decisions delete --ip 198.51.100.42

2. Configuring Administrator Whitelists

To eliminate accidental lockouts of corporate jump hosts, monitoring systems, or administrative VPN gateways, configure an enrichment parser whitelist:

Create /etc/crowdsec/parsers/s02-enrich/01-admin-whitelist.yaml:

# /etc/crowdsec/parsers/s02-enrich/01-admin-whitelist.yaml
name: enterprise/admin-whitelist
description: "Whitelists internal corporate subnets and admin VPNs"
whitelist:
  reason: "Corporate Management Infrastructure"
  ip:
    - "127.0.0.1"
    - "::1"
  cidr:
    - "192.0.2.0/24"     # Example: Corporate Office
    - "198.51.100.0/28"  # Example: Administrative VPN Gateway

Reload the engine:

sudo systemctl reload crowdsec

3. Reviewing Engine Metrics with cscli metrics

# Display processing throughput across parsers, scenarios, and log files
sudo cscli metrics

6. Enterprise Operations, Monitoring & Emergency Runbook

Note for Deployments Behind Reverse Proxies or CDNs (Cloudflare)

When inspecting logs behind Cloudflare or an edge load balancer, the web server default configuration sees only proxy IP addresses. Banning a CDN edge address will inadvertently drop traffic for all legitimate users!

Solution: Ensure Nginx utilizes ngx_http_realip_module (set_real_ip_from ...; real_ip_header CF-Connecting-IP;) so that client IP addresses are properly logged. Also install the crowdsecurity/http-cve collection.

Emergency Triage Runbook

Scenario Immediate Action Permanent Resolution
Administrator Accidentally Banned Execute sudo cscli decisions delete --ip <admin_ip> from console. Immediately append administrative IP/subnet to 01-admin-whitelist.yaml.
Bouncer Ceases Blocking Check service: sudo systemctl status crowdsec-firewall-bouncer. Verify API key with cscli bouncers list. Synchronize API key in /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml.
Log Parsing Failures Run sudo cscli explain --log "<log_line>" --type nginx Install missing parsers via cscli hub or adjust custom Grok patterns.

With CrowdSec and the nftables bouncer deployed, your Linux server participates actively in a collective global defense fabric: adversaries are preemptively neutralized at line rate without imposing CPU penalties.