2022年8月、ホームページを全面リニューアルしました! 情報を分かりやすくお伝えできるサイト作りを目指してまいります。

SquidClamAV日本語サイト

■ イントロダクション:

SquidClamAV は、Squid のための専用ClamAV antivirusリダイレクタです。SquidClamAVは、regex正規表現ライブラリを使ったリダイレクタと、ClamAVの力を借りウィルスをスキャニングすることによって発見したら指定のURLへリダイレクトできます。
このSquidClamAVは、インストールするのが簡単であり、重いSquidアクセスがあっても軽量に働いています。APG(AntiVirus Proxy Gateway、以降APGと言う)は、近年注目されていますが、単独動作のものとSquidからキックされ連携しながら動くものの二種類が有ります。単独動作のAPGは、個別のポートを使いポートフォワード的な動作のため、実際にブラウザからブラウジングするときに多少ストレスを感じますが、Squidからキックし連携しながら動作するSquidClamAV のようなAPGは、あたかもSquidの一プロセスで動くような感じとなり、ほとんどストレス無くブラウジングが出来るのが特徴です。その代わり、 SquidClamAVは、Squid側のsquid.confの設定が少しややこしくなります。しかし、体感的には、すごく軽いです。このSquidClamAVは、 Squirm 正規表現ライブラリを使ったパターンマッチングによるリダイレクタの改変されたモジュールです。しかし、私はこのように区分しています。
Squirm : URLマッチングリダイレクタ
SquidClamAV : ウィルススキャンリダイレクタ
早い話が、私の場合、SquimはSquid用コンテンツフィルタ、SquidClamAVはSquid用ウィルスフィルタとして使っています。

■ SquidClamAVの著作権および経緯:

SquidClamAVは、当初から、作者クリス・フット氏によるSquid を維持するための素晴らしいSquirm Redirectorの改変されたバージョンであったが、しかし、このプロジェクトが続くときには版権を取られました。
Copyright (C) 1998 Chris Foote & Wayne Piekarski

Squirmバージョンが使用したオリジナルはsquirm-1.0betaBでした。その他の部品は、ex1.cプログラムからのカットアンドペーストであり、ClamAVとの分配を考えて版権を取られています。
Copyright (C) 2002 – 2004 Tomasz Kojm

他のすべてのコードの著作権:
All other code: Copyright (C) 2005-2006 Gilles Darold – Groupe SAMSE

このプログラムはフリーソフトウェアです。
Free SoftwareFoundation によって発行されるように、あなたは、GNU一般共有使用許諾(GNU GPL)に関する諸条件でそれを再配付することができ、または、それを変更することができます。 Licenseのバージョン2か(あなたの選択における)後のバージョンのどちらか。

このプログラムは、それが役に立つという望みがあります、また、このプログラムは保障なしで広げられます。
特定の目的のための市販性または適切な黙示的保証がなくても。 その他の詳細に関してGNU一般共有使用許諾を見てください。あなたはこのプログラムに伴うGNU一般共有使用許諾のコピーを受け取るべきです; そうでなければ、 Free SoftwareFoundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. に書いてください。完全な著作権情報のためのこのディレクトリのファイルCOPYINGを見てください。

■ この日本語サイトの目的:

素晴らしい、FreeSoftware(GPL)で有るため、日本での普及を希望します。

■ オフィシャルサイト & ダウンロード先

http://squidclamav.darold.net/ ( オフィシャルサイト ここで最新のソースが紹介されています)


1.インストール

 1)ソースのゲット
 2)ソースの展開
 3)ビルド

2.設定

 1)ClamAVの設定
 2)Squidの設定
 3)SquidClamAVの設定
 4)logファイルの作成

3.起動

 1)Squidの起動
 2)動作確認

4.実際に使ってみる

 1)実際にテストウィルスで検証する
 2)ウィルス検出時のlog出力

5.logローティション


1.インストール

●セットアップ環境は、以下の条件でインストールを説明します。
マシン : Celeron 700MHz
OS : Debian GNU/Linux 4.0 etch
Kernelバージョン : 2.6.18
squid バージョン :
||/ Name Version Description
+++-==============-==============
ii squid 2.6.5-6 Internet Object Cache (WWW proxy cache)

