(IT) 新手の攻撃とその対策

<現象編>
先日(2015/10/19)の攻撃は、中国やマレーシアなどいろいろな国のマシンから
一斉に、このblogが乗ってるwebサーバーの「0jejhcec65c24dslii.com」と
いう名前のサイト(当然存在しない)の「#320」みたいなありもしない
ページ内リンクへのアクセスがしこたま来てた。
access_logはこんな感じ。

117.169.1.140 – – [19/Oct/2015:19:51:54 +0900] “GET /#101 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
177.99.87.146 – – [19/Oct/2015:19:52:07 +0900] “GET /#432 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
124.200.250.22 – – [19/Oct/2015:19:51:50 +0900] “GET /#22 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
114.26.14.87 – – [19/Oct/2015:19:52:07 +0900] “GET /#345 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
190.42.61.126 – – [19/Oct/2015:19:52:08 +0900] “GET /#326 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
91.121.153.214 – – [19/Oct/2015:19:51:54 +0900] “GET /#237 HTTP/1.0” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
113.204.212.50 – – [19/Oct/2015:19:51:50 +0900] “GET /#225 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”
117.169.6.138 – – [19/Oct/2015:19:51:39 +0900] “GET /#220 HTTP/1.1” 500 263 “http://0jejhcec65c24dslii.com” “Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)”

ログを更に見てみると、数分後にこんなエラーが1秒に1回出てた。
存在しないページ内リンク(アンカー)を探しに行くと、apacheの子プロセスが
起動されて、CPUやらメモリやらの資源を食い潰しているのか。

::1 – – [19/Oct/2015:19:55:01 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:04 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:04 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:05 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:06 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:07 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:08 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:09 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”
::1 – – [19/Oct/2015:19:55:10 +0900] “OPTIONS * HTTP/1.0” 200 – “-” “Apache/2.2.15 (CentOS) (internal dummy connection)”

error_logも一応確認したけど、あまりめぼしいものがなくて、タイムスタンプが
近いものとしては、こんなのだけかな。

[Mon Oct 19 19:53:01 2015] [error] server reached MaxClients setting, consider raising the MaxClients setting

<対策編>(Special Thanks to「インフラ部」)
(1)意図しない名前でアクセスされた場合、反応しないための記述。
httpd.confのVirtualHostの先頭にdummyエントリを追加。
今回の大量アクセスは、IPアドレスで到達するけど、ターゲットのサーバー名が
「0jejhcec65c24dslii.com」という存在しないサーバー名宛てに来てたので。

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80
#
<VirtualHost _default_>
ServerName dummy
DocumentRoot /var/www/dummy
<Directory /var/www/dummy>
Order Allow,Deny
</Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin “anonymous@hogehoge”
    DocumentRoot “/foo/bar”
    ServerName www.ryoshr.net
(続く・・・)

(2)「#」で始まるページ内リンクを動作させない。
.htaccessでもいいみたいけど、httpd.confに追記。

<VirtualHost *:80>
    ServerAdmin “anonymous@hogehoge”
    DocumentRoot “/foo/bar”
    ServerName www.ryoshr.net
    ErrorLog logs/hogehoge_error_log
    CustomLog logs/hogehoge_access_log combined
    RewriteEngine On
    RewriteCond %{THE_REQUEST} /#
    RewriteRule .* – [F,L]
</VirtualHost>

(3)その他パラメータを調整。
MaxClient値を半分に(256→128)
MaxRequestsPerChild値を2.5倍に(4000→10000)

(4)Fail2Banをインストール

間違ってたら、ご指摘ください。

コメントを残す

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

CAPTCHA