Linux用のフリーのアンチウィルスソフトであるClam AntiVirusを導入する。
目次 |
[root@host3 ~]# yum --enablerepo=rpmforge install -y clamd Loaded plugins: fastestmirror ・ ・ ・ Complete!
[root@host3 ~]# vi /etc/clamd.conf ← clamd設定ファイル編集 User clamav ↓ #User clamav ← root権限で動作するようにする
[root@host3 ~]# /etc/rc.d/init.d/clamd start ← clamd起動 Starting Clam AntiVirus Daemon: [ OK ] [root@host3 ~]# chkconfig clamd on ← clamd自動起動設定
[root@host3 ~]# sed -i 's/Example/#Example/g' /etc/freshclam.conf ← ウィルス定義ファイル更新機能の有効化 [root@host3 ~]# freshclam ClamAV update process started at Sun Jun 5 15:08:19 2011 main.cvd is up to date (version: 53, sigs: 846214, f-level: 53, builder: sven) Downloading daily.cvd [100%] daily.cvd updated (version: 13148, sigs: 125934, f-level: 60, builder: guitar) Downloading bytecode.cvd [100%] bytecode.cvd updated (version: 143, sigs: 40, f-level: 60, builder: edwin) Database updated (972188 signatures) from db.jp.clamav.net (IP: 203.212.42.128) Clamd successfully notified about the update.
※以後のウィルス定義ファイルのアップデートは、/etc/cron.daily/freshclamにより毎日自動で行われる
[root@host3 ~]# clamscan --infected --remove --recursive ← ウィルススキャンテスト(ウィルスなしの場合) ----------- SCAN SUMMARY ----------- Known viruses: 970823 Engine version: 0.97 Scanned directories: 1 Scanned files: 11 Infected files: 0 ← ウィルスは検知されなかった Data scanned: 0.02 MB Data read: 0.01 MB (ratio 1.67:1) Time: 4.216 sec (0 m 4 s) [root@centos ~]# wget http://www.eicar.org/download/eicar.com ← テスト用ウィルスをダウンロード [root@centos ~]# wget http://www.eicar.org/download/eicar.com.txt ← 〃 [root@centos ~]# wget http://www.eicar.org/download/eicar_com.zip ← 〃 [root@centos ~]# wget http://www.eicar.org/download/eicarcom2.zip ← 〃 [root@host3 ~]# clamscan --infected --remove --recursive ← ウィルススキャンテスト(ウィルスありの場合) /root/eicarcom2.zip: Eicar-Test-Signature FOUND ← ウィルス検知 /root/eicarcom2.zip: Removed. ← ウィルス削除 /root/eicar.com: Eicar-Test-Signature FOUND ← ウィルス検知 /root/eicar.com: Removed. ← ウィルス削除 /root/eicar.com.txt: Eicar-Test-Signature FOUND ← ウィルス検知 /root/eicar.com.txt: Removed. ← ウィルス削除 /root/eicar_com.zip: Eicar-Test-Signature FOUND ← ウィルス検知 /root/eicar_com.zip: Removed. ← ウィルス削除 ----------- SCAN SUMMARY ----------- Known viruses: 970823 Engine version: 0.97 Scanned directories: 1 Scanned files: 15 Infected files: 4 ← 4つのウィルスを検知した Data scanned: 0.02 MB Data read: 0.01 MB (ratio 1.67:1) Time: 4.164 sec (0 m 4 s)
[root@host3 ~]# vi clamscan ← ウィルススキャン実行スクリプト作成
#!/bin/bash
PATH=/usr/bin:/bin
# clamd update
yum -y update clamd > /dev/null 2>&1
# excludeopt setup
excludelist=/root/clamscan.exclude
if [ -s $excludelist ]; then
for i in `cat $excludelist`
do
if [ $(echo "$i"|grep \/$) ]; then
i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d`
excludeopt="${excludeopt} --exclude-dir=$i"
else
excludeopt="${excludeopt} --exclude=$i"
fi
done
fi
# signature update
freshclam > /dev/null
# virus scan
CLAMSCANTMP=`mktemp`
clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \
# report mail send
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root
rm -f $CLAMSCANTMP
[root@host3 ~]# chmod +x clamscan ← ウィルススキャン実行スクリプトへ実行権限付加
[root@host3 ~]# echo "/backup/backup.tar.bz2" >> clamscan.exclude ← 例として/backup/backup.tar.bz2をスキャン対象外にする
[root@host3 ~]# echo "/proc/" >> clamscan.exclude ← 例として/procディレクトリをスキャン対象外にする
[root@host3 ~]# echo "/sys/" >> clamscan.exclude ← 例として/sysディレクトリをスキャン対象外にする
※ディレクトリを除外する場合は末尾に「/」を付加すること
[root@host3 ~]# mv clamscan /etc/cron.daily/ ← ウィルススキャン実行スクリプトを毎日自動実行されるディレクトリへ移動
これで、毎日定期的に全ファイルのウィルススキャンが行われ、ウィルスを検知した場合のみroot宛にメールが送られてくるようになる。
※Clam AntiVirusインストールディレクトリにテスト用ウィルスがあるので、インストール後最初の全体スキャンでは必ずウィルス検知メールがくる