●SquidClamAVのインストールの前に、DebianパッケージのClamAVをインストールする。尚、ClamAVをソースからインストールしたい場合は、 ここ のしょっぱなを参照してください。
michi:~# apt-get update
Get:1 http://ftp.dti.ad.jp stable Release.gpg [378B]
Get:2 http://ftp.dti.ad.jp stable Release [58.2kB]
Get:3 http://www.ring.gr.jp stable Release.gpg [378B]
Ign http://ftp.dti.ad.jp stable/main Packages/DiffIndex
Hit http://www.ring.gr.jp stable Release
Ign http://ftp.dti.ad.jp stable/main Sources/DiffIndex
Get:4 http://ftp.dti.ad.jp stable/main Packages [5629kB]
Ign http://www.ring.gr.jp stable/main Packages/DiffIndex
Ign http://www.ring.gr.jp stable/main Sources/DiffIndex
Hit http://www.ring.gr.jp stable/main Packages
Hit http://www.ring.gr.jp stable/main Sources
Get:5 http://security.debian.org stable/updates Release.gpg [189B]
Get:6 http://security.debian.org stable/updates Release [22.5kB]
Ign http://security.debian.org stable/updates Release
Ign http://security.debian.org stable/updates/main Packages/DiffIndex
Get:7 http://security.debian.org stable/updates/main Packages [146kB]
Get:8 http://ftp.dti.ad.jp stable/main Sources [1653kB]
Fetched 7509kB in 11s (659kB/s)
Reading package lists… Done
W: GPG error: http://security.debian.org stable/updates Release:
The following signatures were invalid: BADSIG A70DAF536070D3A1
Debian Archive Automatic Signing Key (4.0/etch) <ftpmaster@debian.org>
W: You may want to run apt-get update to correct these problems

