squidGuard環境構築

製品紹介

squidGuard
公式HP:http://www.squidguard.org/
インストール:http://www.squidguard.org/Doc/install.html
ブラックリスト:http://www.squidguard.org/blacklists.html

目次

1.概要

2.事前準備

3.squidインストール・設定

4.squidGuardインストール・設定

1.概要

OSSのプロキシソフトウェア、SquidのWebフィルタリング機能です。
ライセンスはGNU Public Licenseです。
SquidはWebプロキシやリバースプロキシサーバソフトウェアとして、非常に長い歴史をもっており、有償サポートも提供しています。

squidGuardは、Squidにコンテンツフィルタリング機能を持たせ、いわゆるペアレンタルコントロールなどの閲覧制限を行うことができます。
これにより、企業の従業員が勤務に無関係なWebサイトを閲覧できないようコントロールし、従業員のPCへのマルウェア感染やランサムウェア感染のリスクを軽減することができます。

従業員数が多い企業では、このような機能を持ったプロキシサーバを採用されている傾向があります。
Webフィルタリングイメージ図

今回の検証では、ローカルPC内にあるVMWare workstationの仮想サーバでプロキシサーバを構築し、ブリッジ接続でホストOSとゲストOSを同じセグメント上に配置します。
ホストOSのブラウザのインターネット接続をゲストOSのプロキシサーバを経由するよう設定し、Webフィルタリングできるよう構築します。

 

2.事前準備

  • VMWare設定
    仮想マシンのネットワークアダプタを「ブリッジ」に設定してください。
  •  

  • CentOS7のMinimam PKGを使用します。
    以下のパッケージをインストールし、環境を整えてください。

    OS最新化
    # yum -y update
    アップデート

    時刻同期のため、ntpdインストール・設定
    インストール方法はこちら

    Firewall設定のため、firewalldインストール・設定
    インストール方法はこちら

    epelリポジトリを追加
    # yum -y install epel-release

    ローカルに作成したブロックページへ転送・表示させるため、httpdインストールとblock.htmlの作成
    インストール方法はこちら

 

3.squidインストール・初期設定

squidをyumでインストールします。バージョンは3.5.20です。
# yum info squid

読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
利用可能なパッケージ
名前                : squid
アーキテクチャー    : x86_64
エポック            : 7
バージョン          : 3.5.20
リリース            : 2.el7_3.2
容量                : 3.1 M
リポジトリー        : updates/7/x86_64
要約                : The Squid proxy caching server
URL                 : http://www.squid-cache.org
ライセンス          : GPLv2+ and (LGPLv2+ and MIT and BSD and Public Domain)
説明                : Squid is a high-performance proxy caching server for Web
                    : clients, supporting FTP, gopher, and HTTP data objects.
                    : Unlike traditional caching software, Squid handles all
                    : requests in a single, non-blocking, I/O-driven process.
                    : Squid keeps meta data and especially hot objects cached in
                    : RAM, caches DNS lookups, supports non-blocking DNS
                    : lookups, and implements negative caching of failed
                    : requests.
                    :
                    : Squid consists of a main server program squid, a Domain
                    : Name System lookup program (dnsserver), a program for
                    : retrieving FTP data (ftpget), and some management and
                    : client tools.

# yum -y install squid

設定はこちらを参照して行いました。
ALl version: http://www.squid-cache.org/Doc/config/
v3.5: http://www.squid-cache.org/Versions/v3/3.5/cfgman/

初期設定を行います。
設定ファイルは/etc/squid/squid.confです。
例1)外部からのアクセスは禁止し、ローカルネットワークと指定ドメインのみ許可する(利用できる)ように設定(LAN環境が192.168.11.0のセグメントの場合)
acl localnet src 192.168.11.0/24
axl localdomain srcdomain .example.com

例2)ポート8080に指定
http_port 8080

例3)HTTP/HTTPSのみ許可し、FTPなど他ポートは無効
acl Safe_ports port 80 # http
#acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
#acl Safe_ports port 70 # gopher
#acl Safe_ports port 210 # wais
#acl Safe_ports port 1025-65535 # unregistered ports
#acl Safe_ports port 280 # http-mgmt
#acl Safe_ports port 488 # gss-http
#acl Safe_ports port 591 # filemaker
#acl Safe_ports port 777 # multiling http
===省略====
#refresh_pattern ^ftp: 1440 20% 10080
#refresh_pattern ^gopher: 1440 0% 1440

例4)ログファイルの設定
access_log /var/log/squid/access.log auto

例6)プロキシサーバ経由でアクセスしていることを隠す
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all
X-FORWARDED-FOR:クライアントPCのIPアドレスがheaderに混入する
Via:中継したソフトウェアやプロトコルが記録される
Cache-Control:キャッシュに関する内容が記述される

例7)プロキシサーバを利用しているクライアントPCのIPアドレスを隠す
forwarded_for off

# Recommended minimum configuration:
#

# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
#acl localnet src 10.0.0.0/8    # RFC1918 possible internal network
#acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
#acl localnet src 192.168.0.0/16        # RFC1918 possible internal network
#acl localnet src fc00::/7       # RFC 4193 local private network range
#acl localnet src fe80::/10      # RFC 4291 link-local (directly plugged) machines
acl localnet src 192.168.11.0/24 #接続先IPレンジ
acl localdomain srcdomain .example.com #接続先ドメイン(ドメイン管理している場合)

acl SSL_ports port 443
acl Safe_ports port 80          # http
#acl Safe_ports port 21         # ftp
acl Safe_ports port 443         # https
#acl Safe_ports port 70         # gopher
#acl Safe_ports port 210                # wais
#acl Safe_ports port 1025-65535 # unregistered ports
#acl Safe_ports port 280                # http-mgmt
#acl Safe_ports port 488                # gss-http
#acl Safe_ports port 591                # filemaker
#acl Safe_ports port 777                # multiling http
acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports

# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports

# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager

# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost

#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#

# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost
http_access allow localdomain

# And finally deny all other access to this proxy
http_access deny all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
#cache_dir ufs /var/spool/squid 100 16 256
cache_mem 128 MB
cache_dir ufs /var/spool/squid 600 16 128
# Leave coredumps in the first cache dir
coredump_dir /var/spool/squid

#
# Add any of your own refresh_pattern entries above these.
#
#refresh_pattern ^ftp:          1440    20%     10080
#refresh_pattern ^gopher:       1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320

#log file
access_log /var/log/squid/access.log squid

#logformat

#request_header_access
request_header_access X-Forwarded-For deny all
request_header_access Via deny all
request_header_access Cache-Control deny all

#forwarded_for
forwarded_for off

設定が正しくされているか、下記コマンドで確認します。

# squid -k parse

2017/02/12 17:54:44| Startup: Initializing Authentication Schemes ...
2017/02/12 17:54:44| Startup: Initialized Authentication Scheme 'basic'
2017/02/12 17:54:44| Startup: Initialized Authentication Scheme 'digest'
2017/02/12 17:54:44| Startup: Initialized Authentication Scheme 'negotiate'
2017/02/12 17:54:44| Startup: Initialized Authentication Scheme 'ntlm'
2017/02/12 17:54:44| Startup: Initialized Authentication.
2017/02/12 17:54:44| Processing Configuration File: /etc/squid/squid.conf (depth 0)
2017/02/12 17:54:44| Processing: acl localnet src 192.168.11.0/24 #my network
2017/02/12 17:54:44| Processing: acl SSL_ports port 443
2017/02/12 17:54:44| Processing: acl Safe_ports port 80         # http
2017/02/12 17:54:44| Processing: acl Safe_ports port 443                # https
2017/02/12 17:54:44| Processing: acl CONNECT method CONNECT
2017/02/12 17:54:44| Processing: http_access deny !Safe_ports
2017/02/12 17:54:44| Processing: http_access deny CONNECT !SSL_ports
2017/02/12 17:54:44| Processing: http_access allow localhost manager
2017/02/12 17:54:44| Processing: http_access deny manager
2017/02/12 17:54:44| Processing: http_access allow localnet
2017/02/12 17:54:44| Processing: http_access allow localhost
2017/02/12 17:54:44| Processing: http_access deny all
2017/02/12 17:54:44| Processing: http_port 8080
2017/02/12 17:54:44| Processing: coredump_dir /var/spool/squid
2017/02/12 17:54:44| Processing: refresh_pattern -i (/cgi-bin/|\?) 0    0%      0
2017/02/12 17:54:44| Processing: refresh_pattern .              0       20%     4320
2017/02/12 17:54:44| Processing: access_log /var/log/squid/access.log squid
2017/02/12 17:54:44| Processing: request_header_access X-Forwarded-For deny all
2017/02/12 17:54:44| Processing: request_header_access Via deny all
2017/02/12 17:54:44| Processing: request_header_access Cache-Control deny all
2017/02/12 17:54:44| Processing: forwarded_for off
2017/02/12 17:55:01| Initializing https proxy context

正常終了すると、「Initializing https proxy context」というログが出力されます。

ポートを開放し、サービスを起動します。
# firewall-cmd --add-port=8080/tcp --permanent
# firewall-cmd --reload
※ポートを指定していない場合は、下記コマンドで対応してください。
# firewall-cmd --add-service=squid --permanent
# systemctl enable squid
# systemctl start squid
# systemctl status squid

● squid.service - Squid caching proxy
   Loaded: loaded (/usr/lib/systemd/system/squid.service; disabled; vendor preset: disabled)
   Active: active (running) since 金 2017-02-10 18:17:16 JST; 9s ago
  Process: 48723 ExecStart=/usr/sbin/squid $SQUID_OPTS -f $SQUID_CONF (code=exited, status=0/SUCCESS)
  Process: 48718 ExecStartPre=/usr/libexec/squid/cache_swap.sh (code=exited, status=0/SUCCESS)
 Main PID: 48726 (squid)
   CGroup: /system.slice/squid.service
           tq48726 /usr/sbin/squid -f /etc/squid/squid.conf
           mq48728 (squid-1) -f /etc/squid/squid.conf

 2月 10 18:16:59 proxy2 systemd[1]: Starting Squid caching proxy...
 2月 10 18:16:59 proxy2 squid[48723]: 2017/02/10 18:16:59| WARNING: Log format 'auto' no ...ad.
 2月 10 18:17:16 proxy2 systemd[1]: Started Squid caching proxy.
 2月 10 18:17:16 proxy2 squid[48726]: Squid Parent: will start 1 kids
 2月 10 18:17:16 proxy2 squid[48726]: Squid Parent: (squid-1) process 48728 started
