転載・引用について

ユーザ用ツール

サイト用ツール


networkapp:waf:mod-security

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

両方とも前のリビジョン前のリビジョン
次のリビジョン
前のリビジョン
networkapp:waf:mod-security [2018/10/30 15:30] – [Monitor Modeの検証] seiriosnetworkapp:waf:mod-security [2018/11/14 17:00] (現在) – [MonitorModeWAF] seirios
行 3: 行 3:
 NGINXを利用して、Proxy/Signature型のWAFを構築する。 NGINXを利用して、Proxy/Signature型のWAFを構築する。
  
-{{ :construct.gif?400 |}} 
 ===== 構成 ===== ===== 構成 =====
  
行 89: 行 88:
 ### ARP cache timeout ### ARP cache timeout
 net.link.ether.inet.max_age=97 net.link.ether.inet.max_age=97
 +</code>
 +
 +セマフォの拡張はboot時に行う必要があるので、/boot/loader.confに記述
 +<code - /boot/loader.conf>
 +### for WAF
 +kern.ipc.semmsl=340 # 340 : max # of semaphores per id
 +kern.ipc.semmns=128000 # 340 : # of semaphores in system
 +kern.ipc.semopm=100 # 100 : max # of operations per semop call
 +kern.ipc.semmni=512 # 50  : # of semaphore identifiers
 +
 +kern.ipc.semaem=16384 # 16384 : adjust on exit max value
 +kern.ipc.semvmx=32767 # 32767 : semaphore maximum value
 +kern.ipc.semusz=632 # 632   : size in bytes of undo structure
 +kern.ipc.semume=50 # 50    : max # of undo entries per process
 +kern.ipc.semmnu=150 # 150   : # of undo structures in system
 </code> </code>
  
行 99: 行 113:
 </code> </code>
   * ''mount -a''を実行   * ''mount -a''を実行
- 
 ==== 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文字でハードコードされている。\\
 +( ''src/core/ngx_log.h'' に ''NGX_MAX_ERROR_STR 2048'' として記述されている。 )
 +
 +syslogは、仕様としてはlog文字長に制限はないが、FreeBSDの ''syslogd'' の場合、2048文字までしか受け付けないようになっているが、remote log systemに ''fluentd'' を利用する場合、logの文字数の制限は事実上撤廃することが可能。
 +(参照: [[serverapp:logging:fluentd|Fluentd]])
 +
 +この場合に、NGINXのlog文字列を増やし、かつ、Mod_Security3用の設定を毎回portsにて行うことは非常に面倒なので、portsを作成した。
 +
 +以下、分かる人向け。
 +
 +BaseにしたNGINXは、個人の好みでnginx-develにした。気に入らない人は、Makefileを書き換えればnginxにもできる。
 +
 +''ports/www/nginx-nginx-modsec3-logextend'' 及び ''ports/www/nginx-nginx-modsec3-logextend/files''を作成
 +<code - Makefile>
 +# Created by: seirios
 +
 +PORTNAME=       nginx
 +PKGNAMESUFFIX=  -modsec3-logextend
 +
 +MAINTAINER=     seirios@seirios.org
 +COMMENT=        Robust and small WWW server (mod_security3 and syslog buffer extended)
 +
 +MASTERDIR=      ${.CURDIR}/../nginx-devel
 +
 +CONFLICTS=      nginx-1.* \
 +                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 "${MASTERDIR}/Makefile"
 +</code>
 +
 +<code diff files/extra-patch-src-core-ngx_log.h>
 +# cat files/extra-patch-src-core-ngx_log.h
 +--- src/core/ngx_log.h.orig     2018-10-30 18:59:30.293977000 +0900
 ++++ src/core/ngx_log.h  2018-10-30 18:59:46.430785000 +0900
 +@@ -73,7 +73,7 @@
 + };
 +
 +
 +-#define NGX_MAX_ERROR_STR   2048
 ++#define NGX_MAX_ERROR_STR   8192
 +
 +
 + /*********************************/
 +</code>
 +あとは、通常通りmakeすれば良い。
 +
 +見れば分かるが、基本 nginx-devel に依存し、参照するので、ngx_log.hが大幅に変更されない限り、継続して利用できるはずである。
 +</WRAP>
 === OWASP CRSのInstall === === OWASP CRSのInstall ===
 mod_security用のsignature dataは /usr/local/wafに置くことにする mod_security用のsignature dataは /usr/local/wafに置くことにする
行 146: 行 219:
 </code> </code>
  
-<WRAP tip>+<WRAP round tip>
 2018/10/26現在、Releaseされているmod_securityは、3.0.2だが、OWASP CRSのHEADは''v3.2/dev''であり、このCRSは、mod_security 3.1.0にて追加される機能を仮定している。\\ 2018/10/26現在、Releaseされているmod_securityは、3.0.2だが、OWASP CRSのHEADは''v3.2/dev''であり、このCRSは、mod_security 3.1.0にて追加される機能を仮定している。\\
 そのため、現在の段階では、以下の追加操作が必要になる。 そのため、現在の段階では、以下の追加操作が必要になる。
行 158: 行 231:
  
 この作業を行わないと、CRSの読み込みの段階で複数のエラーが発生して大ハマりすることになる。 この作業を行わないと、CRSの読み込みの段階で複数のエラーが発生して大ハマりすることになる。
 +
 +なお、現在利用しているBranchを確認するには、''git branch -v''を実行すること
 </WRAP> </WRAP>
  
行 526: 行 601:
                         +- nginx -+- ...                               : FreeBSD portsによって作成される                         +- nginx -+- ...                               : FreeBSD portsによって作成される
                                   +- modsec -+- MM-Base.conf           : MonitorMode用基本設定                                   +- modsec -+- MM-Base.conf           : MonitorMode用基本設定
-                                  |          +- MM.conf                : MonitorMode WAF設定 +                                  |          +- MM0.conf               : MonitorMode WAF#0 設定 
-                                  |          +- MM-preCRS.conf         : MonitorMode用OWASP CRS読み込み前設定 +                                  |          +- MM0-preLoad.conf       : MonitorMode WAF#0rule読み込み前設定 
-                                  |          +- MM-preLocal.conf       : MonitorMode用local signature読み込み前設定 +                                  |          +- MM0-postLoad.conf      : MonitorMode WAF#0rule読み込み後設定
-                                  |          +- MM-postCRS.conf        : MonitorMode用OWASP CRS読み込み後設定 +
-                                  |          +- MM-postLocal.conf      : MonitorMode用local signature読み込み後設定+
                                   |          +- DM-Base.conf           : DropMode用基本設定                                   |          +- DM-Base.conf           : DropMode用基本設定
-                                  |          +- DM.conf                : DropMode WAF設定 +                                  |          +- DM0.conf               : DropMode WAF#0 設定 
-                                  |          +- DM-preCRS.conf         : DropMode用OWASP CRS読み込み前設定 +                                  |          +- DM0-preLoad.conf       : DropMode WAF#0rule読み込み前設定 
-                                  |          +- DM-preLocal.conf       : DropMode用local signature読み込み前設定 +                                  |          +- DM0-postLoad.conf      : DropMode WAF$0rule読み込み後設定
-                                  |          +- DM-postCRS.conf        : DropMode用OWASP CRS読み込み後設定 +
-                                  |          +- DM-postLocal.conf      : DropMode用local signature読み込み後設定+
                                   +- conf.http                         : http configuration                                   +- conf.http                         : http configuration
                                   +- conf.http.d -+- ...               : server/location configuration                                   +- conf.http.d -+- ...               : server/location configuration
