1. The Hub and collections #
Ready-to-use content.
What is a collection? #
A collection groups what is needed to protect a service: parsers, scenarios and sometimes other collections. Install it rather than assembling the pieces by hand. The Hub lists them.
sudo cscli hub update
sudo cscli collections install crowdsecurity/nginx
sudo cscli collections list
sudo cscli scenarios list
sudo cscli parsers list
sudo systemctl reload crowdsec
# Mises à jour régulières
sudo cscli hub update && sudo cscli hub upgrade| Collection | Protects |
|---|---|
crowdsecurity/linux | Linux base, with crowdsecurity/sshd |
crowdsecurity/nginx | Nginx |
crowdsecurity/traefik | Traefik |
crowdsecurity/base-http-scenarios | Scanners, probes, HTTP brute force |
crowdsecurity/http-cve | Exploitation of known flaws |
crowdsecurity/whitelist-good-actors | Excludes known legitimate actors |
2. Parsers #
Understanding each line.
Three stages #
Each line goes through three stages: s00-raw extracts the message, s01-parse recognizes the service, s02-enrich adds date, country or HTTP fields. The result is an event, with fields such as evt.Meta.source_ip.
cscli explain: the essential tool #
Why did this line trigger nothing? cscli explain shows its path. 🟢: the parser succeeded. 🔴: it does not apply to this line.
sudo cscli explain --log "Nov 7 08:58:22 srv sshd[9]: Failed password for root from 203.0.113.70 port 5 ssh2" --type syslogline: Nov 7 08:58:22 srv sshd[9]: Failed password for root from 203.0.113.70 port 5 ssh2
├ s00-raw
| └ 🟢 crowdsecurity/syslog-logs (+12 ~9)
├ s01-parse
| ├ 🔴 crowdsecurity/nginx-logs
| └ 🟢 crowdsecurity/sshd-logs (+9 ~1)
├ s02-enrich
| ├ 🟢 crowdsecurity/dateparse-enrich (+2 ~2)
| ├ 🟢 crowdsecurity/geoip-enrich (+9)
| └ 🔴 crowdsecurity/http-logs
├-------- parser success 🟢
├ Scenarios
├ 🟢 crowdsecurity/ssh-bf
├ 🟢 crowdsecurity/ssh-slow-bf
└ 🟢 crowdsecurity/ssh-time-based-bf3. Scenarios #
Recognizing a behavior.
The leaky bucket #
A burst overflows quickly. A visitor making an occasional mistake never fills their bucket: this is what separates an attack from human error.
| Type | Triggers when… |
|---|---|
leaky | The bucket overflows, the most common case |
trigger | On the first matching event |
counter | A count reached over a fixed duration |
conditional | A condition on the bucket content |
Writing your scenario #
Let us detect brute force on our login form. Create /etc/crowdsec/scenarios/local-login-bf.yaml:
type: leaky
name: local/login-bf
description: "Detects brute force on the login form"
filter: "evt.Meta.service == 'http' && evt.Parsed.verb == 'POST' && evt.Meta.http_path == '/login' && evt.Meta.http_status == '401'"
groupby: evt.Meta.source_ip
capacity: 4
leakspeed: 10s
blackhole: 1m
labels:
remediation: true
service: http
behavior: http:bruteforce
label: "Brute force on /login"| Field | Role |
|---|---|
filter | Which events count |
groupby | One bucket per value, here per IP |
capacity | Bucket size |
leakspeed | Rate at which it empties |
blackhole | Silence after an overflow, to avoid duplicates |
labels.remediation | true: the alert can produce a block |
sudo systemctl reload crowdsec
sudo cscli scenarios list
sudo cscli alerts listTesting safely: simulation #
In simulation, the scenario creates an alert and a decision marked (simul), which bouncers do not enforce. Ideal for measuring false positives.
sudo cscli simulation enable local/login-bf
sudo systemctl reload crowdsec
sudo cscli simulation status
sudo cscli decisions list
# Ip:192.0.2.77 | local/login-bf | (simul)ban
sudo cscli simulation disable local/login-bfSources #
My progress
Sign in to track your progress and take notes. Sign in
Recommended Articles
CrowdSec: understanding the collaborative firewall
What CrowdSec is, how it detects and blocks attacks: Security Engine, parsers, scenarios, Local A...
CrowdSec in production: best practices
Good habits for running CrowdSec in production: LAPI, keys, false positives, database, upgrades a...
Decisions, profiles, allowlists and AppSec in CrowdSec
Manage decisions with cscli, adapt block duration and type with profiles, avoid false positives w...
CrowdSec bouncers: Cloudflare, network devices, Kubernetes and custom bouncer
Block at the CDN with Cloudflare Workers, feed pfSense or MikroTik with Blocklist Mirror, protect...
Installing and configuring CrowdSec: packages, Docker, acquisition
Install CrowdSec with packages or Docker, understand its files, declare the logs to read, enroll ...
CrowdSec bouncers: principles and firewall bouncer
Understanding CrowdSec bouncers: where to block, live and stream modes, API keys, decisions API, ...
CrowdSec observability: banned IPs, blocked attacks, Prometheus and Grafana
Monitoring CrowdSec: cscli metrics, banned IPs, detected attacks, volume blocked by bouncers, Pro...
CrowdSec or Fail2ban: what are the differences?
Comparing CrowdSec and Fail2ban: detection, blocking, sharing, performance, multi-server, and how...
Protecting Traefik with CrowdSec: the bouncer plugin
Setting up the CrowdSec bouncer in Traefik: plugin, middleware, stream and live modes, real IP be...