2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

カーネル2.4のスーパーサーバ!

前書き:
インターネットスーパーサーバって、ご存じのようにinetdデーモンのことです。telnetとかftpその他のモジュールを起動するデーモンです。カーネル2.2のLinuxではinetdデーモンが活躍していました。しかし、ネットの世界も物騒になり、セキュリティ面でinetdの信頼性が疑われるようになりました。そこでカーネル2.4からは、xinetdデーモンというものが採用されました。ここでは、このxinetdについて書いてみました。


1.inetd、xinetdの役割

インターネットスーパーサーバinetd、xinetdは(inetdとxinetdは両者とも役割は同じであるため、以降inetdとして説明する)、一言で言うとtelnetやftpやpopなど、多くのサービスがデーモンとしてメモリに常駐するのではなく、リモートホストから要求が有った場合にinetdと呼ばれるプログラムが、その要求を確認して要求を受けたサービスを起動する。このような役目です。
以前のinetdは /etc/inetd.conf と言うファイルを参照してサービスのリクエストに答えてサービスを起動していた。inetdは、inetd,confの記述でサービスが一元管理されるため、不要なサービスを立ち上げたくない場合は、サービスの起動パラメータをコメントする事により、不要なサービスの起動を防止できる。まあ、ある意味のセキュリティとしては効果的です。
さらに、inetd自体にはアクセス制御が出来ないため、代わりに TCP_Wrapper と言うものでアクセス制御を行うことができる。アクセス制御とは、例えば telnet に Wrapper をかけた場合は、telnetで接続できるホストを /etc/hosts.allow ファイルで指定できる。


2.inetdについて

inetdは、前述したようにinetd.confの内容を参照する。以下にinetd.confの内容をのぞいてみる。

# vi /etc/inetd.conf

#
# inetd.conf This file describes the services that will be available
# through the INETD TCP/IP super server. To re-configure
# the running INETD process, edit this file, then send the
# INETD process a SIGHUP signal.
#
# Version: @(#)/etc/inetd.conf 3.10 05/27/93
#
# Authors: Original taken from BSD UNIX 4.3/TAHOE.
# Fred N. van Kempen,
#
# Modified for Debian Linux by Ian A. Murdock
#
# Modified for RHS Linux by Marc Ewing
# Modified for TurboLinux/TurboLinux Server by Scott Stone
#
# Echo, discard, daytime, and chargen are used primarily for testing.
#
# To re-read this file after changes, just do a ‘killall -HUP inetd’
#

echo stream tcp nowait root internal
echo dgram udp wait root internal
discard stream tcp nowait root internal
discard dgram udp wait root internal
daytime stream tcp nowait root internal
daytime dgram udp wait root internal
chargen stream tcp nowait root internal
chargen dgram udp wait root internal

#
# These are standard services.

#
#ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a

ftp stream tcp nowait root /usr/sbin/tcpd /usr/local/sbin/in.proftpd

以下省略

このような内容のファイルになっている。このファイルでは、例えばftpはproftpdを使って有効にしてあり、telnetはコメントで無効にしてある。
次に、TCP_Wrapperの設定を見ていこう。TCP_Wrapperは、/etc/hosts.allowと/etc/hosts.denyで制御する。

★ /etc/hosts.allow
アクセスを許可するホストの記述。

★ /etc/hosts.deny
アクセスを拒否する記述。

# vi /etc/hosts.deny

#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!

ALL : ALL   ← 全て拒否

Wrappersの基本は、まずhosts.denyでサービスに対して全て拒否する。

# vi /etc/hosts.allow

#
# hosts.allow This file describes the names of the hosts which are
# allowed to use the local INET services, as decided
# by the ‘/usr/sbin/tcpd’ server.
#

ALL : 192.168.255.   ← 192.168.255.*のホストIPの端末からのアクセスを許可
ALL : 127.0.0.      
← ローカルホストからのアクセスを許可

次に、hosts.allowで許可するホストIPを記載する。


3.xinetdについて

xinetdは、inetdと同じ役割を果たしているものの、confファイルでその内容のサービスを実行する形式と少し異なる。確かに、/etcディレクトリにxinetd.confは存在するがサービスの起動内容は記述されていない。以下に、xinetd.confの内容を示す。

# vi /etc/xinetd.conf

#
# Simple configuration file for xinetd
#
# Some defaults, and include /etc/xinetd.d/

defaults
{
instances = 60
log_type = SYSLOG authpriv
log_on_success = HOST PID
log_on_failure = HOST
}
includedir /etc/xinetd.d   
← このディレクトリに各サービスの設定ファイルが入っている。

