ClamAV

Last-modified: 2014-02-16 (日) 20:45:42
最終更新:2014-02-16 (日) 20:45:42
アクセス数(合計):?
利用者; ? アクセス数(本日):? アクセス数(昨日):?

アンチウイルスソフト導入 ClamAV

アンチウイルスソフト ClamAVを導入する。
オープンソース(GPL)で提供されており、Unix系OSでは広く使用されている。


目的

サーバ上でアンチウイルスソフトを稼動することによりセキュリティを強化する

構築条件

構築機器

作成環境

OS    CentOS 6.5 64bit版

サーバ作成条件

サーバIP192.168.0.10/24
ホスト名hogehogeServer
user   hogehoge
userpasswdhogehogepass

手順記入ルール

  • コマンド行頭記号で 「$」はユーザ権限 「#」はスーパーユーザー権限 を表示
  • コマンドが長くなる場合は、行末に「\」を記述し複数行に記述。

ファイル入手

サイト

今回インストールしたファイル

前準備

  1. CentOSインストール 実施
  2. yumリポジトリ設定 実施
  3. yumリポジトリ設定(独自) 実施 ★環境2:インタネットへのアクセス不可の場合

yum登録

★サーバ環境にあわせてrpmのyumリポジトリ登録を実施

環境1:インターネットにアクセス可能

★以下サイト内の最新版リポジトリデータを確認。rpm入手はyumで実施
http://packages.sw.be/rpmforge-release/

  • wgetをyumでインストール
# yum install wget
  • リポジトリデータ入手 (64bit版の場合)
# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  • 確認
# ls -l
-rw-r--r--  1 root root 12640  3月 21 00:59 2013 rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  • リポジトリ登録
# rpm -Uvh rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
  • 確認
# ls -l /etc/yum.repos.d/
-rw-r--r--  1 root root  739  3月 20 23:24 2013 mirrors-rpmforge
-rw-r--r--  1 root root  717  3月 20 23:24 2013 mirrors-rpmforge-extras
-rw-r--r--  1 root root  728  3月 20 23:24 2013 mirrors-rpmforge-testing
-rw-r--r--  1 root root 1128  3月 20 23:24 2013 rpmforge.repo

環境2:インタネットへのアクセス不可

★手順 yumリポジトリ設定(独自)#rpm にて独自リポジトリにrpmを登録


[今回実施手順]

  • ユーザエリア「/home/hogehoge」にrpmファイルをアップ
  • ファイルコピー
# cp clam* /home/yum/rpm/
  • リポジトリ登録
# createrepo -v /home/yum/rpm/

環境3:イントラ内にリポジトリサーバ有り

★手順 yumリポジトリサーバ#server にてリポジトリサーバにrpmを登録


[今回実施手順(yumリポジトリサーバ側)]

  • ユーザエリア「/home/hogehoge」にrpmファイルをアップ
  • ファイルコピー
# cp clam* /var/www/html/yum/rpm/
  • リポジトリ登録
# createrepo -v /var/www/html/yum/rpm/

インストール

【Telnet】

  • rootでログイン
$ su
パスワード:

(1)yumリポジトリ登録確認

  • yumキャッシュクリア
# yum clean all
  • 確認
# yum list | grep clam
clamav.x86_64                               0.98-2.el6.rf               rpmforge
clamav-db.x86_64                            0.98-2.el6.rf               rpmforge
clamav-devel.x86_64                         0.98-2.el6.rf               rpmforge

(2)インストール

  • インストール
# yum install clamd
================================================================================
 Package           Arch           Version                Repository        Size
================================================================================
Installing:
 clamd             x86_64         0.98-2.el6.rf          rpmforge         147 k
Installing for dependencies:
 clamav            x86_64         0.98-2.el6.rf          rpmforge         2.2 M
 clamav-db         x86_64         0.98-2.el6.rf          rpmforge          34 M

