• Ddariusuk

      Moolevel 0

    Bei den script ausführung bekomme errors "{“type”:“error”,“msg”:“authentication failed”}root@debian:~#"

      • DocFraggle

        • Community Hero
        Moolevel 274

      dariusuk hast Du denn YOUR_MAILCOW_API_KEY und YOUR_ABUSEIP_API_KEY mit Deinen API Keys ersetzt?

      • Ddariusuk

          Moolevel 0
        • Edited

        YOUR_MAILCOW_API_KEY was muss da rein? abuse api key ersetz klar aber wie und wo muss ich den mailcow api generieren?

        ich meine bei mailcow unter api lese und schreibe rechte,mein server ip und generieren oder wie?

        • DocFraggle

          • Community Hero
          Moolevel 274

        System -> Konfiguration

        Dann API aufklappen

        • Ddariusuk

            Moolevel 0

          das habe ich gemacht und dort steht nur 1

          • DocFraggle

            • Community Hero
            Moolevel 274

          Fehlt ja auch der Haken bei “API aktivieren” 😉

          • Ddariusuk

              Moolevel 0

            das ist klar aber wenn ich havken mache und speichern will fragt der nach IP und dort muss ich server ip schreiben und das bei beiden optionen?

            • DocFraggle

              • Community Hero
              Moolevel 274

            Na die IP von der aus Du die API nutzen willst. Ich habe da die IPv4 und IPv6 Adresse drin.

            • Ddariusuk

                Moolevel 0

              alles klar,jetzt klappt. danke!!

              6 days later
              • pscriptos

                  Moolevel 2

                Ich möchte mich ebenfalls für dieses Script bedanken!
                Es hat auf Anhieb funktioniert! 🙂

                Grüße, pscriptos

                6 days later
                • Sstefan21

                    Moolevel 16

                  MaxPain Die Mailcow Instanz ist hinter Traefik geschaltet, Port 587 nehme ich mal an da SASL-Authentifizierungsversuche darüber laufen meines wissens nach. Es wird versucht Login daten zu knacken. Username wird random probiert und das pw dazu. Hier die Log als Screenshot. Meine kompletten Logs sind voll damit. Seit Wochen steht der Mailserver unter Feuer.

                  Bisschen älter der Thread…

                  Falls nur Mailserver zu Mailserver kommunizieren soll und eine Firewall vor der mailcow sitzt, dann reicht es IMO nur den Port 25 an der Firewall zu öffnen und zu forwarden. Aus dem LAN alle Ports, die die mailcow braucht erlauben, vom WAN auch nur den Port 25 zur mailcow. Ein VPN (z.B. wireguard) einrichten, alle Clients dann darüber ins LAN verbinden, sollte ausreichend Schutz bieten. Nichts offen ausser dem Port 25.

                    • Mmlcwuser

                        Moolevel 36
                      • Edited

                      stefan21 Kann man natürlich machen, aber ich möchte auch von meinem Handy auf meine Mails zugreifen und da möchte ich auch sofort benachrichtigt werden, wenn neue Mails ankommen, ohne ständig Wireguard aktiv zu haben und dafür müssen in meinem Fall halt zumindest die Ports 465 und 993 auch offen bleiben.

                      Hinzu kommt, dass meine Mailcow auf einem VPS läuft und ich zu Hause eine dynamische IP-Adresse habe. Ich kann also nicht einfach in der Firewall den Zugriff auf meine Heim-IP beschränken, d.h. ich müsste mich dann auch von zuhause aus immer mit Wireguard verbinden.

                      Zu viel Aufwand, nur um die Logs sauber zu halten, imho ;-)

                      • DocFraggle

                        • Community Hero
                        Moolevel 274

                      FYI, ich habe das AbuseIPDB Script und das Drumherum mal für die Mailcow Doku gebastelt, muss nur noch der PR gemerged werden

                      mailcow/mailcow-dockerized-docs826

                      Dabei habe ich auch das Script nochmal ein bisschen überarbeitet

                      Ich hab das jetzt erst mal wieder rausgenommen. Mein Server kommt damit nicht klar. Die Anzeige der GUI wird über Tage nicht aktualisiert und wirklich geblockt wurde damit zumindest bei mir auch nicht mehr wie vorher.

                      • DocFraggle

                        • Community Hero
                        Moolevel 274

                      Also ich habe jetzt keine Probleme mit der GUI, aber jetzt wo Dus sagst und ich genauer geschaut habe: die API ersetzt einfach alle Einträge der Blacklist. D.h. die schon vorhandenen Einträge, oder auch welche die neu dazu gekommen sind direkt durch Fail2Ban, sind dann nicht mehr in der Blacklist :/

                      Richtig das hatte ich vergessen zu erwähnen. Das ist auch ein Thema das stört.

                      OK, ich habe das Script nochmal angepasst, die aktiven Bans die direkt von Fail2Ban ausgelöst wurden werden jetzt auch wieder mit eingefügt

                      #!/bin/bash
                      
                      # Adjust the values of the following variables
                      ABUSEIP_API_KEY="XXXXXXXXX"
                      MAILCOW_API_KEY="YYYYYYYY"
                      MAILSERVER_FQDN="your.mail.server"
                      
                      echo "Retrieve IPs from AbuseIPDB"
                      curl -sG https://api.abuseipdb.com/api/v2/blacklist \
                        -d confidenceMinimum=90 \
                        -d plaintext \
                        -H "Key: $ABUSEIP_API_KEY" \
                        -H "Accept: application/json" \
                        -o /tmp/abuseipdb_blacklist.txt
                      
                      # Capture the exit code from curl
                      exit_code=$?
                      
                      # Check if curl encountered an error
                      if [ $exit_code -ne 0 ]; then
                        echo "Curl encountered an error with exit code $exit_code while rertieving the AbuseIPDB IPs"
                        exit 1
                      fi
                      
                      # Add a newline to the end of the blacklist file
                      echo >> /tmp/abuseipdb_blacklist.txt
                      
                      echo "Get current Fail2Ban config, extract active_bans IPs and add them to the blacklist file"
                      curl -s --header "Content-Type: application/json" \
                           --header "X-API-Key: $MAILCOW_API_KEY" \
                            "https://${MAILSERVER_FQDN}/api/v1/get/fail2ban" |\
                            jq -r '.active_bans[].ip' >> /tmp/abuseipdb_blacklist.txt
                      
                      BLACKLIST=$(awk '{if (index($0, ":") > 0) printf "%s%s/128", sep, $0; else printf "%s%s/32", sep, $0; sep=","} END {print ""}' /tmp/abuseipdb_blacklist.txt)
                      
                      cat <<EOF > /tmp/request.json
                      {
                        "items":["none"],
                        "attr": {
                          "blacklist": "$BLACKLIST"
                        }
                      }
                      EOF
                      
                      echo "Add IPs to Fail2Ban" 
                      curl -s --include \
                           --request POST \
                           --header "Content-Type: application/json" \
                           --header "X-API-Key: $MAILCOW_API_KEY" \
                           --data-binary @/tmp/request.json \
                           "https://${MAILSERVER_FQDN}/api/v1/edit/fail2ban"
                      
                      # Capture the exit code from curl
                      exit_code=$?
                      
                      # Check if curl encountered an error
                      if [ $exit_code -ne 0 ]; then
                        echo "Curl encountered an error with exit code $exit_code while setting the Fail2Ban IPs"
                        exit 1
                      fi
                      
                      echo -e "\n\nAll done, have fun"

                      Das Paket “jq” muss noch zusätzlich installiert werden

                      Wie gesagt, bei mir macht das Script ansonsten keine Probleme.

                      Cool, ich werde das ausprobieren. Danke

                      @DocFraggle

                      Thank’s for improving the script. While running an error is coming up:

                      "
                      Retrieve IPs from AbuseIPDB
                      Get current Fail2Ban config, extract active_bans IPs and add them to the blacklist file
                      jq: error (at <stdin>:49306): Cannot iterate over null (null)
                      Add IPs to Fail2Ban
                      "

                      I assume there are no active bans…

                      Cosmetical?

                      So, hier in schön:

                      #!/bin/bash
                      
                      # Adjust the values of the following variables
                      ABUSEIP_API_KEY="XXXXXXXXXXXXXXXX"
                      MAILCOW_API_KEY="YYYYYYYYYYYYYYYY"
                      MAILSERVER_FQDN="your.mail.server"
                      
                      echo "Retrieve IPs from AbuseIPDB"
                      curl -sG https://api.abuseipdb.com/api/v2/blacklist \
                        -d confidenceMinimum=90 \
                        -d plaintext \
                        -H "Key: $ABUSEIP_API_KEY" \
                        -H "Accept: application/json" \
                        -o /tmp/abuseipdb_blacklist.txt
                      
                      # Capture the exit code from curl
                      exit_code=$?
                      
                      # Check if curl encountered an error
                      if [ $exit_code -ne 0 ]; then
                        echo "Curl encountered an error with exit code $exit_code while rertieving the AbuseIPDB IPs"
                        exit 1
                      fi
                      
                      # Add a newline to the end of the blacklist file
                      echo >> /tmp/abuseipdb_blacklist.txt
                      
                      echo "Get current Fail2Ban config, extract active_bans IPs and add them to the blacklist file"
                      curl -s --header "Content-Type: application/json" \
                           --header "X-API-Key: $MAILCOW_API_KEY" \
                            "https://${MAILSERVER_FQDN}/api/v1/get/fail2ban" |\
                            jq -r 'if .active_bans | length > 0 then .active_bans[].ip else "" end' >> /tmp/abuseipdb_blacklist.txt
                      
                      BLACKLIST=$(awk '{if (index($0, ":") > 0) printf "%s%s/128", sep, $0; else printf "%s%s/32", sep, $0; sep=","} END {print ""}' /tmp/abuseipdb_blacklist.txt)
                      
                      cat <<EOF > /tmp/request.json
                      {
                        "items":["none"],
                        "attr": {
                          "blacklist": "$BLACKLIST"
                        }
                      }
                      EOF
                      
                      echo "Add IPs to Fail2Ban" 
                      curl -s --include \
                           --request POST \
                           --header "Content-Type: application/json" \
                           --header "X-API-Key: $MAILCOW_API_KEY" \
                           --data-binary @/tmp/request.json \
                           "https://${MAILSERVER_FQDN}/api/v1/edit/fail2ban"
                      
                      # Capture the exit code from curl
                      exit_code=$?
                      
                      # Check if curl encountered an error
                      if [ $exit_code -ne 0 ]; then
                        echo "Curl encountered an error with exit code $exit_code while rertieving the AbuseIPDB IPs"
                        exit 1
                      fi
                      
                      echo -e "\n\nAll done, have fun"

                      @pkernstock könntest Du evtl meinen kaputten Post hier eins drüber löschen? 🙂