Skip to content

Commit

Permalink
update default value of CROWDSEC_APPSEC_URL, update BW tags to 1.5.9 …
Browse files Browse the repository at this point in the history
…and add automatic tests for CS appsec
  • Loading branch information
fl0ppy-d1sk committed Jul 15, 2024
1 parent 62c7224 commit 111a4a7
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 29 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ jobs:

- name: Run CrowdSec stream tests
run: ./.tests/crowdsec.sh stream

- name: Run CrowdSec appsec tests
run: ./.tests/crowdsec.sh appsec

- name: Run VirusTotal tests
run: ./.tests/virustotal.sh
Expand Down
50 changes: 34 additions & 16 deletions .tests/crowdsec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@ do_and_check_cmd cp .tests/crowdsec/docker-compose.yml /tmp/bunkerweb-plugins/cr
# Edit compose
do_and_check_cmd sed -i "s@bunkerity/bunkerweb:.*\$@bunkerweb:tests@g" /tmp/bunkerweb-plugins/crowdsec/docker-compose.yml
do_and_check_cmd sed -i "s@bunkerity/bunkerweb-scheduler:.*\$@bunkerweb-scheduler:tests@g" /tmp/bunkerweb-plugins/crowdsec/docker-compose.yml
do_and_check_cmd sed -i "s@CROWDSEC_MODE=.*\$@CROWDSEC_MODE=$1@g" /tmp/bunkerweb-plugins/crowdsec/docker-compose.yml
if [ $1 == "appsec" ] ; then
do_and_check_cmd sed -i "s@CROWDSEC_MODE=.*\$@CROWDSEC_MODE=live@g" /tmp/bunkerweb-plugins/crowdsec/docker-compose.yml
do_and_check_cmd sed -i "s@CROWDSEC_APPSEC_URL=.*\$@CROWDSEC_APPSEC_URL=http://crowdsec:7422@g" /tmp/bunkerweb-plugins/crowdsec/docker-compose.yml
else
do_and_check_cmd sed -i "s@CROWDSEC_MODE=.*\$@CROWDSEC_MODE=$1@g" /tmp/bunkerweb-plugins/crowdsec/docker-compose.yml

fi

# Copy configs
do_and_check_cmd cp .tests/crowdsec/acquis.yaml /tmp/bunkerweb-plugins/crowdsec
Expand Down Expand Up @@ -58,23 +64,35 @@ if [ "$success" == "ko" ] ; then
exit 1
fi

# Run basic attack with dirb
echo "ℹ️ Executing dirb ..."
do_and_check_cmd sudo apt install -y dirb
dirb http://localhost -H "Host: www.example.com" -H "User-Agent: LegitOne" -f > /dev/null 2>&1

# Wait if are in stream mode
if [ "$1" == "stream" ] ; then
sleep 20
fi
if [ "$1" != "appsec" ] ; then
# Run basic attack with dirb
echo "ℹ️ Executing dirb ..."
do_and_check_cmd sudo apt install -y dirb
dirb http://localhost -H "Host: www.example.com" -H "User-Agent: LegitOne" -f > /dev/null 2>&1

# Expect a 403
echo "ℹ️ Checking CS ..."
success="ko"
ret="$(curl -s -o /dev/null -w "%{http_code}" -H "Host: www.example.com" http://localhost)"
# shellcheck disable=SC2181
if [ $? -eq 0 ] && [ "$ret" -eq 403 ] ; then
success="ok"
# Wait if are in stream mode
if [ "$1" == "stream" ] ; then
sleep 20
fi

# Expect a 403
echo "ℹ️ Checking CS ..."
success="ko"
ret="$(curl -s -o /dev/null -w "%{http_code}" -H "Host: www.example.com" http://localhost)"
# shellcheck disable=SC2181
if [ $? -eq 0 ] && [ "$ret" -eq 403 ] ; then
success="ok"
fi
else
# Send an obvious pattern
echo "ℹ️ Sending malicious pattern"
success="ko"
ret="$(curl -s -o /dev/null -w "%{http_code}" -H "Host: www.example.com" http://localhost/?id=/etc/passwd)"
# shellcheck disable=SC2181
if [ $? -eq 0 ] && [ "$ret" -eq 403 ] ; then
success="ok"
fi
fi