michi:~# apt-get install clamav clamav-daemon libclamav-dev
Reading package lists… Done
Building dependency tree… Done
The following extra packages will be installed:
clamav-base clamav-freshclam comerr-dev libbz2-dev libclamav2 libcurl3-dev
libcurl3-openssl-dev libgmp3-dev libgmp3c2 libgmpxx4 libidn11-dev libkadm55
libkrb5-dev libssl-dev pkg-config zlib1g-dev
Suggested packages:
unrar lha clamav-docs daemon doc-base libcurl3-dbg libgmp3-doc libmpfr-dev
krb5-doc libgnome-dev
Recommended packages:
arj unzoo
The following NEW packages will be installed:
clamav clamav-base clamav-daemon clamav-freshclam comerr-dev libbz2-dev
libclamav-dev libclamav2 libcurl3-dev libcurl3-openssl-dev libgmp3-dev
libgmp3c2 libgmpxx4 libidn11-dev libkadm55 libkrb5-dev libssl-dev pkg-config
zlib1g-dev
0 upgraded, 19 newly installed, 0 to remove and 12 not upgraded.
Need to get 17.2MB of archives.
After unpacking 28.3MB of additional disk space will be used.
Do you want to continue [Y/n]? Y
WARNING: The following packages cannot be authenticated!
libclamav2 clamav-base clamav-freshclam clamav clamav-daemon libkadm55
libkrb5-dev libcurl3-openssl-dev libcurl3-dev libclamav-dev
Install these packages without verification [y/N]? y
Get:1 http://www.ring.gr.jp stable/main libgmp3c2 2:4.2.1+dfsg-4 [430kB]
Get:2 http://security.debian.org stable/updates/main libclamav2 0.90.1-3etch4 [366k]
Get:3 http://www.ring.gr.jp stable/main libbz2-dev 1.0.3-6 [31.9kB]
Get:4 http://www.ring.gr.jp stable/main zlib1g-dev 1:1.2.3-13 [406kB]
Get:5 http://www.ring.gr.jp stable/main libssl-dev 0.9.8c-4 [2087kB]
Get:6 http://security.debian.org stable/updates/main clamav-base 0.90.1-3etch4 [201B]
Get:7 http://www.ring.gr.jp stable/main pkg-config 0.21-1 [67.5kB]
Get:8 http://www.ring.gr.jp stable/main libidn11-dev 0.6.5-1 [544kB]
Get:9 http://www.ring.gr.jp stable/main comerr-dev 2.1-1.39+1.40-WIP-2006.11.14+dfs-2 [46.3kB]
Get:10 http://security.debian.org stable/updates/main clamav-freshclam 0.90.1-3etch[9300kB]
Get:11 http://www.ring.gr.jp stable/main libgmpxx4 2:4.2.1+dfsg-4 [217kB]
Get:12 http://www.ring.gr.jp stable/main libgmp3-dev 2:4.2.1+dfsg-4 [511kB]
Get:13 http://security.debian.org stable/updates/main clamav 0.90.1-3etch4 [854kB]
Get:14 http://security.debian.org stable/updates/main clamav-daemon 0.90.1-3etch4 [75kB]
Get:15 http://security.debian.org stable/updates/main libkadm55 1.4.4-7etch2 [174kB]
Get:16 http://security.debian.org stable/updates/main libkrb5-dev 1.4.4-7etch2 [680kB]
Get:17 http://security.debian.org stable/updates/main libcurl3-openssl-dev 7.15.5-1etch1 [765kB]
Get:18 http://security.debian.org stable/updates/main libcurl3-dev 7.15.5-1etch1 [22.2kB]
Get:19 http://security.debian.org stable/updates/main libclamav-dev 0.90.1-3etch4 [368kB]
Fetched 17.2MB in 35s (486kB/s)
Preconfiguring packages …
Selecting previously deselected package libgmp3c2.
(Reading database … 30301 files and directories currently installed.)
Unpacking libgmp3c2 (from …/libgmp3c2_2%3a4.2.1+dfsg-4_i386.deb) …
Selecting previously deselected package libclamav2.
Unpacking libclamav2 (from …/libclamav2_0.90.1-3etch4_i386.deb) …
Selecting previously deselected package clamav-base.
Unpacking clamav-base (from …/clamav-base_0.90.1-3etch4_all.deb) …
Selecting previously deselected package clamav-freshclam.
Unpacking clamav-freshclam (from …/clamav-freshclam_0.90.1-3etch4_i386.deb) …
Selecting previously deselected package clamav.
Unpacking clamav (from …/clamav_0.90.1-3etch4_i386.deb) …
Selecting previously deselected package clamav-daemon.
Unpacking clamav-daemon (from …/clamav-daemon_0.90.1-3etch4_i386.deb) …
Selecting previously deselected package libbz2-dev.
Unpacking libbz2-dev (from …/libbz2-dev_1.0.3-6_i386.deb) …
Selecting previously deselected package zlib1g-dev.
Unpacking zlib1g-dev (from …/zlib1g-dev_1%3a1.2.3-13_i386.deb) …
Selecting previously deselected package libssl-dev.
Unpacking libssl-dev (from …/libssl-dev_0.9.8c-4_i386.deb) …
Selecting previously deselected package pkg-config.
Unpacking pkg-config (from …/pkg-config_0.21-1_i386.deb) …
Selecting previously deselected package libidn11-dev.
Unpacking libidn11-dev (from …/libidn11-dev_0.6.5-1_i386.deb) …
Selecting previously deselected package libkadm55.
Unpacking libkadm55 (from …/libkadm55_1.4.4-7etch2_i386.deb) …
Selecting previously deselected package comerr-dev.
Unpacking comerr-dev (from …/comerr-dev_2.1-1.39+1.40-WIP-2006.11.14+dfsg-2_i386.deb) …
Selecting previously deselected package libkrb5-dev.
Unpacking libkrb5-dev (from …/libkrb5-dev_1.4.4-7etch2_i386.deb) …
Selecting previously deselected package libcurl3-openssl-dev.
Unpacking libcurl3-openssl-dev (from …/libcurl3-openssl-dev_7.15.5-1etch1_i386.deb) …
Selecting previously deselected package libcurl3-dev.
Unpacking libcurl3-dev (from …/libcurl3-dev_7.15.5-1etch1_all.deb) …
Selecting previously deselected package libgmpxx4.
Unpacking libgmpxx4 (from …/libgmpxx4_2%3a4.2.1+dfsg-4_i386.deb) …
Selecting previously deselected package libgmp3-dev.
Unpacking libgmp3-dev (from …/libgmp3-dev_2%3a4.2.1+dfsg-4_i386.deb) …
Selecting previously deselected package libclamav-dev.
Unpacking libclamav-dev (from …/libclamav-dev_0.90.1-3etch4_i386.deb) …
Setting up libgmp3c2 (4.2.1+dfsg-4) …

Setting up libclamav2 (0.90.1-3etch4) …

Setting up clamav-base (0.90.1-3etch4) …
Adding system user `clamav’ (UID 108) …
Adding new group `clamav’ (GID 107) …
Adding new user `clamav’ (UID 108) with group `clamav’ …
Not creating home directory `/var/lib/clamav’.
/etc/mail/aliases: 15 aliases, longest 16 bytes, 176 bytes total

Setting up clamav-freshclam (0.90.1-3etch4) …
Starting ClamAV virus database updater: freshclam.

Setting up clamav (0.90.1-3etch4) …
Setting up clamav-daemon (0.90.1-3etch4) …
Starting ClamAV daemon: clamd Running as user clamav (UID 108, GID 107).

Setting up libbz2-dev (1.0.3-6) …

Setting up zlib1g-dev (1.2.3-13) …
Setting up libssl-dev (0.9.8c-4) …
Setting up pkg-config (0.21-1) …
Setting up libidn11-dev (0.6.5-1) …

Setting up libkadm55 (1.4.4-7etch2) …

Setting up comerr-dev (2.1-1.39+1.40-WIP-2006.11.14+dfsg-2) …

Setting up libkrb5-dev (1.4.4-7etch2) …
Setting up libcurl3-openssl-dev (7.15.5-1etch1) …

Setting up libcurl3-dev (7.15.5-1etch1) …
Setting up libgmpxx4 (4.2.1+dfsg-4) …

Setting up libgmp3-dev (4.2.1+dfsg-4) …
Setting up libclamav-dev (0.90.1-3etch4) …

●動作確認
動いてるかどうかの、clamavのプロセス確認。
michi:~# ps -ef
省略
clamav 23947 1 6 16:42 ? 00:00:06 /usr/bin/freshclam -d –quiet
clamav 24202 1 80 16:42 ? 00:01:26 /usr/sbin/clamd
省略

●freshclam(clamavアップデータ)の起動確認。
michi:~# tail /var/log/clamav/freshclam.log
————————————–
————————————–
freshclam daemon 0.90.1 (OS: linux-gnu, ARCH: i386, CPU: i486)
ClamAV update process started at Sun Aug 19 16:49:38 2007
WARNING: Your ClamAV installation is OUTDATED!
WARNING: Local version: 0.90.1 Recommended version: 0.91.1
DON’T PANIC! Read http://www.clamav.net/support/faq
main.inc is up to date (version: 44, sigs: 133163, f-level: 20, builder: sven)
daily.cvd is up to date (version: 3992, sigs: 14556, f-level: 20, builder: ccordes)
————————————-
これで、ClamAVの準備は完了。

 1)ソースのゲット
michi:~# cd /usr/local/src/

squidclamavの 最新のダウンロードサイト 。2007年8月現在では、 squidclamav-3.0.tar.gz が最新であった(2010年 12月 現在、最新バージョンが有るようです)。
michi:/usr/local/src# wget http://www.kozupon.com/download/squidclamav/squidclamav-3.0.tar.gz
–16:55:12– http://www.samse.fr/GPL/squidclamav/squidclamav-3.0.tar.gz
=> `squidclamav-3.0.tar.gz’
Resolving www.samse.fr… 195.101.77.166
Connecting to www.samse.fr|195.101.77.166|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 128,954 (126K) [application/x-gzip]

100%[====================================================>] 128,954 81.64K/s

