提供:すだちWiki
移動先: 案内検索

ヘルプ:アンチウィルスソフト導入(Clam AntiVirus)(CentOS7)

メインページ > ヘルプ:目次 > ヘルプ:自宅サーバー構築(CentOS7)  > アンチウィルスソフト導入(Clam AntiVirus)(CentOS7)

Clam AntiVirusインストール

[root@host2 ~]# yum --enablerepo=epel -y install clamav clamav-server clamav-server-systemd clamav-update clamav-scanner

ウイルス定義ファイル最新化

ウイルス定義ファイル更新設定

[root@host2 ~]# vi /etc/freshclam.conf ← ウイルス定義ファイル更新設定ファイル編集
# Comment or remove the line below.
#Example ← 行頭に#を追加してコメントアウト(ウイルス定義ファイル更新機能の有効化)

# Send the RELOAD command to clamd.
# Default: no
#NotifyClamd /path/to/clamd.conf
NotifyClamd /etc/clamd.d/scan.conf ← 追加(ウイルス定義ファイル更新をclamdに通知する)

ウイルス定義ファイル自動更新設定

[root@host2 ~]# vi /etc/sysconfig/freshclam ← ウイルス定義ファイル自動更新設定ファイル編集
### !!!!! REMOVE ME !!!!!!
### REMOVE ME: By default, the freshclam update is disabled to avoid
### REMOVE ME: network access without prior activation
#FRESHCLAM_DELAY=disabled-warn  # REMOVE ME ← 行頭に#を追加してコメントアウト

ウイルス定義ファイル最新化

[root@host2 ~]# freshclam ← ウイルス定義ファイル最新化
ClamAV update process started at Sun May  5 21:58:48 2019
Downloading main.cvd [100%]
main.cvd updated (version: 58, sigs: 4566249, f-level: 60, builder: sigmgr)
Downloading daily.cvd [100%]
daily.cvd updated (version: 25440, sigs: 1562805, f-level: 63, builder: raynman)
Downloading bytecode.cvd [100%]
bytecode.cvd updated (version: 328, sigs: 94, f-level: 63, builder: neo)
Database updated (6129148 signatures) from database.clamav.net (IP: 104.16.218.84)
ERROR: Please edit the example config file /etc/clamd.d/scan.conf
ERROR: NotifyClamd: Can't find or parse configuration file /etc/clamd.d/scan.conf

Clam AntiVirus設定

[root@host2 ~]# vi /etc/clamd.d/scan.conf ← Clam AntiVirus設定ファイル編集
# Comment or remove the line below.
#Example ← 行頭に#を追加してコメントアウト

# Run as another user (clamd must be started by root for this option to work)
# Default: don't drop privileges
#User clamscan ← 行頭に#を追加してコメントアウト(root権限で動作するようにする)

# 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 ← 行頭の#を削除

Clam AntiVirus起動

[root@host2 ~]# systemctl start clamd@scan ← clamd起動

[root@host2 ~]# systemctl enable clamd@scan ← clamd自動起動設定

[root@host2 ~]# systemctl status clamd@scan ← clamdステータス
 clamd@scan.service - Generic clamav scanner daemon
   Loaded: loaded (/usr/lib/systemd/system/clamd@scan.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2019-05-05 22:05:37 JST; 19s ago
     Docs: man:clamd(8)
           man:clamd.conf(5)
           https://www.clamav.net/documents/
 Main PID: 28112 (clamd)
   CGroup: /system.slice/system-clamd.slice/clamd@scan.service
           mq28112 /usr/sbin/clamd -c /etc/clamd.d/scan.conf

 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: ELF support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: Mail files support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: OLE2 support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: PDF support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: SWF support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: HTML support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: XMLDOCS support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: HWP3 support enabled.
 5月 05 22:05:36 host2.sudachi.jp clamd[28112]: Self checking every 600 sec....
 5月 05 22:05:37 host2.sudachi.jp systemd[1]: Started Generic clamav scanne....
Hint: Some lines were ellipsized, use -l to show in full.

ウイルススキャンテスト

[root@host2 ~]# clamdscan -c /etc/clamd.d/scan.conf --remove ← ウイルススキャンテスト(ウイルスなしの場合)
/root: OK

----------- SCAN SUMMARY -----------
Infected files: 0 ← ウイルスは検知されなかった
Time: 1.924 sec (0 m 1 s)

[root@host2 ~]# wget http://www.eicar.org/download/eicar.com ← テスト用ウイルスをダウンロード
[root@host2 ~]# wget http://www.eicar.org/download/eicar.com.txt ← テスト用ウイルスをダウンロード
[root@host2 ~]# wget http://www.eicar.org/download/eicar_com.zip ← テスト用ウイルスをダウンロード
[root@host2 ~]# wget http://www.eicar.org/download/eicarcom2.zip ← テスト用ウイルスをダウンロード

[root@host2 ~]# clamdscan -c /etc/clamd.d/scan.conf --remove ← ウイルススキャンテスト(ウイルスありの場合)
/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 -----------
Infected files: 4 ← 4つのウイルスを検知した
Time: 23.913 sec (0 m 23 s)

ウイルススキャン定期自動実行設定

ウイルススキャン定期自動実行設定

[root@host2 ~]# vi /etc/cron.daily/clamdscan ← ウイルススキャン日次実行スクリプト作成
#!/bin/sh

# 設定ファイル
CONFIG=/etc/clamd.d/scan.conf

# スキャン実行
# ※ウイルス検知時は隔離ディレクトリへ隔離
CLAMSCANLOG=`mktemp`
QUARANTINEDIR=/tmp/clamdscan-quarantinedir-$(date +%Y%m%d)
mkdir -p ${QUARANTINEDIR}
clamdscan -c ${CONFIG} --move=${QUARANTINEDIR} / > ${CLAMSCANLOG} 2>&1

# ウイルス検知時のみroot宛にメール通知
if [ -z "$(grep FOUND$ ${CLAMSCANLOG})" ]; then
    rm -rf ${QUARANTINEDIR}
else
    grep -A 1 FOUND$ ${CLAMSCANLOG} | mail -s "Virus Found in `hostname` => ${QUARANTINEDIR}" root
fi

# スキャンログをシスログに出力
cat ${CLAMSCANLOG} | logger -t $(basename ${0})
rm -f ${CLAMSCANLOG}

[root@host2 ~]# chmod +x /etc/cron.daily/clamdscan ← ウイルススキャン日次実行スクリプトへ実行権限付加

[root@host2 ~]# echo ExcludePath ^/tmp/clamdscan-quarantinedir-.*/ >> /etc/clamd.d/scan.conf ← ウイルス隔離ディレクトリをスキャン対象外にする

[root@host2 ~]# echo ExcludePath ^/proc/ >> /etc/clamd.d/scan.conf ← 例として/procディレクトリをスキャン対象外にする

[root@host2 ~]# echo ExcludePath ^/sys/ >> /etc/clamd.d/scan.conf ← 例として/sysディレクトリをスキャン対象外にする

[root@host2 ~]# systemctl restart clamd@scan ← clamd再起動(スキャン除外設定反映)

これで、毎日定期的に全ファイルのウイルススキャンが行われ、ウイルスを検知した場合のみroot宛にメールが送られてくるようになる。

ウイルス検知後の対応

ウイルス検知メールが送られてきた場合、内容を確認し、ウイルスであると確認できた場合、当該ファイルを隔離先(ウイルス検知メール件名に記載)から削除する。
ウイルスでない(ClamAVによる誤検知)と確認できた場合、当該ファイルを隔離先から復元し、次回以降、誤検知しないように当該ファイルをスキャン対象外にする。