31.12.19

Fail2ban für Postfix

# Fail2Ban filter for postfix authentication failures
#

[INCLUDES]

before = common.conf

/etc/fail2ban/filter.d/postfix-sasl.conf

[Definition]

_daemon = (?:postfix/smtpd|postfix/submission/smtpd)

failregex = ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:Login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed:
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:Login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed:
             ^%(__prefix_line)swarning: (.*?)does not resolve to address <HOST>: Name or service not known$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed(: [ A-Za-z0-9+/]*={0,2})?\s*$
             ^%(__prefix_line)swarning: [-._\w]+\[<HOST>\]: SASL (?:login|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed:

# Author: Yaroslav Halchenko
Testen mit
fail2ban-regex /var/log/mail.log /etc/fail2ban/filter.d/postfix-sasl.conf

/etc/fail2ban/jail.local:
[postfix-sasl]
enabled  = true
port     = smtp,ssmtp
filter   = postfix-sasl
logpath  = /var/log/mail.log
maxretry = 3

Jails anzeigen:
fail2ban-client status

IP wieder freigeben:
fail2ban-client set sshd unbanip [IP]

Mail anpassen:
mwl -> /sendmail-common.conf
in action.d/iptables-multiport.conf:
actionban = <iptables> -I f2b-<name> 1 -s <ip> -j <blocktype>
<------>    /usr/local/bin/fail2ban-push.php <name> <protocol> <port> <ip>


Tabelle:
CREATE TABLE `sync_fail2ban` (
 `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
 `hostname` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
 `created` datetime NOT NULL,
 `name` text COLLATE utf8_unicode_ci NOT NULL,
 `protocol` varchar(16) COLLATE utf8_unicode_ci NOT NULL,
 `port` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
 `ip` varchar(64) COLLATE utf8_unicode_ci NOT NULL,
`reversedns` text COLLATE utf8_unicode_ci NOT NULL,
 PRIMARY KEY (`id`),
 KEY `hostname` (`hostname`,`ip`)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

PHP-Script:

#!/usr/bin/php
<?php
$name = $_SERVER["argv"][1];
$protocol = $_SERVER["argv"][2];
$port = $_SERVER["argv"][3];
if (!preg_match('/^\d{1,5}$/', $port))
$port = getservbyname($_SERVER["argv"][3], $protocol);
$ip = $_SERVER["argv"][4];
$date = date("Y-m-d H:i:s");
$hostname = gethostname();

// Verbindungsdaten einfügen | insert your database settings
$link = new mysqli("localhost", "fail2ban", "password", "fail2ban");
// Ab hier nix verändern | don’t change anything below
if ($link->connect_error) {
die("Verbindung fehlgeschlagen: " . $link->connect_error());
}
$query = "INSERT INTO sync_fail2ban (name, protocol, port, ip, created, hostname)
VALUES ('$name', '$protocol', '$port', '$ip', '$date','$hostname')";
if ($link->query($query) === TRUE ){
echo "Eintrag erfolgreich geschrieben";
} else {
echo "ERROR: " .$query . "<br>" . $link->error;
}
$link->close ();
?>


26.2.19

Mount unter Raspbian - diverse Fehler

Ich hatte auf einem RPI Ubuntu laufen mit /etc/fstab:

\\192.168.178.210\Backup /media/nas/Backup cifs username=pi,passwd=[meinPW],gid=1000,uid=1000 0 0


Ein Mounten war problemlos möglich.

Auf einem anderen RPI mit Raspbian kamen immer wieder Fehlermeldungen:

/var/log/kern.log

Unknown mount option "passwd xxx"

Umändern von passwd in password brachte auch nichts...

Google Suche fand natürlich einige Hilfen...
 
Ausprobiert z.B.

sec=ntlmv2

usw. brachte auch Fehlermeldungen
Feb 26 07:49:20 octopi kernel: [227184.735746] CIFS VFS: Send error in SessSetup = -13
Feb 26 07:49:20 octopi kernel: [227184.735785] CIFS VFS: cifs_mount failed w/return code = -13


Erst das Auslagern der credentials machte das Mounten möglich...... warum? .... grübel.... Sonderzeichen waren im PW nicht vorhanden.....

//192.168.178.210/Backup /media/nas/Backup cifs vers=1.0,credentials=/etc/.mycredentials,gid=1000,uid=1000 0 0
 .mycredentials:
username=pi
password=geheimespw



19.2.19

Netplan - mal wieder was Neues

Die Konfiguration unter Ubuntu 18 gestaltet sich mal wieder etwas anders als gewohnt.

Der Befehl netplan erwartet eine Yaml-Datei, die manchmal etwas zickig reagiert, wenn man die Einrückungen nicht besonders beachtet.

Unter /etc/netplan/50-cloud-init.yaml lässt sich diese anpassen

Beispiel mit verschiedenen Routen:
network:
  version: 2
  ethernets:
    ens160:
      addresses: [192.168.180.21/24]
      routes:
        - to: 0.0.0.0/0
          via: 192.168.180.253
          metric: 100
        - to: 192.168.178.0/24
          via: 192.168.180.254
          metric: 100
        - to: 192.168.179.0/24
          via: 192.168.180.254
          metric: 100
      dhcp4: yes
      #gateway4: 192.168.180.253
      nameservers:
        addresses: [192.168.179.30,8.8.8.8]

13.2.19

SSH Zertifikats Check - One-liner

Bash-Script

#!/bin/bash
echo | openssl s_client -servername "$1" -connect "$1":443 2>/dev/null | openssl x509 -noout -issuer -dates -subject
Abspeichern z.B. als checkSSLCert.sh in /usr/bin

chmod +x /usr/bin/checkSSLCert

Aufruf

checkSSLCert [Domain]

Keys checken:

echo "--Certificate:" && openssl x509 -noout -modulus -in certificate_file && echo "--Key:" && openssl rsa -noout -modulus -in private_key


28.1.19

Pfad zu den Zertifikaten in Webmin

/etc/webmin/miniserv.conf

Dort 3 Einträge:
/etc/webmin/miniserv.conf:keyfile=/etc/letsencrypt/live/domain/privkey.pem
/etc/webmin/miniserv.conf:extracas=/etc/webmin/letsencrypt-ca.pem
/etc/webmin/miniserv.conf:certfile=/etc/letsencrypt/live/domain/cert.pem

Openhab und Ecoflow Max - API Anbindung

 Ich wollte die neu erworbene Powerstation in Openhab einbinden, um den aktuellen Status (Ladestand etc.) über Openhab auswerten zu können. ...