プロキシサーバーでウイルスチェックを行う。ここでは、Squid+SquidClamAV+CalmAntiVirusで構築したプロキシサーバーで、クライアントが当該プロキシサーバー経由でアクセスするページのウイルスチェックを行い、ウイルスを検出した場合はアクセスをブロックする。
※Squid、CalmAntiVirus、Apacheが構築済であること
[root@localhost ~]# yum -y install curl-devel ← SquidClamAVインストールに必要なcurl-develインストール |
[root@localhost ~]# wget http://nchc.dl.sourceforge.net/sourceforge/squidclamav/squidclamav-4.0.tar.gz ← SquidClamAVダウンロード |
※最新版のURLはダウンロードページで確認すること |
[root@localhost ~]# tar zxvf squidclamav-4.0.tar.gz ← SquidClamAV展開 |
[root@localhost ~]# cd squidclamav-4.0 ← SquidClamAV展開先ディレクトリへ移動 |
[root@localhost squidclamav-4.0]# ./configure && make && make install ← SquidClamAVインストール |
[root@localhost squidclamav-4.0]# cp squidclamav.conf.dist /etc/squidclamav.conf ← SquidClamAV設定ファイルを所定のディレクトリへコピー |
[root@localhost squidclamav-4.0]# cp clwarn.cgi /var/www/cgi-bin/ ← ウイルス検出時のリダイレクト先スクリプトを所定のディレクトリへコピー |
[root@localhost squidclamav-4.0]# cd ← SquidClamAV展開先ディレクトリを抜ける |
[root@localhost ~]# rm -rf squidclamav-4.0 ← SquidClamAV展開先ディレクトリを削除 |
[root@localhost ~]# rm -f squidclamav-4.0.tar.gz ← ダウンロードしたファイルを削除 |
[root@localhost ~]# vi /etc/squid/squid.conf ← Squid設定ファイル編集 |
# TAG: url_rewrite_program # Specify the location of the executable for the URL rewriter. # Since they can perform almost any function there isn't one included. # # For each requested URL rewriter will receive on line with the format # # URL client_ip "/" fqdn user method urlgroup # # And the rewriter may return a rewritten URL. The other components of # the request line does not need to be returned (ignored if they are). # # The rewriter can also indicate that a client-side redirect should # be performed to the new URL. This is done by prefixing the returned # URL with "301:" (moved permanently) or 302: (moved temporarily). # # It can also return a "urlgroup" that can subsequently be matched # in cache_peer_access and similar ACL driven rules. An urlgroup is # returned by prefixing the returned url with "!urlgroup!" # # By default, a URL rewriter is not used. # #Default: # none url_rewrite_program /usr/local/bin/squidclamav ← 追加 # TAG: url_rewrite_children # The number of redirector processes to spawn. If you start # too few Squid will have to wait for them to process a backlog of # URLs, slowing it down. If you start too many they will use RAM # and other system resources. # #Default: # url_rewrite_children 5 url_rewrite_children 15 ← 追加 # TAG: url_rewrite_access # If defined, this access list specifies which requests are # sent to the redirector processes. By default all requests # are sent. # #Default: # none url_rewrite_access deny localhost ← 追加 http_access deny to_localhost ← 行頭の#を削除してコメント解除 |
[root@localhost ~]# vi /etc/clamd.conf ← clamd設定ファイル編集 |
# Path to a local socket file the daemon will listen on. # Default: disabled (must be specified by a user) LocalSocket /var/run/clamav/clamd.sock ← clamdソケット名変更 # TCP port address. # Default: disabled TCPSocket 3310 ↓ #TCPSocket 3310 ← 行頭に#を追加してコメントアウト(clamdのTCP通信を無効化) |
[root@localhost ~]# /etc/rc.d/init.d/clamd restart ← clamd再起動 Stopping Clam AntiVirus Daemon: [ OK ] Starting Clam AntiVirus Daemon: [ OK ] |
[root@localhost ~]# vi /etc/squidclamav.conf ← SquidClamAVファイル編集 |
proxy http://127.0.0.1:3128/ logfile /var/log/squidclamav.log redirect http://localhost/cgi-bin/clwarn.cgi debug 0 force 1 clamd_local /var/run/clamav/clamd.sock timeout 60 abort ^.*\.gz$ abort ^.*\.bz2$ abort ^.*\.pdf$ abort ^.*\.js$ abort ^.*\.html$ abort ^.*\.css$ abort ^.*\.xml$ abort ^.*\.xsl$ abort ^.*\.js$ abort ^.*\.ico$ aborti ^.*\.gif$ aborti ^.*\.png$ aborti ^.*\.jpg$ aborti ^.*\.swf$ content ^.*application\/.*$ |
[root@localhost ~]# touch /var/log/squidclamav.log ← SquidClamAVログファイル作成 |
[root@localhost ~]# chown squid:squid /var/log/squidclamav.log ← SquidClamAVログファイル所有者変更 |
[root@localhost ~]# vi /etc/logrotate.d/squidclamav ← SquidClamAVログローテーション設定ファイル作成 |
/var/log/squidclamav.log { missingok notifempty sharedscripts postrotate killall -HUP squidclamav > /dev/null 2>/dev/null || true endscript } |
[root@localhost ~]# /etc/rc.d/init.d/squid restart ← Squid再起動 |
Stopping squid: [ OK ] Starting squid: . [ OK ] |
テスト用ウイルスへアクセスして以下のようなページが表示されてウイルスをダウンロードできないことを確認。
SquidClamAv 3.5: Virus detection
The requested URL http://www.eicar.org/download/eicar_com.zip
contains the virus: Eicar-Test-Signature
This URL can not be downloaded.
Origin: 192.168.1.10 / -
Powered by SquidClamAv 3.5.
[root@localhost ~]# vi /var/www/cgi-bin/clwarn.cgi ← clwarn.cgi編集 |
my $TITLE_VIRUS = "SquidClamAv $VERSION: Virus detection"; ↓ my $TITLE_VIRUS = "SquidClamAv $VERSION: ウイルス検出"; ← 変更 print $cgi->header(); ↓ print $cgi->header(-expires=>'+1m',-charset=>'UTF-8'); ← 変更 print $cgi->start_html(-title => $TITLE_VIRUS); ↓ print $cgi->start_html(-title => $TITLE_VIRUS,-lang =>'ja'); ← 変更 The requested URL $url <br> contains the virus: $virus ↓ アクセスしたURL $url <br> ← 変更 検出ウイルス: $virus ← 変更 This URL can not be downloaded. ↓ このURLをダウンロードできません。 ← 変更 Origin: $source / $user ↓ アクセス元: $source / $user ← 変更 |
テスト用ウイルスへアクセスして以下のようなページが表示されてウイルスをダウンロードできないことを確認。
SquidClamAv 3.5: ウイルス検出
アクセスしたURL http://www.eicar.org/download/eicar_com.zip
検出ウイルス: Eicar-Test-Signature
このURLをダウンロードできません。
アクセス元: 192.168.1.10 / -
Powered by SquidClamAv 3.5.