• DocFraggle

    • Community Hero
    Moolevel 274

semaf Bei mir werden random benutzer getestet die gar nicht im System existieren. Habt ihr das auch?

Ja, normales Grundrauschen. Sollte aber von Fail2Ban geregelt werden, da braucht man nichts extra machen

DocFraggle
Checked my blacklist file this morning . Date hasn’t changed so I don’t think the cron job is working for me.

-rw-r--r--  1 root root 142377 Apr  1 11:29 abuseipdb_blacklist.txt

I changed it to run as root.

[demo@mail tmp]$ sudo crontab -l
[sudo] password for demo:
0 */5 * * * /etc/iptables/abuseipdb.sh

[demo@mail tmp]$ cd /etc/iptables
[demo@mail iptables]$ ls
abuseipdb.sh  empty.rules  ip6tables.rules  iptables.rules  simple_firewall.rules

Hmm, please change the crontab entry to:

0 */5 * * * /etc/iptables/abuseipdb.sh 1>/var/log/abuseipdb.log 2>&1

This will create a log file (/var/log/abuseipdb.log) which includes potential error messages. Check it after the next run (15:00)

    DocFraggle Thanks I’ll let you know the result. Shouldn’t it run sooner than that?
    It is 7:14 am here EDT
    I thought the cronjob is running every 5 hours.
    So it would run at:
    12:00 AM
    5:00 AM
    10:00 AM
    3:00 PM (15:00)
    8:00 PM (20:00)
    Then 01:00 AM the next day.

    Yes, 3pm = 15:00, it’s 13:29 in Germany currently 😃

    So your next run at 10am

      DocFraggle No log at 10:00 am
      I am going to do some research on crontab on this OS

        DocFraggle So it looks like I had to run something called cronie and start that as a service.
        I then get this:

        [demo@mail iptables]$ sudo systemctl status cronie
        ● cronie.service - Command Scheduler
             Loaded: loaded (/usr/lib/systemd/system/cronie.service; enabled; preset: disabled)
             Active: active (running) since Wed 2025-04-02 10:37:27 EDT; 2min 26s ago
         Invocation: b1f4eefde6cb40748b9875beb211259f
           Main PID: 1986122 (crond)
              Tasks: 1 (limit: 38332)
             Memory: 908K (peak: 1.6M)
                CPU: 6ms
             CGroup: /system.slice/cronie.service
                     └─1986122 /usr/sbin/crond -n
        
        Apr 02 10:37:27 mail systemd[1]: Started Command Scheduler.
        Apr 02 10:37:27 mail crond[1986122]: (CRON) STARTUP (1.7.2)
        Apr 02 10:37:27 mail crond[1986122]: (CRON) INFO (Syslog will be used instead of sendmail.)
        Apr 02 10:37:27 mail crond[1986122]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 34% if used.)
        Apr 02 10:37:27 mail crond[1986122]: (CRON) INFO (running with inotify support)
        

        From my reading the preferred method to do is , is use systemd timer.

          maybl8 That should do the trick 🙂

          To test it you could add a temporary crontab entry, like

          0 11 * * * /etc/iptables/abuseipdb.sh 1>/var/log/abuseipdb.log 2>&1

          to run at 11:00 am

            DocFraggle I ran it at 12:00 PM and it worked.
            Thanks for the help on this.

            • MMaxPain

                Moolevel 3

              Ich möchte auch mal einen kurzen Dank an @DocFraggle aussprechen, der das Skript für uns bereitstellt und optimiert. Version 2.2 leistet wirklich gute Arbeit. Danke. Vielleicht könnte man es in die Dokumentation aufnehmen. Ich finde das Skript sehr sinnvoll, sodass es irgendwo in der Mailcow-Dokumentation erwähnt werden sollte.

              I just want to take a moment to thank DocFraggle for providing and optimizing the script for us. Version 2.2 does a great job. Thanks. Maybe it could be included in the documentation. I find the script very useful, so it should be mentioned somewhere in the Mailcow documentation or elsewhere.

                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.