投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2016年1月17日日曜日

【Linux CentOS6.7 64bit minimal】ウィルススキャナClamAVのインストールと動作テスト

インストール先の環境は、CentOS 6.7 64bit minimalである。

# uname -a
Linux test.test 2.6.32-573.12.1.el6.x86_64 #1 SMP Tue Dec 15 21:19:08 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux



■リポジトリepelの導入

ClamAVは標準のリポジトリには入っていない。Epelというリポジトリを利用できるようにしておく。

# yum install epel-release
あるいは、
# yum localinstall http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm


■ClamAV等のインストール

高速に動作するデーモンモードで利用することができるように、clamdというパッケージをインストールした
これによって依存パッケージとして、clamavなどのパッケージも自動的に導入された。

# yum install clamd

================================================================================
 Package             Arch             Version              Repository      Size
================================================================================
Installing:
 clamd               x86_64           0.99-3.el6           epel           165 k
Installing for dependencies:
 clamav              x86_64           0.99-3.el6           epel           1.4 M
 clamav-db           x86_64           0.99-3.el6           epel           102 M

Transaction Summary
================================================================================
Install       3 Package(s)

Total size: 104 M
Installed size: 106 M

Installed:
  clamd.x86_64 0:0.99-3.el6

Dependency Installed:
  clamav.x86_64 0:0.99-3.el6            clamav-db.x86_64 0:0.99-3.el6

Complete!



○インストール(clamavパッケージ)によって、clamというユーザーとグループが自動的に設定された。

# grep clam /etc/passwd
clam:x:497:497:Clam Anti Virus Checker:/var/lib/clamav:/sbin/nologin
# grep clam /etc/group
clam:x:497:


◎インストール(clamdパッケージ)によって、サービス起動スクリプトが自動的に設定された。

# chkconfig --list | grep clamd
clamd           0:off   1:off   2:off   3:off   4:off   5:off   6:off


□インストールされたパッケージについて情報を表示させた
# yum info clamav
Name        : clamav
Arch        : x86_64
Version     : 0.99
Release     : 3.el6
Size        : 1.4 M
Repo        : epel
Summary     : Anti-virus software
URL         : http://www.clamav.net/
License     : GPLv2
Description : Clam AntiVirus is a GPL anti-virus toolkit for UNIX. The main
            : purpose of this software is the integration with mail servers
            : (attachment scanning). The package provides a flexible and
            : scalable multi-threaded daemon, a command line scanner, and a tool
            : for automatic updating via Internet.
            :
            : The programs are based on a shared library distributed with the
            : Clam AntiVirus package, which you can use with your own software.
            : Most importantly, the virus database is kept up to date

# yum info clamd
Name        : clamd
Arch        : x86_64
Version     : 0.99
Release     : 3.el6
Size        : 165 k
Repo        : epel
Summary     : The Clam AntiVirus Daemon
URL         : http://www.clamav.net/
License     : GPLv2
Description : The Clam AntiVirus Daemon


■ウイルス定義ファイルの更新

○(注意)定義更新プログラム用のログファイルを作成した。

# touch /var/log/clamav/freshclam.log

パーミッションの設定も行っておく。

# chown clam:clam /var/log/clamav/freshclam.log

# ls -Al /var/log/clamav/freshclam.log
-rw-r--r-- 1 clam clam 0 Jan 16 18:52 /var/log/clamav/freshclam.log

上記のようにパーミッションの設定をログファイルに対して行っていなければ、
下で述べる定義ファイルの更新処理時に次のようなエラーが発生してしまう。
ERROR: Can't open /var/log/clamav/freshclam.log in append mode (check permissions!).
ERROR: Problem with internal logger (UpdateLogFile = /var/log/clamav/freshclam.log).


○更新前の定義ファイルを確認した。

# ls  -Al /var/lib/clamav/
total 104560
-rw-r--r-- 1 clam clam 42346279 Dec  2 09:45 daily.cvd
-rw-r--r-- 1 clam clam 64720632 Sep 27  2013 main.cvd

○定義ファイルを専用コマンドを使って更新した。(初回のみ、時間がかかった。)

# freshclam -l /var/log/clamav/freshclam.log
ClamAV update process started at Sat Jan 16 19:00:36 2016
main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
WARNING: getfile: daily-21124.cdiff not found on remote server (IP: )
WARNING: getpatch: Can't download daily-21124.cdiff from database.clamav.net
WARNING: getfile: Unknown response from remote server (IP: )
WARNING: getpatch: Can't download daily-21124.cdiff from database.clamav.net
nonblock_connect: connect timing out (30 secs)
Can't connect to port 80 of host database.clamav.net (IP: )
Trying host database.clamav.net ()...
WARNING: getfile: daily-21124.cdiff not found on remote server (IP: )
WARNING: getpatch: Can't download daily-21124.cdiff from database.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 21268, sigs: 1802618, f-level: 63, builder: neo)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 270, sigs: 46, f-level: 63, builder: shurley)
[LibClamAV] ******************************************************
[LibClamAV] ***      Virus database timestamp in the future!   ***
[LibClamAV] ***  Please check the timezone and clock settings  ***
[LibClamAV] ******************************************************
Database updated (4226889 signatures) from database.clamav.net (IP: )
上記でtimestampのエラーが発生したのは、マシンの時刻が進んでしまっていたため。


○更新後の定義ファイルを確認した

# ls  -Al /var/lib/clamav/
total 106688
-rw-r--r-- 1 clam clam    75082 Jan 16 19:01 bytecode.cvd
-rw-r--r-- 1 clam clam 44444165 Jan 16 19:01 daily.cvd
-rw-r--r-- 1 clam clam 64720632 Sep 27  2013 main.cvd
-rw------- 1 clam clam      260 Jan 16 19:01 mirrors.dat

