FTPS : FTP Secure over SSL/TLS

Publié: 11 février 2013 dans Debian, Linux, Securité
Tags:, , , , , , , , , , , , , , ,

1.  FTPS : c’est quoi ?

Le FTPS, ou File Transfer Protocol Secure, est un protocole réseau permettant l’échange de fichiers informatiques.

Il se base sur le protocole FTP (RFC 959) mais ajoute une couche de chiffrage des échanges avec les protocoles SSL ou TLS. Ainsi, il permet au visiteur de vérifier l’identité du serveur auquel il accède grâce à un certificat d’authentification.

2. Quel chiffrement ?

La connexion s’effectue sur le port 21, le port de commande FTP standard, et puis soit:

  • la commande « AUTH TLS » (anciennement « AUTH TLS-C ») demande au serveur de chiffrer le transfert de commande en TLS, et le chiffrement du transfert de données se fait par la commande « PROT P ».
  • (non standard) la commande « AUTH SSL » (anciennement « AUTH TLS-P ») demande au serveur de chiffrer le transfert de commande et de données en SSL.

Cette approche est compatible avec les serveurs ou clients FTP ne supportant pas le chiffrement SSL/TLS, auquel cas une connexion non chiffrée pourra être utilisée ou bien refusée.

Le schéma d’URI est ftpes:// ou simplement ftp://

3.  Installation du service FTP

3.1.          Installation de ProFTP

Se connecter sur le serveur cible en tant qu’administrateur

#apt-get install proftpd

4.  Génération du certificat SSL

4.1.          Installation de la couche SSL

#apt-get install openssl

4.2.          Génération du certificat SSL

4.2.1.1.                      Type de certificat

Certificat : DHE-RSA-AES256-SHA (256 bits)

Durée de validité : 365 jours

4.2.1.2.                      Génération

# openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/macleftp.cert.pem -keyout /etc/ssl/certs/macleftp.key.pem

4.2.1.3.                      Configuration

Country Name (2 letter code) [AU]:FR

State or Province Name (full name) [Some-State]:Orleans

Locality Name (eg, city) []:Orleans

Organization Name (eg, company) [Internet Widgits Pty Ltd]:NOM DE MA SOCIETE

Organizational Unit Name (eg, section) []:

Common Name (eg, YOUR name) []:URL DE MON SERVICE FTPS

Email Address []:EMAIL DE L ADMIN FTPS

5. Configuration du service FTPS

#

# /etc/proftpd/proftpd.conf — This is a basic ProFTPD configuration file.

# To really apply changes reload proftpd after modifications.

#

# Includes DSO modules

Include /etc/proftpd/modules.conf

# Set off to disable IPv6 support which is annoying on IPv4 only boxes.

UseIPv6                           on

# If set on you can experience a longer connection delay in many cases.

IdentLookups               off

ServerName                 « FTP »

ServerType                 inetd

#cacher l’identite du serveur

#DeferWelcome              off

ServerIdent                on « FTP Server ready »

DeferWelcome               on

# Autoriser l’usage de /etc/ftpusers pour interdire des users

#TO DO: voir quels comptes sont a interdire

UseFtpUsers                on

MultilineRFC2228           on

DefaultServer              on

ShowSymlinks               on

TimeoutNoTransfer          600

TimeoutStalled                    600

TimeoutIdle                1200

DisplayLogin                    welcome.msg

DisplayChdir                      .message true

ListOptions                       « -l »

DenyFilter                 \*.*/

# Users require a valid shell listed in /etc/shells to login.

# Use this directive to release that constrain.

# RequireValidShell        off

# Port 21 is the standard FTP port.

Port                       21

# In some cases you have to specify passive ports range to by-pass

# firewall limitations. Ephemeral ports can be used for that, but

# feel free to use a more narrow range.

# PassivePorts                  49152 65534

# If your host was NATted, this option is useful in order to

# allow passive tranfers to work. You have to use your public

# address and opening the passive ports used on your firewall as well.

# MasqueradeAddress        1.2.3.4

# This is useful for masquerading address with dynamic IPs:

# refresh any configured MasqueradeAddress directives every 8 hours

<IfModule mod_dynmasq.c>

# DynMasqRefresh 28800

</IfModule>

# To prevent DoS attacks, set the maximum number of child processes

# to 30.  If you need to allow more than 30 concurrent connections

# at once, simply increase this value.  Note that this ONLY works

# in standalone mode, in inetd mode you should use an inetd server

# that allows you to limit maximum number of processes per service

# (such as xinetd)

MaxInstances               30

# Set the user and group that the server normally runs at.

#User                      proftpd

User                       nobody

Group                      nogroup

#####################

# SUPPORT SSL/TLS : #

#####################

#####################

# SUPPORT SSL/TLS : #

#####################

#Securisation des transferts avec TLS – generer le certificat x509 via la commande :

#openssl req -new -x509 -days 365 -nodes -out /etc/ssl/certs/macleftp.cert.pem -keyout /etc/ssl/certs/macleftp.key.pem

TLSEngine on

#On force toutes les connections avec ssl

TLSRequired on

# logs

TLSLog /var/log/proftpd/proftpd.tls_log

# Protocole

TLSProtocol SSLv23

TLSOptions NoCertRequest

# Certif et key

TLSRSACertificateFile /etc/ssl/certs/macleftp.cert.pem

TLSRSACertificateKeyFile /etc/ssl/certs/macleftp.key.pem

TLSVerifyClient off

# Restreint le range ports sur lequel votre serveur FTPS renverra ces informations
# PASV command from a client. Use IANA-registered ephemeral port range of
# 49152-65534
PassivePorts 49152 65534

###########################################################

# Umask 022 is a good standard umask to prevent new files and dirs

# (second parm) from being group and world writable.

Umask                      022  022

# Normally, we want files to be overwriteable.

AllowOverwrite                    on

# Uncomment this if you are using NIS or LDAP via NSS to retrieve passwords:

# PersistentPasswd         off

# This is required to use both PAM-based authentication and local passwords

# AuthOrder                mod_auth_pam.c* mod_auth_unix.c

# Be warned: use of this directive impacts CPU average load!

# Uncomment this if you like to see progress and transfer rate with ftpwho

# in downloads. That is not needed for uploads rates.

#

# UseSendFile              off

#####################

#   FORMATS LOGS :  #

#####################

LogFormat            default « %h %l %u %t \ »%r\ » %s %b »

# Log des logins

#ExtendedLog          /var/log/proftpd/proftpd.auth_log      AUTH auth

# Pour les parranos que nous sommes :

ExtendedLog          /var/log/proftpd/proftpd.paranoid_log  ALL default

#The TransferLog directive configures the full path to the « wu-ftpd style » file transfer log (par defaut)

TransferLog /var/log/xferlog

##########################################################

#TransferLog /var/log/proftpd/xferlog

#SystemLog   /var/log/proftpd/proftpd.log

<IfModule mod_quotatab.c>

QuotaEngine off

</IfModule>

<IfModule mod_ratio.c>

Ratios off

</IfModule>

# Delay engine reduces impact of the so-called Timing Attack described in

# http://security.lss.hr/index.php?page=details&ID=LSS-2004-10-02

# It is on by default.

<IfModule mod_delay.c>

DelayEngine on

</IfModule>

<IfModule mod_ctrls.c>

ControlsEngine        off

ControlsMaxClients    2

ControlsLog           /var/log/proftpd/controls.log

ControlsInterval      5

ControlsSocket        /var/run/proftpd/proftpd.sock

</IfModule>

<IfModule mod_ctrls_admin.c>

AdminControlsEngine off

</IfModule>

#

# Alternative authentication frameworks

#

#Include /etc/proftpd/ldap.conf

#Include /etc/proftpd/sql.conf

#

# This is used for FTPS connections

#

#Include /etc/proftpd/tls.conf

# A basic anonymous configuration, no upload directories.

# <Anonymous ~ftp>

#   User                          ftp

#   Group                         nogroup

#   # We want clients to be able to login with « anonymous » as well as « ftp »

#   UserAlias              anonymous ftp

#   # Cosmetic changes, all files belongs to ftp user

#   DirFakeUser     on ftp

#   DirFakeGroup on ftp

#

#   RequireValidShell             off

#

#   # Limit the maximum number of anonymous logins

#   MaxClients                    10

#

#   # We want ‘welcome.msg’ displayed at login, and ‘.message’ displayed

#   # in each newly chdired directory.

#   DisplayLogin                  welcome.msg

#   DisplayChdir           .message

#

#   # Limit WRITE everywhere in the anonymous chroot

#   <Directory *>

#     <Limit WRITE>

#       DenyAll

#     </Limit>

#   </Directory>

#

#   # Uncomment this if you’re brave.

#   # <Directory incoming>

#   #   # Umask 022 is a good standard umask to prevent new files and dirs

#   #   # (second parm) from being group and world writable.

#   #   Umask                     022  022

#   #            <Limit READ WRITE>

#   #            DenyAll

#   #            </Limit>

#   #            <Limit STOR>

#   #            AllowAll

#   #            </Limit>

#   # </Directory>

#

# </Anonymous>

#####################

#    CONTEXTES :    #

#####################

# Contexte GLOBAL :

<Global>

# Limite les accès depuis Intranet : adresses privées classe B

#        <Limit ALL LOGIN>

#               Order Allow,Deny

#               Allow from 192.168.

#                DenyAll

#        </Limit>

# Chrooter users : Les limiter à leur répertoire personnel

DefaultRoot ~

# NB Pour interdire le ftp à un utilisateur : Ajoutez son nom a la liste contenue dans le fichiers /etc/ftpusers

# Seul le propriétaire d’un fichier peut le modifier.

Umask  022  022

# Messages a l’utilisateur

AccessDenyMsg « Acces non autorise pour l’utilisateur : %u. »

AccessGrantMsg « Bienvenue %u. sur le FTP. »

ListOptions « -l »

HiddenStores on

# Authoriser la reprise des telechargements :

AllowStoreRestart on

AllowRetrieveRestart on

#Filtres

DenyFilter \*.*/

ShowSymlinks on

# Authorise l’ecriture d’un fichier sur un fichier portant le meme nom :

AllowOverwrite on

</Global>

<Directory /home>

<Limit  LOGIN>

DenyAll

</Limit>

</Directory>

#<Directory /~>

#        HideNoAccess on

# Filtrage par IP internes :

#        <Limit LOGIN CWD CDUP RETR STOR RNFR RNTO DELE RMD MKD PWD LIST NLIST>

#                Order Allow,Deny

#               Allow from 192.168.

#                DenyAll

#                IgnoreHidden on

#       </Limit>

#</Directory>

# Contexte Pages Persos :

#<Directory ~/public_html>

#        <Limit LOGIN CWD CDUP RETR STOR RNFR RNTO DELE RMD MKD PWD LIST NLIST>

#                AllowAll

#                IgnoreHidden on

#        </Limit>

#</Directory>

##########################################################

7. FTPS et Firewall

Votre administrateur réseau et sécurité était votre ami ? Il ne l’est plus.

En effet, le protocole FTPS fonctionne différemment des autres protocoles.

Le client distant se connecte sur le port 21 de votre firewall. Ce dernier doit renvoyer le flux vers votre serveur FTPS et lequel renvoit les informations sur un port au hasard mais différent du port 21 !!!

C’est pourquoi vous ajoutez

# PASV command from a client. Use IANA-registered ephemeral port range of
# 49152-65534
PassivePorts 49152 65534

La configuration du firewall devra autoriser les connexions distantes sur le port 21 vers le serveur FTPS et autoriser – sans control – l’envoi d’informations depuis le serveur FTPS vers Internet et sur les prots entre 49152 et 65534

Laisser un commentaire