行 552: 行 623:
       * <code diff MonitorModeBase.conf.diff>       * <code diff MonitorModeBase.conf.diff>
 # diff -u ../../modsecurity/modsecurity.conf.sample MM-Base.conf # diff -u ../../modsecurity/modsecurity.conf.sample MM-Base.conf
---- ../../modsecurity/modsecurity.conf.sample   2018-10-03 16:25:08.000000000 +0900 +--- ../../modsecurity/modsecurity.conf.sample   2018-11-04 09:12:19.000000000 +0900 
-+++ MM-Base.conf        2018-10-26 14:40:57.052583000 +0900++++ MM-Base.conf        2018-11-14 16:54:42.293424000 +0900
 @@ -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 /usr/local/etc/nginx/modsec/MM-Base.conf Include /usr/local/etc/nginx/modsec/MM-Base.conf
  
-OWASP CRS configuration.+Load signature configuration
 Include /usr/local/waf/owasp-modsecurity-crs/crs-setup.conf Include /usr/local/waf/owasp-modsecurity-crs/crs-setup.conf
 Include /usr/local/waf/local-modsecurity-sigs/local-setup.conf Include /usr/local/waf/local-modsecurity-sigs/local-setup.conf
  
 # Preload of omitting signature # Preload of omitting signature
-Include /usr/local/etc/nginx/modsec/MM-preCRS.conf +Include /usr/local/etc/nginx/modsec/MM-preLoad.conf
-Include /usr/local/etc/nginx/modsec/MM-preLocal.conf+
  
