HOME 備忘録 書き込む

自宅サーバーのセキュリティ


Feb 19, 2006

はじめに

自宅サーバーを立ち上げたので、セキュリティには責任を持たなければなりません。

web サーバー

とりあえず Apache のモジュールの mod_security をインストールしました。

インストールの方法は簡単で、ダイナミックモジュールとしてインストールする 場合は、次の様にします。

  1. ソースをダウンロードします。
    http://www.modsecurity.org/download/index.html から Stable releases のソースコード (modsecurity-apache-N.N.N.tar.gz) をダウンロードできます。
  2. アーカイブを解凍します。
    tar xzvf modsecurity-apache-N.N.N.tar.gz
  3. Apache2 が /usr/local/apache2 にある場合は、
    cd modsecurity-apache-N.N.N/apache2
    sudo /usr/local/apache2/bin/apxs -cia mod_security.c
    
    としてダイナミックリンクモジュールとしてコンパイルします。
  4. httpd.conf に以下を加えます。 これは、 ModSecurity for Apache User Guide, Appendix A: Recommended Configuration をそのまま写しました。
    <IfModule security_module>
    # Turn ModSecurity On
    SecFilterEngine On
    
    # Reject requests with status 403
    SecFilterDefaultAction "deny,log,status:403"
    
    # Some sane defaults
    SecFilterScanPOST On
    SecFilterCheckURLEncoding On
    SecFilterCheckUnicodeEncoding Off
    
    # Accept almost all byte values
    SecFilterForceByteRange 1 255
    
    # Server masking is optional
    # SecServerSignature "Microsoft-IIS/5.0"
    
    SecUploadDir /tmp
    SecUploadKeepFiles Off
    
    # Only record the interesting stuff
    SecAuditEngine RelevantOnly
    SecAuditLog logs/audit_log
    
    # You normally won't need debug logging
    SecFilterDebugLevel 0
    SecFilterDebugLog logs/modsec_debug_log
    
    # Only accept request encodings we know how to handle
    # we exclude GET requests from this because some (automated)
    # clients supply "text/html" as Content-Type
    SecFilterSelective REQUEST_METHOD "!^(GET|HEAD)$" chain
    SecFilterSelective HTTP_Content-Type 
    "!(^application/x-www-form-urlencoded$|^multipart/form-data;)"
    
    # Do not accept GET or HEAD requests with bodies
    SecFilterSelective REQUEST_METHOD "^(GET|HEAD)$" chain
    SecFilterSelective HTTP_Content-Length "!^$"
    
    # Require Content-Length to be provided with
    # every POST request
    SecFilterSelective REQUEST_METHOD "^POST$" chain
    SecFilterSelective HTTP_Content-Length "^$"
    
    # Don't accept transfer encodings we know we don't handle
    SecFilterSelective HTTP_Transfer-Encoding "!^$"
    </IfModule>
    
  5. apache2 をリスタートします。
このほかに、 などのセキュリティ措置をとっています。

メールサーバー

SMTP サーバーは Postfix を 、IMAP サーバーは Courie を apt-get して使っています。

Postfix はセキュアな SMTP サーバーとして有名です。 また、Courie も人気のソフトでたくさんのユーザーがいます。 両方とも設定方法などは google で検索するとすぐに見つかります。

終わりに

万全とはいえないと思いますが、いまのところは大丈夫みたいです(たぶん)。