In einem früheren Eintrag hatte ich startssl als Quelle für kostenlose Zertifikate für Server angesprochen, die kostenlosen Class 1 - Zertifikate gelten immer für eine Subdomain und die Domain selbst. Also zB. www.domain.tld und  domain.tld. Hier mein Waschzettel, um das Zertifikat für den Webserver der Domain, Courier (pop3s, imaps) und für die Serververwaltungen Webmin und ISPConfig2 einzubinden.

 
# Verzeichnis für die eigenen Certs anlegen 
mkdir -p  /etc/ssl/certs/startssl/
chmod 700 /etc/ssl/certs/startssl/

# den eigenen key und das von startssl signierte zertifikat hier speichern
# darauf achten bzw. kontrollieren, dass jede dieser Dateien mit einem \n endet
domain.tld.key
domain.tld.crt
chmod 600 domain.tld.key

# die certs von startssl herunterladen
wget https://www.startssl.com/certs/ca.pem
wget https://www.startssl.com/certs/sub.class1.server.ca.pem

# umbenennen ordnet
mv ca.pem startssl.ca.crt
mv sub.class1.server.ca.pem startssl.sub.class1.server.ca.crt

# die ganze Kette zusammenkopieren
cat startssl.sub.class1.server.ca.crt startssl.ca.crt >startssl.chain.class1.server.crt
cat domain.tld.{key,crt} startssl.chain.class1.server.crt >domain.tld.pem
chmod 600  domain.tld.pem

# fuer imap-ssl und pop-ssl eintragen 
# in den beiden .cnf den Pfad zum domain.tld.pem einzutragen funktioniert nicht, 
# courier erwartet das Zertifikat in oder unter /etc/courier
# was dagegen klappt ist ein symlink von dem Zertifikat nach imapd.pem bzw pop3d.pem
mv /etc/courier/imapd.pem /etc/courier/imapd.pem.bkp
mv /etc/courier/pop3d.pem /etc/courier/pop3d.pem.bkp
ln -s /etc/ssl/certs/startssl/domain.tld.pem /etc/courier/imapd.pem
ln -s /etc/ssl/certs/startssl/domain.tld.pem /etc/courier/pop3d.pem

# neu starten
/etc/init.d/courier-imap-ssl stop 
/etc/init.d/courier-imap-ssl start
/etc/init.d/courier-pop-ssl stop
/etc/init.d/courier-pop-ssl start


# fuer webmin eintragen
nano /etc/webmin/miniserv.conf

# dort den eintrag keyfile auskommentieren und stattdessen eintragen:
keyfile=/etc/ssl/certs/startssl/domain.tld.pem

# und neu starten
/etc/init.d/webmin restart


# für ispConfig auf domain.tld:81 einbinden
nano /root/ispconfig/httpd/conf/httpd.conf

# dort auskommentieren
##SSLCertificateFile /root/ispconfig/httpd/conf/ssl.crt/server.crt
##SSLCertificateKeyFile /root/ispconfig/httpd/conf/ssl.key/server.key
ggf. auch #SSLCertificateChainFile und #SSLCACertificateFile

# und stattdessen eintragen:
SSLCertificateFile /etc/ssl/certs/startssl/domain.tld.net.crt
SSLCertificateKeyFile /etc/ssl/private/domain.tld.net.key
SSLCertificateChainFile /etc/ssl/certs/startssl/startssl.chain.class1.server.crt
# neu starten
/etc/init.d/ispconfig_server restart


# für den Apache des betreffenden vhosts in dessen conf gleichermassen eintragen
SSLEngine on
SSLCertificateFile /etc/ssl/certs/startssl/domain.tld.net.crt
SSLCertificateKeyFile /etc/ssl/private/domain.tld.net.key
SSLCertificateChainFile /etc/ssl/certs/startssl/startssl.sub.class1.server.ca.crt

# neu starten
/etc/init.d/apache2 restart


# für postfix
mkdir -p /etc/postfix/ssl/startssl_cert
ln -s /etc/ssl/certs/startssl/domain.tld.crt /etc/postfix/ssl/startssl_cert/domain.tld.crt
ln -s /etc/ssl/certs/startssl/domain.tld.key /etc/postfix/ssl/startssl_cert/domain.tld.key
# 1 Zeile!
ln -s /etc/ssl/certs/startssl/startssl.chain.class1.server.crt 
/etc/postfix/ssl/startssl_cert/startssl.chain.class1.server.crt

# postfix' main.cf editieren und darin einfügen bzw. anpassen:
nano /etc/postfix/main.cf

#TLS Support
## smtpd
smtpd_tls_auth_only = no
smtpd_use_tls = yes

# eigener Key
smtpd_tls_key_file = /etc/postfix/ssl/startssl_cert/domain.tld.key
# eigenes Certificate
smtpd_tls_cert_file = /etc/postfix/ssl/startssl_cert/domain.tld.crt
# public der Certificate Authority
smtpd_tls_CAfile = /etc/postfix/ssl/startssl_cert/startssl.chain.class1.server.crt

smtpd_tls_loglevel = 1
smtpd_tls_received_header = yes
smtpd_tls_session_cache_timeout = 3600s
tls_random_source = dev:/dev/urandom

##smtp
smtp_use_tls = yes
smtp_tls_note_starttls_offer = yes

update:

# fuer dovecot (2.x):
nano /etc/dovecot/local.conf

ssl_cert = </etc/ssl/certs/startssl/domain.tld.crt
ssl_key = </etc/ssl/certs/startssl/domain.tld.key
ssl_ca = </etc/ssl/certs/startssl/startssl.chain.class1.server.crt

#fuer nrpe, bei mir icinga-nrpe-server

nano /etc/icinga-nrpe/nrpe.cfg

cert_file=/etc/ssl/certs/startssl/domain.tld.crt
cacert_file=/etc/ssl/certs/startssl/startssl.chain.class1.server.crt
privatekey_file=/etc/ssl/certs/startssl/domain.tld.key

Alternative Anleitung mit Beispielen für nginx, Lighttpd, Postfix, Dovecot, eJabberd, vsftpd

 

 

 

 

fail2ban fails to start

Thursday, January 27. 2011

I discovered loads of entries in mail.log logging dicionary attacks on port 110. And, going back in time, the logs showed more than just one dictionary being used, and it had been going for some time. Well, it litters the logs and you don't want to risk that finally one of them gets lucky with a user password so I searched for a way to stop the attacks.
I already used denyhosts against brute force attacks on ssh, which works fine but is limited to ssh. Instead I found out about fail2ban. 

It does what I need now but it took some smoothing of edges till I got there.

debian lenny, python 2.5.2 and fail2ban v 0.8.3 wouldn't play nice together. Fail2ban v0.8.3 apparently doesn't run with python2.5 but needs python2.4 instead

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=496633 describes the sort of thing I experienced and I followed the workaround given there:

apt-get install python2.4
apt-get install fail2ban

now edit both /usr/bin/fail2ban-server and /usr/bin/fail2ban-client, first line, to point towards  python2.4 (and not python).

#!/usr/bin/python2.4

Now fail2ban ran but still wouldn't stop the attacks. I followed the howto at http://www.howtoforge.com/fail2ban_debian_etch and while I have found plenty of good advice on that site before and after, this one didn't just work. Additionally to the config described therein a file  filter.d/pop3d.conf was needed (which is easily supplied by 
cp courierlogin.conf pop3d.conf

Further on I had to remove a line from  jail.local until it looked like this:

[pop3d]
enabled = true
port = pop3   
filter = pop3d
logpath = /var/log/mail.log
maxretry = 5

One thing which irritated me debugging the problem was that fail2ban didn't report the errors in the log file even though I had the loglevel set up to 4. To get to see the errors I had to run two shells, running  
/usr/bin/fail2ban-server -x -f
in one of them and then 
/usr/bin/fail2ban-client reload
in the other one.

Update:

Later, I found thousands of log entries re SASL LOGIN:
Feb 10 16:55:42 pipit postfix/smtpd[21738]: warning: unknown[95.62.75.67]: SASL LOGIN authentication failed: authentication failure
Feb 10 16:55:49 pipit postfix/smtpd[21738]: warning: unknown[95.62.75.67]: SASL LOGIN authentication failed: authentication failure
Feb 10 16:55:56 pipit postfix/smtpd[21738]: warning: unknown[95.62.75.67]: SASL LOGIN authentication failed: authentication failure

There was a filter for SASL in the config but it didn't seem to catch them. Google once again found prior art  and the regexp from there did the job:

 failregex = (?i): warning: [-._\w]+\[<HOST>\]: SASL (?:LOGIN|PLAIN|(?:CRAM|DIGEST)-MD5) authentication failed: \w

(Page 1 of 1, totaling 2 entries)