Hint: Some lines were ellipsized, use -l to show in full.

接続テストを行います。
ブラウザはInternet Explorerを使用します。
以下の通り設定してください。

  • 「ツール」→「インターネットオプション」を選択します
  • 「接続」→「LANの設定」を選択します
  • 「プロキシサーバ」でLANにプロキシサーバを使用するにチェックを入れ、プロキシサーバのアドレスとポート番号を入力します

アクセスログから正常にログが検出されていることを確認します。
# tail -f access.log

1486719550.493 64 192.168.11.11 TCP_MISS/204 364 GET http://g.bing.com/uac/response? - HIER_DIRECT/111.221.29.13 -
1486719550.495 65 192.168.11.11 TCP_MISS/204 364 GET http://g.bing.com/uac/response? - HIER_DIRECT/111.221.29.13 -
1486719551.494 67 192.168.11.11 TCP_MISS/204 364 GET http://g.bing.com/uac/response? - HIER_DIRECT/111.221.29.13 -
1486719551.495 66 192.168.11.11 TCP_MISS/204 364 GET http://g.bing.com/uac/response? - HIER_DIRECT/111.221.29.13 -

上記はsquid形式ですが、他に下記形式があります。さらに表示形式をlogformatでカスタマイズすることも可能です。
common

192.168.11.7 - - [15/Feb/2017:11:04:43 +0900] "GET http://www.msn.com/advertisement.ad.js HTTP/1.1" 304 246 TCP_MISS:HIER_DIRECT
192.168.11.7 - - [15/Feb/2017:11:04:45 +0900] "CONNECT ib.adnxs.com:443 HTTP/1.0" 500 0 TAG_NONE:HIER_DIRECT

conbined

192.168.11.7 - - [15/Feb/2017:11:08:55 +0900] "GET http://g.bing.com/uac/response? HTTP/1.1" 204 364 "http://www.msn.com/ja-jp/?cobrand=oem17win10.msn.com&ocid=OEMDHP17&pc=NMTE" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko" TCP_MISS:HIER_DIRECT
192.168.11.7 - - [15/Feb/2017:11:08:55 +0900] "GET http://g.bing.com/uac/response? HTTP/1.1" 204 364 "http://www.msn.com/ja-jp/?cobrand=oem17win10.msn.com&ocid=OEMDHP17&pc=NMTE" "Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko" TCP_MISS:HIER_DIRECT

referer

1487124659.249 192.168.11.7 - store-images.s-microsoft.com:443
1487124659.250 192.168.11.7 - store-images.s-microsoft.com:443

useragent

192.168.11.7 [15/Feb/2017:11:14:38 +0900] "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36"
192.168.11.7 [15/Feb/2017:11:14:44 +0900] "Mozilla/5.0 (Windows NT 10.0; Win64; x64; Trident/7.0; rv:11.0) like Gecko"

 

4.squidGuardインストール・初期設定

squidGuardはパッケージからでもインストール可能です。
EPELのリポジトリを有効にしてバージョンを確認します。
# yum --enablerepo=epel info squidGuard

読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * epel: ftp.riken.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
インストール済みパッケージ
名前                : squidGuard
アーキテクチャー    : x86_64
バージョン          : 1.4
リリース            : 26.el7
容量                : 7.4 M
リポジトリー        : installed
提供元リポジトリー  : epel
要約                : Filter, redirector and access controller plugin for squid
URL                 : http://www.squidguard.org/
ライセンス          : GPLv2
説明                : squidGuard can be used to
                    : - limit the web access for some users to a list of
                    :   accepted/well known web servers and/or URLs only.
                    : - block access to some listed or blacklisted web servers
                    :   and/or URLs for some users.
                    : - block access to URLs matching a list of regular
                    :   expressions or words for some users.
                    : - enforce the use of domainnames/prohibit the use of IP
                    :   address in URLs.
                    : - redirect blocked URLs to an "intelligent" CGI based info
                    :   page.
                    : - redirect unregistered user to a registration form.
                    : - redirect popular downloads like Netscape, MSIE etc. to
                    :   local copies.
                    : - redirect banners to an empty GIF.
                    : - have different access rules based on time of day, day of
                    :   the week, date etc.
                    : - have different rules for different user groups.
                    : - and much more..
                    :
                    : Neither squidGuard nor Squid can be used to
                    : - filter/censor/edit text inside documents
                    : - filter/censor/edit embeded scripting languages like
                    :   JavaScript or VBscript inside HTML

インストールします。
# yum --enablerepo=epel -y install squidGuard

 
squidGuard検証ページへ