【Linux】【セキュリティ】アンチウイルスソフト ~ Clam AntiVirus / 導入編 ~

Clam AntiVirus

Clam AntiVirus(Clam AV) : クラム アンチウイルス
 * Linux用のフリーのウイルスソフト (Windows版もあるらしい)

他のウィルススキャンソフトとの比較 (2017/12/01追記)

https://blogs.yahoo.co.jp/dk521123/37259281.html
より

2015年の結果であるが、Clam AntiVirus(Clam AV)の Linux版 は、66.7% の検出率。

■ 設定

【1】 インストール

# EPELリポジトリ導入
sudo yum -y install epel-release
sudo yum --enablerepo=epel update epel-release

# Clam AntiVirus インストール
sudo yum -y install --enablerepo=epel clamav

# デーモン化する
sudo yum -y install --enablerepo=epel clamav-server
sudo yum -y install --enablerepo=epel clamav-server-systemd

sudo yum -y install --enablerepo=epel clamav-scanner
sudo yum -y install --enablerepo=epel clamav-scanner-systemd

# ウイルスデータベースを更新する(「freshclam」が使用可能)
sudo yum -y install --enablerepo=epel clamav-update

# シンボリックリンク作成
sudo ln -s /etc/clamd.d/scan.conf /etc/clamd.conf
説明:パッケージ
 * clamavClamAVの各種ツール類
 * clamav-data:ウイルスデータベース
 * clamav-devel:ClamAVに必要なライブラリやヘッダーファイル
 * clamav-filesystem:ClamAVに必要とされるユーザ作成スクリプトファイルシステムの構造を提供
 * clamav-lib:ClamAVに必要とされる動的共有ライブラリ
 * clamav-scanner:一般的なclamd用サービス
 * clamav-scanner-systemd:systemd用clamav-scanner起動スクリプト
 * clamav-server:clamdデーモンの実行に必要なファイル
 * clamav-server-systemd:systemd用clamav-serverのテンプレート
 * clamav-update:ウイルスデータベースを更新するためパッケージ。freshclamコマンドがインストールされる

【2】 設定ファイルの変更

sudo vi /etc/clamd.d/scan.conf
# Comment or remove the line below.
# コメントアウト
#Example

# Default: disabled
LogFile /var/log/clamd.scan

# Default: 1M
LogFileMaxSize 2M

# Log time with each message.
# Default: no
LogTime yes

# Use system logger (can work together with LogFile).
# Default: no
LogSyslog yes

# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
# Default: no
LogRotate yes

# Path to a local socket file the daemon will listen on.
# Default: disabled (must be specified by a user)
LocalSocket /var/run/clamd.scan/clamd.sock

# Don't scan files and directories matching regex
# This directive can be used multiple times
# Default: scan all
ExcludePath ^/proc/
ExcludePath ^/sys/

# Run as another user (clamd must be started by root for this option to work)
# Default: don't drop privileges
#User clamscan
User root

# Initialize supplementary group access (clamd must be started by root).
# Default: no
AllowSupplementaryGroups yes
sudo vi /etc/freshclam.conf
# Path to the log file (make sure it has proper permissions)
# Default: disabled
UpdateLogFile /var/log/freshclam.log

# Maximum size of the log file.
# Default: 1M
LogFileMaxSize 2M

# Log time with each message.
# Default: no
LogTime yes

# Use system logger (can work together with UpdateLogFile).
# Default: no
LogSyslog yes

# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
# Default: no
LogRotate yes

# Initialize supplementary group access (freshclam must be started by root).
# Default: no
AllowSupplementaryGroups yes

# Uncomment the following line and replace XY with your country
# code. See http://www.iana.org/cctld/cctld-whois.htm for the full list.
# You can use db.XY.ipv6.clamav.net for IPv6 connections.
#DatabaseMirror db.XY.clamav.net
DatabaseMirror db.jp.clamav.net
DatabaseMirror db.us.clamav.net

# 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 database.clamav.net

# Send the RELOAD command to clamd.
# Default: no
#NotifyClamd /path/to/clamd.conf
NotifyClamd /etc/clamd.conf
説明:設定ファイル
/etc/clamd.d/scan.conf
 => clamd@scan設定

/etc/freshclam.conf
 => ウイルス定義ファイル更新設定ファイル
 => clamav-update をインストールする必要がある

/etc/cron.d/clamav-update
 => 定義ファイル更新用の自動更新設定ファイル
 => デフォルトは、3時間ごとに更新
 => 『MAILTO="your-email-address@sample.com"』のようにメールを設定しておくと
    エラー時に通知してくれる(詳細は以下の関連記事を参照のこと)
https://blogs.yahoo.co.jp/dk521123/37051127.html

【3】 起動

# 起動
sudo systemctl start clamd@scan

# 自動起動
sudo systemctl enable clamd@scan

【4】 動作確認

# 4-0) バージョン確認
clamd --version
# 「ClamAV 0.99.2/...」が出力される

# 4-1) パターンファイル更新
sudo freshclam

# 4-2) テストウィルス(無害)をダウンロード
#   ... 詳細は、以下の「【補足】テスト用ウイルスファイル EICAR について」を参照。
# wgetがまだインスールされていなければ、「sudo yum -y install wget」で。
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

# 4-3) スキャン実行(「--remove」は発見したウィルスは削除)
sudo clamscan --remove

【出力結果】
・・・略・・・
/home/admin/eicar.com: Eicar-Test-Signature FOUND
/home/admin/eicar.com.txt: Eicar-Test-Signature FOUND
/home/admin/eicar_com.zip: Eicar-Test-Signature FOUND
/home/admin/eicarcom2.zip: Eicar-Test-Signature FOUND

----------- SCAN SUMMARY -----------
Known viruses: 6302993
Engine version: 0.99.2
Scanned directories: 1
Scanned files: 24
Infected files: 4 << ★ウィルス発見数★
Data scanned: 62.86 MB
Data read: 58.33 MB (ratio 1.08:1)
Time: 39.378 sec (0 m 39 s)
スキャン結果の項目については、以下の関連記事を参照のこと。
https://blogs.yahoo.co.jp/dk521123/37255846.html

【補足】テスト用ウイルスファイル EICAR について
 * EICAR(European Institute for Computer Antivirus Research)で作成された
  アンチウイルスソフトでスキャンするとウイルスとして検出されるが、無害なファイル

`#`ファイル名`説明`備考
01eicar.com無害な疑似ウイルス-
02eicar.com.txt#01の拡張子を.txtに変更したファイル-
03eicar_com.zip#01をZIP形式で圧縮したファイル-
04eicarcom2.zip#03を更にZIP形式で圧縮したファイル(二重圧縮)-

■ 補足

【1】 アンインストール

sudo yum remove clamav*