Linux Security: 第8章 - Apache HTTPD のキュリティ

| ← |

8.3 Apache モジュールの確認

# apachectl -t -D DUMP_MODULES
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 	:
DBMSの詳細確認
MySQL
$ mysql --version .... MySQL Client バージョン
mysql  Ver 14.12 Distrib 5.0.95, for redhat-linux-gnu (i386) using readline 5.1

$ mysql -u root -phimitu
mysql> select version();
+-----------+
| version() |
+-----------+
| 5.0.95    |
+-----------+
1 row in set (0.00 sec)
PostgreSQL
$ psql

Welcome to psql, the PostgreSQL interactive terminal.

Type: \copyright for distribution terms
\h for help with SQL commands
\? for help on internal slash commands
\g or terminate with semicolon to execute query
\q to quit


test=# SELECT version();
version
-------------------------------------------------------------
PostgreSQL 7.1.3 on i686-pc-linux-gnu, compiled by GCC 2.96
(1 row)

言語プロセッサの詳細確認

8.5 基本認証

tcpdump によるクラッキング例
# tcpdump -l -X -s 3000 -i eth1 
				:
14:08:18.118627 IP hppc.53511 > vbox1.http: P 1:337(336) ack 1 win 16425
        0x0000:  4500 0178 478d 4000 8006 029e c0a8 9701  E..xG.@.........
        0x0010:  c0a8 9702 d107 0050 f48b 2dcf 63f6 9e87  .......P..-.c...
        0x0020:  5018 4029 236e 0000 4745 5420 2f62 6173  P.@)#n..GET./bas
        0x0030:  6963 2f20 4854 5450 2f31 2e31 0d0a 486f  ic/.HTTP/1.1..Ho
        0x0040:  7374 3a20 3139 322e 3136 382e 3135 312e  st:.192.168.151.
        0x0050:  320d 0a55 7365 722d 4167 656e 743a 204d  2..User-Agent:.M
				:
        0x0110:  713d 302e 330d 0a41 6363 6570 742d 456e  q=0.3..Accept-En
        0x0120:  636f 6469 6e67 3a20 677a 6970 2c20 6465  coding:.gzip,.de
        0x0130:  666c 6174 650d 0a43 6f6e 6e65 6374 696f  flate..Connectio
        0x0140:  6e3a 206b 6565 702d 616c 6976 650d 0a41  n:.keep-alive..A
	0x0150:  7574 686f 7269 7a61 7469 6f6e 3a20 4261  uthorization:.Ba
	0x0160:  7369 6320 6333 5268 5a6d 5936 6147 6c74  sic.c3RhZmY6aGlt
	0x0170:  6158 5231 0d0a 0d0a                      aXR1....
				:
$ echo "c3RhZmY6aGltaXR1" | perl -MMIME::Base64 -ne 'print decode_base64($_)."\n"'
staff:himitu

8.6 ダイジェスト認証

アクセス時にサーバから以下の情報が送信される。
Name解説
realmレルム(領土)値、AuthName で指定したもの
nonce乱数
algorithmダイジェストアルゴリズム
qopQuality of Protection,保証する範囲。
auth:認証のみ、auth-int:電文を含めた認証
これを受け、クライアント側では以下の値を生成し返信する。
Name解説
usernameユーザ名
realmサーバから送られてきた値をそのまま返信
nonce(同上)
algorithm(同上)
qopサーバから送られてきた値を選択して返信。auth
uriURL値。http://server/secret/ → /secret/
nc連番、00000001〜
cnonceクライアントで生成した乱数。
responseMD5(R1:nonce:nc:cnonce:qop:R2)
 R1=MD5(USERNAME:realm:PASSWORD)
 R2=MD5(Method:uri)
..
---
HTTP/1.1 401 Authorization Required
Date: Mon, 06 Aug 2012 08:44:26 GMT
Server: Apache
WWW-Authenticate: Digest realm="User staff only",
 nonce="bmyn4pTGBAA=ac87fd122df9e89d805dfa5561a5a4bc6e413ceb",
 algorithm=MD5, qop="auth"
Content-Length: 505
Connection: close
Content-Type: text/html; charset=iso-8859-1
--
GET /digest/ HTTP/1.0
Host: 192.168.151.2
Authorization: Digest username="staff",  realm="User staff only",
 nonce="E7w/0pTGBAA=f072f2b77bcf61749a8942bf0abb556a86c87ff2",
 uri="/digest/", algorithm=MD5, response="93f631a1fb80f472e800d7b19a62e0a4",
 qop=auth, nc=00000001, cnonce="e79e26e0d17c978d"

補足)
R1="staff:User staff only:himitu" = d415be7f72d215007be2011ede6a1b02
R2="GET:/digest/" = 9942091bc79111e32fecde3962416017
response= R1:E7w/0pTGBAA=f072f2b77bcf61749a8942bf0abb556a86c87ff2:00000001:e79e26e0d17c978d:auth:R2
= 93f631a1fb80f472e800d7b19a62e0a4
$ echo -n "staff:User staff only:himitu" | md5sum 
d415be7f72d215007be2011ede6a1b02 -

8.9 .htaccessの制限

httpd.conf:
<Directory /home/*/public_html>
   AllowOverride FileInfo AuthConfig Limit Options=Includes,FollowSymLinks,Indexes
</Directory /home/*/public_html>

~/public_html/.htaccess:
Options -Includes
許可されていない Options を指定すると、エラーとなる。
[Mon Aug 06 20:04:39 2012] [alert] [client 192.168.151.1] /home/student/public_
html/.htaccess: Option ExecCGI not allowed here

8.10 CGI利用の注意

AddHandler .cgi を設定した場合、~user/ 下の CGI は、suEXEC の管理下となる。
# /usr/sbin/suexec -V
 -D AP_DOC_ROOT="/var/www"
 -D AP_GID_MIN=100
 -D AP_HTTPD_USER="apache"
 -D AP_LOG_EXEC="/var/log/httpd/suexec.log"
 -D AP_SAFE_PATH="/usr/local/bin:/usr/bin:/bin"
 -D AP_UID_MIN=500
 -D AP_USERDIR_SUFFIX="public_html"

# head /var/log/httpd/suexec.log
[2012-07-20 18:14:33]: uid: (500/student) gid: (500/500) cmd: a.cgi
[2012-07-20 18:14:33]: directory is writable by others: (/home/student/public_html)
[2012-07-20 18:15:46]: uid: (500/student) gid: (500/500) cmd: a.cgi
[2012-07-20 18:15:46]: file is writable by others: (/home/student/public_html/a.cgi)

SSL/TLS 認証

→ 13章にて詳しく解説

その他

Apache のバナー