LoginSignup
12
14

オープンソースのアンチウイルスソフトウェア、ClamAVをCentOS 7にインストールする

Last updated at Posted at 2019-09-05

TL;DR

  • CentOSにClamAVをインストールしたい
  • EPELからインストールするのが簡単
  • clamdおよびfreshclamの設定をする
  • clamdscanを定期的に実行できるようにする

ClamAV

ClamAVは、オープンソースのアンチウイルスソフトウェアです。

ClamAV

image.png

スタンダードだよ(メールのスキャンで)、みたないことを言っています。

ClamAV® is the open source standard for mail gateway scanning software.

ClamAVの機能は、こちら。

About

  • Command-line scanner
  • Milter interface for sendmail
  • Advanced database updater with support for scripted updates and digital signatures
  • Virus database updated multiple times per day
  • Built-in support for all standard mail file formats
  • Built-in support for various archive formats, including Zip, RAR, Dmg, Tar, Gzip, Bzip2, OLE2, Cabinet, CHM, BinHex, SIS and others
  • Built-in support for ELF executables and Portable Executable files packed with UPX, FSG, Petite, NsPack, wwpack32, MEW, Upack and obfuscated with SUE, Y0da Cryptor and others
  • Built-in support for popular document formats including MS Office and MacOffice files, HTML, Flash, RTF and PDF

コマンドラインのスキャナーがあり、ウイルス定義データベースのアップデートが可能だったり、多くのファイルフォーマットをサポートしている、という感じです。

環境

インストール先のCentOSのバージョンは、こちらです。

/etc/redhat-release

CentOS Linux release 7.6.1810 (Core)

今回利用するClamAVのバージョンは、0.101.4です。

インストール

CentOSへのインストール手順はあるのですが、ソースコードからのコンパイルからになります。

Installation on Redhat and CentOS Linux Distributions

EPELを使用した導入方法も書かれているので、今回はこちらを使いましょう。

Fedora & EPEL

EPELを有効にする

今回のClamAVは

$ sudo yum install epel-release

必要なパッケージをインストールする

以下のコマンドで、必要なパッケージをインストールします。

$ sudo yum install clamav clamav-update clamd

各パッケージに含まれている役割は以下に書かれています。

Usage

clamd

ファイルに対するウイルススキャンの機能を提供するDaemonで、他のツールと連動して動作します。

clamdscan

スキャンクライアントで、clamdと連動して動作します。

on-access scanning

リアルタイムプロテクション機能をclamdに提供します(オンアクセススキャン)。

こちらは、参考程度に。

freshclam

ClamAVのウイルス定義データベースのダウンロード、更新を行います。

freshclam

freshclamの設定とウイルス定義データベースの初回作成

freshclamを使用して、clamdが使用するウイルス定義データベースの初回作成を行います。これをやらないと、clamdが起動できません。

freshclamの設定ファイル、/etc/freshclam.confを修正します。

ウイルス定義に更新があった場合の通知先となる、clamdの設定ファイルパスのコメントアウトを解除し、以下のように設定します。

NotifyClamd /etc/clamd.d/scan.conf

インターネットアクセスにプロキシサーバーが必要な場合は、以下を設定してください。

#HTTPProxyServer myproxy.com
#HTTPProxyPort 1234

以下のコマンドを実行すると、ウイルス定義ファイルをダウンロードしてきて、データベースを作成します。

$ sudo freshclam 

以降は、/etc/cron.d/clamav-updateによりcronで自動アップデートされます。

## user 'clamupdate' as soon as possible
0  */3 * * * root /usr/share/clamav/freshclam-sleep

clamdの設定を行う

設定ファイル/etc/clamd.d/scan.confを修正します。

このファイルにExapmleと書かれたままだとちゃんと動作しないので、

# Comment or remove the line below.
Example

これをコメントアウトします。

# Comment or remove the line below.
#Example

また、TCPソケットもしくはUNIXドメインソケットを使ってサーバーを起動する必要があるので、今回はUNIXドメインソケットを使用します。

# 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

また、実行ユーザーはrootにしておきます。

User root

/proc/sysはスキャン除外設定にしておくと良いでしょう(コメントアウトを解除すればOKです)。

ExcludePath ^/proc/
ExcludePath ^/sys/

systemdclamd@scanを有効化して、clamd@scanを起動。

$ sudo systemctl enable clamd@scan
$ sudo systemctl start clamd@scan