16:55:15 (81.55 KB/s) – `squidclamav-3.0.tar.gz’ saved [128954/128954]

 2)ソースの展開
michi:/usr/local/src/squidclamav# tar zxvf squidclamav-3.0.tar.gz
michi:/usr/local/src# cd squidclamav

 3)ビルド
michi:/usr/local/src/squidclamav# ./configure

checking for a BSD-compatible install… /usr/bin/install -c
checking whether build environment is sane… yes
checking for gawk… no
checking for mawk… mawk
checking whether make sets $(MAKE)… yes
checking for gcc… gcc
checking for C compiler default output file name… a.out
checking whether the C compiler works… yes
checking whether we are cross compiling… no
checking for suffix of executables…
checking for suffix of object files… o
checking whether we are using the GNU C compiler… yes
checking whether gcc accepts -g… yes
checking for gcc option to accept ANSI C… none needed
checking for style of include used by make… GNU
checking dependency style of gcc… gcc3
checking for a BSD-compatible install… /usr/bin/install -c
checking for main in -lcurl… yes
checking how to run the C preprocessor… gcc -E
checking for egrep… grep -E
checking for ANSI C header files… yes
checking for sys/types.h… yes
checking for sys/stat.h… yes
checking for stdlib.h… yes
checking for string.h… yes
checking for memory.h… yes
checking for strings.h… yes
checking for inttypes.h… yes
checking for stdint.h… yes
checking for unistd.h… yes
checking arpa/inet.h usability… yes
checking arpa/inet.h presence… yes
checking for arpa/inet.h… yes
checking fcntl.h usability… yes
checking fcntl.h presence… yes
checking for fcntl.h… yes
checking netdb.h usability… yes
checking netdb.h presence… yes
checking for netdb.h… yes
checking netinet/in.h usability… yes
checking netinet/in.h presence… yes
checking for netinet/in.h… yes
checking for stdlib.h… (cached) yes
checking for string.h… (cached) yes
checking sys/socket.h usability… yes
checking sys/socket.h presence… yes
checking for sys/socket.h… yes
checking sys/timeb.h usability… yes
checking sys/timeb.h presence… yes
checking for sys/timeb.h… yes
checking for unistd.h… (cached) yes
checking for size_t… yes
checking for stdlib.h… (cached) yes
checking for GNU libc compatible malloc… yes
checking for function prototypes… yes
checking whether setvbuf arguments are reversed… no
checking return type of signal handlers… void
checking for ftime… yes
checking for gethostbyname… yes
checking for memset… yes
checking for regcomp… yes
checking for socket… yes
checking for strdup… yes
checking for strspn… yes
checking for strstr… yes
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands

michi:/usr/local/src/squidclamav# make clean
michi:/usr/local/src/squidclamav# make

make all-am
make[1]: Entering directory `/usr/local/src/squidclamav’
if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT config.o -MD -MP -MF “.deps/config.Tpo”
-c -o config.o config.c; \
then mv -f “.deps/config.Tpo” “.deps/config.Po”; else rm -f “.deps/config.Tpo”; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT lists.o -MD -MP -MF “.deps/lists.Tpo” -c -o lists.o lists.c; \
then mv -f “.deps/lists.Tpo” “.deps/lists.Po”; else rm -f “.deps/lists.Tpo”; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT log.o -MD -MP -MF “.deps/log.Tpo” -c -o log.o log.c; \
then mv -f “.deps/log.Tpo” “.deps/log.Po”; else rm -f “.deps/log.Tpo”; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT main.o -MD -MP -MF “.deps/main.Tpo” -c -o main.o main.c; \
then mv -f “.deps/main.Tpo” “.deps/main.Po”; else rm -f “.deps/main.Tpo”; exit 1; fi
if gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -MT squidclamav.o -MD -MP -MF “.deps/squidclamav.Tpo” -c -o squidclamav.o squidclamav.c; \
then mv -f “.deps/squidclamav.Tpo” “.deps/squidclamav.Po”; else rm -f “.deps/squidclamav.Tpo”; exit 1; fi
gcc -g -O2 -o squidclamav config.o lists.o log.o main.o squidclamav.o -lcurl
make[1]: Leaving directory `/usr/local/src/squidclamav’

michi:/usr/local/src/squidclamav# make install
make[1]: Entering directory `/usr/local/src/squidclamav’
test -z “/usr/local/bin” || mkdir -p — “/usr/local/bin”
/usr/bin/install -c ‘squidclamav’ ‘/usr/local/bin/squidclamav’
make[1]: Nothing to be done for `install-data-am’.
make[1]: Leaving directory `/usr/local/src/squidclamav