○試しに、もう一度、定義ファイルの更新操作を行った。
(初回時とは違って、早く処理が完了した。)

# freshclam -l /var/log/clamav/freshclam.log
ClamAV update process started at Sun Jan 17 04:11:31 2016
main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo)
daily.cvd is up to date (version: 21268, sigs: 1802618, f-level: 63, builder: neo)
bytecode.cvd is up to date (version: 270, sigs: 46, f-level: 63, builder: shurley)


◎指定した時間に自動的に定義更新処理が行われるように設定した。
(例では、AM1:00に処理が行われるようにした。)

# crontab -e
0       1       *       *       *       /usr/bin/freshclam -l /var/log/clamav/freshclam.log


■スキャンを試す


<準備と確認>

clamdscanコマンド(clamscanではない!)で、スキャンを行う場合、clamdサービスが起動している必要があった。
サービスが起動していなければ、次のようにエラーが表示された。
(clamscanコマンドの場合は、サービスの起動は不要)

# clamdscan
ERROR: Could not connect to clamd on 127.0.0.1: Connection refused

----------- SCAN SUMMARY -----------
Infected files: 0
Total errors: 1
Time: 0.000 sec (0 m 0 s)

(1) clamdサービスを起動した。

サービスの起動にはやや時間がかかった。メモリが350MBほど消費されるようである

# service clamd start
Starting Clam AntiVirus Daemon:                            OK  ]

clamdのソケットファイルが作成された。
(他のプログラムと連携する場合に必要になるので、ファイルへのパスに留意しておく。)

# ls /var/run/clamav/ -al
total 12
drwxr-xr-x   2 clam clam 4096 Jan 17 06:02 .
drwxr-xr-x. 14 root root 4096 Feb 10 18:06 ..
-rw-rw-r--   1 root root    5 Jan 17 06:02 clamd.pid
srw-rw-rw-   1 root root    0 Jan 17 06:02 clamd.sock

システム起動時に自動的にサービスが動作するように設定した。

# chkconfig clamd on


カレントディレクトリ(/root)のスキャンを行った。
次のエラーになった。デフォルトではスキャンを行うプログラムの動作権限が低いということがわかった。
[root@test ~]# clamdscan
/root: lstat() failed: Permission denied. ERROR

----------- SCAN SUMMARY -----------
Infected files: 0
Total errors: 1
Time: 0.000 sec (0 m 0 s)

(2) スキャンを行うプログラムの動作権限の限定を解除した。 
コンフィグファイル内で次の項目をコメントアウトした

# 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 clam
(略)


設定変更後、サービスの再起動を行った
[root@test ~]# service clamd restart



<動作テスト>

再び、スキャン用プログラムを起動した。
[root@test ~]# clamdscan
/root: OK

----------- SCAN SUMMARY -----------
Infected files: 0
Time: 0.067 sec (0 m 0 s)
エラーなくスキャンが完了した。
対象ファイルが大量にある場合、結果が表示されるまで時間がかかった。



◆スキャン方法についてオプション

スキャンに際して、次のオプションを利用できる。

# clamdscan --help
                       ClamAV Daemon Client 0.99
           By The ClamAV Team: http://www.clamav.net/about.html#credits
           (C) 2007-2015 Cisco Systems, Inc.

    --help              -h             Show help
    --version           -V             Print version number and exit
    --verbose           -v             Be verbose
    --quiet                            Be quiet, only output error messages
    --stdout                           Write to stdout instead of stderr
                                       (this help is always written to stdout)
    --log=FILE          -l FILE        Save scan report in FILE
    --file-list=FILE    -f FILE        Scan files from FILE
    --remove                           Remove infected files. Be careful!
    --move=DIRECTORY                   Move infected files into DIRECTORY
    --copy=DIRECTORY                   Copy infected files into DIRECTORY
    --config-file=FILE                 Read configuration from FILE.
    --allmatch            -z           Continue scanning within file after finding a match.
    --multiscan           -m           Force MULTISCAN mode
    --infected            -i           Only print infected files
    --no-summary                       Disable summary at end of scanning
    --reload                           Request clamd to reload virus database
    --fdpass                           Pass filedescriptor to clamd (useful if clamd is running as a different user)
    --stream                           Force streaming files to clamd (for debugging and unit testing)


◆clamd の動作状況を確認

topコマンドのような専用コマンドが用意されている。
これによって、clamdがどれくらいのメモリを消費しているかがわかった。

# clamdtop



◆検出されないが「怪しいファイル」が見つかった場合

明らかに怪しいファイルだが、ClamAVで検出されない場合、次のサイトでチェックしてみる。

https://www.virustotal.com

そして、もし有害であれば、そのファイルをClamAVのチームに提出できる。
次のサイトから簡単にアップロードが可能である。

http://www.clamav.net/reports/malware

こうして、ウイルス定義データベースが更新されていくらしい。
みんなで協力しましょう。


Quick Configuration of Postfix Mail Server to Support Anti Spam and Anti Virus Using Two Methods (English Edition)



<参考>

・清水正人 「Postfix 実践入門」 技術評論社 2010年、P.330-338

・03-01-12 clamavのインストール
< http://d.hatena.ne.jp/flageo/20120301/p1 > 2016年1月17日

・ClamAV(Clam AntiVirus)の設定方法
< http://hikaku-server.com/linux/entry460.html > 2016年1月17日

・ClamAV/Clamwin/Clam Sentinelで検出されたファイルをVirusTotalで検査してClamAVに報告する方法
< http://ohtsuka.cocolog-nifty.com/blog/2011/05/clamavclamwincl.html > 2016年3月21日

投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad