Squid + ClamAV + Apache でゲートウェイ型ウイルス検索プロキシサーバ作ってみた

最近、いろいろセキュリティ関連が荒ぶっているため、勢いで作ってみた。
OS はとりあえず CentOS 6。
最初は Squid と ClamAV で作ってみたが、どーも読み込みがおっそい。
やっぱ Squid が並列読み込みが得意でないせいかボトルネックになっているようだ。
そんなわけで、Ver2 として Apache + mod_clamav + ClamAV で作ってみたが・・・

■Ver.1
Squid + ClamAV (Squid, SquidClamav, c-icap, ClamAV)
Squid が並列処理に弱いっぽく、CPU パワー使いきれてない。

■Ver.2
Apache + ClamAV (Apache, mod_clamav, ClamAV)
mod_clamavがいろいろ大変だった。
そもそも clamd を root で動かさないと稼働しないとか泣いた。
さらにエラーログが・・・

【エラーログ】
[Sat Jan 16 22:55:08 2016] [error] [client XXX.XXX.XXX.XXX] [PID] cannot create mutex /var/tmp/test/clamav.lock, referer: http://example.com/
[Sat Jan 16 22:55:08 2016] [error] [client XXX.XXX.XXX.XXX] [PID] cannot create mutex /var/tmp/test/clamav.lock, referer: http://example.com/
[Sat Jan 16 22:55:08 2016] [error] [client XXX.XXX.XXX.XXX] [PID] cannot create mutex /var/tmp/test/clamav.lock, referer: http://example.com/
調べてみたけど、どうも mod_clamav が腐っているようだ。
なので仕方なく、「ウイルス検索エンジン」と「キャッシュサーバ」と割ることにした。

■Ver.3
Apache + Squid + ClamAV (Apache, Squid, SquidClamav, c-icap, ClamAV)
プロキシとしての動作は問題なし。
キャッシュもうまく効いてる。
とりあえず問題なく動いているっぽいので、メモとして Config を残しておく。

【/etc/c-icap.conf の Diff】

# diff -uprN /etc/c-icap.conf.org /etc/c-icap.conf
--- /etc/c-icap.conf.org        2016-01-09 04:39:20.536958814 +0900
+++ /etc/c-icap.conf    2016-01-09 04:41:32.286114361 +0900
@@ -158,7 +158,7 @@ Port 1344
 #      about this server (logs, info service, etc)
 # Default:
 #      No value
-ServerAdmin you@your.address
+ServerAdmin root@localhost

 # TAG: ServerName
 # Format: ServerName aServerName
@@ -167,7 +167,7 @@ ServerAdmin you@your.address
 #      server (logs, info service, etc)
 # Default:
 #      No value
-ServerName YourServerName
+ServerName cielnotron.sgv417.dip.jp

 # TAG: TmpDir
 # Format: TmpDir dir
@@ -609,6 +609,7 @@ AccessLog /usr/local/var/log/access.log
 # Example:
 #      Service echo srv_echo.so
 Service echo srv_echo.so
+Service squidclamav squidclamav.so

 # Module: sys_logger
 # Description:

【/etc/squidclamav.conf の Diff】

# diff -uprN /usr/local/etc/squidclamav.conf.default /usr/local/etc/squidclamav.conf
--- /usr/local/etc/squidclamav.conf.default     2016-01-09 04:45:13.072014836 +0900
+++ /usr/local/etc/squidclamav.conf     2016-01-09 04:49:01.204077165 +0900
@@ -15,7 +15,8 @@ maxsize 5000000

 # When a virus is found then redirect the user to this URL. If this directive
 # is disabled squidclamav will use c-icap error templates to report issues.
-redirect http://proxy.domain.dom/cgi-bin/clwarn.cgi
+#redirect http://proxy.domain.dom/cgi-bin/clwarn.cgi
+redirect http://XXX.XXX.XXX.XXX/squidclamav/alert.html

 # Path to the squiGuard binary if you want URL filtering, note that you'd better
 # use the squid configuration directive 'url_rewrite_program' instead.
@@ -24,7 +25,8 @@ redirect http://proxy.domain.dom/cgi-bin
 # Path to the clamd socket, use clamd_local if you use Unix socket or if clamd
 # is listening on an Inet socket, comment clamd_local and set the clamd_ip and
 # clamd_port to the corresponding value.
-clamd_local /var/run/clamav/clamd.ctl
+#clamd_local /var/run/clamav/clamd.ctl
+clamd_local /var/run/clamav/clamd.sock
 #clamd_ip 192.168.1.5,127.0.0.1
 #clamd_port 3310

【/etc/squid/squid.conf 追記部分】

cache_mem 10 MB

# Anonymous
#request_header_access Referer deny all
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all
forwarded_for off

# SquidClamav
icap_enable on
icap_send_client_ip on
icap_send_client_username on
icap_client_username_header X-Authenticated-User
icap_service service_req reqmod_precache bypass=1 icap://127.0.0.1:1344/squidclamav
adaptation_access service_req allow all
icap_service service_resp respmod_precache bypass=1 icap://127.0.0.1:1344/squidclamav
adaptation_access service_resp allow all

【/etc/httpd/conf.d/proxy.conf】
※mod_mem_cache を有効化すること。

Listen 8080
<VirtualHost *:8080>
    ServerAdmin root@localhost
    DocumentRoot /var/www/html
    ServerName localhost:8080
    ErrorLog logs/proxy-error_log
    CustomLog logs/proxy-access_log common

    ProxyRemote * http://127.0.0.1:3128/
   <IfModule mod_proxy.c>
      ProxyRequests On

      <Proxy *>
          Order deny,allow
          Deny from all
          Allow from XXX.XXX.XX.
      </Proxy>

      <IfModule mod_disk_cache.c>
         CacheEnable disk /
         CacheRoot "/var/cache/mod_proxy"
         CacheDirLevels 3
         CacheDirLength 2
         CacheMinFileSize 524288
         CacheMaxFileSize 1073741824
      </IfModule>

      <IfModule mod_mem_cache.c>
         CacheEnable mem /
         MCacheSize 512000
         MCacheMinObjectSize 1
         MCacheMaxObjectSize 1048576
         MCacheMaxObjectCount 10000
      </IfModule>
   </IfModule>
</VirtualHost>
カテゴリー: めも パーマリンク

4 Responses to Squid + ClamAV + Apache でゲートウェイ型ウイルス検索プロキシサーバ作ってみた

  1. ピンバック: Squid でローカル向けプロキシを立てるときの注意 | まこぴかっと

  2. ピンバック: Apache の Reverse Proxy 設定調整 | まこぴかっと

  3. ピンバック: Enterprise Linux 6.8 で Squid の Config に使用できないものが増えた | まこぴかっと

  4. ピンバック: トラフィック削減用 Proxy サーバを作ってみた | まこぴかっと

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です