RousselTMLEARNING

Article · CrowdSec: From Discovery to Expertise

Collections, parsers and scenarios

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.

A collection groups parsers and scenarios; a line goes through s00-raw, s01-parse and s02-enrich

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
CollectionProtects
crowdsecurity/linuxLinux base, with crowdsecurity/sshd
crowdsecurity/nginxNginx
crowdsecurity/traefikTraefik
crowdsecurity/base-http-scenariosScanners, probes, HTTP brute force
crowdsecurity/http-cveExploitation of known flaws
crowdsecurity/whitelist-good-actorsExcludes 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 syslog
line: 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-bf

3. Scenarios #

Recognizing a behavior.

The leaky bucket #

Leaky bucket: capacity of 4, one drop leaves every 10 seconds, overflow triggers an alert

A burst overflows quickly. A visitor making an occasional mistake never fills their bucket: this is what separates an attack from human error.

TypeTriggers when…
leakyThe bucket overflows, the most common case
triggerOn the first matching event
counterA count reached over a fixed duration
conditionalA 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"
FieldRole
filterWhich events count
groupbyOne bucket per value, here per IP
capacityBucket size
leakspeedRate at which it empties
blackholeSilence after an overflow, to avoid duplicates
labels.remediationtrue: the alert can produce a block
sudo systemctl reload crowdsec
sudo cscli scenarios list
sudo cscli alerts list

Testing 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-bf

Sources #

📄 CrowdSec collections, parsers and scenarios →

My progress

  • ⏱ Estimated time : ≈ 9 min

Sign in to track your progress and take notes. Sign in

💬 Ask a question

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...

Support us

♥ SUPPORT US

Support RousselTM Learning

Courses, articles, labs and certificates stay free with no intrusive ads. A voluntary contribution, of any amount you choose, pays for hosting, lab environments and new content.

Contribute with PayPal Any amount · card or PayPal accountLearn more
QR code PayPal
Or scan this QR code with your phone

Thank you, every contribution counts!