昨今、Webサービスへの不正アクセスが大人気のようです。
当方の場末のサーバでも、アクセスログを見てると不正アクセスの痕跡が散見されるんで
WAF(Web Application Firewall)であるmod_securityを導入してみました。
なお、mod_securityはApacheモジュールの1つです。
■設定環境
OS :CentOS6.4 64bit
Apache :httpd-2.2.15
mod_security :2.7.3
mod_security_crs :2.2.6
1. mod_securityのインストール
mod_secrity本体とcore Rule Set(CRS)をインストールします。
なお、epelリポジトリは事前にインストールしておく必要があります。
# yum install mod_security_crs mod_security Loaded plugins: fastestmirror, priorities Determining fastest mirrors epel/metalink | 6.3 kB 00:00 * epel: ftp.kddilabs.jp * extras: www.ftp.ne.jp * rpmforge: ftp.kddilabs.jp base | 3.7 kB 00:00 epel | 3.9 kB 00:00 epel/primary_db | 5.1 MB 00:00 extras | 3.5 kB 00:00 rpmforge | 1.9 kB 00:00 updates | 3.5 kB 00:00 93 packages excluded due to repository priority protections Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package mod_security.x86_64 0:2.7.3-1.el6 will be installed --> Processing Dependency: httpd-mmn = 20051115 for package: mod_security-2.7.3-1.el6.x86_64 ---> Package mod_security_crs.noarch 0:2.2.6-3.el6 will be installed --> Running transaction check --> Finished Dependency Resolution Dependencies Resolved ======================================================================= Package Arch Version Repository Size ======================================================================= Installing: mod_security x86_64 2.7.3-1.el6 epel 168 k mod_security_crs noarch 2.2.6-3.el6 epel 92 k ~~~~~省略~~~~~ Complete!
2. mod_securityの基本設定
通常は設定を変更する必要はありませんが、下記サイトが詳しく説明いただいてますんで
各自の環境に合う設定をした方が良いと思います。
http://open-groove.net/modsecurity/modsecurity-basic-config/
# vi /etc/httpd/conf.d/mod_security.conf 基本ルールセット以外に独自ルールセットを格納したい場合 Include modsecurity.d/*.conf Include modsecurity.d/activated_rules/*.conf バッファ・メモリの設定 SecRequestBodyLimit 131072 SecRequestBodyNoFilesLimit 131072 SecRequestBodyInMemoryLimit 131072
3. ホワイトリストの作成
mod_securityでフィルタリングしないローカルネットワーク(127.0.0.1と192.168.0.0/16)を追加します
# vi /etc/httpd/modsecurity.d/whitelist.conf SecRule REMOTE_ADDR "^127.0.0.1$" "phase:1,nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off,id:2013051201" SecRule REMOTE_ADDR "^192.168" "phase:1,nolog,allow,ctl:ruleEngine=Off,ctl:auditEngine=Off,id:2013051202"
ModSecurity Changes
Posted on December 27, 2012 by Sarah
http://cpanel.net/modsecurity-changes/
最近のmod_securityでは、idを追加しないとエラーがでます(apacheの起動に失敗します)
4. mod_securityの開始
apacheを再起動してmod_securityを開始(設定を反映)します
# /etc/rc.d/init.d/httpd restart httpd を停止中: [ OK ] httpd を起動中: [ OK ]
番外編1
# apachectl configtest
Syntax error on line 59 of /etc/httpd/conf.d/mod_security.conf:
ModSecurity: No action id present within the rule
設定されているルールセットの構文が間違ってます。
上記エラー内容だと、”/etc/httpd/conf.d/mod_security.conf”の59行目が間違えてます。
番外編2
# cat /var/log/httpd/modsec_audit.log --c5fa547b-A-- [11/May/2013:00:00:00 +0900] UY5fJ38AAAEAAC0NCIkAAAAg 123.156.77.174 62329 192.168.0.1 80 --c5fa547b-B-- POST /wordpress/wp-comments-post.php HTTP/1.0 Accept: */* User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.1634 Safari/535.19 YI Referer: https://www.isoppe.jp/?p=2585+%5BPLM=0%5D+GET+https://www.isoppe.jp/?p=2585 Content-Type: application/x-www-form-urlencoded Host: www.ys-network.info Content-Length: 3259 Pragma: no-cache --c5fa547b-C-- author=ypbodker&email=couugmyh%40zyet.com&url=http ~~~省略~~~ ateikakaku.html><%2Fa>%0D%0A&submit=%E3%82%B3%E3%83%A1%E3%83%B3%E3%83%88%E3%82%92%E9%80%81%E4%BF%A1&comment_post_ID= --c5fa547b-F-- HTTP/1.1 403 Forbidden Content-Length: 317 Connection: close Content-Type: text/html; charset=iso-8859-1 --c5fa547b-E-- --c5fa547b-H-- Message: Access denied with code 403 (phase 2). Pattern match "(?i:(?:union\\s*?(?:all|distinct|[(!@]*?)?\\s*?[([]*?\\s*?select) ~~~省略~~~ [file "/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf"] [line "234"] [id "981245"] [msg "Detects basic SQL authentication bypass attempts 2/3"] ~~~省略~~~ Action: Intercepted (phase 2) Apache-Handler: php5-script Stopwatch: 1368284967538688 208542 (- - -) Stopwatch2: 1368284967538688 208542; combined=30202, p1=304, p2=29861, p3=0, p4=0, p5=36, sr=79, sw=1, l=0, gc=0 Response-Body-Transformed: Dechunked Producer: ModSecurity for Apache/2.7.3 (http://www.modsecurity.org/); OWASP_CRS/2.2.6. Server: Apache/2.2.15 (CentOS) Engine-Mode: "ENABLED" --c5fa547b-Z--
上記のログからすると
ルールセット”/etc/httpd/modsecurity.d/activated_rules/modsecurity_crs_41_sql_injection_attacks.conf”にある
“id 981245″に該当するからアクセスを拒否した
とあります。誤爆なら修正しましょう
===============================================================
4月は気絶してました。
昇格したってのに、昇給額が24歳(前年度の新卒)と同額とはどういうことでしょうか。
会社が傾いてるとか、前年度が赤字とかだったらわかりますが・・・。イミガワカリマセン