|
ウィルススキャナー clamav |
2015年2月24日 | 2016年4月6日 追記 |
ウィルス対策としてclamavを導入します。 これによりメールやホームページデータのウィルスチェックを行います。 |
メールや各種データのウィルスチェックに従来からClamAntiVirus(clamav)というソフトを使ってきました。
今回もこれを導入します。
ただこのパッケージはCentOSの標準にはなく、repoforgeやEPELなどからの導入になります。
どちらにしようかいつも悩みます。
repoforgeは
clamd-0.98.4-1.el7.rf.x86_64.rpm
でパッケージは一個だけ。
一方EPELは
clamav-0.98.5-1.el7.x86_64.rpm
を筆頭に合計14個のパッケージに別れています。
必要なものだけ入れて使えということのようです。
EPELは慣れないとちょっと設定などが難しそうですが、ウィルススキャナについては少しでも新しいバージョンを使いたいのと、今後のためにEPEL方式にも慣れておかねばと思い、今回はEPELを使ってみることにしました。
また、メールサーバーとの接続にはclamavのclamav-milterを使います。
インストール
使うのはclamav-scanner+clamav-serverとclamav-milterですが、結局依存関係でいろいろ導入されます。
clamav-data-0.98.5-1.el7.noarch …ウィルス定義ファイルのもと
clamav-devel-0.98.5-1.el7.x86_64 …設定ファイルの元やREADMEが入っている
clamav-filesystem-0.98.5-1.el7.noarch
clamav-lib-0.98.5-1.el7.x86_64
clamav-milter-systemd-0.98.5-1.el7.noarch
clamav-milter-0.98.5-1.el7.x86_64 …メールサーバーとの接続用
clamav-scanner-0.98.5-1.el7.noarch
clamav-scanner-systemd-0.98.5-1.el7.noarch
clamav-server-0.98.5-1.el7.x86_64 …clamavのデーモンプログラム(clamd)
clamav-server-systemd-0.98.5-1.el7.noarch
clamav-update-0.98.5-1.el7.x86_64 …データベースの更新(freshclam)
clamav-0.98.5-1.el7.x86_64 …clamavのコマンドプログラムやドキュメントなど
sendmail-milter-8.14.7-4.el7.x86_64 …メールスキャン用のメールサーバー側接続ソフト。依存関係で導入された。
以下設定ファイルのディフォルトから変わったところ。
データベースアップデート設定
/etc/cron.d/clamav-update は変更なし(3時間ごとの設定)。
/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 …#で無効化。
....
/etc/freshclam.conf
# Comment or remove the line below.
#Example …#で無効化。
....
# Path to the log file (make sure it has proper permissions)
# Default: disabled
UpdateLogFile /var/log/clamupdate/freshclam.log …ログをとることにしてログファイルを指定。
....
# Maximum size of the log file.
LogFileMaxSize 2M …最大ログサイズ指定。
....
# Use system logger (can work together with UpdateLogFile).
LogSyslog yes …syslogを使う。
....
# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
LogRotate yes …ログローテートする。
....
ためしに
~]# freshclam
をやってみてデータベースがアップデートされログがちゃんと記録されるのを確認し、OK。
clamavサーバー clamd.scanサービス設定
clamdを動かしておかなくてもclamav-milterでウィルススキャンは可能とのことですが、その起動に都度時間がかかるとのことですので、あらかじめclamdサーバーを動かしておくことにします。
最近のclamavがそうなったのか、あるいはEPELのがそうなのか、calmdにサービス名を設定してサービスごとに必要な条件で動かすことができるようです。
scanという名前のサービスがすでに設定されてますのでこれをそのまま使います。
/etc/clamd.d/scan.conf
# Comment or remove the line below.
#Example …#で無効化。
....
# Uncomment this option to enable logging.
LogFile /var/log/clamscan/clamd.scan …いちおう最初だけでもログをとる。ログの場所はディフォルトから少し変更。以下にログ関係設定。
....
# Maximum size of the log file.
LogFileMaxSize 2M
....
# Log time with each message.
LogTime yes
....
# Use system logger (can work together with LogFile).
# Default: no
LogSyslog yes
....
# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
LogRotate yes
....
# Path to a local socket file the daemon will listen on.
LocalSocket /var/run/clamd.scan/clamd.sock …接続用ソケット。
....
そしてログファイル用のフォルダ /var/log/clamscan をつくり、user:groupをroot:clamscanとし、グループに書込権限を与えておきます。
設定したら
~]# systemctl start clamd@scan.service
で起動してみて、
~]# systemctl status clamd@scan.service
で起動確認。OKなら自動起動設定。
~]# syatemctl enable clamd@scan.service
clamav-milter 設定
ひとまずclamav側を設定しておきます。
/etc/mail/clamav-milter.conf
# Comment or remove the line below.
#Example …#で無効化。
....
# Define the interface through which we communicate with sendmail
MilterSocket unix:/var/run/clamav-milter/clamav-milter.socket …メールサーバーとの接続用ソケット。
....
# Define the group ownership for the (unix) milter socket.
MilterSocketGroup clamilt
....
# Sets the permissions on the (unix) milter socket to the specified mode.
MilterSocketMode 660
....
# Default: unset (don't drop privileges)
User clamilt
....
# Initialize supplementary group access (clamav-milter must be started by root).
AllowSupplementaryGroups yes
....
# Define the clamd socket to connect to for scanning.
ClamdSocket unix:/var/run/clamd.scan/clamd.sock …clamdサーバーとの接続用ソケット。
....
# If this option is set to "Replace" (or "Yes"), an "X-Virus-Scanned" and an
# "X-Virus-Status" headers will be attached to each processed message, possibly
# replacing existing headers.
AddHeader Yes
....
# When AddHeader is in use, this option allows to arbitrary set the reported
hostname. ....
ReportHostname moonlight.iroribata.net …スキャン記録をメールヘッダーに付加。
....
# Uncomment this option to enable logging.
LogFile /var/log/clamscan/clamav-milter.log …いちおうログをとる。以下にログ関係設定。
....
# Maximum size of the log file.
LogFileMaxSize 2M
....
# Log time with each message.
LogTime yes
....
# Use system logger (can work together with LogFile).
LogSyslog yes
....
# Enable log rotation. Always enabled when LogFileMaxSize is enabled.
LogRotate yes
....
clamav-milterのMilterSocketGroupはclamiltですが、このグループにclamav-milterを使うユーザ(postfix)を追加しておきます。
あるいはMilterSocketMode 660を666に変えてもいいのかもしれない。
clamav-milterについても同様に起動テストし、自動起動を設定しておきます。
~]# systemctl start clamav-milter.service
~]# systemctl status clamav-milter.service
....
~]# syatemctl enable clamav-milter.service
~]# setsebool -P antivirus_can_scan_system 1
あとはメールサーバーを立ち上げてから接続して最終確認と調整をします。
バージョンアップで一時動かなくなる (2016.4.6 追記)
.... freshclam[9452]: Your ClamAV installation is OUTDATED!
.... freshclam[9452]: Local version: 0.99 Recommended version: 0.99.1
ClamAVのバージョンが古いといっていますがバージョンアップが遅いのはいつものことで、そのうちバージョンアップされるだろうと放ってありました。
今日アップデートをチェックしたらClamAvのアップデートがあったのでさっそく適用。
そのとたん、今度は以下のログが一分おきに出ています。
.... clamav-milter[7882]: No clamd server appears to be available
clamavサーバーが動かずこのままではメールの送受信ができません。少しあせり。
設定ファイルが変わったのかなと見直したり再起動してみましたがだめです。
ふと再起動時のログに
.... clamd[2799]: Can't verify database integrity
.... systemd: clamd@scan.service: main process exited, code=exited, status=1/FAILURE
とあったので、もしやと思い、
# freshclam
を実行するとずいぶん長い時間かかってデータベースを作り直していましたが、その後はちゃんと起動し、OK。
バージョンアップしたらすぐにfreshclamしたほうがいいという教訓でした。