Clam AntiVirusのインストール

概要:Clam Antivirus(クラム・アンチウイルス。略称Clam AV)とは、LinuxやBSD、Mac OS Xなど各種UNIX系のシステムで動作するオープンソース(GPL)で提供されているアンチウイルスソフトである。このClam AntiVirusを導入する。
前提:

1. Clam AntiVirusインストール

# yum -y --enablerepo=rpmforge install clamd ← Clam AntiVirusのインストール

2. Clam AntiVirus設定

# vi /etc/clamd.conf ← clamd設定ファイル編集
  User clamav
    
  #User clamav ← root権限で動作するようにする
# 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. Clam AntiVirus起動と自動起動設定

# /etc/rc.d/init.d/clamd start ← clamd起動
Starting Clam AntiVirus Daemon:                            [  OK  ]

# chkconfig clamd on ← clamd自動起動設定

# chkconfig --list clamd ← clamd自動起動設定確認
clamd           0:off   1:off   2:on    3:on    4:on    5:on    6:off
 ← ランレベル2~5のonを確認

4. ウィルス定義ファイル最新化

# freshclam ← ウィルス定義ファイル最新化

ClamAV update process started at Wed Jan 21 02:07:17 2009
main.cvd is up to date (version: 49, sigs: 437972, f-level: 35, builder: sven)
WARNING: getfile: daily-8684.cdiff not found on remote server (IP: 203.178.137.175)
WARNING: getpatch: Can't download daily-8684.cdiff from db.jp.clamav.net
WARNING: getfile: daily-8684.cdiff not found on remote server (IP: 203.178.137.175)
WARNING: getpatch: Can't download daily-8684.cdiff from db.jp.clamav.net
WARNING: getfile: daily-8684.cdiff not found on remote server (IP: 203.178.137.175)
WARNING: getpatch: Can't download daily-8684.cdiff from db.jp.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 8881, sigs: 56877, f-level: 38, builder: ccordes)
Database updated (494849 signatures) from db.jp.clamav.net (IP: 203.212.42.128)
Clamd successfully notified about the update.

注:以後のウィルス定義ファイルのアップデートは、/etc/cron.daily/freshclamにより毎日自動で行われる。

5. ウィルススキャンテスト

  1. ) ウィルススキャンテスト(ウィルスなしの場合)
    # clamscan --infected --remove --recursive
    ----------- SCAN SUMMARY -----------
    Known viruses: 494392
    Engine version: 0.94.2
    Scanned directories: 84
    Scanned files: 254
    Infected files: 0 ← ウィルスは検知されなかった
    Data scanned: 2.86 MB
    Time: 4.692 sec (0 m 4 s)
    
  2. ) ウィルススキャンテスト(ウィルスありの場合)
    # wget http://www.eicar.org/download/eicar.com ← テスト用ウィルスをダウンロード
    # wget http://www.eicar.org/download/eicar.com.txt ← 〃
    # wget http://www.eicar.org/download/eicar_com.zip ← 〃
    # wget http://www.eicar.org/download/eicarcom2.zip ← 〃
    
    # clamscan --infected --remove --recursive
    /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 ← ウィルス削除
    /root/eicarcom2.zip: Eicar-Test-Signature FOUND ← ウィルス検知
    /root/eicarcom2.zip: Removed ← ウィルス削除
    
    ----------- SCAN SUMMARY -----------
    Known viruses: 494392
    Engine version: 0.94.2
    Scanned directories: 84
    Scanned files: 258
    Infected files: 4 ← 4つのウィルスを検知した
    Data scanned: 2.86 MB
    Time: 3.261 sec (0 m 3 s)
    

6. ウィルススキャン定期自動実行設定

# vi /etc/cron.daily/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
# chmod 700 /etc/cron.daily/clamscan ← ウィルススキャン実行スクリプトへ実行権限付加

これで、毎日定期的に全ファイルのウィルススキャンが行われ、ウィルスを検知した場合のみroot宛にメールが送られてくるようになる。
注:Clam AntiVirusインストールディレクトリにテスト用ウィルスがあるので、インストール後最初の全体スキャンでは必ずウィルス検知メールがくる。その時テスト用ウィルスは削除されるので、その後同じ内容のメールは来ない。

7. スキャン対象外にする方法の例

# echo "/backup/backup.tar.bz2" >> /root/clamscan.exclude
 ← 例として/backup/backup.tar.bz2をスキャン対象外にする。
# echo "/sys/" >> /root/clamscan.exclude
 ← 例として/sysディレクトリをスキャン対象外にする。

注:ディレクトリを除外する場合は末尾に「/」を付加する。


最終更新のRSS
Last-modified: 2014-03-11 (火) 01:59:57 (3692d)