Skip to main content
Security Engine version:
Version: v1.6

Expression

Let's whitelist a specific user-agent (of course, it's just an example, don't do this in production !).

Since we are using data that is present from the parsing stage we can do this within Parsing Whitelist level. Please see introduction for your OS specific paths.

YAML
name: "my/whitelist" ## Must be unique
description: "Whitelist events from private ipv4 addresses"
whitelist:
reason: "private ipv4 ranges"
expression:
- evt.Parsed.http_user_agent == 'MySecretUserAgent'
Reload CrowdSec
SHReload CrowdSec
sudo systemctl reload crowdsec

For the record, I edited nikto's configuration to use 'MySecretUserAgent' as user-agent, and thus :

SH
nikto -host myfqdn.com
SH
tail -f /var/log/crowdsec.log

CrowdSec will inform you some lines have been discarded because they are whitelisted by the expression.

How can I find which data is present from parsing stage?โ€‹

You can use cscli explain to generate output from a given log line or log file.

For example:

SH
sudo cscli explain --log '5.5.8.5 - - [04/Jan/2020:07:25:02 +0000] "GET /.well-known/acme-challenge/FMuukC2JOJ5HKmLBujjE_BkDo HTTP/1.1" 404 522 "-" "MySecretUserAgent"' --type nginx -v
Output:
SH
line: 5.5.8.5 - - [04/Jan/2020:07:25:02 +0000] "GET /.well-known/acme-challenge/FMuukC2JOJ5HKmLBujjE_BkDo HTTP/1.1" 404 522 "-" "MySecretUserAgent"
โ”œ s00-raw
| โ”œ ๐ŸŸข crowdsecurity/non-syslog (+5 ~8)
| โ”œ update evt.ExpectMode : %!s(int=0) -> 1
| โ”œ update evt.Stage : -> s01-parse
| โ”œ update evt.Line.Raw : -> 5.5.8.5 - - [04/Jan/2020:07:25:02 +0000] "GET /.well-known/acme-challenge/FMuukC2JOJ5HKmLBujjE_BkDo HTTP/1.1" 404 522 "-" "MySecretUserAgent"
| โ”œ update evt.Line.Src : -> /tmp/cscli_explain156736029/cscli_test_tmp.log
| โ”œ update evt.Line.Time : 0001-01-01 00:00:00 +0000 UTC -> 2023-07-21 14:05:09.67803335 +0000 UTC
| โ”œ create evt.Line.Labels.type : nginx
| โ”œ update evt.Line.Process : %!s(bool=false) -> true
| โ”œ update evt.Line.Module : -> file
| โ”œ create evt.Parsed.message : 5.5.8.5 - - [04/Jan/2020:07:25:02 +0000] "GET /.well-known/acme-challenge/FMuukC2JOJ5HKmLBujjE_BkDo HTTP/1.1" 404 522 "-" "MySecretUserAgent"
| โ”œ create evt.Parsed.program : nginx
| โ”œ update evt.Time : 0001-01-01 00:00:00 +0000 UTC -> 2023-07-21 14:05:09.678072613 +0000 UTC
| โ”œ create evt.Meta.datasource_path : /tmp/cscli_explain156736029/cscli_test_tmp.log
| โ”œ create evt.Meta.datasource_type : file
โ”œ s01-parse
| โ”œ ๐ŸŸข crowdsecurity/nginx-logs (+22 ~2)
| โ”œ update evt.Stage : s01-parse -> s02-enrich
| โ”œ create evt.Parsed.remote_addr : 5.5.8.5
| โ”œ create evt.Parsed.request_length :
| โ”œ create evt.Parsed.verb : GET
| โ”œ create evt.Parsed.http_user_agent : MySecretUserAgent
| โ”œ create evt.Parsed.request : /.well-known/acme-challenge/FMuukC2JOJ5HKmLBujjE_BkDo
| โ”œ create evt.Parsed.body_bytes_sent : 522
| โ”œ create evt.Parsed.remote_user : -
| โ”œ create evt.Parsed.time_local : 04/Jan/2020:07:25:02 +0000
| โ”œ create evt.Parsed.http_referer : -
| โ”œ create evt.Parsed.request_time :
| โ”œ create evt.Parsed.proxy_alternative_upstream_name :
| โ”œ create evt.Parsed.proxy_upstream_name :
| โ”œ create evt.Parsed.status : 404
| โ”œ create evt.Parsed.target_fqdn :
| โ”œ create evt.Parsed.http_version : 1.1
| โ”œ update evt.StrTime : -> 04/Jan/2020:07:25:02 +0000
| โ”œ create evt.Meta.http_status : 404
| โ”œ create evt.Meta.http_user_agent : MySecretUserAgent
| โ”œ create evt.Meta.log_type : http_access-log
| โ”œ create evt.Meta.service : http
| โ”œ create evt.Meta.http_path : /.well-known/acme-challenge/FMuukC2JOJ5HKmLBujjE_BkDo
| โ”œ create evt.Meta.http_verb : GET
| โ”œ create evt.Meta.source_ip : 5.5.8.5
โ”œ s02-enrich
| โ”œ ๐ŸŸข crowdsecurity/dateparse-enrich (+2 ~2)
| โ”œ create evt.Enriched.MarshaledTime : 2020-01-04T07:25:02Z
| โ”œ update evt.Time : 2023-07-21 14:05:09.678072613 +0000 UTC -> 2020-01-04 07:25:02 +0000 UTC
| โ”œ update evt.MarshaledTime : -> 2020-01-04T07:25:02Z
| โ”œ create evt.Meta.timestamp : 2020-01-04T07:25:02Z
| โ”œ ๐ŸŸข crowdsecurity/geoip-enrich (+13)
| โ”œ create evt.Enriched.ASNumber : 6805
| โ”œ create evt.Enriched.Latitude : 51.299300
| โ”œ create evt.Enriched.SourceRange : 5.4.0.0/14
| โ”œ create evt.Enriched.ASNOrg : Telefonica Germany
| โ”œ create evt.Enriched.IsInEU : true
| โ”œ create evt.Enriched.IsoCode : DE
| โ”œ create evt.Enriched.Longitude : 9.491000
| โ”œ create evt.Enriched.ASNNumber : 6805
| โ”œ create evt.Meta.ASNOrg : Telefonica Germany
| โ”œ create evt.Meta.IsInEU : true
| โ”œ create evt.Meta.IsoCode : DE
| โ”œ create evt.Meta.ASNNumber : 6805
| โ”œ create evt.Meta.SourceRange : 5.4.0.0/14
| โ”œ ๐ŸŸข crowdsecurity/http-logs (+7)
| โ”œ create evt.Parsed.impact_completion : false
| โ”œ create evt.Parsed.file_ext :
| โ”œ create evt.Parsed.file_frag : FMuukC2JOJ5HKmLBujjE_BkDo
| โ”œ create evt.Parsed.file_name : FMuukC2JOJ5HKmLBujjE_BkDo
| โ”œ create evt.Parsed.static_ressource : false
| โ”œ create evt.Parsed.file_dir : /.well-known/acme-challenge/
| โ”œ create evt.Meta.http_args_len : 0
| โ”” ๐ŸŸข my/whitelist (unchanged)
โ”œ-------- parser success ๐ŸŸข
โ”œ Scenarios
โ”œ ๐ŸŸข crowdsecurity/http-crawl-non_statics
โ”” ๐ŸŸข crowdsecurity/http-probing

You can see what data can be used from s01-parse stage.

CrowdSec Docs
We use cookies

This site uses cookies to help us improve your experience. You can accept or decline below.