上記のように、xinetd.confにはこれしか書いていない。この内容は、inetd.confの場合と違ってインクルードディレクトリを指定して、このディレクトリに各サービスの設定内容が個別に保存してあり、xinetd.confではディレクトリをインクルードしてるだけなのである。では、そのインクルードディレクトリのサービスの設定内容を見てみよう。

# cd /etc/xinetd.d

例えば、wu-ftpdのファイルを参照してみる。

# vi wu-ftpd

# default: on
# description: The wu-ftpd FTP server serves FTP connections. It uses \
# normal, unencrypted usernames and passwords for authentication.
service ftp
{
disable = no            
← このサービスが有効な状態にある。
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.ftpd
server_args = -l -a
log_on_success += DURATION USERID
log_on_failure += USERID
nice = 10
}

コンパイルしたProftpdの場合、

# Service Proftpd

service ftp
{
disable = no
socket_type = stream
wait = no
nice = 10
user = root
server = /usr/local/sbin/proftpd
instances = 4
log_on_success += DURATION HOST USERID
}

上記のような内容になっている。個別のファイルになっているだけで、内容的にはさほど変わりないが、このwu-ftpdのサービスはこの設定で有効になっている。
では、xinetdのサービスを許可するか無効にするかを設定するにはどうすればいいか?もちろん、各設定ファイルのdesableをyesにすればいいが、簡単に設定できる。以下に説明する。また、例えば、サービスとしてqmailのsmtpサービスを追加したい場合は、以下のように記述し/etc/xinetd.dディレクトリに置く。

service smtp
{
disable = no                   
← このsmtpサービスが有効な状態にある。
flags = REUSE NAMEINARGS
socket_type = stream
protocol = tcp
wait = no
user = qmaild
server = /usr/sbin/tcpd
server_args = /var/qmail/bin/tcp-env /var/qmail/bin/qmail-smtpd
}

ついでに、qmailのpop3サービスも追加したい場合は、pop3というファイルに、

service pop3
{
disable = no
socket_type = stream
protocol = tcp
wait = no
user = root
server = /var/qmail/bin/qmail-popup
server_args = <メールサーバFQDN> /bin/checkpassword /var/qmail/bin/qmail-pop3d Maildir
log_on_failure = HOST RECORD
}

と記述して保存する。
注:このpop3の設定の場合、/etc/servicesの中で、

pop-3 110/tcpをpop3 110/tcpに訂正する必要がある。

現在、xinetdで許可及び無効になっているサービスを調べるには、

# chkconfig –list

前略
xinetd based services:

rsync: off
chargen: off
chargen-udp: off
daytime: off
daytime-udp: off
echo: off
echo-udp: off
time: off
time-udp: off
wu-ftpd: on
finger: off
rexec: off
rlogin: off
rsh: off
ntalk: off
talk: off
telnet: off
linuxconf-web: off
smtp: on
pop3: on

ここで、例えばtelnetを許可したい場合は、以下のコマンドで許可にする。無効にする場合は、offを記述すればよい。

# chkconfig telnet on

設定の確認のため、もう一度、

# chkconfig –list

これで、xinetdをリスタートすれば設定が反映される。

# /etc/rc.d/init.d/xinetd restart

これで終わりである。


4.xinetdのアクセス制御

xinetdのアクセス制御はTCP_Wrapperで従来通り行える。TCP_Wrapperの設定は、inetdの時と同じである。ただし、xinetd単体でアクセス制御を行うことも出来る。それについて説明する。
xinetdのアクセス制御は、/etc/xinetd.dディレクトリの中の各サービスファイルに記述する。

only_from = 192.168.255.0    ← 192.168.255.0/255.255.255.0からのアクセスを許可する
no_access = 192.168.255.44  ← 192.168.255.44/255.255.255.0からのアクセスを拒否する


5.カーネル2.4のセキュリティレベル

RedHat7.x、Laser5 7.xの製品をインストールするときに、サーバインストールを選ぶとセキュリティーレベルについて聞かれる。段階的には、高、中、低のような感じであるが、 デフォルトでは中に設定される。
デフォルトの中では、sshサービスが許可になっており、スーパーサーバの設定は全てoff状態になっている。以前の6.xのバージョンの時のインストールでは、ほとんどのサービスが許可状態になっており、セキュリティ的にも問題があった。余計なサービスを立ち上げなくなったと言うことでは、かなり進化したのではないだろうか。

以上

コメント