2.設定

 1)ClamAVの設定

michi:/usr/local/src/squidclamav# more /etc/clamav/clamd.conf
LogFile /var/log/clamav/clamav.log

LogFileMaxSize 0

LogTime yes

LogSyslog yes

PidFile /var/run/clamav/clamd.pid

TemporaryDirectory /var/tmp

DatabaseDirectory /var/lib/clamav

LocalSocket /var/run/clamav/clamd.ctl

FixStaleSocket yes

TCPSocket 3310

TCPAddr 127.0.0.1

MaxConnectionQueueLength 30

MaxThreads 50

ReadTimeout 300

User clamav

AllowSupplementaryGroups yes

ScanPE yes

ScanELF yes

DetectBrokenExecutables yes
ScanOLE2 yes

ScanMail yes

ScanArchive yes

ArchiveMaxCompressionRatio 300

ArchiveBlockEncrypted no

ArchiveBlockMax no

特に青の濃い文字のTCP Socketの項目をちゃんと書いておいてください。さらに、clamdを実行したときにSocketのパスにちゃんとTCP Socketが出来ていることを確認してください。

 2)squidの設定
michi:/usr/local/src/squidclamav# vi /etc/squid/squid.conf
visible_hostname michi.hogehoge.com
# エラー・メッセージなどで特別なホスト名を指定したい場合は、これを定義する。デフォルトでは、squidのソース中のgethostname()の返り値が使用される。クラスタに多数のキャッシュを持っており、IPフォワードに関するエラーを得るならば、このセッティングを備えた個々の名前を定義しなければならない。

http_port 3128
# squidがHTTPクライアント・リクエストを受け取るソケット・アドレス。この場合は、Port 3128。

cache_mem 16MB
# squidのキャッシュメモリに16Mバイトのメモリを割り当てる。

cache_dir /var/spool/squid 200 16 256
# キャッシュエリアの場所とその最大サイズを定義。通常はデフォルトのままで良い。この場合は、/var/spool/squidへキャッシュサイズ200MB領域を確保し、「ディレクトリー」の下に作り出される最初のレベルのサブディレクトリーの数を16個(デフォルトは16)、第1レベルディレクトリの下に作られる第2レベルのサブディレクトリーの数を256個(デフォルトは256)作ることが出来る。尚、このディレクトリのアクセス権は後述の「cache_effective_user」で指定したユーザがアクセスできるようになっている必要がある。

redirect_program /usr/local/bin/squidclamav
# squidclamavをリダイレクトプログラムとして起動。

redirect_children 15
# squidclamavに必要なチャイルドプロセス、15個。

acl all src 0.0.0.0/0.0.0.0
# ソース(~へ)0.0.0.0/0.0.0.0をラベルallとして定義。

acl to_localhost dst 127.0.0.0/8
# ディスティネーション(~から)アドレス127.0.0.0/8をラベルto_localhostとして定義。

acl manager proto cache_object
# cachemgr.cgiと言う統計情報を出すためのプログラムが使用するcache_objectにmanagerという名前を定義している。

acl localhost src 127.0.0.1/32
# ソース(~へ)127.0.0.1/32をラベルlocalhostとして定義。

acl SSL_ports port 443 563
# Port 443と563をラベルSSL_portsとして定義。

acl Safe_ports port 80 21 443 563 70 210 1025-65535
# Port 80と21と443と563と70と210と1025~65535迄をラベルSafe_portsとして定義。

acl CONNECT method CONNECT
# 接続するためのメソッドをラベルCONNECTとして定義。

acl mitynet src 192.168.255.0/255.255.255.0
# ソース(~へ)192.168.255.0/255.255.255.0をラベルmitynetとして定義。

http_access allow localhost
# localhostからのhttpアクセスは許可する。

http_access allow mitynet
# mitynetへのhttpアクセスは許可する。

