Hatena::ブログ(Diary)

てけらぼ このページをアンテナに追加 RSSフィード

人生ブレまくり

2006-07-28 SPAM!SPAM!SPAM!

[][]mod_securityなんてのが

アクセスパターンを細かく見て排除できるそうです。

mod_antihackなんてのを昔入れてたんですがその発展系?

アプリケーションサーバスクリプトエンジンで排除するテクニックを使うのはコスト的に好きじゃないので、できるだけ水際に近いところで排除ということでポイント高い。

http://gigazine.net/index.php?/news/comments/20060713_mod_security/

http://www.softek.co.jp/Sec/mod_security1.html

http://hp.vector.co.jp/authors/VA027424/mod_security/v_1_9_stable_ja_.html

ブラックリストもあり、だそうで。

http://www.gotroot.com/tiki-index.php?page=mod_security+rules

入れてみるかどうするか。

[][]libapache2-mod-security 1.8.7-1

Debianな鯖に入れてみる。

/etc/apache2/mod_securityというディレクトリを掘って、先のブラックリスト/ルール集のconfファイルを入れる。/etc/apache2/mods-available/mod-security.loadに対するsymlinkをmods-enabledに張る。mod-security.confを作る。同じようにsymlinkを張る。

内容はとりあえずほぼサンプルどおり。

apache2再起動

Syntax error on line 37 of /etc/apache2/mod_security/exclude.conf:
Invalid command 'SecFilterRemove', perhaps mis-spelled or defined by a module not included in the server configuration

あれ....

Debian的には違うのか。

echo 'Include /usr/share/doc/mod-security-common/examples/httpd2.conf.example-full' > /etc/apache2/conf.d/mod-security.conf

で、テストして見ろと。

# cd /usr/share/mod-security/tests
# ./run-test.pl localhost *.test

Test "01 Simple keyword filter": OK
Test "02 Self referencing directories": OK
Test "03 Evasion via path traversal": OK
Test "04 Evasion via a double slash in the path": OK
Test "05 Mixed case addresses": OK
Test "06 Evasion via URL encoding": OK
Test "07 Special characters in the path": OK
Test "08 Invalid URI encoding in parameters": OK
Test "09 Directory traversal in parameters": OK
Test "10 Keyword in POST": OK
Test "11 XSS attack": OK
Test "12 HTML forbidden": OK
Test "13 SQL injection": OK
Test "14 Redirect action (requires 302)": OK
Test "15 Not an attack (requires 200)": OK
Test "16 Request without Host header": OK
Test "17 Request without User-Agent header": OK
Test "18 Keyword in POST only": OK
Test "19 Keyword in POST only, negative (requires 200)": OK
Test "20 Keyword in QUERY_STRING only": OK
Test "21 Keyword in QUERY_STRING only, negative (requires 200)": OK
Test "22 Keyword in ARGS, method GET": OK
Test "23 Keyword in ARGS, method POST": OK
Test "24 Keyword in single variable": OK
Test "25 Keyword in single variable, negative (requires 200)": OK
Test "26 Keyword variable exclusion (requires 200)": OK
Test "27 Keyword variable exclusion, negative": OK
Test "28 Simple keyword inverted pattern": OK
Test "29 Filter variable names": OK
Test "30 Filter variable values": OK
Test "31 Test for the URL encoding plus bug": OK
Test "32 SQL injection 2: SELECT test": OK
Test "33 XSS attack 2": OK
Test "34 Invalid byte range in parameters": OK
Test "35 Invalid byte range in the URL": OK
Test "37 URL decoding bug 2": OK
Test "38 Unicode test 1": OK
Test "39 Unicode test 2": OK
Test "40 Unicode test 3": OK
Test "41 post variable parsing bug test #1 (requires 200)": OK
Test "42 post variable parsing bug test #2": OK
Test "43 post range check bug": OK
Test "44 normalisation bug": OK
Test "45 null byte attack": OK
Test "43 multipart/form-data test": OK
Test "47 test action "allow" (requires 200)": OK
Test "48 chained rules test #1": OK
Test "49 chained rules test #2 (requires 200)": OK
Test "50 chained rules test #3 (requires 200)": OK
Test "51 skipnext test 1, without a parameter (requires 200)": OK
Test "52 skipnext test2 , with a parameter (requires 200)": OK
Test "53 named cookie test": OK
Test "54 named cookie test, positive (requires 200)": OK
Test "55 cookie names test": OK
Test "56 cookie values test": OK
Test "57 regex hex escape test": Failed (status = 200)
Test "69 bug false url encoding valudation test (requires 200)": Failed (status = 500)
Test "70 bug bad ARGS filtering (requires 200)": Failed (status = 500)

最後3つFailedと出てるけどどうなんだろう。

アクセスして見ると実害なさそうなので経過観察。

[][]と思ったら、w3cのバリデータが蹴られるらしい

[Fri Jul 28 21:03:51 2006] [error] [client 128.30.52.13] mod_security: Access denied with code 500. Pattern match "!(mod_security|mozilla)" at HEADER [hostname "www.****.net"] [uri "/****/index.html"]

や、困りましたね。exclude.conf設定しないといけない?

答えは簡単だった。

    # Only allow our own test utility to send requests (or Mozilla)
    SecFilterSelective HTTP_USER_AGENT "!(mod_security|mozilla|w3c)"

のように、UAにw3cバリデータがくるときに入れる、"w3c"を入れれば良いと。

しかし他にもなんか、蹴りそうなUAがある気がする。細かく調整が必要だろうなぁ。

[][]とはいっても

ここに出てくるような偽装UAは....

http://members.at.infoseek.co.jp/g_ua/

ダメ過ぎなのが多い(汗

さしあたり、ここをざっと流す。あんましマイナーなクローラとか明らかにおかしいのは排除。

http://x68000.q-e-d.net/~68user/cgi-bin/view-browser.cgi