CentOS6で構築してみた 以前はCentOS5の場合です(router/SquidClamAV/CentOS5)
ブリッジにClamAVを載せたような物を検討している。
ルータのようにネットワークセグメントは切り替わらず、同じIP体系で両方を繋いでその間でClamAVを機能させたい。
もしルータとして行うのなら pfsense にある SquidClamAV 機能を使ったほうがいいのかも。
pfsenseでもできそうかな?って思ったのだがBridgeの設定でうまくできなかった。単に調査不足もありえるが。
全体像はこんな感じ

*VMwareESXiでBridge環境を構築する際にはvSwitchを調整する必要があります VMware/Bridge
CentOS6.7の最小構成版(minimal)。Gnomeも開発環境も入ってない構成です。
それに対して、selinuxの無効化、ip6tablesの無効化、各種デーモンの停止、ntpの導入を行った。
[root@bridge ~]# sed -i 's/=enforcing/=disabled/' /etc/selinux/config
[root@bridge ~]# for i in auditd blk-availability ip6tables iscsi iscsid lvm2-monitor mdmonitor;do chkconfig $i off;done
[root@bridge ~]# echo prefer=ftp.riken.jp >> /etc/yum/pluginconf.d/fastestmirror.conf
[root@bridge ~]# yum clean plugins
[root@bridge ~]# yum -y install ntp
[root@bridge ~]# cat << _EOF_ >/etc/ntp.conf
driftfile /var/lib/ntp/drift
server 192.168.0.3
_EOF_
[root@bridge ~]# echo "192.168.0.3" >> /etc/ntp/step-tickers
[root@bridge ~]# chkconfig ntpd on && chkconfig ntpdate oneth0とeth1でbridgeを作成する
[root@bridge ~]# cat /etc/sysconfig/network-scripts/ifcfg-br0
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.0.71
BROADCAST=192.168.0.255
NETMASK=255.255.255.0
ONBOOT=yes
[root@bridge ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
HWADDR=00:1D:73:E6:9D:82
ONBOOT=yes
BRIDGE=br0
[root@bridge ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth1
TYPE=Ethernet
HWADDR=00:26:18:7A:1E:D7
ONBOOT=yes
BRIDGE=br0
[root@bridge ~]#これを反映させるために再起動を行って、bridgeを確認する
[root@bridge ~]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.001d73e69d82 no eth0
eth1
[root@bridge ~]#CentOS6のリポジトリには Clam AntiVirus は存在せず、他のリポジトリならインストール可能であった。
ここでは epel リポジトリを導入して、clamavをインストール
[root@bridge ~]# yum -y install epel-release
[root@bridge ~]# yum -y install clamav clamav-db clamdclamdの設定ファイル(/etc/clamd.conf)はそのまま使用します。
ウイルス検出パターンファイルを更新してから clamd を起動させる。
ウイルス検出パターンファイルを更新する freshclam の定義ファイル/etc/freshclam.conf
[root@bridge ~]# freshclam
[root@bridge ~]# chkconfig --list clamd
clamd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@bridge ~]# chkconfig clamd on && /etc/init.d/clamd starthttp://www.eicar.org/85-0-Download.html
にウイルス検出向けのファイルがある。
これをダウンロードしてスキャンさせ、検出できるかを試す
[root@bridge ~]# curl -O http://www.eicar.org/download/eicar.com
[root@bridge ~]# clamscan --no-summary --infected ./*
./eicar.com: Eicar-Test-Signature FOUND
[root@bridge ~]#と認識はできた模様
br0に届く80番ポートのリクエストを 3128 ポートへリダイレクトさせ quid に渡す。
ここでは一旦 iptable の既存の設定を消去して、そのリダイレクトを設定します。
[root@bridge ~]# cp /etc/sysconfig/iptables /etc/sysconfig/iptables.160424
[root@bridge ~]# iptables -F -t filter && iptables -X -t filter *filterテーブルの初期化
[root@bridge ~]# iptables -F -t nat && iptables -X -t nat *natテーブルの初期化
[root@bridge ~]# /etc/init.d/iptables status
テーブル: nat
Chain PREROUTING (policy ACCEPT)
num target prot opt source destination
Chain POSTROUTING (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
テーブル: filter
Chain INPUT (policy ACCEPT)
num target prot opt source destination
Chain FORWARD (policy ACCEPT)
num target prot opt source destination
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
[root@bridge ~]#そして、natテーブルへポートへリダイレクトの設定を加える
[root@bridge ~]# iptables -t nat -A PREROUTING -i br0 -p tcp --dport 80 -j REDIRECT --to-port 3128
[root@bridge ~]# iptables -L -t nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
REDIRECT tcp -- anywhere anywhere tcp dpt:http redir ports 3128
Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
[root@bridge ~]#この設定を保存します。加えてBridgeインターフェイスでもiptablesが有効になる設定を加える
[root@bridge ~]# /etc/init.d/iptables save
ファイアウォールのルールを /etc/sysconfig/iptables に保存中[ OK ]
[root@bridge ~]# cat /proc/sys/net/bridge/bridge-nf-call-iptables
0
[root@bridge ~]#
[root@bridge ~]# echo 1 >> /proc/sys/net/bridge/bridge-nf-call-iptables
[root@bridge ~]# echo net.bridge.bridge-nf-call-iptables=1 >> /etc/sysctl.confiptableで80ポートへの要求を 3128 ポートへリダイレクトさせた。このリダイレクトされたデータを待ち受ける squid を用意する
CentOS6で採用されている squid は 3.1 である。CentOS5は 2.6
[root@bridge ~]# yum -y install squidCentOS5の時は、squidからウイルススキャンを実行するアプリ(/usr/local/bin/squidclamav)を呼び出していたが(下図下段)、効率化のためか、安全のためか、squidから直接squidclamavを呼び出さず、ICAP(Internet Content Adaptation Protocol)を経由してsquidclamavを使うのが宜しいみたい(下図上段)。

っで、このyumでインストールした squid-3.1.23 は、このICAPを利用可能で、下記のようにして確認できる
[root@bridge ~]# /usr/sbin/squid -v | sed 's/ /\n/g' | grep -i icap
'--enable-icap-client'
[root@bridge ~]#設定ファイル(/etc/squid/squid.conf)に ICAP の設定を加える
ICAP serverの実装となる c-icap をインストールします。
https://sourceforge.net/projects/c-icap/files/
からソースをダウンロードしてコンパイルします。
[root@bridge ~]# gzip -cd c_icap-0.4.3.tar.gz | tar xf -
[root@bridge ~]# cd c_icap-0.4.3
[root@bridge c_icap-0.4.3]# ./configure --enable-large-files
[root@bridge c_icap-0.4.3]# make && make check && make install
[root@bridge c_icap-0.4.3]# cp c-icap.conf c-icap.magic /etc*事前に開発環境をインストールするか、yum -y install gcc make zlib-devel bzip2-devel と最低限パッケージインストールを行う
ここでは、c_icap_modulesでc-icapとclamavを連携させず、squidclamavで連携させてみる。
設定ファイル(/etc/c-icap.conf) に Service を追加します
スタートアップスクリプトが用意されていないようで、、、自作した(/etc/init.d/c-icap)
本家 SquidClamav
よりソースコードをダウンロードします。
一応以前の redirect_program な方式も使用できるのだが、ここでは c-icap を通じて利用する
[root@bridge ~]# gzip -cd squidclamav-6.15.tar.gz | tar xf -
[root@bridge ~]# cd squidclamav-6.15
[root@bridge squidclamav-6.15]# ./configure --with-c-icap
[root@bridge squidclamav-6.15]# make && make install*なんかこれ、prefixが効かないみたい...
cg-bin 向けのファイルは、/usr/local/libexec/squidclamavに、
/etc/c-icap.confで指定される squidclamav.so は/usr/local/lib/c_icapに、
設定ファイル squidclamav.conf は、/usr/local/etc に、
それぞれインストールされる。
設定ファイル /usr/local/etc/squidclamav.conf を調整します
[root@bridge ~]# yum -y install httpd perl-CGI
[root@bridge ~]# chkconfig httpd on
[root@bridge ~]# cp /usr/local/libexec/squidclamav/clwarn.cgi /var/www/cgi-bin/はじめに c-icap サーバを起動します
[root@bridge ~]# /etc/init.d/httpd start
httpd を起動中: [ OK ]
[root@bridge ~]#
[root@bridge ~]# /etc/init.d/c-icap start
Starting c-icap: [ OK ]
[root@bridge ~]#正しく動いているかは、下記にて確認
[root@bridge ~]# tail /var/log/c-icap/server.log次に、squidを起動します
[root@bridge ~]# /etc/init.d/squid start
squid を起動中: . [ OK ]
[root@bridge ~]#Bridge先の通常コンテンツにアクセスすると

と正常に表示されるが、ウイルスなコンテンツにアクセスすると、

と表示される。
*警告表示のwebサイトに自動的に移動する点に留意