http_access deny to_localhost
# to_localhostへのhttpアクセスは禁止する。

url_rewrite_access deny localhost
# localhostからの要求をリダイレクタへ送るのは禁止する。 デフォルトで、すべての要求をリダイレクタへ送る。

http_access deny manager
# managerへのhttpアクセスは禁止する。

http_access deny !Safe_ports
# Safe_portsリストにないポートへのURLでのポート番号指定を禁止する。

http_access deny CONNECT !SSL_ports
# SSL_ports以外のポートへの接続を禁止する。

http_access deny all
# それ以外は全てアクセス禁止。

icp_access deny all
# icpアクセス全て禁止。

forwarded_for off
# Proxyを使用しているローカルIPを隠蔽。

cache_effective_user proxy
# squidをここで指定したユーザ権限で動作させる。尚、「cache_dir」とログ関係のディレクトリがここで指定したユーザで書き込めるようにしておく必要がある。

濃い青文字が、squidclamavで必須設定です。ここが旨く設定できてないとsquidclamavは思うように動かないので注意してください。

注:squid.confには、他のリダイレクターを併記しないこと。起動しなくなるので注意。

 3)SquidClamAVの設定
michi:/usr/local/src/squidclamav# cp squidclamav.conf.dist /etc/squidclamav.conf

■ Squidclamav Patterns(正規表現の表記方法):
squidclamav.confファイルの中の系列の構文フォーム:

regex|regexi pattern
または、
abort|aborti pattern
または、
content|contenti pattern
または、
redirect cgi_url_redirection

GNU Regex libary(正規表現ライブラリ)の使用で完全なregexマッチングを利用可能にします。
それは、またパターンバッファをもサポートします。

以下は、case insensitive extension(大文字・小文字を区別しない)で .exe、.com、および.zipファイルのClamAvアンチウィルス対象ファイルに対してチェックしたいと宣言している。ここに宣言してるものは、これらの拡張子を含んでるラインです:

regexi ^.*\.exe$
regexi ^.*\.com$
regexi ^.*\.zip$

イメージファイルとHTMLファイルをチェックしたくないならば、コンフィグファイルに以下のラインを含んでいるべきです:

aborti ^.*\..gif$
aborti ^.*\..png$
aborti ^.*\..jpg$
abort ^.*\..html$
abort ^.*\..htm$

もしあなたがディレクトリ・リストまたはデフォルトindex.htmlをチェックしたくないならば、以下のラインを追加してください:

abort ^.*\/$

