tests_post-install_4cold-logs.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #! /usr/bin/env bash
  2. # -*- coding: utf-8 -*-
  3. source tests_base.sh
  4. # install sshd collection
  5. ${CSCLI} collections install crowdsecurity/sshd
  6. ${CSCLI} decisions delete --all
  7. ${SYSTEMCTL} reload crowdsec
  8. # generate a fake bf log -> cold logs processing
  9. rm -f ssh-bf.log
  10. for i in `seq 1 10` ; do
  11. echo `LC_ALL=C date '+%b %d %H:%M:%S '`'sd-126005 sshd[12422]: Invalid user netflix from 1.1.1.172 port 35424' >> ssh-bf.log
  12. done;
  13. ${CROWDSEC} -dsn "file://./ssh-bf.log" -type syslog -no-api
  14. ${CSCLI} decisions list -o=json | ${JQ} '. | length == 1' || fail "expected exactly one decision"
  15. ${CSCLI} decisions list -o=json | ${JQ} '.[].decisions[0].value == "1.1.1.172"' || fail "(exact) expected ban on 1.1.1.172"
  16. ${CSCLI} decisions list -r 1.1.1.0/24 -o=json --contained | ${JQ} '.[].decisions[0].value == "1.1.1.172"' || fail "(range/contained) expected ban on 1.1.1.172"
  17. ${CSCLI} decisions list -r 1.1.2.0/24 -o=json | ${JQ} '. == null' || fail "(range/NOT-contained) expected no ban on 1.1.1.172"
  18. ${CSCLI} decisions list -i 1.1.1.172 -o=json | ${JQ} '.[].decisions[0].value == "1.1.1.172"' || fail "(range/NOT-contained) expected ban on 1.1.1.172"
  19. ${CSCLI} decisions list -i 1.1.1.173 -o=json | ${JQ} '. == null' || fail "(exact) expected no ban on 1.1.1.173"
  20. # generate a live ssh bf
  21. ${CSCLI} decisions delete --all
  22. echo "" | sudo tee -a /etc/crowdsec/acquis.yaml > /dev/null
  23. echo "filename: /tmp/test.log" | sudo tee -a /etc/crowdsec/acquis.yaml > /dev/null
  24. echo "labels:" | sudo tee -a /etc/crowdsec/acquis.yaml > /dev/null
  25. echo " type: syslog" | sudo tee -a /etc/crowdsec/acquis.yaml > /dev/null
  26. touch /tmp/test.log
  27. ${SYSTEMCTL} restart crowdsec
  28. sleep 1
  29. ${SYSTEMCTL} status crowdsec
  30. cat ssh-bf.log >> /tmp/test.log
  31. sleep 2
  32. ${CSCLI} decisions list -o=json | ${JQ} '.[].decisions[0].value == "1.1.1.172"' || fail "(live) expected ban on 1.1.1.172"