networkapp:waf:mod-security
差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン前のリビジョン次のリビジョン | 前のリビジョン | ||
networkapp:waf:mod-security [2018/10/30 15:31] – [Drop Modeの検証] seirios | networkapp:waf:mod-security [2018/11/14 17:00] (現在) – [MonitorModeWAF] seirios | ||
---|---|---|---|
行 3: | 行 3: | ||
NGINXを利用して、Proxy/ | NGINXを利用して、Proxy/ | ||
- | {{ : | ||
===== 構成 ===== | ===== 構成 ===== | ||
行 89: | 行 88: | ||
### ARP cache timeout | ### ARP cache timeout | ||
net.link.ether.inet.max_age=97 | net.link.ether.inet.max_age=97 | ||
+ | </ | ||
+ | |||
+ | セマフォの拡張はboot時に行う必要があるので、/ | ||
+ | <code - / | ||
+ | ### for WAF | ||
+ | kern.ipc.semmsl=340 # | ||
+ | kern.ipc.semmns=128000 # | ||
+ | kern.ipc.semopm=100 # | ||
+ | kern.ipc.semmni=512 # | ||
+ | |||
+ | kern.ipc.semaem=16384 # | ||
+ | kern.ipc.semvmx=32767 # | ||
+ | kern.ipc.semusz=632 # | ||
+ | kern.ipc.semume=50 # | ||
+ | kern.ipc.semmnu=150 # | ||
</ | </ | ||
行 99: | 行 113: | ||
</ | </ | ||
* '' | * '' | ||
- | |||
==== WAFのInstall ==== | ==== WAFのInstall ==== | ||
行 137: | 行 150: | ||
これで、NGINX+mod_security3のバイナリーがInstallされる。 | これで、NGINX+mod_security3のバイナリーがInstallされる。 | ||
+ | |||
+ | <WRAP round tip> | ||
+ | WAFを作成する場合に、logをHDDに書き出す場合、HDDの書き込み速度が律速になり、NGINX自体が遅くなることがある。 | ||
+ | しかし、WAFで、検査したRequestをできるだけ書き出したい場合もある。 | ||
+ | |||
+ | NGINXは、標準でsyslogにlogを書き出すことができるが、その場合、log文字数は2048文字でハードコードされている。\\ | ||
+ | ( '' | ||
+ | |||
+ | syslogは、仕様としてはlog文字長に制限はないが、FreeBSDの '' | ||
+ | (参照: [[serverapp: | ||
+ | |||
+ | この場合に、NGINXのlog文字列を増やし、かつ、Mod_Security3用の設定を毎回portsにて行うことは非常に面倒なので、portsを作成した。 | ||
+ | |||
+ | 以下、分かる人向け。 | ||
+ | |||
+ | BaseにしたNGINXは、個人の好みでnginx-develにした。気に入らない人は、Makefileを書き換えればnginxにもできる。 | ||
+ | |||
+ | '' | ||
+ | <code - Makefile> | ||
+ | # Created by: seirios | ||
+ | |||
+ | PORTNAME= | ||
+ | PKGNAMESUFFIX= | ||
+ | |||
+ | MAINTAINER= | ||
+ | COMMENT= | ||
+ | |||
+ | MASTERDIR= | ||
+ | |||
+ | CONFLICTS= | ||
+ | nginx-devel-1.* \ | ||
+ | nginx-full-1.* \ | ||
+ | nginx-naxsi-1.* | ||
+ | |||
+ | OPTIONS_DEFAULT=DSO FILE_AIO IPV6 THREADS WWW \ | ||
+ | HTTP HTTP_ADDITION HTTP_AUTH_REQ HTTP_CACHE HTTP_DAV HTTP_FLV \ | ||
+ | HTTP_GEOIP HTTP_REALIP HTTP_REWRITE HTTP_SSL HTTP_STATUS HTTPV2 \ | ||
+ | LUA MODSECURITY3 | ||
+ | |||
+ | .include " | ||
+ | </ | ||
+ | |||
+ | <code diff files/ | ||
+ | # cat files/ | ||
+ | --- src/ | ||
+ | +++ src/ | ||
+ | @@ -73,7 +73,7 @@ | ||
+ | }; | ||
+ | |||
+ | |||
+ | -#define NGX_MAX_ERROR_STR | ||
+ | +#define NGX_MAX_ERROR_STR | ||
+ | |||
+ | |||
+ | / | ||
+ | </ | ||
+ | あとは、通常通りmakeすれば良い。 | ||
+ | |||
+ | 見れば分かるが、基本 nginx-devel に依存し、参照するので、ngx_log.hが大幅に変更されない限り、継続して利用できるはずである。 | ||
+ | </ | ||
=== OWASP CRSのInstall === | === OWASP CRSのInstall === | ||
mod_security用のsignature dataは / | mod_security用のsignature dataは / | ||
行 146: | 行 219: | ||
</ | </ | ||
- | <WRAP tip> | + | < |
2018/ | 2018/ | ||
そのため、現在の段階では、以下の追加操作が必要になる。 | そのため、現在の段階では、以下の追加操作が必要になる。 | ||
行 158: | 行 231: | ||
この作業を行わないと、CRSの読み込みの段階で複数のエラーが発生して大ハマりすることになる。 | この作業を行わないと、CRSの読み込みの段階で複数のエラーが発生して大ハマりすることになる。 | ||
+ | |||
+ | なお、現在利用しているBranchを確認するには、'' | ||
</ | </ | ||
行 526: | 行 601: | ||
+- nginx -+- ... : FreeBSD portsによって作成される | +- nginx -+- ... : FreeBSD portsによって作成される | ||
+- modsec -+- MM-Base.conf | +- modsec -+- MM-Base.conf | ||
- | | +- MM.conf : MonitorMode WAF設定 | + | | +- MM0.conf |
- | | +- MM-preCRS.conf | + | | +- MM0-preLoad.conf : MonitorMode |
- | | +- MM-preLocal.conf : MonitorMode用local signature読み込み前設定 | + | | +- MM0-postLoad.conf : MonitorMode |
- | | +- MM-postCRS.conf | + | |
- | | +- MM-postLocal.conf : MonitorMode用local signature読み込み後設定 | + | |
| +- DM-Base.conf | | +- DM-Base.conf | ||
- | | +- DM.conf : DropMode WAF設定 | + | | +- DM0.conf |
- | | +- DM-preCRS.conf | + | | +- DM0-preLoad.conf : DropMode |
- | | +- DM-preLocal.conf : DropMode用local signature読み込み前設定 | + | | +- DM0-postLoad.conf : DropMode |
- | | +- DM-postCRS.conf | + | |
- | | +- DM-postLocal.conf : DropMode用local signature読み込み後設定 | + | |
+- conf.http | +- conf.http | ||
+- conf.http.d -+- ... : server/ | +- conf.http.d -+- ... : server/ | ||
行 552: | 行 623: | ||
* <code diff MonitorModeBase.conf.diff> | * <code diff MonitorModeBase.conf.diff> | ||
# diff -u ../ | # diff -u ../ | ||
- | --- ../ | + | --- ../ |
- | +++ MM-Base.conf | + | +++ MM-Base.conf |
@@ -35,7 +35,8 @@ | @@ -35,7 +35,8 @@ | ||
# to the size of data, with files excluded. You want to keep that value as | # to the size of data, with files excluded. You want to keep that value as | ||
行 620: | 行 691: | ||
# | # | ||
- | # ModSecurity configuration for DropMode. | + | # ModSecurity configuration for DetectMode. |
Include / | Include / | ||
- | # OWASP CRS configuration. | + | # Load signature |
Include / | Include / | ||
Include / | Include / | ||
# Preload of omitting signature | # Preload of omitting signature | ||
- | Include / | + | Include / |
- | Include / | + | |
- | # Include OWASP CRS Configurations and Signature Rules. | + | # Load Signature Rules. |
Include / | Include / | ||
Include / | Include / | ||
# Postload of omitting signature | # Postload of omitting signature | ||
- | Include / | + | Include / |
- | Include / | + | |
</ | </ | ||
- | - 以下、MM-(pre|post)(CRS|Local).confを作成する | + | - 以下、MM-(pre|post)Load.confを作成する |
- | - <code - MM-preCRS.conf> | + | - <code - MM-preLoad.conf> |
# | # | ||
- | # ModSecurity preload | + | # ModSecurity preload |
# | # | ||
- | # id: 1000 - 2999 | + | # id: 1000 - 1999 : for OWASP CRS |
+ | # id: 2000 - 2999 : Reserve | ||
+ | # id: 3000 - 4999 : for local Sigs | ||
#SecAction " | #SecAction " | ||
- | |||
- | # ModSecurity BUG. fixed at 3.1.0. | ||
- | #SecAction " | ||
</ | </ | ||
- | - <code - MM-preLocal.conf> | + | - <code - MM-postLoad.conf> |
# | # | ||
- | # ModSecurity | + | # ModSecurity |
# | # | ||
- | # id: 3000 - 4999 | + | # id: 5000 - 5999 : for OWASP CRS |
+ | # id: 6000 - 6999 : Reserve | ||
+ | # id: 7000 - 8999 : for local Sigs | ||
- | #SecAction " | + | #SecRuleRemoveById |
- | </ | + | |
- | - <code - MM-postCRS.conf> | + | |
- | # | + | |
- | # ModSecurity postload omitting signatures for OWASP CRS | + | |
- | # | + | |
- | # id: 5000 - 6999 | + | |
- | + | ||
- | #SecAction " | + | |
- | </ | + | |
- | - <code - MM-postLocal.conf> | + | |
- | # | + | |
- | # ModSecurity postload omitting signatures for OWASP CRS | + | |
- | # | + | |
- | # id: 7000 - 8999 | + | |
- | + | ||
- | #SecAction " | + | |
</ | </ | ||
これで、MonitorMode WAFの設定ファイルが完成。 | これで、MonitorMode WAFの設定ファイルが完成。 | ||
- | |||
=== DropModeWAF === | === DropModeWAF === | ||
- 次にDropMode WAFを構築する。 | - 次にDropMode WAFを構築する。 | ||
行 699: | 行 752: | ||
これで、DropMode WAFの構築も終了。 | これで、DropMode WAFの構築も終了。 | ||
- | <WRAP info> | + | < |
なお、実際には、MonitorModeは検出のみだから全Signatureを利用していても性能が劣化する程度で済むことが多いが、DropModeの場合は、preLoadやPostloadの設定で、不要なSignatureをOffにする、もしくは重みつけを0にする必要があることに注意。 | なお、実際には、MonitorModeは検出のみだから全Signatureを利用していても性能が劣化する程度で済むことが多いが、DropModeの場合は、preLoadやPostloadの設定で、不要なSignatureをOffにする、もしくは重みつけを0にする必要があることに注意。 | ||
- | preCRSやPostCRSを作成してあるのはそのため。 | + | preLoadやPostLoadを作成してあるのはそのため。 |
</ | </ | ||
行 827: | 行 880: | ||
# ID | # ID | ||
- | # 1000-2999: Preload | + | # 1000-1999: Preload |
- | # 3000-4999: Preload | + | # 2000-3999: Reserve |
- | # 5000-6999: Postload ommiting signature list of OWASP CRS | + | # 4000-4999: Preload |
- | # 7000-8999: | + | # 5000-5999: Preload for OWASP CRS |
+ | # 6000-7999: Reserve | ||
+ | # 8000-8999: | ||
# 10000-10999: | # 10000-10999: | ||
# 11000-11999: | # 11000-11999: |
networkapp/waf/mod-security.txt · 最終更新: 2018/11/14 17:00 by seirios