あなたは、すべての『application/*』ファイルのための、例えば内容タイプに基づくウイルススキャンをしたいかもしれません、そんな場合は、content命令に続けて以下のラインを書いてください:

content ^application\/.*$

■ squidclamav.confの編集と設定
michi:/usr/local/src/squidclamav# vi /etc/squidclamav.conf
proxy http://127.0.0.1:3128                         ← SquidClamAVを設定したProxyホストとProxyPortを設定する。

logfile /var/log/squidclamav.log

redirect http://proxy.xxxxxxxx.com/cgi-bin/clwarn.cgi      ← 自分がカスタマイズしたリダイレクト先を設定する。ここでは、squidclamavに付属の clwarn.cgi と言うPerlスクリプトへリダイレクトするように設定した。

# squidguard /usr/local/squidGuard/bin/squidGuard              ← 他のマッチングリダイレクタ(SquidGuard)と併用する事が出来る。その場合は、SquidGuardのコンフィグファイルに記述することによってSquidClamAVがチューニングされます。但し、SquidGuard以外のリダイレクタには対応してないようだ。

debug 0

force 1

stat 1

clamd_local /var/run/clamav/clamd.ctl        ← ClamAVの local socketのパス。

clamd_ip 127.0.0.1    ← TCP socketを使うためのclamdが動いているホストのIPアドレス。
clamd_port 3310                      ← さらに、そのPort番号。
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\/.*$

 4)logファイルの作成
michi:/usr/local/src/squidclamav# touch /var/log/squidclamav.log
michi:/usr/local/src/squidclamav# chown proxy.proxy /var/log/squidclamav.log


3.起動

 1)squidの起動
michi:/usr/local/src/squidclamav# /etc/init.d/squid restart

 2)動作確認
  ①プロセス確認
squidclamavの起動状態を確認する。
michi:/usr/local/src/squidclamav# ps -ef
省略
clamav 24202 1 3 16:47 ? 00:03:02 /usr/sbin/clamd
clamav 24471 1 0 16:54 ? 00:00:00 /usr/bin/freshclam -d –quiet
root 26598 1 0 18:05 ? 00:00:00 /usr/sbin/squid -D -sYC
proxy 26600 26598 0 18:05 ? 00:00:00 (squid) -D -sYC
proxy 26601 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26602 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26607 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26608 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26609 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26610 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26611 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26612 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26613 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26614 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26615 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26616 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26617 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26618 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26619 26600 0 18:05 ? 00:00:00 (squidclamav)
proxy 26620 26600 0 18:05 ? 00:00:00 (unlinkd)
root 26623 23509 0 18:08 pts/0 00:00:00 ps -ef

  ②logの確認
起動時にエラーが無いか確認する。
michi:/usr/local/src/squidclamav# tail /var/log/squidclamav.log
Sun Aug 19 18:05:06 2007 [26610] LOG SquidClamav (PID 26610) started
Sun Aug 19 18:05:06 2007 [26612] LOG SquidClamav (PID 26612) started
Sun Aug 19 18:05:06 2007 [26613] LOG SquidClamav (PID 26613) started
Sun Aug 19 18:05:06 2007 [26611] LOG SquidClamav (PID 26611) started
Sun Aug 19 18:05:06 2007 [26614] LOG SquidClamav (PID 26614) started
Sun Aug 19 18:05:06 2007 [26615] LOG SquidClamav (PID 26615) started
Sun Aug 19 18:05:06 2007 [26617] LOG SquidClamav (PID 26617) started
Sun Aug 19 18:05:06 2007 [26618] LOG SquidClamav (PID 26618) started
Sun Aug 19 18:05:06 2007 [26616] LOG SquidClamav (PID 26616) started
Sun Aug 19 18:05:06 2007 [26619] LOG SquidClamav (PID 26619) started


4.実際に使ってみる

 1)実際にテストウィルスで検証する
クライアントのブラウザには、 < Squidが走ってるホスト > : 3128 を設定する。
ここでは、 テストウィルス を使って実際にウィルスファイルをブラウザでダウンロードしてみた。また、その時のリダイレクト先は、squidclamavソースに付属(ソースを展開したら、展開したディレクトリの直下にある)のclwarn.cgiを localWebサーバへ設置してリダイレクトするようにした。結果は、テストウィルスをダウンロードしようとすると、リダイレクトされ以下の画面1が表示された。
 

画面1

 2)ウィルス検出時のlog出力
さらに、squidclamav.logを見ると以下のようなlogが書き込まれていた。旨く行ったようだ。
michi:/usr/local/src/squidclamav# tail /var/log/squidclamav.log
省略
Fri Aug 24 22:09:52 2007 [4068] LOG Redirecting URL to: http://www.hogehoge.info/cgi/clwarn.cgi?url=http://hoge.hogehoge.com/download/
test_virus/eicar.com&source=192.168.255.250/-&user=
-& virus=stream: Eicar-Test-Signature FOUND

 3)オリジナル日本語リダイレクトCGI画面作成
オリジナルリダイレクトCGIを作成しました、よろしければ使ってくだっさい。リダイレクト画面は、以下の画面2のようになります。

画面2

このCGIソースは、 ここ からダウンロードしてください。


5.logローティション
logが肥大化しそうなので、logのローテーションを行う。
michi:/usr/local/src/squidclamav# apt-get update
michi:/usr/local/src/squidclamav# apt-get install psmisc
michi:/usr/local/src/squidclamav# cd /etc/logrotate.d

michi:/etc/logrotate.d# vi squidclamav
/var/log/squidclamav.log {
  weekly
  rotate 4
  compress
  missingok
  postrotate
  killall -HUP squidclamav > /dev/null
  endscript
}


SquidClamAV was made by Chris Foote & Wayne Piekarski.

As for the Japanese site of SquidClamAV 

made it.