Vous trouverez ici quelques trucs à faire pour rendre votre serveur plus sécurisé.
Absolument pas de garantie, utilisez à vos propres risques.

1.) Désactiver la ServerSignature d'Apache comme celle-ci

Apache/2.2.3 (Debian) mod_fastcgi/2.4.2 mod_perl/2.0.2 Perl/v5.8.8

Mettez uniquement ces lignes dans votre httpd.conf (Sous Debian Etch vous devez les mettrent dans votre apache2.conf)

# Disable ServerInfo
ServerSignature Off
ServerTokens Prod

2.) Désactiver la fonction de Debogage

Un individu malveillant peut utiliser cette faille pour tromper vos utilisateurs, afin qu'ils lui donne du pouvoir. Ajoutez les lignes suivantes pour chaque serveur virtuel dans votre fichier de configuration afin de désactiver le Débogage

RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]

3.) Désactiver la bannière de ProFTPD

La connection à votre serveur FTP ressemble à ca

Verbindung mit 62.75.xx.xx wurde hergestellt.
220 ProFTPD 1.3.0 Server (vsxxxxxx) [62.75.xx.xx]
Benutzer (62.75.xx.xx:(none)):

Pour désactiver la bannière, ajoutez la ligne suivante à votre proftpd.conf

ServerIdent                    off

4.) Activer le SSL dans ProFTPD

Pour des transferts sécurisés, vous pouvez ajouter le SSL à ProFTPD

Créer un certificat SSL:

openssl req -new -x509 -days 365 -nodes  -out /etc/proftpd/ssl.crt -keyout /etc/proftpd/ssl.key

Ouvrir le fichier proftpd.conf pour activer le SSL

# vi /etc/proftpd/proftpd.conf

Passez la variable TLSEngine sur "on" comme ci-dessous

#
# SSL via TLS
#
<IfModule mod_tls.c>
  TLSEngine             on              # on for use of TLS
  TLSLog                                /var/log/proftpd/ftp_ssl.log            # where to log to
  TLSProtocol                           SSLv23                                  # SSLv23 or TLSv1
  TLSOptions                            NoCertRequest                           # either to request the certificate or not
  TLSRSACertificateFile                 /etc/proftpd/ssl.crt                    # SSL certfile
  TLSRSACertificateKeyFile              /etc/proftpd/ssl.key                    # SSL keyfile
  TLSVerifyClient                       off                                     # client verification
</IfModule>

Redemarer proftpd pour activer le SSL:

# /etc/init.d/proftpd restart

5.) Changer la bannière SMTP

Si vous désirez changer la bannière Postfix SMPT:

Connected to your-domain.tld.
Escape character is '^]'.
220 your-domain.tld. ISPCP 1.0 Priamos Managed ESMTP 1.0.0 RC2 OMEGA

Ouvrez votre "/etc/postfix/main.cf" et changer la bannière ci-dessous par ce que vous voulez.

smtpd_banner = $myhostname ISPCP 1.0 Priamos Managed ESMTP 1.0.0 RC2 OMEGA

6. Installer & Configurer fail2ban

Fail2Ban bloque automatiquement les adresses IP après plusieurs échecs d'authentifications.

Il fonctionne avec Apache,SSH,FTP et Mail.

Installation de fail2ban avec apt-get

# apt-get install fail2ban

Après l'installation vous pouvez configurer fail2ban grâce à ces deux fichiers de configuration qui sont dans : /etc/fail2ban/

/etc/fail2ban/fail2ban.conf
/etc/fail2ban/jail.conf

Ouvrez jail.conf pour activer le bloquage de certains Services.

# vi /etc/fail2ban/jail.conf

Maintenant vous pouvez activer ou désactiver les services que vous voulez protéger.

Par defaut SSH est activé.

Si vous voulez activer Apache,

Il faut modifier ce qui suit:

#
# HTTP servers
#

[apache]

enabled = false
port    = http
filter  = apache-auth
logpath = /var/log/apache*/*access.log
maxretry = 6

en

#
# HTTP servers
#

[apache]

enabled = true
port    = http
filter  = apache-auth
logpath = /var/log/apache2/users/*access.log
maxretry = 6

Pour le FTP (proftpd)

[proftpd]

enabled  = false
port     = ftp
filter   = proftpd
logpath  = /var/proftpd/proftp.log
maxretry = 6

modifier en

[proftpd]

enabled  = true
port     = ftp
filter   = proftpd
logpath  = /var/log/auth.log
maxretry = 3

Vous pouvez changer le nombre maximum d'essais avant le ban avec

maxretry = X

Si vous souhaitez changer la durée du ban

bantime  = 600 (is set in seconds)

Attention: fail2ban utilise les règles du Firewall pour bloquer les IPs.
Le ban par defaut est de 10 minutes, après cette période l'IP est automatiquement débloquée.

Le log de fail2ban est dans le répertoire

/var/log/fail2ban.log

7.) SSL pour le Service Mail (Courier)

Pour commencer installez le packet courier-ssl.

# apt-get install courier-imap-ssl courier-pop-ssl

Un certificat par defaut est créé à l'installation. Nous devons donc le changer.

Ouvrez the /etc/courier/imapd.cnf

# vi /etc/courier/imapd.cnf

et modifier les attributs en fonction de vos besoins.
Faite de même pour le fichier /etc/courier/pop3d.cnf

# vi /etc/courier/pop3d.cnf 

Après ces modification, faite un backup de l'ancien certificat avant d'en générer un nouveau.

# cd /etc/courier/ && mv pop3d.pem pop3d.pem.orig && mv imapd.pem imapd.pem.orig

Maintenant on peut générer le nouveau certificat:

# dpkg-reconfigure courier-pop-ssl && dpkg-reconfigure courier-imap-ssl

Le service Mail est prêt pour le SSL.
Modifier votre client afin d'utiliser POP3-SSL sur le port 995 et IMAP-SSL sur le port 993

8.) Make SSH safer

Every Scriptkiddy checks your Server for a open Port 22 and test to login with the root account.
We will change these things to the good with an other Port and disable the root login via ssh.

First we need a user on the system for a later login. If there is already one, jump over to the next step. If not, create it:

# adduser new_username

Open your sshd_config to change the settings:

# vi /etc/ssh/sshd_config

Change the Port from

Port 22

to

Port 222

Change this line:

PermitRootLogin yes

to

PermitRootLogin no

Restart the SSH-Server

# /etc/init.d/ssh restart

Close your connection and connect again to your Server on Port 222 with your new Username.
To become root, only do a:

# su

9.) Prevent DOS-Attacks
To prevent simple Denial-of-Service attacks you can use the mod_evasive module. Download the actual version from http://www.zdziarski.com/projects/mod_evasive/ and unpack it. Make sure, that apache2-prefork-dev is installed.

# apt-get install apache2-prefork-dev
# wget http://www.zdziarski.com/projects/mod_evasive/mod_evasive_1.10.1.tar.gz
# tar -xzf mod_evasive_1.10.1.tar.gz
# cd mod_evasive

Install it with Apache Extensions Module (apxs).

#  apxs2 -i -a -c mod_evasive20.c

The module will be built and installed into your httpd.conf.

Optionally you can change some specific directives in your /etc/apache2/apache2.conf file. Just add the following lines and change them to your needs.

<IfModule mod_evasive20.c>
    DOSHashTableSize    3097
    DOSPageCount        2
    DOSSiteCount        50
    DOSPageInterval     1
    DOSSiteInterval     1
    DOSBlockingPeriod   10
</IfModule>

ATTENTION: This config may produce "403 Forbidden" Errors on regular sites (to example: typo3, gallery,...)

You can also add the following directives:

    DOSEmailNotify      you@yourdomain.com
    DOSSystemCommand    "su - someuser -c '/sbin/... %s ...'"
    DOSLogDir           "/var/lock/mod_evasive"

After all, just restart your Apache to load the module.

# sudo /etc/init.d/apache2 restart

10.) Securing Open DNS server (BIND 9) After a clean install of a Debian server, dnsstuff.com reports the server as an open dns server(anyone can query the server about any domain => high load and high transfer). 2 steps for fixing this problem:

a. first edit /etc/bind/named.conf.options (or /etc/named/named.conf for other distros, options paragraph) and add:

recursion no;
transfer-format many-answers; //this is for speed up the transfer to a secondary dns

b. we need to modify the template used by ISPCP to generate to zone files, on Debian this is /etc/ispcp/bind/parts/cfg_entry.tpl. The file after modification should looks like:

zone "{DMN_NAME}" {
        type    master;
        file    "{DB_DIR}/{DMN_NAME}.db";
        notify  YES;
        allow-query {
                any;
        };
};

Restart BIND:

/etc/init.d/bind9 restart

You are done.