SELinuxが有効な場合は、antivirus_can_scan_systemonにしておきます。

$ sudo setsebool -P antivirus_can_scan_system on

参考:オンアクセススキャンの設定

ClamAVでは、オンアクセススキャンを行うこともできます。

以下のドキュメントに沿って、ScanOnAccessOnAccessIncludePathOnAccessPreventionを設定します。

On-Access Scanning

clamdだけでは、スキャンは行われません。

スキャンを行う、clamdscanの利用が必要です。
clamscanというコマンドで、clamdなしで実行もできますが、こちらは参考程度に

確認

スキャンは、clamdscanを使用して行います。

テスト用のウイルス入りファイルをダウンロードして、確認してみます。

$ cd /tmp

$ wget https://secure.eicar.org/eicar.com
$ wget https://secure.eicar.org/eicar.com.txt
$ wget https://secure.eicar.org/eicar_com.zip
$ wget https://secure.eicar.org/eicarcom2.zip

以下のように、-cで設定ファイルを指定し、/で全ディレクトリをスキャンしてみましょう。

$ sudo clamdscan -c /etc/clamd.d/scan.conf /

スキャン結果の中に、以下のような出力が含まれているはずです。

/tmp/eicar_com.zip: Eicar-Test-Signature FOUND
/tmp/eicar.com.txt: Eicar-Test-Signature FOUND
/tmp/eicar.com: Eicar-Test-Signature FOUND
/tmp/eicarcom2.zip: Eicar-Test-Signature FOUND

なお、実行にはけっこうリソースを使い、CPUひとつとメモリ1Gくらいを使ったりしてました…。

これを削除する場合は、--removeを付与してclamdscanを実行します。

$ sudo clamdscan -c /etc/clamd.d/scan.conf --remove /

検出されたファイルは、削除されます。

/tmp/eicar_com.zip: Eicar-Test-Signature FOUND
/tmp/eicar_com.zip: Removed.
/tmp/eicar.com.txt: Eicar-Test-Signature FOUND
/tmp/eicar.com.txt: Removed.
/tmp/eicar.com: Eicar-Test-Signature FOUND
/tmp/eicar.com: Removed.
/tmp/eicarcom2.zip: Eicar-Test-Signature FOUND
/tmp/eicarcom2.zip: Removed.

どこか別のディレクトリに退避する場合は、--moveと退避先のディレクトリを指定してclamdscanを実行します。

$ sudo clamdscan -c /etc/clamd.d/scan.conf --move [検出したウイルスの退避先ディレクトリ] /

例えば、以下のようなディレクトリを作成して退避するようにする場合は…

$ mkdir /tmp/clamdscan-quarantinedir

設定ファイル/etc/clamd.d/scan.confを修正して、退避先をスキャン対象外にして

ExcludePath ^/tmp/clamdscan-quarantinedir/

実行。

$ sudo clamdscan -c /etc/clamd.d/scan.conf --move /tmp/clamdscan-quarantinedir /

今度は、退避が行われます。

/tmp/eicarcom2.zip: Eicar-Test-Signature FOUND
/tmp/eicarcom2.zip: moved to '/tmp/clamdscan-quarantinedir/eicarcom2.zip'
/tmp/eicar.com: Eicar-Test-Signature FOUND
/tmp/eicar.com: moved to '/tmp/clamdscan-quarantinedir/eicar.com'
/tmp/eicar_com.zip: Eicar-Test-Signature FOUND
/tmp/eicar_com.zip: moved to '/tmp/clamdscan-quarantinedir/eicar_com.zip'
/tmp/eicar.com.txt: Eicar-Test-Signature FOUND
/tmp/eicar.com.txt: moved to '/tmp/clamdscan-quarantinedir/eicar.com.txt'

定期的にスキャンする

定期的にスキャンを行うには、clamdscancronで定期実行するように仕込めばOKです。

0 3 * * * clamdscan -c /etc/clamd.d/scan.conf --remove /

検出したファイルを退避する場合は、--moveと組み合わせるとよいでしょう。

clamdfreshclamのログ設定

clamdにもfreshclamにも、ログ出力設定があります。デフォルトではsyslogを使うように構成されていますが、必要に応じて設定しましょう。

clamdの場合はこのあたりを

LogFile
LogFileMaxSize
LogTime
LogRotate

freshclamの場合は、このあたりを設定します。

UpdateLogFile
LogFileMaxSize
LogTime
LogRotate
12
14
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
14