UJP - 技術情報1

Life is fun and easy!

不正IP報告数

Okan Sensor
 
メイン
ログイン
ブログ カテゴリ一覧

vsFTPdをセキュアに使えるように設定する

vsFTPdをセキュアに使えるように設定する


0.改訂履歴

  • 2005.10.21 新規作成
  • 2006.06.13 諸設定の追加
  • 2006.06.19 xinetdのFTPが動作している場合の設定について追加

1.はじめに

 このドキュメントでは,vsFTPdを使って,セキュアなFTPサーバを構築する手順を説明する. vsFTPdは,それまで使われていたwu-ftpdに変わってRedHatが採用したFTPサーバである. 以前のFTPサーバはセキュリティホールが頻繁に見つかるとして有名であった.

 この資料では,vsFTPサーバの単純な起動から,セキュアに運用するための制限されたディレクトリ以外にアクセスできないように設定する方法などを記述する.

2.モジュールの確認と動作

  • RPMでインストールされていることを確認する.
[root@springboard root]# rpm -qa | grep ftpd
vsftpd-1.2.1-3E.1
[root@springboard root]# 
  • vsftpdを起動する.
[root@springboard root]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@springboard root]#
  • プロセスを確認する.
[root@springboard root]# ps -ef | grep ftp
root  933  1  0 22:35 pts/1 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf
root 1495 834 0 22:50 pts/1 00:00:00 grep ftp
[root@springboard root]# 
  • 動作していることが確認できた.

3.ディレクトリ参照を制限するユーザを作成する

  • vsftpd.confファイルを書き換え,制限を付ける.
[root@springboard root]# locate vsftpd.conf
/etc/vsftpd/vsftpd.conf
/usr/share/man/man5/vsftpd.conf.5.gz
[root@springboard root]#  
  • 下記のように書き換える.
変更前
#
# 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().
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
変更後
#
# 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().
chroot_list_enable=YES
# (default follows)
chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
  • リストファイルに,制限したいユーザを記述する.
[root@springboard root]# cat /etc/vsftpd.chroot_list
seigenuser
[root@springboard root]#
  • この場合,seigenuserというアカウントで接続してきた場合は,アクセス範囲が制限される.
  • FTPデーモンを再起動する.
[root@springboard root]# /etc/init.d/vsftpd restart
Shutting down vsftpd:                                      [  OK  ]
Starting vsftpd for vsftpd:                                [  OK  ]
[root@springboard root]# 
  • 接続してみる.
iMacG5:~ shinnai$ ftp secureftp.ujp.jp
Connected to imacg5.ujp.jp.
220 (vsFTPd 1.2.1)
Name (192.168.0.1:shinnai): seigenuser
331 Please specify the password.
Password: ■■■■■■■■■■
230 Login successful.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp> 
  • ログインできた.
  • ファイルリストを取得する.
ftp> ls
229 Entering Extended Passive Mode (|||11437|)
150 Here comes the directory listing.
226 Directory send OK.
ftp> 
  • 何も表示されてない・・・のは,表示可能なファイルがないから.
  • 隠しファイルも表示してみる.
ftp> ls -la
229 Entering Extended Passive Mode (|||50188|)
150 Here comes the directory listing.
drwx------    4 1157     1157         4096 Jun 12 11:24 .
drwx------    4 1157     1157         4096 Jun 12 11:24 ..
-rw-r--r--    1 1157     1157           24 Jun 12 11:24 .bash_logout
-rw-r--r--    1 1157     1157          191 Jun 12 11:24 .bash_profile
-rw-r--r--    1 1157     1157          124 Jun 12 11:24 .bashrc
-rw-r--r--    1 1157     1157         5542 Jun 12 11:24 .canna
-rw-r--r--    1 1157     1157          237 Jun 12 11:24 .emacs
-rw-r--r--    1 1157     1157          120 Jun 12 11:24 .gtkrc
drwxr-xr-x    3 1157     1157         4096 Jun 12 11:24 .kde
drwxr-xr-x    2 1157     1157         4096 Jun 12 11:24 .xemacs
-rw-r--r--    1 1157     1157          136 Jun 12 11:24 .zshrc
226 Directory send OK.
ftp> 
  • ホームディレクトリの中身が表示されることは確認できた.
  • ルートディレクトリに移動してみる.
ftp> cd /
250 Directory successfully changed.
ftp> ls -la
229 Entering Extended Passive Mode (|||63529|)
150 Here comes the directory listing.
drwx------    4 1157     1157         4096 Jun 12 11:24 .
drwx------    4 1157     1157         4096 Jun 12 11:24 ..
-rw-r--r--    1 1157     1157           24 Jun 12 11:24 .bash_logout
-rw-r--r--    1 1157     1157          191 Jun 12 11:24 .bash_profile
-rw-r--r--    1 1157     1157          124 Jun 12 11:24 .bashrc
-rw-r--r--    1 1157     1157         5542 Jun 12 11:24 .canna
-rw-r--r--    1 1157     1157          237 Jun 12 11:24 .emacs
-rw-r--r--    1 1157     1157          120 Jun 12 11:24 .gtkrc
drwxr-xr-x    3 1157     1157         4096 Jun 12 11:24 .kde
drwxr-xr-x    2 1157     1157         4096 Jun 12 11:24 .xemacs
-rw-r--r--    1 1157     1157          136 Jun 12 11:24 .zshrc
226 Directory send OK.
ftp> 
  • ローカルのディレクトリしか確認できない.
  • 他のディレクトリに移動してみる.
