Crowdsec SSH Bruteforce Beispiel: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
 
(5 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 41: Zeile 41:
 
* wget https://xinux.de/downloads/bad-passwords
 
* wget https://xinux.de/downloads/bad-passwords
 
; Hydra installieren
 
; Hydra installieren
 +
* apt update
 
* apt install hydra -y
 
* apt install hydra -y
 
; Attacke
 
; Attacke
* hydra -l root -P bad-passwords ssh://10.0.10.132 -V
+
* hydra -l kit -P bad-passwords ssh://10.88.213.41 -s 6666 -V
 
 
== Die IP sollte hier erscheinen ==
 
* ipset list  crowdsec-blacklists-1
 
 
 
Name: crowdsec-blacklists-1
 
Type: hash:net
 
Revision: 7
 
Header: family inet hashsize 1024 maxelem 131072 timeout 300 bucketsize 12 initval 0xadaaeb46
 
Size in memory: 520
 
References: 1
 
Number of entries: 1
 
Members:
 
10.0.10.109 timeout 14298
 
 
 
==Alle böse IPs==
 
* ipset list  crowdsec-blacklists-0
 
  
 
== Überprüfung der erkannten SSH-Angriffe ==
 
== Überprüfung der erkannten SSH-Angriffe ==

Aktuelle Version vom 2. Juli 2025, 13:09 Uhr

Wichtig

Vorraussetzung Crowdsec ist installiert
Im Labor empfielt es sich die Whitelist zu bearbeiten.
  • vi /etc/crowdsec/parsers/s02-enrich/whitelists.yaml
name: crowdsecurity/whitelists
description: "Whitelist events from private ipv4 addresses"
whitelist:
  reason: "private ipv4/ipv6 ip/ranges"
  ip:
    - "::1"
    - "192.168.178.1"
  cidr:
   # - "127.0.0.0/8"
   # - "192.168.0.0/16"
   # - "10.0.0.0/8"
   # - "172.16.0.0/12"
# expression:
   #   - "'foo.com' in evt.Meta.source_ip.reverse"
  • systemctl restart crowdsec

Installation der SSH-Collection

  • sudo cscli collections install crowdsecurity/sshd
  • sudo systemctl reload crowdsec

Installation des nftables Bouncers

Wenn noch nicht geschehen
  • apt install crowdsec-firewall-bouncer-nftables

Neustart des Bouncers

  • sudo systemctl restart crowdsec-firewall-bouncer
  • sudo systemctl status crowdsec-firewall-bouncer

Überprüfen, ob der Bouncer mit CrowdSec verbunden ist

  • sudo cscli bouncers list

Überprüfung der installierten SSH-Szenarien

  • sudo cscli scenarios list | grep ssh

Auf dem Attacker starten wir nun einen Angriff

Passwortliste besorgen
Hydra installieren
  • apt update
  • apt install hydra -y
Attacke

Überprüfung der erkannten SSH-Angriffe

  • sudo cscli alerts list
+----+-------------------+---------------------------+---------+----+-----------+-----------------------------------------+
| ID |       value       |          reason           | country | as | decisions |               created_at                |
+----+-------------------+---------------------------+---------+----+-----------+-----------------------------------------+
| 3  | Ip:10.0.10.99     | crowdsecurity/ssh-slow-bf |         |    | ban:1     | 2025-03-08 10:07:24.268224992 +0000 UTC |
| 2  | Ip:10.0.10.99     | crowdsecurity/ssh-bf      |         |    | ban:1     | 2025-03-08 10:07:24.268879637 +0000 UTC |
+----+-------------------+---------------------------+---------+----+-----------+-----------------------------------------+

Anzeige der gebannten IP-Adressen

  • sudo cscli decisions list
╭───────┬──────────┬───────────────┬───────────────────────────┬────────┬─────────┬────┬────────┬────────────────────┬──────────╮
│  ID   │  Source  │  Scope:Value  │          Reason           │ Action │ Country │ AS │ Events │     expiration     │ Alert ID │
├───────┼──────────┼───────────────┼───────────────────────────┼────────┼─────────┼────┼────────┼────────────────────┼──────────┤
│ 15002 │ crowdsec │ Ip:10.0.10.99 │ crowdsecurity/ssh-slow-bf │ ban    │         │    │ 13     │ 3h58m41.750831936s │ 3        │
╰───────┴──────────┴───────────────┴───────────────────────────┴────────┴─────────┴────┴────────┴────────────────────┴──────────╯
1 duplicated entries skipped
  • cscli decisions delete --ip 10.0.10.109

Live-Log der CrowdSec-Analyse anzeigen

  • sudo journalctl -u crowdsec -f

Überprüfung der installierten Parser, Szenarien und Bouncer

  • sudo cscli parsers list
  • sudo cscli scenarios list
  • sudo cscli bouncers list

Test: Anzeige der letzten SSH-Fehlversuche

  • sudo journalctl -u ssh -g "Failed password" --no-pager | tail -n 20