Some requirements are needed in order to be able to write your own end-to-end configurations. During all this documentation, we are going to show as an exemple how we wrote a full port scan detection scenario (from acqusition to scenario, including parser)
Create the test environment¶
First of all, please download the latest release of Crowdsec.
Then run the following commands:
tar xzvf crowdsec-release.tgz
./test_env.sh # the -o is facultative, default is "./tests/"
./test_env.sh script creates a local (non privileged) working environement for Crowdsec and cscli.
The deployed environment is intended to write and test parsers and scenarios easily.
$ tar xzvf ./crowdsec-release.tgz $ cd ./crowdsec-v0.0.18/ $ ./test_env.sh [09/05/2020:20:02:19][INFO] Creating test arboresence in /tmp/crowdsec-v0.0.18/tests [09/05/2020:20:02:19][INFO] Arboresence created [09/05/2020:20:02:19][INFO] Copying needed files for tests environment [09/05/2020:20:02:19][INFO] Files copied [09/05/2020:20:02:19][INFO] Setting up configurations INFO Failed to open config /tmp/crowdsec-v0.0.18/tests/config/crowdsec-cli/config : open /tmp/crowdsec-v0.0.18/tests/config/crowdsec-cli/config: no such file or directory WARN creating skeleton! INFO wrote config to /tmp/crowdsec-v0.0.18/tests/config/crowdsec-cli/config INFO wrote config to /tmp/crowdsec-v0.0.18/tests/config/crowdsec-cli/config INFO Wrote new 45625 bytes index to /tmp/crowdsec-v0.0.18/tests/config/crowdsec-cli/.index.json INFO crowdsecurity/syslog-logs : OK INFO crowdsecurity/geoip-enrich : OK INFO crowdsecurity/dateparse-enrich : OK INFO crowdsecurity/linux : OK INFO /tmp/crowdsec-v0.0.18/tests/config/collections doesn\'t exist, create INFO /tmp/crowdsec-v0.0.18/tests/config/parsers/s00-raw doesn\'t exist, create INFO Enabled parsers : crowdsecurity/syslog-logs INFO /tmp/crowdsec-v0.0.18/tests/config/parsers/s02-enrich doesn\'t exist, create INFO Enabled parsers : crowdsecurity/geoip-enrich INFO Enabled parsers : crowdsecurity/dateparse-enrich INFO Enabled collections : crowdsecurity/linux INFO Enabled crowdsecurity/linux [09/05/2020:20:02:20][INFO] Environment is ready in /tmp/crowdsec-v0.0.18/tests
Logs parsing is divided into stage, and each stage can contain one or more parser. Stages are named using a "sXX-
next_stage, the event is forwarded to the next stage (and the remaining parsers of the current stage aren't parsed).
Stages and parsers are being processed alphabetically, thus the expected order would be :
s00-raw/syslog.yaml s01-parse/apache.yaml s01-parse/nginx.yaml s02-enrich/geoip.yaml s02-enrich/rdns.yaml
The preliminary stage (
s00-raw) is mostly the one that will parse the structure of the log. This is where syslog-logs are parsed for example. Such a parser will parse the syslog header to detect the program source.
The main stage (
s01-parse) is the one that will parse actual applications logs and output parsed data and static assigned values. There is one parser for each type of software. To parse the logs, regexp or GROK pattern are used. If the parser is configured to go to the
next_stage, then it will be process by the
The enrichment (
s02-enrich) stage is the one that will enrich the normalized log (we call it an event now that it is normalized) in order to get more information for the heuristic process. This stage can be composed of grok patterns and so on, but as well of plugins that can be writen by the community (geiop enrichment, rdns ...) for example geoip-enrich.
You can now jump to the next step : writing our own parser !
It is possible to write custom stage. If you want some specific parsing or enrichment to be done after the
s02-enrich stage, it is possible by creating a new folder
s03-<custom_stage> (and so on). The configuration that will be created in this folder will process the logs configured to go to
next_stage in the