●Clam AntiVirusのインストール(CentOS 8、Rocky Linux 9)
参考URL:アンチウィルスソフト導入(Clam AntiVirus)(CentOS8)
参考URL:CentOS 8 にClam AntiVirusのインストール
参考URL:Install ClamAV on CentOS 8 – freshclam(clamav-update)
参考URL:clamd.conf の 説明
EPELからダウンロードします。
EPELを使用しますので、事前に使用できるよう設定してください。
EPELは通常使用しないように設定してください。
スキャン機能を有効化します。
設定状態を確認するには、clamconfコマンドを使用することができます。
●Clam AntiVirusのインストール(内容古いかも)
デフォルト状態のyumではClam AntiVirusをインストールすることができないため、リポジトリの設定を行います。
●Clam AntiVirusのインストール(Fedora 21)
RPM Findより「clamav-0.98.5-1.el6.src.rpm」をダウンロードします。Fedora 21用のRPMパッケージを作成します。
●Clam AntiVirusのインストール(CentOS 7)
EPELからダウンロードします。
●Clam AntiVirusの設定
●Clam AntiVirusの起動
●ウィルス定義ファイルを最新版にする
●ウィルス定義ファイルのアップデートエラー
root宛に3時間毎に下記のようなメールが送られてくるようになりました。
●ウィルス定義ファイルのバージョンを調べる
ウィルス定義ファイルが最新がどうかを確認するには、下記コマンドを実行してください。
●ウィルススキャンのテスト
●ウィルススキャンの定期実行(CentOS 8)
ウィルススキャン用の実行スクリプトを作成します。
●ウィルススキャンの定期実行(CentOS 7)
ウィルススキャン用の実行スクリプトを作成します。
●手動によるウィルススキャンの例
システム全体をスキャンする場合。
特定のディレクトリやファイルを除外して検索する場合 --exclude (ファイル指定) --exclude-dir (ディレクトリ指定)
上記を踏まえて。 /etc/ 以下と /var/ 以下を除外する場合。
●yumの設定(暫定処置)
ClamAV をインストールすると、clamav-dbとclamav衝突し、yumによるupdateができなくなります。
したがって、yumのアップデート対象からClamav関連のパッケージを除外します。
(抜本的解決にはなりませんが、ClamAVの為にyum updateが出来ない方が問題なので、今回の措置を取ることにしました。)
yumの設定ファイルであるyum.confをエディタで開きます。
●Cron <root@server> /usr/share/clamav/freshclam-sleep
root宛に下記のようなメールが送られてくるようになりました。
そのため下記の作業を実施しました。
無事アップデートできるようになりました。
●SSL connect error
Logwatchで下記のような情報が記録されるようになりました。
手動でウィルス定義ファイルを更新しましたが、エラーが発生し更新できませんでした。
参考URL:アンチウィルスソフト導入(Clam AntiVirus)(CentOS8)
参考URL:CentOS 8 にClam AntiVirusのインストール
参考URL:Install ClamAV on CentOS 8 – freshclam(clamav-update)
参考URL:clamd.conf の 説明
EPELからダウンロードします。
EPELを使用しますので、事前に使用できるよう設定してください。
EPELは通常使用しないように設定してください。
# vi /etc/yum.repos.d/epel.repo enabled=0Clam AntiVirusのインストールをインストールします。
# dnf --enablerepo=epel install clamav clamav-scanner-systemd clamav-updateClam AntiVirus設定ファイルを編集します。
# vi /etc/clamd.d/scan.conf #Example ← 行頭に#を追加してコメントアウト(ウイルススキャン機能の有効化) #User clamscan ← 行頭に#を追加してコメントアウト(root権限で動作するようにする) LogFile /var/log/clamd.scan ← 行頭の#を削除 LogFileMaxSize 2M ← 行頭の#を削除 LogTime yes ← 行頭の#を削除 LogRotate yes ← 行頭の#を削除 LocalSocket /run/clamd.scan/clamd.sock ← 行頭の#を削除 FixStaleSocket yes ← 行頭の#を削除 ExcludePath ^/proc/ ← 行頭の#を削除 ExcludePath ^/sys/ ← 行頭の#を削除 User root ← 変更ウイルス定義ファイル更新を設定します。
# vi /etc/freshclam.conf # Examplee ← 行頭に#を追加してコメントアウト(ウイルス定義ファイル更新機能の有効化) UpdateLogFile /var/log/freshclam.log ← 行頭の#を削除 LogFileMaxSize 2M ← 行頭の#を削除 LogTime yes ← 行頭の#を削除 LogRotate yes ← 行頭の#を削除 DatabaseOwner root ← 変更 DatabaseMirror db.jp.clamav.net ← 変更 NotifyClamd /etc/clamd.d/scan.conf ← 変更ウイルス定義ファイルを最新に更新します。
# freshclam ClamAV update process started at Sun Feb 14 18:09:35 2021 daily database available for update (local version: 25931, remote version: 26079) Current database is 148 versions behind. Downloading database patch # 25932... WARNING: downloadFile: file not found: https://database.clamav.net/daily-25932.cdiff WARNING: getpatch: Can't download daily-25932.cdiff from https://database.clamav.net/daily-25932.cdiff Downloading database patch # 25932... WARNING: downloadFile: file not found: https://database.clamav.net/daily-25932.cdiff WARNING: getpatch: Can't download daily-25932.cdiff from https://database.clamav.net/daily-25932.cdiff Downloading database patch # 25932... WARNING: downloadFile: file not found: https://database.clamav.net/daily-25932.cdiff WARNING: getpatch: Can't download daily-25932.cdiff from https://database.clamav.net/daily-25932.cdiff WARNING: Incremental update failed, trying to download daily.cvd Time: 10.1s, ETA: 0.0s [========================>] 102.76MiB/102.76MiB Testing database: '/var/lib/clamav/tmp.4b1e9c2cdd/clamav-13c4c6f497315ba1d9f72448a42b8ee9.tmp-daily.cvd' ... Database test passed. daily.cvd updated (version: 26079, sigs: 4070509, f-level: 63, builder: raynman) main.cvd database is up to date (version: 59, sigs: 4564902, f-level: 60, builder: sigmgr) bytecode.cvd database is up to date (version: 331, sigs: 94, f-level: 63, builder: anvilleg)インストール直後のウィルス定義ファイル更新化の実行時は、いくつかWARNINGが表示されますが無視して問題ありません。
スキャン機能を有効化します。
# systemctl enable --now clamd@scan # systemctl status clamd@scan ● clamd@scan.service - clamd scanner (scan) daemon Loaded: loaded (/usr/lib/systemd/system/clamd@.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-02-14 18:17:17 JST; 11s ago Docs: man:clamd(8) man:clamd.conf(5) https://www.clamav.net/documents/ Main PID: 21975 (clamd) Tasks: 2 (limit: 100596) Memory: 1.0G CGroup: /system.slice/system-clamd.slice/clamd@scan.service └─21975 /usr/sbin/clamd -c /etc/clamd.d/scan.conf ※正常に起動しない場合の対処方法 下記のようにエラーが表示され、正常に起動しない場合があります。 Job for clamd@scan.service failed because the control process exited with error code. この場合、下記のように対処します。 # vi /lib/systemd/system/clamd@.service [Service] Type = forking ExecStart = /usr/sbin/clamd -c /etc/clamd.d/%i.conf # Reload the database ExecReload=/bin/kill -USR2 $MAINPID Restart = on-failure TimeoutStartSec=600 ← 起動完了までに待機する時間を10分に変更 # systemctl daemon-reload ← clamd起動スクリプト修正反映 # systemctl start clamd@scan ← clamd起動 # systemctl enable clamd@scan ← clamd自動起動設定ウイルススキャンテストを実施します。
# clamscan --infected --remove --recursive /root ← ウイルススキャンテスト(ウイルスなしの場合)
----------- SCAN SUMMARY -----------
Known viruses: 8619830
Engine version: 0.103.0
Scanned directories: 168
Scanned files: 347
Infected files: 0
Data scanned: 57.91 MB
Data read: 48.96 MB (ratio 1.18:1)
Time: 19.317 sec (0 m 19 s)
Start Date: 2021:02:14 18:19:42
End Date: 2021:02:14 18:20:01
試験用ウィルスをダウンロードします。
# 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 ← ウイルススキャンテスト(ウイルスありの場合) /root/eicar.com: Win.Test.EICAR_HDB-1 FOUND ← ウイルス検知 /root/eicar.com: Removed. ← ウイルス削除 /root/eicar.com.txt: Win.Test.EICAR_HDB-1 FOUND ← ウイルス検知 /root/eicar.com.txt: Removed. ← ウイルス削除 /root/eicar_com.zip: Win.Test.EICAR_HDB-1 FOUND ← ウイルス検知 /root/eicar_com.zip: Removed. ← ウイルス削除 /root/eicarcom2.zip: Win.Test.EICAR_HDB-1 FOUND ← ウイルス検知 /root/eicarcom2.zip: Removed. ← ウイルス削除 ----------- SCAN SUMMARY ----------- Known viruses: 8619830 Engine version: 0.103.0 Scanned directories: 168 Scanned files: 351 Infected files: 4 ← ウイルスを4つ検知 Data scanned: 57.91 MB Data read: 48.96 MB (ratio 1.18:1) Time: 19.248 sec (0 m 19 s) Start Date: 2021:02:14 18:23:36 End Date: 2021:02:14 18:23:56定義ファイルの更新を有効化します。
# systemctl enable --now clamav-freshclam以上で、設定は完了です。
設定状態を確認するには、clamconfコマンドを使用することができます。
# clamconf -n
Checking configuration files in /etc
Config file: clamd.d/scan.conf
------------------------------
LogFile = "/var/log/clamd.scan"
LogFileMaxSize = "2097152"
LogTime = "yes"
LogSyslog = "yes"
LogRotate = "yes"
LocalSocket = "/run/clamd.scan/clamd.sock"
ExcludePath = "^/proc/", "^/sys/"
User = "root"
Config file: freshclam.conf
---------------------------
LogFileMaxSize = "2097152"
LogTime = "yes"
LogSyslog = "yes"
LogRotate = "yes"
UpdateLogFile = "/var/log/freshclam.log"
DatabaseOwner = "root"
DatabaseMirror = "database.clamav.net"
NotifyClamd = "/path/to/clamd.conf"
mail/clamav-milter.conf not found
Software settings
-----------------
Version: 0.103.3
Optional features supported: MEMPOOL IPv6 AUTOIT_EA06 BZIP2 LIBXML2 PCRE2 ICONV JSON
Database information
--------------------
Database directory: /var/lib/clamav
main.cvd: version 61, sigs: 6607162, built on Thu Jul 15 11:39:10 2021
bytecode.cvd: version 333, sigs: 92, built on Tue Mar 9 00:21:51 2021
daily.cvd: version 26233, sigs: 1961297, built on Thu Jul 15 16:31:54 2021
Total number of signatures: 8568551
Platform information
--------------------
uname: Linux 4.18.0-315.el8.x86_64 #1 SMP Mon Jun 28 19:09:44 UTC 2021 x86_64
OS: linux-gnu, ARCH: x86_64, CPU: x86_64
zlib version: 1.2.11 (1.2.11), compile flags: a9
platform id: 0x0a217c7c0800000002080401
Build information
-----------------
GNU C: 8.4.1 20200928 (Red Hat 8.4.1-1) (8.4.1)
CPPFLAGS: -I/usr/include/libprelude
CFLAGS: -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
CXXFLAGS: -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
LDFLAGS: -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--as-needed -lprelude
Configure: '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--enable-milter' '--disable-clamav' '--disable-static' '--disable-zlib-vcheck' '--disable-unrar' '--enable-id-check' '--enable-dns' '--with-dbdir=/var/lib/clamav' '--with-group=clamupdate' '--with-user=clamupdate' '--disable-rpath' '--disable-silent-rules' '--enable-clamdtop' '--enable-prelude' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'CXXFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--as-needed' 'CFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig' sizeof(void*) = 8
Engine flevel: 124, dconf: 124
Checking configuration files in /etc
Config file: clamd.d/scan.conf
------------------------------
LogFile = "/var/log/clamd.scan"
LogFileMaxSize = "2097152"
LogTime = "yes"
LogSyslog = "yes"
LogRotate = "yes"
LocalSocket = "/run/clamd.scan/clamd.sock"
ExcludePath = "^/proc/", "^/sys/"
User = "root"
Config file: freshclam.conf
---------------------------
LogFileMaxSize = "2097152"
LogTime = "yes"
LogSyslog = "yes"
LogRotate = "yes"
UpdateLogFile = "/var/log/freshclam.log"
DatabaseOwner = "root"
DatabaseMirror = "database.clamav.net"
NotifyClamd = "/path/to/clamd.conf"
mail/clamav-milter.conf not found
Software settings
-----------------
Version: 0.103.3
Optional features supported: MEMPOOL IPv6 AUTOIT_EA06 BZIP2 LIBXML2 PCRE2 ICONV JSON
Database information
--------------------
Database directory: /var/lib/clamav
main.cvd: version 61, sigs: 6607162, built on Thu Jul 15 11:39:10 2021
bytecode.cvd: version 333, sigs: 92, built on Tue Mar 9 00:21:51 2021
daily.cvd: version 26233, sigs: 1961297, built on Thu Jul 15 16:31:54 2021
Total number of signatures: 8568551
Platform information
--------------------
uname: Linux 4.18.0-315.el8.x86_64 #1 SMP Mon Jun 28 19:09:44 UTC 2021 x86_64
OS: linux-gnu, ARCH: x86_64, CPU: x86_64
zlib version: 1.2.11 (1.2.11), compile flags: a9
platform id: 0x0a217c7c0800000002080401
Build information
-----------------
GNU C: 8.4.1 20200928 (Red Hat 8.4.1-1) (8.4.1)
CPPFLAGS: -I/usr/include/libprelude
CFLAGS: -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
CXXFLAGS: -O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection
LDFLAGS: -Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--as-needed -lprelude
Configure: '--build=x86_64-redhat-linux-gnu' '--host=x86_64-redhat-linux-gnu' '--program-prefix=' '--disable-dependency-tracking' '--prefix=/usr' '--exec-prefix=/usr' '--bindir=/usr/bin' '--sbindir=/usr/sbin' '--sysconfdir=/etc' '--datadir=/usr/share' '--includedir=/usr/include' '--libdir=/usr/lib64' '--libexecdir=/usr/libexec' '--localstatedir=/var' '--sharedstatedir=/var/lib' '--mandir=/usr/share/man' '--infodir=/usr/share/info' '--enable-milter' '--disable-clamav' '--disable-static' '--disable-zlib-vcheck' '--disable-unrar' '--enable-id-check' '--enable-dns' '--with-dbdir=/var/lib/clamav' '--with-group=clamupdate' '--with-user=clamupdate' '--disable-rpath' '--disable-silent-rules' '--enable-clamdtop' '--enable-prelude' 'build_alias=x86_64-redhat-linux-gnu' 'host_alias=x86_64-redhat-linux-gnu' 'CXXFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now -specs=/usr/lib/rpm/redhat/redhat-hardened-ld -Wl,--as-needed' 'CFLAGS=-O2 -g -pipe -Wall -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fstack-protector-strong -grecord-gcc-switches -specs=/usr/lib/rpm/redhat/redhat-hardened-cc1 -specs=/usr/lib/rpm/redhat/redhat-annobin-cc1 -m64 -mtune=generic -fasynchronous-unwind-tables -fstack-clash-protection -fcf-protection' 'PKG_CONFIG_PATH=:/usr/lib64/pkgconfig:/usr/share/pkgconfig' sizeof(void*) = 8
Engine flevel: 124, dconf: 124
●Clam AntiVirusのインストール(内容古いかも)
デフォルト状態のyumではClam AntiVirusをインストールすることができないため、リポジトリの設定を行います。
# yum -y install rpmforge-release続いて、Clam AntiVirusをインストールします。
# sed -i 's/enabled = 1/enabled = 0/g' /etc/yum.repos.d/rpmforge.repo ↑ 基本リポジトリとのパッケージ競合を避けるため、デフォルトは無効にしておく # yum --enablerepo=rpmforge install clamd ← Clam AntiVirusインストールclamav、clamav-db、clamdがインストールされます。
●Clam AntiVirusのインストール(Fedora 21)
RPM Findより「clamav-0.98.5-1.el6.src.rpm」をダウンロードします。Fedora 21用のRPMパッケージを作成します。
# rpmbuild --rebuild /home/hoge/Downloads/clamav-0.98.5-1.el6.src.rpm 書き込み完了: /root/rpmbuild/RPMS/i686/clamav-0.98.5-1.fc21.i686.rpm 書き込み完了: /root/rpmbuild/RPMS/i686/clamd-0.98.5-1.fc21.i686.rpm 書き込み完了: /root/rpmbuild/RPMS/i686/clamav-milter-0.98.5-1.fc21.i686.rpm 書き込み完了: /root/rpmbuild/RPMS/i686/clamav-db-0.98.5-1.fc21.i686.rpm 書き込み完了: /root/rpmbuild/RPMS/i686/clamav-devel-0.98.5-1.fc21.i686.rpm 書き込み完了: /root/rpmbuild/RPMS/i686/clamav-debuginfo-0.98.5-1.fc21.i686.rpm続いて、Clam AntiVirusをインストールします。
# yum install clamd clamav* ← Clam AntiVirusインストール
●Clam AntiVirusのインストール(CentOS 7)
EPELからダウンロードします。
# yum --enablerepo=epel -y install clamav clamav-update 総ダウンロード容量: 98 M インストール容量: 106 M Downloading packages: (1/5): clamav-0.98.6-1.el7.x86_64.rpm | 804 kB 00:00:00 (2/5): clamav-data-0.98.6-1.el7.noarch.rpm | 93 MB 00:00:19 (3/5): clamav-filesystem-0.98.6-1.el7.noarch.rpm | 18 kB 00:00:00 (4/5): clamav-lib-0.98.6-1.el7.x86_64.rpm | 3.7 MB 00:00:01 (5/5): clamav-update-0.98.6-1.el7.x86_64.rpm | 89 kB 00:00:00 ---------------------------------------------------------------------------------------------------- 合計 4.5 MB/s | 98 MB 00:00:21 Running transaction check Running transaction test Transaction test succeeded Running transaction インストール中 : clamav-filesystem-0.98.6-1.el7.noarch 1/5 インストール中 : clamav-data-0.98.6-1.el7.noarch 2/5 インストール中 : clamav-lib-0.98.6-1.el7.x86_64 3/5 インストール中 : clamav-0.98.6-1.el7.x86_64 4/5 インストール中 : clamav-update-0.98.6-1.el7.x86_64 5/5 検証中 : clamav-lib-0.98.6-1.el7.x86_64 1/5 検証中 : clamav-data-0.98.6-1.el7.noarch 2/5 検証中 : clamav-0.98.6-1.el7.x86_64 3/5 検証中 : clamav-update-0.98.6-1.el7.x86_64 4/5 検証中 : clamav-filesystem-0.98.6-1.el7.noarch 5/5 インストール: clamav.x86_64 0:0.98.6-1.el7 clamav-update.x86_64 0:0.98.6-1.el7 依存性関連をインストールしました: clamav-data.noarch 0:0.98.6-1.el7 clamav-filesystem.noarch 0:0.98.6-1.el7 clamav-lib.x86_64 0:0.98.6-1.el7 完了しました! # sed -i -e "s/^Example/#Example/" /etc/freshclam.confパターンファイルを更新してみます。
# freshclam ClamAV update process started at Tue Apr 28 10:04:01 2015 main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo) WARNING: getfile: daily-19996.cdiff not found on remote server (IP: 120.29.176.126) WARNING: getpatch: Can't download daily-19996.cdiff from database.clamav.net WARNING: getfile: daily-19996.cdiff not found on remote server (IP: 218.44.253.75) WARNING: getpatch: Can't download daily-19996.cdiff from database.clamav.net WARNING: getfile: daily-19996.cdiff not found on remote server (IP: 203.212.42.128) WARNING: getpatch: Can't download daily-19996.cdiff from database.clamav.net WARNING: Incremental update failed, trying to download daily.cvd Downloading daily.cvd [100%] daily.cvd updated (version: 20386, sigs: 1378813, f-level: 63, builder: neo) Downloading bytecode.cvd [100%] bytecode.cvd updated (version: 250, sigs: 42, f-level: 63, builder: neo) Database updated (3803080 signatures) from database.clamav.net (IP: 219.94.128.99)CentOS 7では、下記ファイルで3時間毎にパターンファイル更新を試みます。
/etc/cron.d/clamav-update
●Clam AntiVirusの設定
# vi /etc/clamd.conf ← 編集 User clam ↓ #User clam ← root権限で動作させる
●Clam AntiVirusの起動
# /etc/rc.d/init.d/clamd start ← clamdの起動 Starting Clam AntiVirus Daemon: [ OK ] # chkconfig clamd on ← 自動起動設定 # chkconfig --list clamd ← 自動起動設定の確認 clamd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
●ウィルス定義ファイルを最新版にする
# sed -i 's/Example/#Example/g' /etc/freshclam.conf ↑ ウィルス定義ファイル更新機能の有効化 # freshclam ← ウィルス定義ファイル最新化 ClamAV update process started at Tue Apr 28 10:04:01 2015 main.cvd is up to date (version: 55, sigs: 2424225, f-level: 60, builder: neo) WARNING: getfile: daily-19996.cdiff not found on remote server (IP: 120.29.176.126) WARNING: getpatch: Can't download daily-19996.cdiff from database.clamav.net WARNING: getfile: daily-19996.cdiff not found on remote server (IP: 218.44.253.75) WARNING: getpatch: Can't download daily-19996.cdiff from database.clamav.net WARNING: getfile: daily-19996.cdiff not found on remote server (IP: 203.212.42.128) WARNING: getpatch: Can't download daily-19996.cdiff from database.clamav.net WARNING: Incremental update failed, trying to download daily.cvd Downloading daily.cvd [100%] daily.cvd updated (version: 20386, sigs: 1378813, f-level: 63, builder: neo) Downloading bytecode.cvd [100%] bytecode.cvd updated (version: 250, sigs: 42, f-level: 63, builder: neo) Database updated (3803080 signatures) from database.clamav.net (IP: 219.94.128.99)下記のようなエラーが表示された場合は、freshclam.logの所有者を「clam」に変更してください。
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). # chown clam.clamav /var/log/clamav/freshclam.log ERROR: Can't create temporary directory /var/lib/clamav/clamav-4f6961cbb0d1ff20e9d60f0b353edd37.tmp Hint: The database directory must be writable for UID 499 or GID 499 # cat /etc/passwd | grep 499 clam:x:499:499:Clam Anti Virus Checker:/var/lib/clamav:/sbin/nologin # chown -R clam:clam /var/lib/clamav今後、ウィルス定義ファイルのアップデートは、/etc/cron.daily/freshclamにより毎日自動で行われるようになります。
●ウィルス定義ファイルのアップデートエラー
root宛に3時間毎に下記のようなメールが送られてくるようになりました。
件名:Cron >root@server< /usr/share/clamav/freshclam-sleep WARNING: update of clamav database is disabled; please see '/etc/sysconfig/freshclam' for information how to enable the periodic update resp. how to turn off this message.どうもアップデートされていないようです。下記のようにコメントアウトします。
# 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 ← コメントアウト
●ウィルス定義ファイルのバージョンを調べる
ウィルス定義ファイルが最新がどうかを確認するには、下記コマンドを実行してください。
# sigtool --version ClamAV 0.98.7/20497/Fri May 22 13:35:23 2015
●ウィルススキャンのテスト
# clamscan --infected --remove --recursive /home ← ウィルススキャンテスト ----------- SCAN SUMMARY ----------- Known viruses: 3797494 Engine version: 0.98.6 Scanned directories: 173 Scanned files: 489 Infected files: 0 ← ウィルス検知なし Data scanned: 42.43 MB Data read: 46.38 MB (ratio 0.91:1) Time: 14.788 sec (0 m 14 s)ウィルスが検知されるかどうか確認するためテストファイルをダウンロードします。
# 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 ← テスト用ウィルスをダウンロード # clamscan --infected --remove --recursive .span class="green"> ← ウィルススキャンテスト /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. ← ウィルス削除 ----------- SCAN SUMMARY ----------- Known viruses: 1192480 Engine version: 0.97.4 Scanned directories: 1760 Scanned files: 5403 Infected files: 3 ← 3個のウィルスを検知 Data scanned: 205.49 MB Data read: 225.54 MB (ratio 0.91:1) Time: 23.546 sec (0 m 23 s)
●ウィルススキャンの定期実行(CentOS 8)
ウィルススキャン用の実行スクリプトを作成します。
# vi clamscan #!/bin/bash PATH=/usr/bin:/bin # clamd update dnf -y update clamav clamav-filesystem clamav-lib clamav-update > /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 # 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 $CLAMSCANTM # chmod +x clamscan ← ウィルススキャン実行スクリプトへ実行権限付加 # echo "/backup/backup.tar.bz2" >> clamscan.exclude ↑ 例として/backup/backup.tar.bz2をスキャン対象外にする # echo "/proc/" >> clamscan.exclude ↑ 例として/procディレクトリをスキャン対象外にする # echo "/sys/" >> clamscan.exclude ←↑ 例として/sysディレクトリをスキャン対象外にする ※ディレクトリを除外する場合は末尾に「/」を付加する # mv clamscan /etc/cron.daily/ ↑ ウィルススキャン実行スクリプトを毎日自動実行されるディレクトリへ移動
●ウィルススキャンの定期実行(CentOS 7)
ウィルススキャン用の実行スクリプトを作成します。
# vi 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 +x clamscan ← ウィルススキャン実行スクリプトへ実行権限付加 # echo "/backup/backup.tar.bz2" >> clamscan.exclude ↑ 例として/backup/backup.tar.bz2をスキャン対象外にする # echo "/proc/" >> clamscan.exclude ↑ 例として/procディレクトリをスキャン対象外にする # echo "/sys/" >> clamscan.exclude ←↑ 例として/sysディレクトリをスキャン対象外にする ※ディレクトリを除外する場合は末尾に「/」を付加する # mv clamscan /etc/cron.daily/ ↑ ウィルススキャン実行スクリプトを毎日自動実行されるディレクトリへ移動これで、毎日定期的に全ファイルのウィルススキャンが行われ、ウィルスを検知した場合のみroot宛にメールが送られてくるようになります。
●手動によるウィルススキャンの例
システム全体をスキャンする場合。
# clamscan --infected --remove --recursive /スキャンするディレクトリを指定する場合は以下のコマンドを実行します。例では/home以下のみをスキャンします。
# clamscan --infected --remove --recursive /home設定例
特定のディレクトリやファイルを除外して検索する場合 --exclude (ファイル指定) --exclude-dir (ディレクトリ指定)
上記を踏まえて。 /etc/ 以下と /var/ 以下を除外する場合。
# clamscan --infected --remove --recursive / --exclude-dir="etc|var"
*.core という拡張子と *.snap という拡張子が付くファイルを除外する場合。
# clamscan --infected --remove --recursive / --exclude=".*\.core|.*\.snap"$
ウィルスを発見次第削除する場合には以下のオプションを付けて実行します。
# clamscan --remove
●yumの設定(暫定処置)
ClamAV をインストールすると、clamav-dbとclamav衝突し、yumによるupdateができなくなります。
したがって、yumのアップデート対象からClamav関連のパッケージを除外します。
(抜本的解決にはなりませんが、ClamAVの為にyum updateが出来ない方が問題なので、今回の措置を取ることにしました。)
yumの設定ファイルであるyum.confをエディタで開きます。
# vi /etc/yum.conf 以下の一文を追記します。 exclude=clamav*これでyumのアップデート対象から「clamav」の文字を含んだものが除外されます。他のモジュールがある場合は半角スペースで区切ります。
●Cron <root@server> /usr/share/clamav/freshclam-sleep
root宛に下記のようなメールが送られてくるようになりました。
件名: Cron <root@server> /usr/share/clamav/freshclam-sleep 内容: ERROR: Can't create temporary directory /var/lib/clamav/clamav-08254efb88e7ada1a01ee49aa1ae1cbe.tmp調べてみたところclamavがアップデートされており使用するアカウントが変わっているようでした。
そのため下記の作業を実施しました。
# useradd -c 'Clamav database update user' clamav -d /var/lib/clamav -s /sbin/nologin
useradd: 警告: ホームディレクトリが既に存在します。
skel ディレクトリからのコピーは行いません。
# chown -R clam:clamav /var/lib/clamav
# freshclam
ClamAV update process started at Fri Jul 8 15:04:56 2016
main.cvd is up to date (version: 57, sigs: 4218790, f-level: 60, builder: amishhammer)
WARNING: getfile: daily-21724.cdiff not found on db.local.clamav.net (IP: 27.96.54.66)
WARNING: getpatch: Can't download daily-21724.cdiff from db.local.clamav.net
nonblock_connect: connect timing out (30 secs)
Can't connect to port 80 of host db.local.clamav.net (IP: 120.29.176.126)
Trying host db.local.clamav.net (203.178.137.175)...
WARNING: getfile: daily-21724.cdiff not found on db.local.clamav.net (IP: 203.178.137.175)
WARNING: getpatch: Can't download daily-21724.cdiff from db.local.clamav.net
Trying host db.local.clamav.net (218.44.253.75)...
WARNING: getfile: daily-21724.cdiff not found on db.local.clamav.net (IP: 218.44.2
53.75) WARNING: getpatch: Can't download daily-21724.cdiff from db.local.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 21863, sigs: 394867, f-level: 63, builder: neo)
Downloading bytecode-279.cdiff [100%]
Downloading bytecode-280.cdiff [100%]
Downloading bytecode-281.cdiff [100%]
Downloading bytecode-282.cdiff [100%]
Downloading bytecode-283.cdiff [100%]
bytecode.cld updated (version: 283, sigs: 53, f-level: 63, builder: neo)
[LibClamAV] Detected duplicate databases /var/lib/clamav/daily.cld and /var/lib/clamav/daily.cvd. The /var/lib/clamav/daily.cld database is older and will not be loaded, you should manually remove it from the database directory.
Database updated (4613710 signatures) from db.local.clamav.net (IP: 203.212.42.128)
useradd: 警告: ホームディレクトリが既に存在します。
skel ディレクトリからのコピーは行いません。
# chown -R clam:clamav /var/lib/clamav
# freshclam
ClamAV update process started at Fri Jul 8 15:04:56 2016
main.cvd is up to date (version: 57, sigs: 4218790, f-level: 60, builder: amishhammer)
WARNING: getfile: daily-21724.cdiff not found on db.local.clamav.net (IP: 27.96.54.66)
WARNING: getpatch: Can't download daily-21724.cdiff from db.local.clamav.net
nonblock_connect: connect timing out (30 secs)
Can't connect to port 80 of host db.local.clamav.net (IP: 120.29.176.126)
Trying host db.local.clamav.net (203.178.137.175)...
WARNING: getfile: daily-21724.cdiff not found on db.local.clamav.net (IP: 203.178.137.175)
WARNING: getpatch: Can't download daily-21724.cdiff from db.local.clamav.net
Trying host db.local.clamav.net (218.44.253.75)...
WARNING: getfile: daily-21724.cdiff not found on db.local.clamav.net (IP: 218.44.2
53.75) WARNING: getpatch: Can't download daily-21724.cdiff from db.local.clamav.net
WARNING: Incremental update failed, trying to download daily.cvd
Downloading daily.cvd [100%]
daily.cvd updated (version: 21863, sigs: 394867, f-level: 63, builder: neo)
Downloading bytecode-279.cdiff [100%]
Downloading bytecode-280.cdiff [100%]
Downloading bytecode-281.cdiff [100%]
Downloading bytecode-282.cdiff [100%]
Downloading bytecode-283.cdiff [100%]
bytecode.cld updated (version: 283, sigs: 53, f-level: 63, builder: neo)
[LibClamAV] Detected duplicate databases /var/lib/clamav/daily.cld and /var/lib/clamav/daily.cvd. The /var/lib/clamav/daily.cld database is older and will not be loaded, you should manually remove it from the database directory.
Database updated (4613710 signatures) from db.local.clamav.net (IP: 203.212.42.128)
無事アップデートできるようになりました。
●SSL connect error
Logwatchで下記のような情報が記録されるようになりました。
--------------------- clam-update Begin ------------------------ No updates detected in the log for the freshclam daemon (the ClamAV update process). If the freshclam daemon is not running, you may need to restart it. Other options: A. If you no longer wish to run freshclam, deleting the log file (configured is /var/log/freshclam.log ) will suppress this error message. B. If you use a different log file, update the appropriate configuration file. For example: echo "LogFile = log_file" >> /etc/logwatch/conf/logfiles/clam-update.conf where log_file is the filename of the freshclam log file. C. If you are logging using syslog, you need to indicate that your log file uses the syslog format. For example: echo "*OnlyService = freshclam" >> /etc/logwatch/conf/logfiles/clam-update.conf echo "*RemoveHeaders" >> /etc/logwatch/conf/logfiles/clam-update.conf ---------------------- clam-update End -------------------------ウィルス定義ファイルのバージョンを確認(# sigtool --version)したところ、古い日付のままでした。
手動でウィルス定義ファイルを更新しましたが、エラーが発生し更新できませんでした。
Mon Sep 30 10:08:26 2023 -> -------------------------------------- Mon Sep 30 10:08:26 2023 -> ClamAV update process started at Mon Sep 30 10:08:26 2023 Mon Sep 30 10:08:26 2023 -> daily database available for download (remote version: 27412) Mon Sep 30 10:08:26 2023 -> WARNING: Download failed (35) Mon Sep 30 10:08:26 2023 -> WARNING: Message: SSL connect error Mon Sep 30 10:08:26 2023 -> WARNING: Can't download daily.cvd from https://database.clamav.net/daily.cvd Mon Sep 30 10:08:26 2023 -> Trying again in 5 secs... Mon Sep 30 10:08:31 2023 -> daily database available for download (remote version: 27412) Mon Sep 30 10:08:31 2023 -> WARNING: Download failed (35) Mon Sep 30 10:08:31 2023 -> WARNING: Message: SSL connect error Mon Sep 30 10:08:31 2023 -> WARNING: Can't download daily.cvd from https://database.clamav.net/daily.cvd Mon Sep 30 10:08:31 2023 -> Trying again in 5 secs... Mon Sep 30 10:08:36 2023 -> daily database available for download (remote version: 27412) Mon Sep 30 10:08:36 2023 -> ERROR: Download failed (35) Mon Sep 30 10:08:36 2023 -> ERROR: Message: SSL connect error Mon Sep 30 10:08:36 2023 -> ERROR: Can't download daily.cvd from https://database.clamav.net/daily.cvd Mon Sep 30 10:08:36 2023 -> Giving up on https://database.clamav.net... Mon Sep 30 10:08:36 2023 -> ERROR: Update failed for database: daily Mon Sep 30 10:08:36 2023 -> ERROR: Database update process failed: Connection failed Mon Sep 30 10:08:36 2023 -> ERROR: Update failed.ウィルス定義ファイルが保存されているフォルダ内を一度すべて空にし、他のサーバからコピーしました。
[hoge@serverA ~]# rm -f /var/lib/clamav/* [hoge@serverB ~]# ls -l /var/lib/clamav 合計 367064 -rw-r--r-- 1 root root 1411072 12月 28 2023 bytecode.cld -rw-r--r-- 1 root root 203972608 9月 29 19:13 daily.cld -rw-r--r-- 1 root root 69 9月 10 2023 freshclam.dat -rw-r--r-- 1 root root 170479789 9月 10 2023 main.cvd [hoge@serverB ~]# scp /var/lib/clamav/* serverA:/var/lib/clamav/これにより問題が解消しました