SSブログ

---追記用---「vsftpd」の設定 [vsftpd]

---追記用---「vsftpd」の設定

■「/etc/vsftpd/」のデフォルトの状態確認。

       
[root@centos vsftpd]# ll
合計 20
-rw-------. 1 root root  125  ftpusers
-rw-------. 1 root root  361  user_list
-rw-------. 1 root root 4600  vsftpd.conf
-rwxr--r--. 1 root root  338  vsftpd_conf_migrate.sh
       
      
 必要に迫られたときに調べた内容を追記していくページにします。

■「/etc/vsftpd/ftpusers」のデフォルトの状態確認。

       
# Users that are not allowed to login via ftp
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

       
      

■「/etc/vsftpd/user_list」のデフォルトの状態確認。

       
# vsftpd userlist
# If userlist_deny=NO, only allow users in this file
# If userlist_deny=YES (default), never allow users in this file, and
# do not even prompt for a password.
# Note that the default vsftpd pam config also checks /etc/vsftpd/ftpusers
# for users that are denied.
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
news
uucp
operator
games
nobody

       
      

■「/etc/vsftpd/vsftpd.conf」のデフォルトの状態確認。

       
# Example config file /etc/vsftpd/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=YES
#
# Uncomment this to allow local users to log in.
#local_enable=YES ←「#」外すとローカルユーザーのアクセスとダウンロード可能に。
#
# Uncomment this to enable any form of FTP write command.
#write_enable=YES ←「#」外すとローカルユーザーのアップロード可能に。
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022 ←「#」外すとパーミッション「755」に。
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd/banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
#chroot_local_user=YES
#chroot_list_enable=YES ←「chroot_list_file」のファイルを使用する宣言。
# (default follows)
#chroot_list_file=/etc/vsftpd/chroot_list ←使用する場合は作成しなくてはならない。
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

       
      

■ローカルユーザーの上位ディレクトリ参照の制限。

       
[root@centos vsftpd]# vi /etc/vsftpd/vsftpd.conf
---省略---
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list

ftpクライアント→ログイン
500 OOPS: unrecognised variable in config file: allow_writable_root ←エラー。

[root@centos vsftpd]# vi /etc/vsftpd/vsftpd.conf
---省略---
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list
allow_writeable_chroot=YES ←追記。
       
      
 初めてローカルユーザーにて接続したところ、「/」まで参照できたので驚きました。
 まぁ、ターミナルで移動できる場所を考えれば、それと同様の移動ができるのは自然なことなのでしょう。
 ただローカルユーザーを他人に使わせるために作成した場合、上位ディレクトリを参照されるのはセキュリティ上好ましくないような気がします。
 なのでこれを制限する方法を記述しておきます。

 上記の設定ですと、「chroot_list」に記載されたユーザーがホームディレクトリの上位ディレクトリに移動できるという設定のはずです。
 しかし実際には、未記載「bibo-roku」ユーザーは「local_enable=YES」であるにも拘わらずログインさえできませんでした。
 試しに「chroot_list」「bibo-roku」を書き込むとログインはできるのですが、当然上位にも移動できてしまいました。
 調べてみると、上記の条件の場合「ホームディレクトリ(bibo-roku)」のパーミッションが「書き込み可能」になっているとログイン「できない」ということらしいです。
 試してみたところ、確かにログインできて上位に移動できなくなりました。
 しかしこれでは書き込み(アップロード)できないし……。

 で!
「allow_writeable_chroot=YES」これを追記することで「ローカルユーザーをホームディレクトリ以上のディレクトリに移動させない」が実現できました。

■「/etc/vsftpd/chroot_list」の作成。

       
[root@centos vsftpd]# vi /etc/vsftpd/vsftpd.conf
---省略---
chroot_local_user=YES
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd/chroot_list ←使用するためにはファイルを作成する必要あり。
allow_writeable_chroot=YES

[root@centos vsftpd]# vi chroot_list
root
bibo-roku

[root@centos vsftpd]# ll
合計 24
-rw-------. 1 root root chroot_list

       
      
 上記の設定だと「chroot_list」に記載されているローカルユーザーはホームディレクトリの上位ディレクトリへ移動できる。を実現します。
 そのリストはデフォルトではないので、作ります。パーミッションは「600」で良いようです。

■「SElinux」を有効にして動作させる。

       
[bibo-roku@centos ~]$ sudo /usr/sbin/getsebool -a | grep ftp ←ルール確認コマンドツール。
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> off  ←ホームディレクトリへのアクセス。
ftpd_connect_db --> off
ftpd_use_fusefs --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_use_cifs --> off
tftp_use_nfs --> off

[bibo-roku@centos ~]$ sudo setsebool -P ftp_home_dir 1 ←「1」で「on」に。

[bibo-roku@centos ~]$ sudo /usr/sbin/getsebool -a | grep ftp ←確認。
allow_ftpd_anon_write --> off
allow_ftpd_full_access --> off
allow_ftpd_use_cifs --> off
allow_ftpd_use_nfs --> off
ftp_home_dir --> on ←変更された。
ftpd_connect_db --> off
ftpd_use_fusefs --> off
ftpd_use_passive_mode --> off
httpd_enable_ftp_server --> off
tftp_anon_write --> off
tftp_use_cifs --> off
tftp_use_nfs --> off
       
      
「SElinux」を有効にしてセキュリティを有効にしてみる。
 anonymousユーザーではanonymousユーザーのデフォルト設定で(アップロードはできないとか)接続ができました。
 しかし、一般ユーザー(今回はbibo-roku)は接続が不可能でした。homeディレクトリへのアクセスが禁止されている。とのこと。
「getsebool -a | grep ftp」はSELinuxの組み込みルールの有効/無効状態(boolean)を確認するコマンドツールで、「ftp」だけを取り出しました。
 ふーむ。つまりこれだけの項目が「SElinux」により制御されているのでしょうかね。
 今回は「ftp_home_dir」を「on」に変更します。
「setsebool [-P] <boolean><value>」にて設定します。[-P]を付けることによりシステム設定に自動反映され、次回起動時にも反映されます。 <value>は「0=off」「1=on」です。
「SElinux」や「vsftpd」の再起動無くhomeディレクトリへのアクセスが可能になりました。



nice!(0)  コメント(1)  トラックバック(0) 
共通テーマ:パソコン・インターネット

nice! 0

コメント 1

Florentina

That is a really good tip particularly to those new to the blogosphere.
Simple but very precise information… Thanks for sharing
this one. A must read article!
by Florentina (2020-02-07 02:52) 

コメントを書く

お名前:
URL:
コメント:
画像認証:
下の画像に表示されている文字を入力してください。

トラックバック 0

この広告は前回の更新から一定期間経過したブログに表示されています。更新すると自動で解除されます。