-Include OWASP CRS Configurations and Signature Rules.+Load Signature Rules.
 Include /usr/local/waf/owasp-modsecurity-crs/rules/*.conf Include /usr/local/waf/owasp-modsecurity-crs/rules/*.conf
 Include /usr/local/waf/local-modsecurity-sigs/rules/*.conf Include /usr/local/waf/local-modsecurity-sigs/rules/*.conf
  
 # Postload of omitting signature # Postload of omitting signature
-Include /usr/local/etc/nginx/modsec/MM-postCRS.conf +Include /usr/local/etc/nginx/modsec/MM-postLoad.conf
-Include /usr/local/etc/nginx/modsec/MM-postLocal.conf+
 </code> </code>
-  - 以下、MM-(pre|post)(CRS|Local).confを作成する +  - 以下、MM-(pre|post)Load.confを作成する 
-    - <code - MM-preCRS.conf>+    - <code - MM-preLoad.conf>
 # #
-# ModSecurity preload omitting signatures for OWASP CRS+# ModSecurity preload configuration.
 # #
-# id: 1000 - 2999+# id: 1000 - 1999 : for OWASP CRS 
 +# id: 2000 - 2999 : Reserve 
 +# id: 3000 - 4999 : for local Sigs
  
 #SecAction "id:'1000',phase:1,t:none,pass,nolog,ctl:ruleRemoveById=900000" #SecAction "id:'1000',phase:1,t:none,pass,nolog,ctl:ruleRemoveById=900000"
- 
-# ModSecurity BUG. fixed at 3.1.0. 
-#SecAction "id:'1001',phase:1,t:none,pass,nolog,ctl:ruleRemoveById=901350" 
 </code> </code>
-    - <code - MM-preLocal.conf>+    - <code - MM-postLoad.conf>
 # #
-# ModSecurity preload omitting signatures for Local signatures.+# ModSecurity postload configuration.
 # #
-# id: 3000 4999+# id: 5000 5999 : for OWASP CRS 
 +# id: 6000 - 6999 : Reserve 
 +# id: 7000 - 8999 : for local Sigs
  
-#SecAction "id:'3000',phase:1,t:none,pass,nolog,ctl:ruleRemoveById=10000" +#SecRuleRemoveById 900000
-</code> +
-    - <code - MM-postCRS.conf> +
-+
-# ModSecurity postload omitting signatures for OWASP CRS +
-+
-# id: 5000 - 6999 +
- +
-#SecAction "id:'5000',phase:1,t:none,pass,nolog,ctl:ruleRemoveById=900000+
-</code> +
-    - <code - MM-postLocal.conf> +
-+
-# ModSecurity postload omitting signatures for OWASP CRS +
-+
-# id: 7000 - 8999 +
- +
-#SecAction "id:'7000',phase:1,t:none,pass,nolog,ctl:ruleRemoveById=10000"+
 </code> </code>
  
 これで、MonitorMode WAFの設定ファイルが完成。 これで、MonitorMode WAFの設定ファイルが完成。
- 
 === DropModeWAF === === DropModeWAF ===
   - 次にDropMode WAFを構築する。   - 次にDropMode WAFを構築する。
行 699: 行 752:
 これで、DropMode WAFの構築も終了。 これで、DropMode WAFの構築も終了。
  
-<WRAP info>+<WRAP round info>
 なお、実際には、MonitorModeは検出のみだから全Signatureを利用していても性能が劣化する程度で済むことが多いが、DropModeの場合は、preLoadやPostloadの設定で、不要なSignatureをOffにする、もしくは重みつけを0にする必要があることに注意。 なお、実際には、MonitorModeは検出のみだから全Signatureを利用していても性能が劣化する程度で済むことが多いが、DropModeの場合は、preLoadやPostloadの設定で、不要なSignatureをOffにする、もしくは重みつけを0にする必要があることに注意。
  
-preCRSPostCRSを作成してあるのはそのため。+preLoadPostLoadを作成してあるのはそのため。
 </WRAP> </WRAP>
  
行 827: 行 880:
  
 # ID # ID
-# 1000-2999: Preload ommiting signature list of OWASP CRS +# 1000-1999: Preload for OWASP CRS 
-3000-4999: Preload ommiting signature list of LOCAL SIGNATURES +2000-3999: Reserve 
-# 5000-6999Postload ommiting signature list of OWASP CRS +# 4000-4999: Preload for local Sigs. 
-7000-8999: Postload ommiting signature list of LOCAL SIGNATURES+# 5000-5999Preload for OWASP CRS 
 +6000-7999: Reserve 
 +# 8000-8999: Preload for local Sigs.
 # 10000-10999: local signatures part 1 # 10000-10999: local signatures part 1
 # 11000-11999: local signatures part 2 (Reserved) # 11000-11999: local signatures part 2 (Reserved)
行 975: 行 1030:
 xxxx/xx/xx xx:xx:xx [info] 3985#100131: *108 ModSecurity: Access denied with code %d (phase 1). Matched "Operator `Contains' with parameter `test' against variable `ARGS:testparams' (Value: `test' ) [file "/usr/local/etc/nginx/modsec/DM.conf"] [line "115"] [id "10000"] [rev ""] [msg ""] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989194.699201"] [ref "o0,4v17,4"], client: 192.0.2.254, server: , request: "GET /?testparams=test HTTP/1.1", host: "waf" xxxx/xx/xx xx:xx:xx [info] 3985#100131: *108 ModSecurity: Access denied with code %d (phase 1). Matched "Operator `Contains' with parameter `test' against variable `ARGS:testparams' (Value: `test' ) [file "/usr/local/etc/nginx/modsec/DM.conf"] [line "115"] [id "10000"] [rev ""] [msg ""] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989194.699201"] [ref "o0,4v17,4"], client: 192.0.2.254, server: , request: "GET /?testparams=test HTTP/1.1", host: "waf"
  
-xxxx/xx/xx 15:11:31 [warn] 3985#100131: *108 [client 10.2.255.181] ModSecurity: Warning. Matched "Operator `Contains' with parameter `test' against variable `ARGS:testparams' (Value: `test' ) [file "/usr/local/etc/nginx/modsec/DM.conf"] [line "115"] [id "10000"] [rev ""] [msg ""] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989194.699201"] [ref "o0,4v17,4"], client: 192.0.2.254, server: , request: "GET /?testparams=test HTTP/1.1", host: "waf"+xxxx/xx/xx 15:11:31 [warn] 3985#100131: *108 [client 192.0.2.254] ModSecurity: Warning. Matched "Operator `Contains' with parameter `test' against variable `ARGS:testparams' (Value: `test' ) [file "/usr/local/etc/nginx/modsec/DM.conf"] [line "115"] [id "10000"] [rev ""] [msg ""] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989194.699201"] [ref "o0,4v17,4"], client: 192.0.2.254, server: , request: "GET /?testparams=test HTTP/1.1", host: "waf"
  
 # OWASP CRS検出分(union+select) # OWASP CRS検出分(union+select)
行 982: 行 1037:
 xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Access denied with code %d (phase 2). Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "36"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989855.740312"] [ref ""], client: 192.0.2.254, server: , request: "GET /?union+select HTTP/1.1", host: "waf" xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Access denied with code %d (phase 2). Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "36"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [tag "application-multi"] [tag "language-multi"] [tag "platform-multi"] [tag "attack-generic"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989855.740312"] [ref ""], client: 192.0.2.254, server: , request: "GET /?union+select HTTP/1.1", host: "waf"
  
-xxxx/xx/xx xx:xx:xx [warn] 3985#100131: *109 [client 10.2.255.181] ModSecurity: Warning. Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "36"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989855.740312"] [ref ""], client: 192.0.2.254, server: , request: "GET /?union+select HTTP/1.1", host: "waf"+xxxx/xx/xx xx:xx:xx [warn] 3985#100131: *109 [client 192.0.2.254] ModSecurity: Warning. Matched "Operator `Ge' with parameter `5' against variable `TX:ANOMALY_SCORE' (Value: `5' ) [file "/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf"] [line "36"] [id "949110"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Score: 5)"] [data ""] [severity "2"] [ver ""] [maturity "0"] [accuracy "0"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989855.740312"] [ref ""], client: 192.0.2.254, server: , request: "GET /?union+select HTTP/1.1", host: "waf"
  
 xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Warning. Matched "Operator `Ge' with parameter `5' against variable `TX:INBOUND_ANOMALY_SCORE' (Value: `5' ) [file "/usr/local/waf/owasp-modsecurity-crs/rules/RESPONSE-980-CORRELATION.conf"] [line "61"] [id "980130"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Inbound Score: 5 - SQLI=5,XSS=0,RFI=0,LFI=0,RCE=0,PHPI=0,HTTP=0,SESS=0): Detects MSSQL code execution and information gathering attempts'"] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [tag "event-correlation"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989855.740312"] [ref ""] while logging request, client: 192.0.2.254, server: , request: "GET /?union+select HTTP/1.1", host: "waf" xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Warning. Matched "Operator `Ge' with parameter `5' against variable `TX:INBOUND_ANOMALY_SCORE' (Value: `5' ) [file "/usr/local/waf/owasp-modsecurity-crs/rules/RESPONSE-980-CORRELATION.conf"] [line "61"] [id "980130"] [rev ""] [msg "Inbound Anomaly Score Exceeded (Total Inbound Score: 5 - SQLI=5,XSS=0,RFI=0,LFI=0,RCE=0,PHPI=0,HTTP=0,SESS=0): Detects MSSQL code execution and information gathering attempts'"] [data ""] [severity "0"] [ver ""] [maturity "0"] [accuracy "0"] [tag "event-correlation"] [hostname "192.0.2.254"] [uri "/"] [unique_id "154087989855.740312"] [ref ""] while logging request, client: 192.0.2.254, server: , request: "GET /?union+select HTTP/1.1", host: "waf"
  
 </code> </code>
- 
 ==== Monitor Modeの検証 ==== ==== Monitor Modeの検証 ====
  
networkapp/waf/mod-security.1540881005.txt.gz · 最終更新: 2018/10/30 15:30 by seirios

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki