LoginSignup
1
3

More than 5 years have passed since last update.

Moodle 3.1以降でのClamAV設定

Last updated at Posted at 2017-06-08

Moodleのウイルススキャン設定

Moodle3.1以降ではファイルアップロード時のウイルススキャン設定が多少変わっているため設定メモを残しておく。

設定について

前置き

シングルサーバ構成でCentOS 7環境にMoodle 3.2.3をインストールしたものとする。また、clamscanより高速なclamdscanを利用する。

設定方法

パッケージの導入

ClamAV本体と更新用およびsystemd用パッケージを導入

# yum install -y --enablerepo=epel clamav clamav-update clamav-scanner clamav-scanner-systemd

SELinux設定

SELinuxにルールを追加

# cd /usr/share/selinux/packages
# mkdir clamdscan
# cd clamdscan
# vi clamdscan.te
/usr/share/selinux/packages/clamdscan/clamdscan.te
module clamdscan 1.0;
require {
type httpd_t;
type httpd_tmp_t;
type clamscan_exec_t;
type clamscan_t;
type clamd_t;
class dir {read search getattr};
class file {read open getattr execute};
class sock_file write;
class unix_stream_socket connectto;
class fifo_file {getattr write};
class process sigchld;
}

#============= httpd_t ==============
allow httpd_t clamscan_exec_t:dir {read search getattr};
allow httpd_t clamscan_exec_t:file {read open getattr execute};
allow httpd_t clamscan_exec_t:sock_file write;
allow httpd_t clamscan_exec_t:unix_stream_socket connectto;

#============= clamscan_t ===========
allow clamscan_t httpd_t:fifo_file {getattr write};
allow clamscan_t httpd_t:process sigchld;
allow clamscan_t httpd_tmp_t:file {read getattr};

#============== clamd_t =============
allow clamd_t httpd_tmp_t:file {read getattr open}; 
# checkmodule -M -m -o clamdscan.mod clamdscan.te
# semodule_package -o clamdscan.pp -m clamdscan.mod
# semodule -i clamdscan.pp

# getsebool -a | grep virus
# setsebool -P antivirus_can_scan_system 1
# getsebool -a | grep virus

httpdの設定変更

Moodleでアップロードされた一時ファイルにclamdscanからアクセス可能なように、httpdの設定を一部変更する。

# mkdir -p /etc/systemd/system/httpd.service.d
# vi /etc/systemd/system/httpd.service.d/httpd.conf
/etc/systemd/system/httpd.service.d/httpd.conf
[Service]
PrivateTmp=false
# systemctl daemon-reload
# systemctl restart httpd.service

ClamAVの設定

ClamAVの更新用設定を行う

# vi /etc/freshclam.conf
元の値 変更後
Example #Example
#UpdateLogFile /var/log/freshclam.log UpdateLogFile /var/log/freshclam.log
#LogTime yes LogTime yes
#PidFile /var/run/freshclam.pid PidFile /var/run/freshclam.pid

ClamAVの更新ができるかチェック

# freshclam

自動更新が有効になるよう設定

# vi /etc/sysconfig/freshclam
元の値 変更後
#FRESHCLAM_DELAY=disabled-warn # REMOVE ME FRESHCLAM_DELAY=disabled-warn # REMOVE ME
# vi /etc/clamd.d/scan.conf
元の値 変更後
Example #Example
#LogFile /var/log/clamd.scan LogFile /var/log/clamd.scan
#LogTime yes LogTime yes
#PidFile /var/run/clamd.scan/clamd.pid PidFile /var/run/clamd.scan/clamd.pid
#LocalSocket /var/run/clamd.scan/clamd.sock LocalSocket /var/run/clamd.scan/clamd.sock
User clamscan #User clamscan
# systemctl start clamd@scan

設定が正しいかチェック。起動直後は問題なくても数分後に死ぬことがあるため、数回チェック。

# systemctl status clamd@scan

問題がなければ自動起動するよう設定

# systemctl enable clamd@scan

clamdscanが動作するように設定ファイルのリンクを作成

# ln -s /etc/clamd.d/scan.conf /etc/clamd.conf

httpdからclamdscanを呼び出すため /var/run/clamd.scan/ にアクセス出来るようにする。ディレクトリの権限変更だと再起動後に初期化されるためグループに追加する。

# usermod -aG clamscan apache

Moodle上での設定

  1. [サイト管理] > [プラグイン] > [アンチウイルスプラグイン] > [アンチウイルスプラグインを管理する] に移動する。
  2. 「ClamAVアンチウイルス」を有効にする。
  3. 「ClamAVアンチウイルス」の「設定」をクリックして以下のように設定
    • 実行方法 : コマンドライン
    • コマンドライン : /usr/bin/clamdscan
    • Unixドメインソケット : (null)
    • ClamAV失敗時 : ファイルをOKとして扱う

動作チェックは「ClamAV失敗時」に「ファイルをウイルスとして扱う」に設定して適当な場所でファイルアップロードを行う。正常に動作していればファイルがアップロードできる。

参考リンク: https://moodle.org/mod/forum/discuss.php?d=316066#p1277102

1
3
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
1
3