MaxPain

Dem kann ich mich nur voll und ganz anschließen. Dank des Skripts ist es nun wirklich ruhiger auf meinem Mailserver geworden. 😊 Wäre wirklich klasse, wenn das mit in der Doko mit aufgenommen werden würde. Dient ja schließlich auch dem Schutz des Mailservers. Dank des Skripts und die Erweiterung von Crowdsec bin ich ja nun auch aktiver Melder von bösen IPs an die AbuseIPdb geworden.

Falls jemand auch Crowdsec am laufen hat und die bösen IPs an AbuseIPDB melden möchte, kann das relativ einfach bewerkstelligen.

Im Config Verzeichnis die Datei im Unterordnet notifications html.yaml Datei bearbeiten
crowdsec/config/notifications/http.yaml und folgendes eintragen:

---
type: http
name: http_report_abuseipdb

log_level: debug

url: https://api.abuseipdb.com/api/v2/report
method: POST
headers:
  Content-Type: application/json
  Key:  <API Key von AbuseIPdb>
format: |
  {
    {{range . -}}
    {{$alert := . -}}
    {{range .Decisions -}}
    "ip": "{{ $alert.Source.IP }}",
    "categories": [
      {{ if contains $alert.Scenario "crowdsecurity/test alert" }} "1" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/andreasbrett/paperless-ngx-bf" }} "5" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/apache_log4j2_cve-2021-44228" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/appsec-vpatch" }} "21" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2017-9841" }} "21" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2019-18935" }} "20" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2021-4034" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-26134" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-35914" }} "21" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-37042" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-40684" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-41082" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-41697" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-42889" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-44877" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2022-46169" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2023-22515" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2023-22518" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2023-23397" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2023-49103" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2023-4911" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/CVE-2024-3875" }} "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/f5-big-ip-cve-2020-5902" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/fortinet-cve-2018-13379" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/grafana-cve-2021-43798" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-admin-interface-probing" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-bad-user-agent" }} "21", "19" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-bf-wordpress_bf" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-crawl-non_statics" }} "21", "19" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-cve-2021-41773" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-cve-2021-42013" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-cve-probing" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-generic-bf" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-open-proxy" }} "21" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-path-traversal-probing" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-probing" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-sensitive-files" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-sqli-probing" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-wordpress_user-enum" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-wordpress_wpconfig" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-wordpress-scan" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-xss-probing" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/iptables-scan-multi_ports" }} "14" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/jira_cve-2021-26086" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/mariadb-bf" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/netgear_rce" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/nextcloud-bf" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/nginx-req-limit-exceeded" }} "21", "6" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/pfsense-gui-bf" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/pulse-secure-sslvpn-cve-2019-11510" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/spring4shell_cve-2022-22965" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/ssh-bf" }} "22", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/ssh-slow-bf" }} "22", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/thinkphp-cve-2018-20062" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/vmware-cve-2022-22954" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/vmware-vcenter-vmsa-2021-0027" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/windows-bf" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/windows-CVE-2022-30190-msdt" }} "21", "15" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/wireguard-auth" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/http-sensitive-files" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/postfix-non-smtp-command" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "crowdsecurity/postfix-spam" }} "21", "18" {{end}}
      {{ if contains $alert.Scenario "firewallservices/pf-scan-multi_ports" }} "21", "14" {{end}}
      {{ if contains $alert.Scenario "firix/authentik-bf" }} "21", "18" {{end}}
    ],
    "comment": "This IP was detected by CrowdSec triggering {{ $alert.Scenario }}"
    {{end -}}
    {{end -}}
  }

Die Scenarios kann man an eurer Konfigurationen anpassen, entsprechend entfernen oder hinzufügen. Die Nummer hinter der Zeile [...] }} "21", "15" {{end}} entsprechen der Kategorien von AbuaseIPDB

.
In dem Fall für 21 ist Web App Attack und 15 für Hacking

Damit das ganze auch aufgerufen wird, muss noch das Plugin aktiviert werden. Das wird in der Konfig Datei config/profiles.yaml erledigt, dort muss man dann nur noch den Namen der der Notification aktivieren. In diesem fall müsst ihr nur - http_report_abuseipdb eintragen zum Aktivieren der Notifikation.

Eine vollständige Konfiguration sieht dann als Beispiel so aus:

---
name: default_ip_remediation
# debug: true
filters:
 - Alert.Remediation == true && Alert.GetScope() == "Ip"
decisions:
 - type: ban
   duration: 14h
duration_expr: Sprintf('%dh', (GetDecisionsCount(Alert.GetValue()) + 1) * 14)
notifications:
#   - slack_default  # Set the webhook in /etc/crowdsec/notifications/slack.yaml before enabling this.
#   - splunk_default # Set the splunk url and token in /etc/crowdsec/notifications/splunk.yaml before enabling th>
 - http_telegram
 - http_report_abuseipdb
# Set the required http parameters in /etc/crowdsec/notifications/http.yaml before enabling thi>
#   - email_default  # Set the required email parameters in /etc/crowdsec/notifications/email.yaml before enablin>
on_success: break
---
name: default_range_remediation
# debug: true
filters:
 - Alert.Remediation == true && Alert.GetScope() == "Range"
