Seven-day timeline: on the right, the 5,000 kept alerts cover only the last two and a half hours, at about 2,000 per hour; a real injection attempt at 06:00 is already evicted; after the fix, 34 alerts in six days
|

A noisy WAF can erase your security history: CRS false positives and a 5,000-alert ceiling

A web application firewall in observation mode, logging without blocking anything, looks harmless. If it’s wrong, nobody is stopped from working; at worst it makes a bit of noise. That’s what I thought until the day I found that the noise had erased everything else: for hours, my server kept no security alert other than…

A web application firewall in observation mode, logging without blocking anything, looks harmless. If it’s wrong, nobody is stopped from working; at worst it makes a bit of noise. That’s what I thought until the day I found that the noise had erased everything else: for hours, my server kept no security alert other than false positives about my own monitoring tool. A real intrusion attempt would have been recorded, then forgotten less than three hours later.

The setting: CrowdSec, its WAF and the OWASP CRS

On my servers, CrowdSec reads logs and bans addresses that misbehave. For a few weeks I’ve also used its AppSec component, an application firewall that inspects HTTP requests before they reach the applications. There are two families of rules. CrowdSec’s “virtual patching” rules block specific attacks on known vulnerabilities, with very few false positives. The OWASP CRS, ModSecurity’s historic Core Rule Set, is much broader: it looks for SQL injection, command execution or XSS patterns in everything that passes, and adds up an anomaly score.

Because the CRS is known for false positives, I enabled it out-of-band: the request always goes through, and if its score exceeds the threshold, CrowdSec creates an alert instead of blocking. It’s the careful way to measure before tightening. I planned to look at the alerts after a few weeks, fix the false positives, then switch to blocking.

The discovery: 5,016 alerts, all alike

While investigating something else entirely, I list the home server’s alerts. The usual command shows a table of recent CrowdSec alerts, all on the same target: my home-made monitoring tool, which receives every machine’s metrics and serves the dashboards. Nothing alarming at first sight, the table fits on one screen. Except the table is truncated: cscli alerts list shows only the fifty most recent alerts by default, without saying so. You need --limit 0 to see everything.

$ cscli alerts list | grep -c '^| [0-9]'
50
$ cscli alerts list --limit 0 -o json | jq length
5016

Five thousand and sixteen alerts. The number is suspicious in itself, because it’s nearly round. And the oldest dated from that very morning, 07:00. On a machine that has been running for months, an alert database that only goes back a few hours is a database being emptied somewhere.

The ceiling you don’t see

CrowdSec keeps its alerts in a local database, SQLite by default, and prunes it by two rules set in the flush section of its configuration. max_items sets the maximum number of alerts kept, 5,000 here; beyond that, the oldest go. max_age removes those older than a week. Both limits are healthy: without them the database would grow forever. But they have a consequence I hadn’t measured: the memory span isn’t a week, it’s the shorter of the two, and the first depends only on volume.

# /etc/crowdsec/config.yaml (excerpt)
db_config:
  flush:
    max_items: 5000     # keep at most 5,000 alerts
    max_age: 7d         # and none older than a week

To find out who was filling the database, I grouped the alerts by target host and by hour. jq extracts the target from each alert’s metadata and the hour from its creation time; uniq -c counts.

# who fills the database? group every stored alert by target host and by hour
cscli alerts list --limit 0 -o json | jq -r '
  .[] | [ (.events[0].meta[] | select(.key=="target_fqdn") | .value) // "?",
          (.created_at[0:13]) ] | @tsv' | sort | uniq -c | sort -rn | head
# on that morning: about 2,000 alerts per hour, every one on metrics.example.lan

About two thousand alerts an hour, all on the same host. At that rate, five thousand alerts is two and a half hours. Any older alert, however important, is pushed out by the flood. If someone had tried an injection on one of my sites at 06:00, I could have found it at 08:00, but no longer at 10:00. “Security history” no longer existed on that machine.

Seven-day timeline: on the right, the 5,000 kept alerts cover only the last two and a half hours, at about 2,000 per hour; a real injection attempt at 06:00 is already evicted; after the fix, 34 alerts in six days
When noise reaches 2,000 alerts an hour, max_items decides the memory span, not max_age.

Why monitoring looks like an attack

The false positives had two sources, both typical of a metrics tool. The first is remote write: each agent sends its measurements every few seconds with a POST to /api/v1/write, whose body is snappy-compressed protobuf. That’s binary. To the CRS, which reads the body as text, a run of random bytes sooner or later contains a quote, a semicolon or a suspicious keyword, and every rule family ends up firing. With a dozen agents, that’s a lot of requests.