ftp> cd /tmp
550 Failed to change directory.
ftp> cd /var
550 Failed to change directory.
ftp> 
  • 移動できない.

4.自動起動設定

  • OSの起動時に,vsFTPdが起動するように設定する.
  • まずは,現在の設定を確認する.
[root@springboard root]# /sbin/chkconfig --list | grep ftp
vsftpd          0:off   1:off   2:off   3:off   4:off   5:off   6:off
        gssftp: off
        tftp:   off
[root@springboard root]#
  • 起動されないようになっているので,起動させる.
[root@springboard root]# /sbin/chkconfig --level 35 vsftpd on
[root@springboard root]# /sbin/chkconfig --list | grep ftp
vsftpd          0:off   1:off   2:off   3:on    4:off   5:on    6:off
        gssftp: off
        tftp:   off
[root@springboard root]# 
  • これで次回からOS起動時に自動起動される.

5.その他設定

  • vsftpd.confの設定でよく使いそうな物を紹介する.
  • 項目で先頭に#が付いている物は,コメントアウトなので有効ではない.
項目 説明
anonymous_enable=YES
 匿名FTPを禁止にするかどうか.
 NOに設定すべき.
local_enable=YES
 ローカルユーザーを許可
write_enable=YES
 書き込みを許可する
local_umask=022
 PUTしたファイルのアクセス権を設定する.
#anon_upload_enable=YES
 匿名FTPのアップロードを許可
#anon_mkdir_write_enable=YES
 匿名FTPのディレクトリ作成等を許可する
dirmessage_enable=YES
 匿名FTPでログインとき/var/ftp/.messageを表示する.
xferlog_enable=YES
 xferlogを有効にする.
#xferlog_file=/var/log/vsftpd.log
 xferlog_fileの場所を指定する.
xferlog_std_format=YES
 標準的なFTPログにする.
log_ftp_protocol=YES
 ftpコマンドログに残るようにする.
connect_from_port_20=YES
 FTP接続時のポート番号を設定する.
#idle_session_timeout=600
 アイドル時セッションのタイムアウト(10分)
#data_connection_timeout=120
 データ接続時のタイムアウト(2分)
#ftpd_banner=Welcome to blah FTP service.
 login時にバナーメッセージを表示する場合.
userlist_enable=YES
 ユーザーリストを有効にする.
userlist_deny=NO
 vsftpd.user_listに書かれている動きが変わる.

 NOの場合は,リストのユーザがログイン許可ユーザとなる.
 YESの場合は,リストのユーザがログイン拒否ユーザとなる

chroot_list_enable=YES
 chrootリストを有効にする
#chroot_list_file=/etc/vsftpd.chroot_list
 chrootを行う場合に制限するユーザリストを記述するファイルを指定する.
#chown_uploads=YES
#chown_username=whoever
#nopriv_user=ftpsecure
#async_abor_enable=YES
#ascii_upload_enable=YES
#ascii_download_enable=YES
#deny_email_enable=YES
#banned_email_file=/etc/vsftpd.banned_emails
#ls_recurse_enable=YES
pam_service_name=vsftpd
listen=YES
  • 以上.

7.xinetdのFTP設定を変更する

  • vsftpdを起動しても,動作しない場合がある
[root@springboard admin]# /etc/init.d/vsftpd start
vsftpd用のvsftpdを起動中:                                  [  OK  ]
[root@springboard admin]# ps -ef | grep ftpd
root     18778 18088  0 16:26 pts/1    00:00:00 grep ftpd
[root@springboard admin]#
  • プロセスが動作していない.
  • chkconfigを使って,ftpプロセスについて確認する.
[root@springboard admin]$ /sbin/chkconfig --list ftp
ftp             on
[root@springboard admin]$ 
  • 動作するようになっている.
  • もう少し詳しく見てみる.
[root@springboard admin]$ /sbin/chkconfig --list
microcode_ctl   0:off   1:off   2:on    3:on    4:on    5:on    6:off
gpm             0:off   1:off   2:on    3:on    4:on    5:on    6:off

〜略〜


sshd2           0:off   1:off   2:on    3:on    4:on    5:on    6:off
httpd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
xinetd based services:
        krb5-telnet:    off
        rsync:  off
        eklogin:        off
        gssftp: off
        klogin: off
        chargen-udp:    off
        kshell: off
        auth:   on
        chargen:        off
        daytime-udp:    off
        daytime:        off
        echo-udp:       off
        echo:   off
        ftp:    on
        services:       off
        time:   off
        time-udp:       off
        cups-lpd:       off
        sgi_fam:        on
        telnet: on
        dbskkd-cdb:     off
        tftp:   off
        finger: off
[root@springboard admin]$ 
  • xinetdのサブプロセスとしてFTPが稼働していることがわかる.
  • FTPを停止する.
[root@springboard cdj]# /sbin/chkconfig --level 12345 ftp off
[root@springboard cdj]# /sbin/chkconfig --list ftp
ftp             off
[root@springboard cdj]# 
  • この後は,vsFTPdを稼働させればよい.


広告スペース
Google