decisions:
 - type: ban
   duration: 14h
duration_expr: Sprintf('%dh', (GetDecisionsCount(Alert.GetValue()) + 1) * 14)
notifications:
#   - slack_default  # Set the webhook in /etc/crowdsec/notifications/slack.yaml before enabling this.
#   - splunk_default # Set the splunk url and token in /etc/crowdsec/notifications/splunk.yaml before enabling th>
 - http_telegram   # Set the required http parameters in /etc/crowdsec/notifications/http.yaml before enabling thi>
#   - email_default  # Set the required email parameters in /etc/crowdsec/notifications/email.yaml before enablin>
on_success: break

Nur noch den Crowdsec neustarten und abwarten bis der erste gemeldet wird. 😉

Das sieht dann bei AbuseIPDB Reports so aus:

Ich finde das ganz Praktisch und hilft die Datenbank Aktuell zu halten.
Ohne das Skript von @DocFraggle wäre ich gar nicht auf AbuseIPDB aufmerksam geworden. Danke! 😃

    DocFraggle Stimmt, soll ja nicht unerwähnt bleiben, wer den Stein ins rollen gebracht hat. 😉

    • semaf

        Moolevel 2

      curiosity Vielen dank für das sharen! Das Reporting wird natürlich uns allen helfen. Außerdem ist mit Crowdsec noch ein Sicherheitsebene da. Also werde es installiert und nutzt kann etwas beitragen.

      Crowdsec installation gibt es hier -> Protecting mailcow with Crowdsec

        Hallo Zusammen,
        ich habe seit meiner Server neu Installation mit Debian 12 das Problem das der tägliche Cronjob nicht mehr geht.

        35 8 * * * /usr/local/etc/mailcow-scripts/abuseipdb.sh 1>/var/log/abuseipdb.log 2>&1

        in der Log kommt dann ipset NOT found, please install package. ipset und jq ist natürlich installiert.

        Wird das Script manuell ausgeführt funktioniert alles wunderbar.

          • DocFraggle

            • Community Hero
            Moolevel 274

          bekenz762 Du hast das aber schon in die Root Crontab gepackt oder? Wenn ja, dann probiers mal so:

          0 */5 * * * PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin /usr/local/etc/mailcow-scripts/abuseipdb.sh 1>/var/log/abuseipdb.log 2>&1

          Falls Cron die PATH Umgebungsvariable nicht hat

            DocFraggle
            Vielen Dank! Hat jetzt geklappt lag an der “PATH Umgebungsvariable” für Cron.

            • Aaccolon

                Moolevel 31

              Danke für das Skript! Ich hatte mir etwas ähnliches für einen anderen Server gestrickt, wo ich die Regeln einfach in die INPUT-Chain packe bzw. packen kann, da ich dort ohne Docker kein FORWARDING hab. Das hier hilft mir sehr auf der mailcow.

              Zwei spontane Anmerkungen:

              1. Die aktuelle Version des Skripts prüft noch auf jq, aber das wird gar nicht mehr verwendet.
              2. Der Name der Chain MAILCOW wird einerseits in einer Variable festgelegt und an ensure_rule_at_top() übergeben, andererseits ist der Name aber an einigen Stellen innerhalb der Funktion (und in dem Block zu den Logging-Regeln) trotzdem fest kodiert.

                Hier nochmal eine schöne Seite als Ergänzung, die auf die Absicherung eines Linux Servers mit Crowdsec eingeht (was man natürlich auch in Verbindung mit mailcow gilt) und noch mal ein paar konfigurations Beispiele für die Benachrichtung per Mail oder Telegramm und den Bannzeiten eingeht. Mir hat es gut geholfen bei der Einarbeitung in Crowdsec. Vor allem da es mal eine der wenigen Anleitung ist, die in meiner Muttersprache verfasst wurde. 😇 Stehe leider mit Englisch etwas auf Kriegsfuß. 🥴 Hätte ich das damals in der Schule gewusst wie wichtig das mal wird, dann hätte ich besser aufgepasst. 😆

                Hier der Link -> andersgood.de Icon In 15 Minuten Linux-Server mit CrowdSec absichern | andersGOOD Blog

                DocFraggle The cronjob is running fine however I am noticing that I lose the LOG entry but I don’t know when . When I first run it manually the LOG is there. Somewhere after the script runs it looks like I lose the LOG function.

                Chain MAILCOW (2 references)
                 pkts bytes target     prot opt in     out     source               destination
                  810 51144 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            match-set abuseipdb_blacklist_v4 src
                   20  1552 REJECT     all  --  *      *       73.173.151.120       0.0.0.0/0            reject-with icmp-port-unreachable
                    9   513 REJECT     all  --  *      *       129.224.201.45       0.0.0.0/0            reject-with icmp-port-unreachable
                   21  1604 REJECT     all  --  *      *       73.138.56.10         0.0.0.0/0            reject-with icmp-port-unreachable
                   20  1552 REJECT     all  --  *      *       67.242.117.151       0.0.0.0/0            reject-with icmp-port-unreachable
                

                  maybl8 You have to add --enable-log to the crontab line

                  No one is typing