ClamAVでウイルスを検出する
Modified: 22 March 2008
Created: 10 February 2008CentOS5で、Spamassassin、ClamAV、Postfixの組み合わせで、ウイルスメールをチェックして、ブロックする実験。
ClamAVのインストール (10 February 2008)
ClamAVの起動とテスト (10 February 2008)
freshclamによるパターンファイルの更新 (10 February 2008)
CentOS5の場合、以下のコマンドでインストールできます。
# yum install --enablerepo=rpmforge clamav clamd
期限切れ後の更新も上記コマンドでできます。
以下のメッセージが出れば更新切れです。
# /usr/bin/freshclam
ClamAV update process started at Sat Mar 22 13:41:58 2008
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.92 Recommended version: 0.92.1
DON'T PANIC! Read http://www.clamav.net/support/faq
main.cvd is up to date (version: 45, sigs: 169676, f-level: 21, builder: sven)
Downloading daily-6318.cdiff [100%]
Downloading daily-6319.cdiff [100%]
Downloading daily-6320.cdiff [100%]
Downloading daily-6321.cdiff [100%]
Downloading daily-6322.cdiff [100%]
Downloading daily-6323.cdiff [100%]
daily.inc updated (version: 6323, sigs: 63474, f-level: 26, builder: ccordes)
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Current functionality level = 25, recommended = 26
DON'T PANIC! Read http://www.clamav.net/support/faq
Database updated (233150 signatures) from db.jp.clamav.net (IP: 203.212.42.128)
Clamd successfully notified about the update.
#
ClamAVのプラグインのインストール
http://wiki.apache.org/spamassassin/ClamAVMultipleScores
上記ページに、"clamav.cf"の内容が書かれているので、それをコピペで、"/etc/mail/spamassassin/clamav.cf"を作り、以下を変更して保存します。
:
# ClamAV phishing signatures
meta CLAMAV_PHISH (CLAMAV && __CLAMAV_PHISH && !__CLAMAV_SANE && !__CLAMAV_PHISH_HEUR)
describe CLAMAV_PHISH Phishing email found by ClamAV default signatures
score CLAMAV_PHISH 20.0
:http://wiki.apache.org/spamassassin/ClamAVPlugin
上記ページに、"clamav.pm"の内容が書かれているので、それをコピペで、"/etc/mail/spamassassin/clamav.pm"を作り、以下を変更して保存します。
package ClamAV;
use strict;
# our $CLAMD_SOCK = 3310; # for TCP-based usage
our $CLAMD_SOCK = "/tmp/clamd.socket";
:
上記の変更は、以下の"/etc/clamd.conf" に合わせています。
:
# Path to a local socket file the daemon will listen on.# Default: disabled (must be specified by a user)
LocalSocket /tmp/clamd.socket
:
Perlモジュールのインストール
なぜかエラーになるので、途中で修正を加えて、インストールします。
cpan> test File::Scan::ClamAV
:
ERROR: Parse error at line 2: Option Foreground requires boolean argument.
ERROR: Can't open/parse the config file clamav.conf
<Ctrl>+C
make: *** wait: 子プロセスがありません. 中止.
make: *** 未完了のジョブを待っています....
make: *** wait: 子プロセスがありません. 中止.
/usr/bin/make test -- NOT OK
cpan> look File::Scan::ClamAV
Running look for module File::Scan::ClamAV
Trying to open a subshell in the build directory...
Working directory is /root/.cpan/build/File-Scan-ClamAV-1.8
#エラーになるので、一旦シェルに落とします。
そして、以下を変更します。
"/root/.cpan/build/File-Scan-ClamAV-1.8/clamav.conf"
LocalSocket /root/.cpan/build/File-Scan-ClamAV-1.8/clamsock
Foreground true
MaxThreads 1
ScanArchive true
ArchiveMaxFileSize 1M
ArchiveMaxRecursion 1
ArchiveMaxFiles 2変更後、インストールして、戻って、終了します。
# make install
Installing /usr/lib/perl5/site_perl/5.8.8/File/Scan/ClamAV.pm
Installing /usr/share/man/man3/File::Scan::ClamAV.3pm
Writing /usr/lib/perl5/site_perl/5.8.8/i386-linux-thread-multi/auto/File/Scan/ClamAV/.packlist
Appending installation info to /usr/lib/perl5/5.8.8/i386-linux-thread-multi/perllocal.pod
# exit
cpan> q
Terminal does not support GetHistory.
Lockfile removed.
#
ClamAVの起動
ClamAVを起動します。
# service clamd start
Starting Clam AntiVirus Daemon: [ OK ]
# service spamassassin restart
spamd を停止中: [ OK ]
spamd を起動中: [ OK ]
#
テストウイルスの入手
http://www.eicar.org/anti_virus_test_file.htm
上記から、eicar.com.txt をダウンロードして、メールを出してみます。
# cat eicar.com.txt | mail tomo
実行確認
ログを確認します。
Feb 11 01:40:16 mailserver spamd[18528]:
prefork: child states: II
Feb 11 01:40:17 mailserver postfix/cleanup[18570]:
61328282C6: to=<tomo@tomo.ac>, orig_to=<tomo>, relay=none, delay=1.6, delays=1.6/0/0/0,
dsn=5.7.1, status=bounced (Blocked by SpamAssassin)
Feb 11 01:40:17 mailserver postfix/cleanup[18577]:
081B3282C8: message-id=<20080210164017.081B3282C8@mailserver.tomo.ac>
Feb 11 01:40:17 mailserver postfix/bounce[18575]:
61328282C6: sender non-delivery notification: 081B3282C8
Feb 11 01:40:17 mailserver postfix/qmgr[17799]:
081B3282C8: from=<>, size=2322, nrcpt=1 (queue active)
Feb 11 01:40:17 mailserver postfix/cleanup[18570]:
10C5E282C5: message-id=<20080210164017.081B3282C8@mailserver.tomo.ac>
Feb 11 01:40:17 mailserver postfix/local[18578]:
081B3282C8: to=<root@tomo.ac>, relay=local, delay=0.07, delays=0.03/0.02/0/0.01,
dsn=2.0.0, status=sent (forwarded as 10C5E282C5)
Feb 11 01:40:17 mailserver postfix/qmgr[17799]:
081B3282C8: removed
Feb 11 01:40:17 mailserver postfix/qmgr[17799]:
10C5E282C5: from=<>, size=2460, nrcpt=1 (queue active)
Feb 11 01:40:17 mailserver postfix/qmgr[17799]:
10C5E282C5: removed
ログを見ると、Virusがブロックされ、送信元にエラーメールが返送されていることが確認できます。
返信されたメールは、以下です。
This is the mail system at host mailserver.tomo.ac.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
<tomo@tomo.ac> (expanded from <tomo>): Blocked by SpamAssassin
ブロックされて返信されたことがわかります。んーーーーん、成功!!
設定ファイル
まず、設定ファイル("/etc/freshclam.conf")を確認します。
CentOS5 では、デフォルトのままで動作します。
手動更新
まず、手動で更新を実行してみます。
# /usr/bin/freshclam
ClamAV update process started at Mon Feb 11 07:52:09 2008
main.cvd is up to date (version: 45, sigs: 169676, f-level: 21, builder: sven)
Downloading daily-5765.cdiff [100%]
Downloading daily-5766.cdiff [100%]
Downloading daily-5767.cdiff [100%]
daily.cvd updated (version: 5767, sigs: 38354, f-level: 21, builder: sven)
Database updated (208030 signatures) from db.jp.clamav.net (IP: 203.178.137.175)
Clamd successfully notified about the update.
#
更新は、成功しました。
以下のように、試しに、再度実行してみると、更新直後なので、なにも実行されず終了します。
# /usr/bin/freshclam
ClamAV update process started at Mon Feb 11 07:52:27 2008
main.cvd is up to date (version: 45, sigs: 169676, f-level: 21, builder: sven)
daily.inc is up to date (version: 5767, sigs: 38354, f-level: 21, builder: sven)
#
自動更新の設定
crontabに以下を設定し、定期的に実行させます。
# ---(ClamAV update)--------------------------------
0 3 * * * /usr/bin/freshclam --daemon-notify --quiet"--daemon-notify"は、更新後、ClamAVに反映させるために指定しています。