設定

(1)config設定

  • ClamAVをroot権限で動作
# vi /etc/clamd.conf
  • 以下修正
    # Run as another user (clamd must be started by root for this option to work)
    # Default: don't drop privileges
    User clamav
       ↓
    #User clamav
  • ウィルスパターンファイルを日本に変更(確認)
# vi /etc/freshclam.conf
  • 以下修正
    # database.clamav.net is a round-robin record which points to our most
    # reliable mirrors. It's used as a fall back in case db.XY.clamav.net is
    # not working. DO NOT TOUCH the following line unless you know what you
    # are doing.
    DatabaseMirror db.jp.clamav.net ←あることを確認。無い場合は追加
    DatabaseMirror db.local.clamav.net

起動登録

  • 起動登録
# /etc/rc.d/init.d/clamd start
Starting Clam AntiVirus Daemon:
LibClamAV Warning: **************************************************
LibClamAV Warning: ***  The virus database is older than 7 days!  ***
LibClamAV Warning: ***   Please update it as soon as possible.    ***
LibClamAV Warning: **************************************************
                                                          [  OK  ]
  • clamd自動起動設定
# chkconfig clamd on
  • clamd自動起動設定確認
# chkconfig --list clamd
clamd           0:off   1:off   2:on    3:on    4:on    5:on    6:off

ウイルススキャン実行登録

  • パターンファイル更新
# freshclam
ClamAV update process started at Sun Feb 16 20:03:32 2014

  :

  • ウイルススキャン試験
# clamscan -i -r --remove
----------- SCAN SUMMARY -----------
Known viruses: 3119779
Engine version: 0.98
Scanned directories: 61
Scanned files: 39
Infected files: 0   ← ウィルス検出0確認
Data scanned: 0.25 MB
Data read: 0.16 MB (ratio 1.52:1)
Time: 9.148 sec (0 m 9 s)
  • 自動スキャンスクリプト作成
# vi /etc/cron.daily/clamscan.sh

★以下のパターンを参考に登録

  • 全面追加(環境1:インターネットにアクセス可能 でのお勧め設定)
    #!/bin/bash
PATH=/usr/bin:/bin
# clamd更新
yum -y update clamd > /dev/null 2>&1
# 除外リスト処理
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
# ウィルス定義ファイル更新
freshclam > /dev/null
# ウィルススキャン
CLAMSCANTMP=`mktemp`
clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \
# 検知時メール通知
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root
rm -f $CLAMSCANTMP
  • 全面追加(簡易版)
    #!/bin/bash
PATH=/usr/bin:/bin
# ウィルススキャン
clamscan -i -r --remove >> /root/clamavlog
  • 実行権付与
# chmod +x /etc/cron.daily/clamscan.sh
  • 確認
# ls -l /etc/cron.daily/
-rwxr-xr-x  1 root root 795  2月 16 20:15 2014 clamscan.sh
  • 動作試験
# /etc/cron.daily/clamscan.sh

 終了まで10分ぐらいかかる

  • 終了
# exit
exit
$

遭遇したトラブル

「chkconfig」がnot foundになる

問題:
「chkconfig」コマンドがnot found となって動作しない

原因:
「su -」でのログイン忘れ

謝辞

テキスト作成にあたり、以下サイトを参考にさせて頂きました。ありがとうございます。

http://clamav-jp.sourceforge.jp/
http://www.miloweb.net/clamav.html
http://kgworks.blog47.fc2.com/blog-entry-40.html
http://centossrv.com/clamav.shtml
http://www.mycurse.net/linux%E3%82%B5%E3%83%BC%E3%83%90%E6%A7%8B%E7%AF%89/%E3%82%BB%E3%82%AD%E3%83%A5%E3%83%AA%E3%83%86%E3%82%A3/clamd%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%BC%E3%83%AB%E3%83%BB%E8%A8%AD%E5%AE%9A/