# We're done
Expand Down
5 changes: 5 additions & 0 deletions .tests/crowdsec/appsec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
appsec_config: crowdsecurity/appsec-default
labels:
type: appsec
listen_addr: 127.0.0.1:7422
source: appsec
4 changes: 3 additions & 1 deletion .tests/crowdsec/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ services:
- CROWDSEC_API=http://crowdsec:8080
- CROWDSEC_API_KEY=s3cr3tb0unc3rk3y
- CROWDSEC_MODE=
- CROWDSEC_APPSEC_URL=
- LOG_LEVEL=info
- USE_MODSECURITY=no
- USE_BLACKLIST=no
Expand Down Expand Up @@ -61,10 +62,11 @@ services:
volumes:
- cs-data:/var/lib/crowdsec/data
- ./acquis.yaml:/etc/crowdsec/acquis.yaml
- ./appsec.yaml:/etc/crowdsec/acquis.d/appsec.yaml
- bw-logs:/var/log:ro
environment:
- BOUNCER_KEY_bunkerweb=s3cr3tb0unc3rk3y
- COLLECTIONS=crowdsecurity/nginx
- COLLECTIONS=crowdsecurity/nginx crowdsecurity/appsec-virtual-patching crowdsecurity/appsec-generic-rules crowdsecurity/appsec-crs
- DISABLE_PARSERS=crowdsecurity/whitelists
networks:
- bw-universe
Expand Down
4 changes: 2 additions & 2 deletions clamav/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ version: '3'
services:

bunkerweb:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_CLAMAV=yes
Expand All @@ -59,7 +59,7 @@ version: '3'
services:

mybunker:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_CLAMAV=yes
Expand Down
2 changes: 1 addition & 1 deletion crowdsec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ metadata:
| `CROWDSEC_EXCLUDE_LOCATION` | | global | no | The locations to exclude while bouncing. It is a list of location, separated by commas. |
| `CROWDSEC_CACHE_EXPIRATION` | `1` | global | no | The cache expiration, in second, for IPs that the bouncer store in cache in live mode. |
| `CROWDSEC_UPDATE_FREQUENCY` | `10` | global | no | The frequency of update, in second, to pull new/old IPs from the CrowdSec local API. |
| `CROWDSEC_APPSEC_URL` | `http://crowdsec:7422` | global | no | URL of the Application Security Component. |
| `CROWDSEC_APPSEC_URL` | | global | no | URL of the Application Security Component. |
| `CROWDSEC_APPSEC_FAILURE_ACTION` | `passthrough` | global | no | Behavior when the AppSec Component return a 500. Can let the request passthrough or deny it. |
| `CROWDSEC_APPSEC_CONNECT_TIMEOUT` | `100` | global | no | The timeout in milliseconds of the connection between the remediation component and AppSec Component. |
| `CROWDSEC_APPSEC_SEND_TIMEOUT` | `100` | global | no | The timeout in milliseconds to send data from the remediation component to the AppSec Component. |
Expand Down
2 changes: 1 addition & 1 deletion crowdsec/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"CROWDSEC_APPSEC_URL": {
"context": "global",
"default": "http://crowdsec:7422",
"default": "",
"help": "URL of the Application Security Component.",
"id": "crowdsec-appsec-url",
"label": "AppSec URL",
Expand Down
4 changes: 2 additions & 2 deletions discord/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ version: '3'
services:

bunkerweb:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_DISCORD=yes
Expand All @@ -54,7 +54,7 @@ version: '3.5'
services:

mybunker:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_DISCORD=yes
Expand Down
4 changes: 2 additions & 2 deletions slack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ version: '3'
services:

bunkerweb:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_SLACK=yes
Expand All @@ -54,7 +54,7 @@ version: '3.5'
services:

mybunker:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_SLACK=yes
Expand Down
4 changes: 2 additions & 2 deletions virustotal/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ version: '3'
services:

bunkerweb:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_VIRUSTOTAL=yes
Expand All @@ -53,7 +53,7 @@ version: '3'
services:

mybunker:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_VIRUSTOTAL=yes
Expand Down
4 changes: 2 additions & 2 deletions webhook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ version: '3'
services:

bunkerweb:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
...
environment:
- USE_WEBHOOK=yes
Expand All @@ -52,7 +52,7 @@ version: '3'
services:

mybunker:
image: bunkerity/bunkerweb:1.5.8
image: bunkerity/bunkerweb:1.5.9
..
environment:
- USE_WEBHOOK=yes
Expand Down

0 comments on commit 111a4a7

Please sign in to comment.