The second source is the dashboards’ query language. An expression like 100 * (1 - avg by (instance) (rate(cpu_idle[5m]))) travels in the request’s URL. Nested parentheses, operators, words like by or count: to rules written against SQL injection and command execution, that’s exactly what an attack looks like. The dashboard refreshes every thirty seconds, and each panel sends its own query.

Choosing what to exclude, and why not everything

The first idea, turning the CRS off for the whole site, would have worked, but it also removes the protection if the site is ever exposed. So I did two things. First, this site is only reachable from the LAN and the VPN; it joins the list of hosts the WAF doesn’t inspect, like the other internal tools. Second, I wrote precise exclusions, which will be there if the site ever goes back behind the WAF.

CrowdSec AppSec exclusions are written in a configuration file with a pre_eval section, evaluated before the rules. Each entry has a filter, an expression on the request, and a list of actions. RemoveOutBandRuleByID disables one rule for the requests matching the filter; RemoveOutBandRuleByTag disables every rule carrying a tag, and the OWASP_CRS tag covers the whole CRS. For the binary write, parsing the body makes no sense: the whole CRS is skipped, but only for that path and method. For the dashboard queries, I removed only the rules that actually fired.

# CrowdSec AppSec: CRS exclusions, evaluated before the rules (pre_eval)
name: local/crs-exclusions
pre_eval:
  # remote-write: the body is snappy-compressed protobuf, every CRS family misfires
  - filter: 'IsOutBand == true && (req.Host == "metrics.example.lan" && req.Method == "POST" && req.URL.Path == "/api/v1/write")'
    apply:
      - RemoveOutBandRuleByTag("OWASP_CRS")
  # query endpoints: PromQL looks like SQL and shell to the CRS
  - filter: 'IsOutBand == true && (req.Host == "metrics.example.lan" && req.URL.Path in ["/api/v1/query", "/api/v1/query_range"])'
    apply:
      - RemoveOutBandRuleByID(932115)
      - RemoveOutBandRuleByID(942100)
      - RemoveOutBandRuleByID(942190)
      # ... nine rule IDs in total, each one seen in the alerts

To find those rules, read the IDs in the alerts’ events rather than guessing them. The following command counts them by path. Nine IDs came out, in the 932 (Unix command execution), 933 (PHP) and 942 (SQL injection) families.

# which CRS rules fire, on which path? (each event carries the uri and the rule)
cscli alerts list --limit 0 -o json | jq -r '
  .[] | .events[].meta | from_entries
      | [(.uri // "?" | sub("\\?.*"; "")), .rule_name // "?"] | @tsv' \
  | sort | uniq -c | sort -rn | head

The verification, before declaring victory

An exclusion that’s too broad is as dangerous as a false positive. So I checked two things, in that order, before even adding the bypass. First that the noise was gone: two minutes of real traffic, with agents writing and a dashboard open, produced no new alert. Then that the WAF still saw real attacks elsewhere: a classic SQL injection sent to another site on the same server did create a sql_injection alert.

# 1. two minutes of real agent traffic and dashboard queries, then count new alerts
before=$(cscli alerts list --limit 0 -o json | jq length); sleep 120
after=$(cscli alerts list --limit 0 -o json | jq length); echo $((after - before))
0
# 2. the WAF still works elsewhere: a classic SQL injection on another site
curl -s -o /dev/null -w '%{http_code}\n' "https://wiki.example.lan/?id=1%27%20OR%201=1--"
cscli alerts list -l 1    # a new out-of-band sql_injection alert on wiki.example.lan

Six days later, the database holds thirty-four alerts in total, against five thousand in two and a half hours. It covers the whole week max_age allows again, and every line is worth reading.

Requests from agents and dashboards, coming from the LAN or VPN, pass the bypassed host to the application; in reserve, two pre_eval exclusions: the whole CRS removed for POST /api/v1/write, nine rules removed for the queries; verified by zero alerts in two minutes and an SQL injection still detected elsewhere
The bypass solves it today; the precise exclusions protect the day the host goes back behind the WAF.

What I take away

Observation mode isn’t free of consequences. It blocks nobody, but it writes, and what it writes fills a database of limited size. A frequent false positive doesn’t only cost attention; it shortens the whole system’s memory. Alert volume is therefore a metric to watch in its own right, even when no single alert is serious.

Two reflexes follow. First: never draw a conclusion about volume or timing from a command that silently truncates, and always add --limit 0 to cscli alerts list. Second: look at the date of the oldest alert. If it’s much more recent than max_age, max_items is at work, and a noise source is erasing everything else.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *