ぼぶろぐ -36ページ目

ぼぶろぐ

以前は、あいらぶLinux♪というタイトルでしたが、
最近はLinux以外のことも書いているので、タイトルを変更しました。
ぼぶちゃんのぶろぐでぼぶろぐです。

前回の続きで、今回はApacheのproxyモジュールを使ってWindowsXPからの通信を制御します。
制御するUser-Agentの情報やネットワーク構成は前回と一緒です。

前回 WindowsXPからの通信をProxyサーバでブロック その1 (squid)
http://ameblo.jp/hackerbobchan/entry-11789417030.html


以下参考にしたサイトになります。

Apache モジュール mod_proxy
http://httpd.apache.org/docs/2.2/ja/mod/mod_proxy.html

.htaccessによるURLの書き換え Rewrite(リライト)
http://hoshiya.biz/blog/2012/02/htaccessurl-rewrite.php


以下設定内容になります。

---
<IfModule mod_proxy.c>
ProxyRequests On

<Proxy *>
Order deny,allow
Deny from all
Allow from 192.168.
RewriteEngine On
RewriteCond %{SERVER_NAME} !192\.168\.0 [NC]
RewriteCond %{HTTP_USER_AGENT} MSIE\ 4\.0 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} MSIE\ 5\.0 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} MSIE\ 6\.0 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} compatible [NC,OR]
RewriteCond %{HTTP_USER_AGENT} Mozilla/3\.0 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} windows\ NT\ 5 [NC,OR]
RewriteCond %{HTTP_USER_AGENT} windows\ 9 [NC]
RewriteRule ^.*$ [F]
</Proxy>

ProxyVia Block

<IfModule mod_disk_cache.c>
CacheEnable disk /
CacheRoot "/var/cache/httpd"
</IfModule>

</IfModule>

LogLevel debug
RewriteLogLevel 9
RewriteLog /var/log/httpd/rewrite_log
---

今回は、{SERVER_NAME}で通信を制御する設定を入れています。
この設定を使うことで、社内向け通信のみ許可するなどの柔軟な設定が可能です。
上記の設定ですと、{SERVER_NAME}に"192.168.0"を含まなければ通信不可になりますので、
逆に"192.168.0"を含んでいると通信可能となります。

今回も通信時のデバッグログを取得しました。

■WindowsXPで通信した時のデバッグログ

通常のInternetアクセス
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (3) [perdir */] applying pattern '^.*$' to uri 'proxy:http://www.microsoft.com/isapi/redir.dll?prd=ie&pver=6&ar=msnhome'
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (4) [perdir */] RewriteCond: input='www.microsoft.com' pattern='!192\\.168\\.0' [NC] => matched
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (4) [perdir */] RewriteCond: input='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)' pattern='MSIE\\ 4\\.0' [NC] => not-matched
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (4) [perdir */] RewriteCond: input='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)' pattern='MSIE\\ 5\\.0' [NC] => not-matched
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (4) [perdir */] RewriteCond: input='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)' pattern='MSIE\\ 6\\.0' [NC] => not-matched
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (4) [perdir */] RewriteCond: input='Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)' pattern='compatible' [NC] => matched
192.168.0.4 - - [15/Mar/2014:21:59:15 +0900] [www.microsoft.com/sid#1939fa0][rid#1dcb358/initial] (2) [perdir */] rewrite 'proxy:http://www.microsoft.com/isapi/redir.dll?prd=ie&pver=6&ar=msnhome' -> '[F]'

- まず、SERVER_NAMEに192.168.0が含まれていない(条件にマッチしている)ので、次の処理に進みます。次にHTTP_USER_AGENTにcompatibleが含まれている(条件にマッチしている)ので、通信を拒否しています。


http://192.168.0.10/index.htmlへアクセス
192.168.0.4 - - [15/Mar/2014:22:06:35 +0900] [192.168.0.10/sid#1939fa0][rid#1dd1370/initial] (3) [perdir */] applying pattern '^.*$' to uri 'proxy:http://192.168.0.10/index.html'
192.168.0.4 - - [15/Mar/2014:22:06:35 +0900] [192.168.0.10/sid#1939fa0][rid#1dd1370/initial] (4) [perdir */] RewriteCond: input='192.168.0.10' pattern='!192\\.168\\.0' [NC] => not-matched
192.168.0.4 - - [15/Mar/2014:22:06:35 +0900] [192.168.0.10/sid#1939fa0][rid#1dd1370/initial] (1) [perdir */] pass through proxy:http://192.168.0.10/index.html

- SERVER_NAMEに192.168.0を含んでいる(条件にマッチしていない)ので、通信が許可されています。


■Windows7で通信した時のデバッグログ

通常のInternetアクセス
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (3) [perdir */] applying pattern '^.*$' to uri 'proxy:http://lenovo.msn.com/'
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='lenovo.msn.com' pattern='!192\\.168\\.0' [NC] => matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='MSIE\\ 4\\.0' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='MSIE\\ 5\\.0' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='MSIE\\ 6\\.0' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='compatible' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='Mozilla/3\\.0' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='windows\\ NT\\ 5' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (4) [perdir */] RewriteCond: input='Mozilla/5.0 (Windows NT 6.1; Trident/7.0; MALC; rv:11.0) like Gecko' pattern='windows\\ 9' [NC] => not-matched
192.168.0.3 - - [15/Mar/2014:22:09:35 +0900] [lenovo.msn.com/sid#1939fa0][rid#1dcd360/initial] (1) [perdir */] pass through proxy:http://lenovo.msn.com/

- 全ての条件にマッチしませんでしたので、Internetアクセスが可能です。


Apacheのproxyモジュールを利用しても、WindowsXPの通信を制御することができました。

WindowsXPのサポートが終了する前に、現在のWindowsXPユーザがOSバージョンアップなどの
対策をすることで、サポート終了後にセキュリティインシデントが起こらないことを願っています。
WindowsXPのサポートが切れるまであと1ヶ月ほどとなりました。

- Windows XP および、Office 2003 のサポート終了についてのご案内
https://www.microsoft.com/ja-jp/windows/lifecycle/sp3eos.aspx  

ですが、おそらくまだ職場でWindowsXPを使っている人はいると思います。

Windows7などに買い替えるのが最もよい方法とは思いますが、
できるだけセキュリティリスクを減らすために、Proxyサーバで制御をかけます。
(例えば、野良XPがいきなり社内LANにつながった時など)

きっかけは某セキュリティスペシャリストの方にWindowsXPからの
通信をsquidで制御できるんじゃないのと言われたことから始まりました。
そこでできるかどうかが気になったので、自宅環境で検証してみました。

自宅の検証環境は以下のような感じですが、実際に使用しているのは、
Windows7のノートPC1台だけです。

Windows7 :ノートPC
Proxy(squid):CentOS6.5 (VMWarePlayer)
WindowsXP :Windows XP Mode (Windows Virtual PC)

クライアントの全てのWeb通信をProxy経由で行うようにします。





某セキュリティスペシャリストの方にかなり調べていただきました。
ありがとうございます!以下、原文になります。

>>>

[セキュリティ]サポート終了したWindowsのインターネットアクセスを制限する方法

acl aclname browser [-i] regexp ...
# pattern match on User-Agent header (see also req_header below) [fast]

http://www.squid-cache.org/Doc/config/acl/
MSIE 7.0 Internet Explorer 7
MSIE 7.0b Internet Explorer 7 (Beta 1 プレリリース バージョンのみ)
MSIE 6.0 Internet Explorer 6
MSIE 6.0b Internet Explorer 6 (プレリリース)
MSIE 5.5 Internet Explorer 5.5
MSIE 5.01 Internet Explorer 5.01
MSIE 5.0 Internet Explorer 5
MSIE 5.0b1 Internet Explorer 5 (プレリリース)
MSIE 4.01 Internet Explorer 4.01
http://msdn.microsoft.com/ja-jp/library/ms537503%28v=vs.85%29.aspx

また、組み合わせは以下より情報をいただきました。

XP+IEは2014年4月8日
Vista+IE7は、2017年4月11日
Vista+IE8は、2020年1月14日

http://www.tama200x.com/blog/?p=1776

現在サポートされているWindows XP以降のクライアント向けOSのサポート終了日、そのOS上で動作するブラウザは以下の通りとなります。

User-AgentのOS状況


Windows NT 5.1 Windows XP

Windows NT 5.01 Windows 2000, Service Pack 1 (SP1)

Windows NT 5.0 Windows 2000

Windows NT 4.0 Microsoft Windows NT 4.0

Windows 98; Win 9x 4.90 Windows Millennium Edition (Windows Me)

Windows 98 Windows 98

Windows 95 Windows 95

Windows CE Windows CE
http://msdn.microsoft.com/ja-jp/library/ms537503%28v=vs.85%29.aspx

以下より、

acl user-agent browser regexp "/etc/squid/user-agent.txt"
http_access deny user-agent

http://networklinuxcisco.blog49.fc2.com/blog-entry-4.html

「/etc/squid/user-agent.txt」に拒否するユーザエージェントの文字列を正規表現にて記載します。

MSIE 5\.0
MSIE 5\.5
MSIE 6\.0
Mozilla\/3\.0

ここに、URL Redirectの設定がブラウザベースで記載されている

###################################
# we redirect mobiles to mobile.mysite.com
url_rewrite_program /etc/squid/redirect_mobile.sh

acl symbian browser Symbian
acl iphone browser iP(hone|od)
acl mobile_url dstdomain mobile.monsite.com

url_rewrite_access deny mobile_url
url_rewrite_access allow symbian
url_rewrite_access allow iphone
url_rewrite_access deny all

http://positon.org/squid-26-redirection

なので

acl user-agent browser regexp "/etc/squid/user-agent.txt"
url_rewrite_program /etc/squid/redirect_unsupportos.sh
url_rewrite_access allow user-agent
url_rewrite_access deny all

/etc/squid/user-agent.txtに
MSIE 4\.0
MSIE 5\.0
MSIE 5\.5
MSIE 6\.
compatible
Mozilla\/3\.0
Windows NT 5\.
Windows 9

redirect_unsupportos.sh
#!/bin/sh
while read line
do
echo "301:http://localdomain/xp_support_end "
done

>>>
※最後のリダイレクトのURLは適宜修正が必要です。
※プラットフォームトークンのWindows NT 5.2は、Windows XPの64bitとWindows Server 2003が一緒なので、上記設定を使う場合は、クライアントにWindows Server 2003が無いことが条件になります。


実際に通信してみたところ、WindowsXPで通信の制御を行うことができました。
自宅環境に原因があると思うのですが、リダイレクトの処理はうまくいきませんでした。
これは後日、じっくり調べたいと思います。

以下のコマンドを実行して通信時のsquidのデバッグログを取得しました。

# squid -k debug

※このコマンドを実行するとかなりの量のログがとれます。2,3回プロキシ経由で通信したら
cache.logがかなりの容量になってしまいました。

いっぱい取れたデバッグログのうち、一部を以下に記載します。

■WindowsXPで通信した時のデバッグログ

2014/03/05 23:06:48.122| ACLChecklist::preCheck: 0x1b484b8 checking 'url_rewrite_access allow user-agent'
2014/03/05 23:06:48.122| ACLList::matches: checking user-agent
2014/03/05 23:06:48.122| ACL::checklistMatches: checking 'user-agent'
2014/03/05 23:06:48.122| aclRegexData::match: checking 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)'
2014/03/05 23:06:48.122| aclRegexData::match: looking for 'regexp'
2014/03/05 23:06:48.122| aclRegexData::match: looking for 'compatible'
2014/03/05 23:06:48.122| aclRegexData::match: match 'compatible' found in 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)'
2014/03/05 23:06:48.122| ACL::ChecklistMatches: result for 'user-agent' is 1
2014/03/05 23:06:48.122| ACLList::matches: result is true


- acl user-agentにマッチしました。

2014/03/05 23:06:48.123| redirectHandleRead: {301:http://192.168.0.10/xp_support_end}
2014/03/05 23:06:48.123| clientRedirectDone: 'http://isearch.avg.com/search?cid={92C0A9A0-B5FA-4666-AA3E-8468500830E5}&mid=46e603d010b947d09f56d14ab9eab17c-1d89aade1dff4d4d9f2d896766c1c27f194cba33&lang=ja&ds=AVG&pr=fr&d=2012-10-25%2023:03:06&v=15.4.0.5&pid=avg&sg=0&sap=dsp&q=bbb' result=301:http://192.168.0.10/xp_support_end
2014/03/05 23:06:48.123| client_side_request.cc(1311) doCallouts: Doing calloutContext->clientAccessCheck2()
2014/03/05 23:06:48.123| client_side_request.cc(547) clientAccessCheck2: No adapted_http_access configuration.
2014/03/05 23:06:48.123| The request GET http://isearch.avg.com/search?cid={92C0A9A0-B5FA-4666-AA3E-8468500830E5}&mid=46e603d010b947d09f56d14ab9eab17c-1d89aade1dff4d4d9f2d896766c1c27f194cba33&lang=ja&ds=AVG&pr=fr&d=2012-10-25%2023:03:06&v=15.4.0.5&pid=avg&sg=0&sap=dsp&q=bbb is ALLOWED, because it matched 'user-agent'


- そのあとにリダイレクト処理が始まりましたが、
自宅環境だとリダイレクト先がうまく表示されませんでした。
(ログが多すぎてどこを切り取っていいかわからない… )


■Windows7で通信した時のデバッグログ

2014/03/05 23:07:00.379| ACLChecklist::preCheck: 0x1b484b8 checking 'url_rewrite_access allow user-agent'
2014/03/05 23:07:00.379| ACLList::matches: checking user-agent
2014/03/05 23:07:00.379| ACL::checklistMatches: checking 'user-agent'
2014/03/05 23:07:00.379| aclRegexData::match: checking 'Mozilla/5.0 (Windows NT 6.1; rv:27.0) Gecko/20100101 Firefox/27.0'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'regexp'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'compatible'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'MSIE 4\.0'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'MSIE 5\.0'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'MSIE 5\.5'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'MSIE 6\.'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'Mozilla\/3\.0'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'Windows NT 5\.'
2014/03/05 23:07:00.379| aclRegexData::match: looking for 'Windows 9'
2014/03/05 23:07:00.379| ACL::ChecklistMatches: result for 'user-agent' is 0
2014/03/05 23:07:00.379| ACLList::matches: result is false


- acl user-agentにマッチしませんでした。
ですから、そのままInternet上のWebページを見ることができます。


上記設定ですとWindowsXPは何もできなくなってしまいますので、
せめて自社ネットワークだけにでもつなげられる方法を調べます。

また、今回はsquidでしたが、apacheのプロキシでも同じことを
試しましたので、近々アップします。
久しぶりに書いてみました。

今年の初めごろにこんなのが届きました。

あいらぶLinux♪ あいらぶLinux♪

LPICの認定期限が5年なので、4年前に取得したLPIC302の認定期限が切れるそうです。

ただ、302まで持っているので、単純に303に合格すれば期限が更新されるのかなと思っていたら、そうではないようです。

LPIのサイトを確認したところ、303は302の上位資格ではないので、303に合格しても302の認定期限は更新されないとのことです。

再認定ポリシー
http://www.lpi.or.jp/examination/attention3.shtml


なので、認定期限を延長するには、302にもう一度合格しないといけないということです。
また、302、303、304を持っている人は、5年おきに全て合格し続けないと認定期限が切れてしまうみたいです。持っている人は更新するだけで大変そうです。