今回、メールサーバのウイルス対策をしてみました。
採用したウィルス対策は、ClamAVです。
ClamAVとは、Linux、UNIX系で動くアンチウイルスソフトです。OSSなので、無料で使えます。
有料では、トレンドのIMSSなどがありますが、そんなお金はありませんw
なので、ClamAVを採用しました。
以下は、導入した時のメモです。
ちなみに、環境(バーチャルドメイン環境)は以下の通りです。
CentOS5.4+Postfix+PostfixAdmin+Mysql+dovecot
(1)ClamAVをインストールする。
ClamAVをyumでインストールする場合、RPMforgeリポジトリが必要です。
まず、RPMforgeリポジトリを導入する前に、yum-prioritiesプラグインをインストールする。
[root@hoge ~]# yum -y install yum-priorities [root@hoge ~]# vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever – Base mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 priority=1 ← 追加
#released updates [updates] name=CentOS-$releasever – Updates mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 priority=1 ← 追加
#packages used/produced in the build but not released [addons] name=CentOS-$releasever – Addons mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons #baseurl=http://mirror.centos.org/centos/$releasever/addons/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 priority=1 ← 追加
#additional packages that may be useful [extras] name=CentOS-$releasever – Extras mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5 priority=1 ← 追加 |
次に、GPG Keyのインポートと、rpmforgeリポジトリをインストールする。
[root@hoge ~]# rpm –import http://dag.wieers.com/rpm/packages/RPM-GPG- [root@centos ~]# rpm -ivh http://apt.sw.be/redhat/el5/en/i386/RPMS.dag/rpmforge |
(2)ClamAVをインストールする。
[root@hoge ~]# yum -y install clamd |
(3)ClamAVの設定を行う。
・ClamAVをroot権限で動作するように設定する場合
[root@hoge ~]# vi /etc/clamd.conf User clamav ↓ #User clamav ← コメントアウト |
・ウイルスのデータベースをダウンロードするサイトを日本に変更する
[root@hoge ~]# vi /etc/freshclam.conf # Uncomment the following line and replace XY with your country # code. See http://www.iana.org/cctld/cctld-whois.htm for the full list. #DatabaseMirror db.XY.clamav.net DatabaseMirror db.jp.clamav.net ← 追加 |
(3)ClamAVの起動、自動起動設定を行う。
[root@hoge ~]# /etc/rc.d/init.d/clamd start [root@hoge ~]# chkconfig clamd on |
注)ウイルスのデータベースが古い場合は、ClamAVの起動時に以下のような警告が発生する。
(4)ClamAVのウイルスデータベースをアップデートする。
[root@hoge ~]# freshclam ClamAV update process started at Sat Nov 21 03:01:19 2009 main.cvd is up to date (version: 51, sigs: 545035, f-level: 42, builder: sven) WARNING: getfile: daily-9956.cdiff not found on remote server (IP: 203.178.137.175) WARNING: getpatch: Can’t download daily-9956.cdiff from db.jp.clamav.net Trying host db.jp.clamav.net (203.212.42.128)… WARNING: getfile: daily-9956.cdiff not found on remote server (IP: 203.212.42.128) WARNING: getpatch: Can’t download daily-9956.cdiff from db.jp.clamav.net Trying host db.jp.clamav.net (211.10.155.48)… WARNING: getfile: daily-9956.cdiff not found on remote server (IP: 211.10.155.48) WARNING: getpatch: Can’t download daily-9956.cdiff from db.jp.clamav.net WARNING: Incremental update failed, trying to download daily.cvd Trying host db.jp.clamav.net (218.44.253.75)… Downloading daily.cvd [100%] daily.cvd updated (version: 10052, sigs: 110135, f-level: 44, builder: ccordes) Database updated (655170 signatures) from db.jp.clamav.net (IP: 218.44.253.75) Clamd successfully notified about the update. |
(5)ClamAVの設定を行う。
[root@hoge ~]# vi /etc/clamd.conf # TCP port address. # Default: no TCPSocket 3310 ← コメントアウト ↓ #TCPSocket 3310 |
(6)ClamAVの設定を反映させるために再起動させる。
[root@hoge ~]# /etc/rc.d/init.d/clamd restart |
(7)ClamAVとPostfixを連携させるために、amavisd-newをインストールする。
[root@hoge ~]# yum -y install amavisd-new |
(8)amavisd-newの設定を行う。
[root@hoge ~]# yum -y install amavisd-new [root@hoge ~]# vi /etc/amavisd.conf # @bypass_spam_checks_maps = (1); # controls running of anti-spam code ↓ スパムチェックを行わないので、先頭のコメントアウトを外す @bypass_spam_checks_maps = (1); # controls running of anti-spam code
$mydomain = ‘example.com’; # a convenient default for other settings ↓ メールで使用しているドメイン名に変更 $mydomain = ‘mydomain name; # a convenient default for other settings
$QUARANTINEDIR = “/var/virusmails”; ↓ ウイルスメールを隔離しない場合はコメントアウト #$QUARANTINEDIR = “/var/virusmails”;
$virus_admin = “virusalert\@kurobuti.com”; # notifications recip. ↓ ウイルス検知メールを管理者に通知しない場合はコメントアウト(通知する場合はアドレスを変更する) #$virus_admin = “virusalert\@kurobuti.com”; # notifications recip.
# ### http://www.clamav.net/ # [‘ClamAV-clamd’, # \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd"], # qr/\bOK$/m, qr/\bFOUND$/m, # qr/^.*?: (?!Infected Archive)(.*) FOUND$/m ], ——-以下を追加(ここから)——- ### http://www.clamav.net/ [‘ClamAV-clamd’, \&ask_daemon, ["CONTSCAN {}\n", "/var/run/clamav/clamd.sock"], qr/\bOK$/, qr/\bFOUND$/, qr/^.*?: (?!Infected Archive)(.*) FOUND$/ ], —————ここまで————–
### BLOCKED ANYWHERE # qr’^UNDECIPHERABLE$’, # is or contains any undecipherable components qr’^\.(exe-ms|dll)$’, # banned file(1) types, rudimentary # qr’^\.(exe|lha|tnef|cab|dll)$’, # banned file(1) types ↓ exeファイルを受信可能にする場合は、コメントアウト ### BLOCKED ANYWHERE # qr’^UNDECIPHERABLE$’, # is or contains any undecipherable components # qr’^\.(exe-ms|dll)$’, # banned file(1) types, rudimentary # qr’^\.(exe|lha|tnef|cab|dll)$’, # banned file(1) types |
(9)amavisdを起動し、自動起動設定を行う。
[root@hoge ~]# /etc/rc.d/init.d/amavisd start [root@hoge ~]# chkconfig amavisd on |
(10)Postfixの設定を行う。
main.cfに以下を追加する。
[root@hoge ~]# vi /etc/postfix/main.cf #Clamav+Postfix ↓ 最終行にでも追加する content_filter=smtp-amavis:[127.0.0.1]:10024 |
master.cfに以下を追加する。
[root@hoge ~]# vi /etc/postfix/master.cf #ClamAV+Postfix ↓ 最終行にでも追加する smtp-amavis unix - - n - 2 smtp -o smtp_data_done_timeout=1200 -o smtp_send_xforward_command=yes -o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - - smtpd -o content_filter= -o local_recipient_maps= -o relay_recipient_maps= -o smtpd_restriction_classes= -o smtpd_client_restrictions= -o smtpd_helo_restrictions= -o smtpd_sender_restrictions= -o smtpd_recipient_restrictions=permit_mynetworks,reject -o mynetworks=127.0.0.0/8 -o strict_rfc821_envelopes=yes -o smtpd_error_sleep_time=0 -o smtpd_soft_error_limit=1001 -o smtpd_hard_error_limit=1000 |
注)-oの部分は、必ずスペース又はtabを入れること。入れない場合はエラーになる。
(11)Postfixの設定を反映させるために、再起動を行う。
[root@hoge ~]# /etc/rc.d/init.d/postfix restart |
以上で、設定は終わりです。
うまく動作しているかテストしてみました。
■テスト方法
①何も添付せずにメールを送信
②テストウイルスをメールに添付し送信
注)どちらもコマンドラインからメール送信を行った。
注2)テストウイルスは、ここからダウンロードできる。
①何も添付せずにメールを送信した場合
[root@hoge ~]# mail -s ‘test’ hoge@example.com |
・受信時のログ
Nov 21 03:42:57 example amavis[29807]: (29807-02) Passed CLEAN, |
Passed CLEANと出てますね。
と、言う事は、きちんとスキャンできているみたいですw
②テストウイルスを添付して送信した場合
[root@hoge ~]# uuencode ./eicar.com eicar.com | mail -s ‘test’ hoge@example.com |
・受信時のログ
Nov 21 03:43:06 example amavis[29806]: (29806-03) Blocked INFECTED (Eicar-Test-Signature), <root@example2.com> -> <hoge@example.com>, Message-ID: <20091120184304.86B1D78419@example2.com>, mail_id: VXa9d-tMannG, Hits: -, size: 427, 1610 ms |
ウイルスを添付したメールでは、Blocked INFECTED と出て、メールは受信されませんでした。
うまいこと動いているみたいですw
参考文献
http://centossrv.com/postfix-clamav-spamassassin.shtml
http://shinjuku-vipper.cocolog-nifty.com/blog/2008/05/post_3c67.html
http://www.ksknet.net/linux/mail.html