<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="http://www.seirios.org/seirios/dokuwiki/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>ほほほのほ - networkapp:waf</title>
        <description></description>
        <link>http://www.seirios.org/seirios/dokuwiki/</link>
        <lastBuildDate>Thu, 09 Apr 2026 10:18:42 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>http://www.seirios.org/seirios/dokuwiki/lib/exe/fetch.php?media=wiki:dokuwiki.svg</url>
            <title>ほほほのほ</title>
            <link>http://www.seirios.org/seirios/dokuwiki/</link>
        </image>
        <item>
            <title>NGINX mod_security</title>
            <link>http://www.seirios.org/seirios/dokuwiki/doku.php?id=networkapp:waf:mod-security</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;nginx_mod_security&quot;&gt;NGINX mod_security&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
NGINXを利用して、Proxy/Signature型のWAFを構築する。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;NGINX mod_security&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;nginx_mod_security&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-101&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;構成&quot;&gt;構成&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
今回のWAFの構成は以下の通り
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;              +---------+  |  +---+  |  +-----+  |  +--+
           +--|LB(NGINX)|--+--|IPS|--+--|httpd|--+--|DB|
 +------+  |  +---------+  |  +---+  |  +-----+  |  +--+
 |Router|--+               |         |           |
 +------+  |  +---------+  |  +---+  |  +-----+  |  +--+
           +--|LB(NGINX)|--+--|IPS|--+--|httpd|--+--|DB|
              +---------+  |  +---+  |  +-----+  |  +--+
                           |
                           |  +---+
                           +--|WAF|
                           |  +---+
                           |
                           |  +---+
                           +--|WAF|
                           |  +---+&lt;/pre&gt;

&lt;p&gt;
通信は以下のように流れる予定
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; 外部node → LB (TCP terminate) : LBはReverse Proxy/Cacheなので、HTTP通信は全て終端する&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; LB → WAF (TCP terminate) : WAFはProxy-WAFなので、HTTP通信を全て終端する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; この時、LBは、必要な情報をHTTP Headerに付加して、WAFに送る&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WAF → LB (TCP terminate) : WAFは、通信内容を検査し、問題がなければLBに返送する。送り先は、LB内Dispatcher&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; LB → httpd : LBは、(2)で付加された情報をもとに、接続先Web Server(httpd)を決定し、リクエストをIPS経由で送る&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; IPSは、Router modeなので、検査の結果問題がなければ、通常通りトラフィックをForwardingする。&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; HTTP/HTTPs通信に限っては、IPSは不要とも言えるので、構成上再検討の余地はある。&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; httpd → LB(dispatcher) : LBがproxyモードなので、返答の送付先は自動的にdispatcherになる&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; LB(dispatcher) → WAF : WAFがproxyモードなので、返答の送付先は自動的にWAFになる&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WAF → LB : LBがproxyモードなので、返答の送付先は自動的にWAFになる&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; LB → 外部node&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u69cb\u6210&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u69cb\u6210&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;102-2039&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;install&quot;&gt;Install&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
例によってFreeBSDのServerを構築する。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Install&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;install&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2040-2111&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;諸元&quot;&gt;諸元&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
VMの諸元は以下の通り
&lt;/p&gt;
&lt;div class=&quot;table sectionedit5&quot;&gt;&lt;table class=&quot;inline&quot;&gt;
	&lt;tr class=&quot;row0&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; CPU &lt;/th&gt;&lt;td class=&quot;col1&quot;&gt; vCPU x2 &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row1&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; Memory &lt;/th&gt;&lt;td class=&quot;col1&quot;&gt; 4G &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row2&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; Disk 0 &lt;/th&gt;&lt;td class=&quot;col1&quot;&gt; 20G &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; Boot disk &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row3&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; NIC 0 &lt;/th&gt;&lt;td class=&quot;col1&quot;&gt; &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; Management I/F &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row4&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; NIC 1 &lt;/th&gt;&lt;td class=&quot;col1&quot;&gt; &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; WAF I/F &lt;/td&gt;
	&lt;/tr&gt;
	&lt;tr class=&quot;row5&quot;&gt;
		&lt;th class=&quot;col0&quot;&gt; &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; &lt;/th&gt;&lt;td class=&quot;col1&quot;&gt; FreeBSD &lt;/td&gt;&lt;td class=&quot;col2&quot;&gt; 11.2-p4 (2018/10/19) &lt;/td&gt;
	&lt;/tr&gt;
&lt;/table&gt;&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;table&amp;quot;,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;2162-2319&amp;quot;} --&gt;
&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u8af8\u5143&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u8af8\u5143&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;2112-2320&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit6&quot; id=&quot;osのinstall&quot;&gt;OSのInstall&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
通常通り、minimum installを行う
&lt;/p&gt;

&lt;p&gt;
WAFは、今回はProxy Serverと同じ扱いになるので、&lt;code&gt;/etc/sysctl.conf&lt;/code&gt;に以下を追記する。
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# IP Tuning
net.inet.ip.portrange.randomized=0
net.inet.ip.portrange.first=1024
net.inet.ip.portrange.last=65535

# ICMP Tuning
net.inet.icmp.icmplim=3000

# TCP Tuning
net.inet.tcp.msl=1000
net.inet.tcp.finwait2_timeout=3000
net.inet.tcp.nolocaltimewait=1
net.inet.tcp.fast_finwait2_recycle=1
net.inet.tcp.syncookies=1
net.inet.tcp.recvspace=8192
# for XenServer VM
net.inet.tcp.tso=0

# HTTP tunning
kern.ipc.nmbclusters=262144     # default=25600
kern.ipc.nmbjumbop=128000       # default=12800
kern.ipc.somaxconn=32768
kern.ipc.maxsockets=204800
kern.ipc.maxsockbuf=20480000
kern.maxfiles=204800
kern.maxfilesperproc=200000

### ARP cache timeout
net.link.ether.inet.max_age=97&lt;/pre&gt;

&lt;p&gt;
セマフォの拡張はboot時に行う必要があるので、/boot/loader.confに記述
&lt;/p&gt;
&lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=2&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;/boot/loader.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;### 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&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;p&gt;
ModSecurityの処理は高速であることが望ましいので、modsecurity用のFilesystemをMemory Filesystemにする
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; /var/modsecurityを作成&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;/etc/fstab&lt;/code&gt;に以下の行を追加する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=3&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_&quot;&gt;fstab&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;tmpfs           /var/modsecurity tmpfs  rw,size=1G      0 0&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;mount -a&lt;/code&gt;を実行&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;OS\u306eInstall&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;os\u306einstall&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;2321-4192&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit7&quot; id=&quot;wafのinstall&quot;&gt;WAFのInstall&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Installには複数の手法があるが、今回は、構築・運用の簡便のため、FreeBSD Portsを利用することにする。
&lt;/p&gt;

&lt;p&gt;
真面目にportsからCompileすると、大量のPackageをCompileする羽目になるので、一部binary packageでInstallする
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# pkg install git GeoIP luajit mod_security3&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;WAF\u306eInstall&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;waf\u306einstall&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;4193-4553&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit8&quot; id=&quot;geoip関連の設定&quot;&gt;GeoIP関連の設定&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; GeoIPが利用するアドレス情報をDownloadする&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;# /bin/sh /usr/local/bin/geoipupdate.sh&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; cronでDailyにGeoIP情報を更新する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;# crontab -e

0       6       *       *       *               /usr/local/bin/geoipupdate.sh &amp;gt; /dev/null&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;GeoIP\u95a2\u9023\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;geoip\u95a2\u9023\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:5,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;4554-4875&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit9&quot; id=&quot;nginxをinstallする&quot;&gt;NGINXをInstallする&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
本体のNGINXは、Binary Packagesのnginx-develがmod_securityを含んでいないことや、WAFには不要な機能が大量に組み込まれているため、Portsを利用する。
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; FreeBSD ports collectionをシステムに展開する（略)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;cd /usr/ports/www/nginx-devel&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;make configure&lt;/code&gt; &lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Checkを外す : MAIL, MAIL_SSL, STREAM, STREAM_SSL&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; Checkを入れる ; HTTP_GEOIP, LUA, MODSECURITY3&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;make&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;make install&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;pkg lock nginx-devel&lt;/code&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; pkg upgradeなどで自動更新されないようにする。&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
これで、NGINX+mod_security3のバイナリーがInstallされる。
&lt;/p&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:10,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;wrap_round wrap_tip plugin_wrap&quot;&gt;
&lt;p&gt;
WAFを作成する場合に、logをHDDに書き出す場合、HDDの書き込み速度が律速になり、NGINX自体が遅くなることがある。
しかし、WAFで、検査したRequestをできるだけ書き出したい場合もある。
&lt;/p&gt;

&lt;p&gt;
NGINXは、標準でsyslogにlogを書き出すことができるが、その場合、log文字数は2048文字でハードコードされている。&lt;br/&gt;

( &lt;code&gt;src/core/ngx_log.h&lt;/code&gt; に &lt;code&gt;NGX_MAX_ERROR_STR 2048&lt;/code&gt; として記述されている。 )
&lt;/p&gt;

&lt;p&gt;
syslogは、仕様としてはlog文字長に制限はないが、FreeBSDの &lt;code&gt;syslogd&lt;/code&gt; の場合、2048文字までしか受け付けないようになっているが、remote log systemに &lt;code&gt;fluentd&lt;/code&gt; を利用する場合、logの文字数の制限は事実上撤廃することが可能。
(参照: &lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?id=serverapp:logging:fluentd&quot; class=&quot;wikilink1&quot; title=&quot;serverapp:logging:fluentd&quot; data-wiki-id=&quot;serverapp:logging:fluentd&quot;&gt;Fluentd&lt;/a&gt;)
&lt;/p&gt;

&lt;p&gt;
この場合に、NGINXのlog文字列を増やし、かつ、Mod_Security3用の設定を毎回portsにて行うことは非常に面倒なので、portsを作成した。
&lt;/p&gt;

&lt;p&gt;
以下、分かる人向け。
&lt;/p&gt;

&lt;p&gt;
BaseにしたNGINXは、個人の好みでnginx-develにした。気に入らない人は、Makefileを書き換えればnginxにもできる。
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;ports/www/nginx-nginx-modsec3-logextend&lt;/code&gt; 及び &lt;code&gt;ports/www/nginx-nginx-modsec3-logextend/files&lt;/code&gt;を作成
&lt;/p&gt;
&lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=7&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_&quot;&gt;Makefile&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;# 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 &amp;quot;${MASTERDIR}/Makefile&amp;quot;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=8&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_h&quot;&gt;files/extra-patch-src-core-ngx_log.h&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code diff&quot;&gt;# cat files/extra-patch-src-core-ngx_log.h
&lt;span class=&quot;re3&quot;&gt;--- src/core/ngx_log.h.orig     2018-10-30 18:59:30.293977000 +0900&lt;/span&gt;
&lt;span class=&quot;re4&quot;&gt;+++ src/core/ngx_log.h  2018-10-30 18:59:46.430785000 +0900&lt;/span&gt;
&lt;span class=&quot;re6&quot;&gt;@@ -73,7 +73,7 @@&lt;/span&gt;
 &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;re7&quot;&gt;-#define NGX_MAX_ERROR_STR   2048&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#define NGX_MAX_ERROR_STR   8192&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 /*********************************/&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;p&gt;
あとは、通常通りmakeすれば良い。
&lt;/p&gt;

&lt;p&gt;
見れば分かるが、基本 nginx-devel に依存し、参照するので、ngx_log.hが大幅に変更されない限り、継続して利用できるはずである。
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:11,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;
&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;NGINX\u3092Install\u3059\u308b&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;nginx\u3092install\u3059\u308b&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:7,&amp;quot;secid&amp;quot;:9,&amp;quot;range&amp;quot;:&amp;quot;4876-8131&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit12&quot; id=&quot;owasp_crsのinstall&quot;&gt;OWASP CRSのInstall&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
mod_security用のsignature dataは /usr/local/wafに置くことにする
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# mkdir /usr/local/waf
# cd /usr/local/waf
# git clone https://github.com/SpiderLabs/owasp-modsecurity-crs.git&lt;/pre&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:13,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;wrap_round wrap_tip plugin_wrap&quot;&gt;
&lt;p&gt;
2018/10/26現在、Releaseされているmod_securityは、3.0.2だが、OWASP CRSのHEADは&lt;code&gt;v3.2/dev&lt;/code&gt;であり、このCRSは、mod_security 3.1.0にて追加される機能を仮定している。&lt;br/&gt;

そのため、現在の段階では、以下の追加操作が必要になる。
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# cd /usr/local/waf/owasp-modsecurity-crs
# git checkout v3.0/master&lt;/pre&gt;

&lt;p&gt;
これにより、CRSが&lt;code&gt;v3.0.2&lt;/code&gt;相当のものになる。
&lt;/p&gt;

&lt;p&gt;
この作業を行わないと、CRSの読み込みの段階で複数のエラーが発生して大ハマりすることになる。
&lt;/p&gt;

&lt;p&gt;
なお、現在利用しているBranchを確認するには、&lt;code&gt;git branch -v&lt;/code&gt;を実行すること
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:14,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;
&lt;p&gt;
また、OWASP CRSは比較的高頻度で更新されるので、ともあれ定期的にUpdateすることが必要
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;mkdir /usr/local/waf/bin&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;crsupdate.sh&lt;/code&gt;を作成&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=11&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_sh&quot;&gt;bash crsupdate.sh&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;#! /bin/sh
cd /usr/local/waf/owasp-modsecurity-crs;
/usr/local/bin/git pull&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 試験&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;/bin/sh /usr/local/waf/bin/crsupdate.sh&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 問題なく終了すればOK&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; 本来なら、Error Checkなどを行うべきだが、それは各自の&lt;strong&gt;宿題&lt;/strong&gt;ということで。&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; cronに仕掛ける&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;10      6       *       *       *               /bin/sh /usr/local/waf/bin/crsupdate.sh &amp;gt; /dev/null&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;OWASP CRS\u306eInstall&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;owasp_crs\u306einstall&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:9,&amp;quot;secid&amp;quot;:12,&amp;quot;range&amp;quot;:&amp;quot;8132-9712&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit15&quot; id=&quot;全体環境の整備&quot;&gt;全体環境の整備&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
今回修正が必要になるのは、LB部分。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u5168\u4f53\u74b0\u5883\u306e\u6574\u5099&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u5168\u4f53\u74b0\u5883\u306e\u6574\u5099&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:13,&amp;quot;secid&amp;quot;:15,&amp;quot;range&amp;quot;:&amp;quot;9713-9799&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit16&quot; id=&quot;処理の流れ&quot;&gt;処理の流れ&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
今回の構成の場合。LBには、以下の機能が必要。
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; 外部からの通信を受け付ける。以下本節内では、&lt;strong&gt;RLB&lt;/strong&gt; (Receive LB)とする&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WAFからの返答を受け取って、Web ServerにRequestを送る。 以下本節内では、&lt;strong&gt;DLB&lt;/strong&gt; (dispatcher LB)とする&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
通信は以下のようになる。
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;
node -&amp;gt; RLB(1) -&amp;gt; WAF -&amp;gt; DLB(1) -&amp;gt; Web Server -&amp;gt; DLB(2) -&amp;gt; WAF -&amp;gt; RLB(2) -&amp;gt; node
Request --------------------------&amp;gt;|        |-------------------------&amp;gt; Response
&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u51e6\u7406\u306e\u6d41\u308c&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u51e6\u7406\u306e\u6d41\u308c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:13,&amp;quot;secid&amp;quot;:16,&amp;quot;range&amp;quot;:&amp;quot;9800-10343&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit17&quot; id=&quot;各点で必要となる処理&quot;&gt;各点で必要となる処理&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
RLB(1) / DLB(1) / DLB(2) / RLB(2) のそれぞれの点で、正しく処理を行うための情報の加工が必要になる。
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;: RLB(1) : HTTP Headerにサイト内追加情報を付記し、SourceとDestの情報を保持する。WAFにSession単位でトラフィックを分散する
: DLB(1) : R+B(1)で追加されたHTTP Headerを除去し、バックエンドのWeb ServerにSession単位でTrafficを分散する
: DLB(2) : 特段の処理はない(戻りトラフィックであるため)
: RLB(2) : 特段の処理はない(戻りトラフィックであるため)&lt;/pre&gt;

&lt;p&gt;
RLB(1) で追加する HTTP Header は以下の通り
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;proxy_set_header Host              $host;
proxy_set_header X-Forwarded-Host  $host;
proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP         $remote_addr;
proxy_set_header X-WAF-URL-FLAG    $scheme://$host:$server_port;&lt;/pre&gt;

&lt;p&gt;
ここで重要なのは、X-WAF-&lt;abbr title=&quot;Uniform Resource Locator&quot;&gt;URL&lt;/abbr&gt;-FLAGである。dispatcherは、このHeaderを参照して、配送先のWeb Serverを決定する。
なお、X-WAF-&lt;abbr title=&quot;Uniform Resource Locator&quot;&gt;URL&lt;/abbr&gt;-FLAGは、内部処理に必要な情報であり、このHeaderを付記したリクエストによってNGINXが混乱させられることを避けるため、必ず、本Headerを一度削除してから追加すること
&lt;/p&gt;

&lt;p&gt;
DLB(1)で削除する HTTP Header は以下の通り
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; X-WAF-&lt;abbr title=&quot;Uniform Resource Locator&quot;&gt;URL&lt;/abbr&gt;-FLAG : これは、Site 内部でのみ必要な情報なので、Web Serverに引き渡す必要はない&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
これ以外のHeaderは、通常のHTTP Protocolの規定通りに処理すれば良い。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u5404\u70b9\u3067\u5fc5\u8981\u3068\u306a\u308b\u51e6\u7406&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u5404\u70b9\u3067\u5fc5\u8981\u3068\u306a\u308b\u51e6\u7406&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:14,&amp;quot;secid&amp;quot;:17,&amp;quot;range&amp;quot;:&amp;quot;10344-12001&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit18&quot; id=&quot;lbの設定例&quot;&gt;LBの設定例&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
今回の構成では、RLB/DLB共にLBとしてまとめている。
これは、今回投入するシステムの検査対象トラフィック量が少ないからであって、これを分離する構成も当然ながらとることが可能。
&lt;/p&gt;

&lt;p&gt;
なお、分離構成する場合、以下のような２種類の構成を考えることも可能
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;Structure 1                                 Structure 2
         |  +---+  |  +---+  |  +---+         +---+  |  +---+  |  +---+  |         |
         +--|WAF|--+--|DLB|--+--|Web|       --|RLB|--+--|WAF|--+--|DLB|--+         |
         |  +---+  |  +---+  |  +---+         +---+  |  +---+  |  +---+  |         |
         |         |         |                  |    |         |         |         |
  +---+  |  +---+  |  +---+  |  +---+           |    |  +---+  |  +---+  |  +---+  |
--|RLB|--+--|WAF|--+--|DLB|--+--|WEB|           |    +--|WAF|--+--|DLB|--+--|IPS|--+
  +---+  |  +---+  |  +---+  |  +---+     +=====+    |  +---+  |  +---+  |  +---+  |
         |                   |            |     |    |                   |         |
  +---+  |       +---+       |  +----+    |   +---+  |                   |  +---+  |
--|RLB|--+-------|IPS|-------+--|Step|    | --|RLB|--+                   +--|IPS|--+
  +---+  |       +---+       |  +----+    |   +---+  |                   |  +---+  |
         |                   |            |                              |
         |       +---+       |            +==============================+ 
         +-------|IPS|-------+                                           |
         |       +---+       |              &lt;/pre&gt;

&lt;p&gt;
Structure 1はHTTP通信に関してはIPSでの検査を行わないモデルであり、Structure 2は、今回作成するRLB/DLB一体構造を展開したものとなる。
&lt;/p&gt;

&lt;p&gt;
これらの「展開された構成」は、トラフィックが多く、LBへの負荷が高くなってしまうような場合に採用する。
&lt;/p&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:19,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;plugin_wrap&quot;&gt;
&lt;p&gt;
本構成において、RLBは比較的高負荷になることが予想される。これは、
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WAFは暗号化されたRequestを検査することはできないので、RLBでSSLを展開する必要がある&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WAFによる通信検査は比較的負荷が高いため、WAFに流入する通信は少なくなることが望ましい。そのため、RLBにおいて、画像などのCacheを行うことで負荷を軽減する策をとることが望ましい&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
からである。
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:20,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;
&lt;p&gt;
以上より、LBにて行うべき処理は以下の通り
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; HTTP/HTTPs Requestの終端&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; (必要に応じて) SSLの展開&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; 静止画像など、変更が少ないデータのCache&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; 必要な情報を付加した上での、HTTP通信をWAFへ転送&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; WAFからの検査結果通信の終端とWebServerへのリクエスト&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
以下に、NGINX.confのサンプルを記載する
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# NGINX.conf

http {
    include                   mime.types;
    server_tokens             off;
    ignore_invalid_headers    on;
    sendfile                  on;
    tcp_nopush                on;
    open_file_cache           max=100 inactive=300s;

    proxy_cache_key           $scheme$proxy_host$request_uri;
    proxy_temp_path           /var/tmp/nginx/temp 1 2;

    proxy_cache_valid         200 302 1h;
    proxy_cache_valid         any     1m;

ssl_ciphers ECDHE+RSAGCM:ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:!EXPORT:!DES:!3DES:!MD5:!DSS;
    ssl_prefer_server_ciphers on;
    ssl_protocols             TLSv1.2;
    ssl_session_cache         shared:SSLresumption:10m;
    ssl_session_timeout       10m;

##### For RLB

upstream WAF01 {
    ip_hash;
    server 192.0.2.11:80 max_fails=3 fail_timeout=300;
    server 192.0.2.12:80 max_fails=3 fail_timeout=300;

}

upstream WWW_EXAMPLE.COM {
    server 203.0.113.101:80 max_fails=3 fail_timeout=300;
    server 203.0.113.102:80 max_fails=3 fail_timeout=300;
}

upstream WWW_EXAMPLE.NET {
    server 203.0.113.111:80 max_fails=3 fail_timeout=300;
    server 203.0.113.112:80 max_fails=3 fail_timeout=300;
}

proxy_cache_path /var/tmp/nginx/cache/EXAMPLE_COM levels=1:2 keys_zone=EXAMPLE_COM:60m max_size=4000m inactive=8h;
proxy_cache_path /var/tmp/nginx/cache/EXAMPLE_NET levels=1:2 keys_zone=EXAMPLE_NET:60m max_size=4000m inactive=8h;

server { #RLB Configuration
    listen      198.51.100.1:80:
    server_name www.example.com;
    error_log   /var/log/nginx/example_com_error.log error;
    access_log  /var/log/nginx/example_com_access.log;

    location / {
        return 301 https://$host$request_uri;
    }
}

server { #RLB Configuration
    listen      198.51.100.1:443 ssl http2;
    server_name www.example.com;
    error_log   /var/log/nginx/example_com_ssl_error.log error;;
    access_log  /var/log/nginx/example_com_ssl_access.log;

    ssl_certificate     /usr/local/etc/Certs/www.example.com.cert;
    ssl_certificate_key /usr/local/etc/Certs/www.example.com.key;

    location / {
        proxy_pass        http://WAF01;
        proxy_cache       EXAMPLE.COM;
        proxy_cache_valid 200 302     1440m;
        proxy_cache_valid 404         1m;
        proxy_cache_valid 500 502 504 1m;
        proxy_set_header          Host $host;
        proxy_set_header          X-Forwarded-Host $host;
        proxy_set_header          X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header          X-Forwarded-Proto $scheme;
        proxy_set_header          X-Real-IP $remote_addr;
        proxy_set_header          X-WAF-URL-FLAG $scheme://$host:$server_port;
    }
}

....

##### For DLB
map $http_X_WAF_URL_FLAG $MYUPSTREAM {
    https://www.example.com:443 http://WWW_EXAMPLE_COM;		# ここには、upstreamを記載する
    https://www.example.net:443 http://WWW_EXAMPLE_NET;		# ここには、upstreamを記載する
}

server { #DLB
    listen 192.0.2.11:10080 accept_filter=httpready;
    server_name DLB1;
    error_log   /var/log/nginx/dlb01.err error;
    access_log  /var/log/nginx/dlb01.acc;

    location / {
        proxy_pass        $MYUPSTREAM;
        proxy_pass_header X-Accel-Buffering;
        proxy_set_header  Host $http_x_forwarded_host;
        proxy_set_header  X-WAF-URL-FLAG  &amp;quot;&amp;quot;;
        proxy_set_header  X-Forwarded-Host $http_host;
        proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    }
}&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;LB\u306e\u8a2d\u5b9a\u4f8b&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;lb\u306e\u8a2d\u5b9a\u4f8b&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:15,&amp;quot;secid&amp;quot;:18,&amp;quot;range&amp;quot;:&amp;quot;12002-18362&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit21&quot; id=&quot;wafの設定&quot;&gt;WAFの設定&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
本節で、&lt;strong&gt;NGINX&lt;/strong&gt;および&lt;strong&gt;mod_security&lt;/strong&gt;の設定を記載し、WAFとして動作させる。
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://docs.nginx.com/nginx-waf/admin-guide/nginx-plus-modsecurity-waf-installation-logging/&quot; class=&quot;urlextern&quot; title=&quot;https://docs.nginx.com/nginx-waf/admin-guide/nginx-plus-modsecurity-waf-installation-logging/&quot;&gt;https://docs.nginx.com/nginx-waf/admin-guide/nginx-plus-modsecurity-waf-installation-logging/&lt;/a&gt;参照&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.netnea.com/cms/nginx-tutorial-7_including-owasp-modsecurity-core-rule-set/&quot; class=&quot;urlextern&quot; title=&quot;https://www.netnea.com/cms/nginx-tutorial-7_including-owasp-modsecurity-core-rule-set/&quot;&gt;https://www.netnea.com/cms/nginx-tutorial-7_including-owasp-modsecurity-core-rule-set/&lt;/a&gt;参照&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;WAF\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;waf\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:17,&amp;quot;secid&amp;quot;:21,&amp;quot;range&amp;quot;:&amp;quot;18363-18700&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit22&quot; id=&quot;まずは簡単な試験&quot;&gt;まずは簡単な試験&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;ol&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; NGINXの動作確認&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; NGINXの設定(/usr/local/etc/nginx/nginx.confを作成&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=17&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;nginx.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;load_module /usr/local/libexec/nginx/ngx_http_geoip_module.so;
load_module /usr/local/libexec/nginx/ndk_http_module.so;
load_module /usr/local/libexec/nginx/ngx_http_lua_module.so;

user www www;
worker_processes 1;
events {
  use kqueue;
  worker_connections 4096;
  accept_mutex on;
  accept_mutex_delay 500ms;
}

http {
  server {
    listen localhost:8085;
    location / {
      default_type text/plain;
      return 200 &amp;quot;Thank you for requesting ${request_uri}\n&amp;quot;;
    }
  }
}&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; nginxを起動する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; /etc/rc.conf.localに&lt;code&gt;nginx_enable=“YES”&lt;/code&gt;を追加&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;service nginx start&lt;/code&gt;を実行&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; Errorが出ていないことを確認する&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 正しく返答が返ってくることを確認&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;curl -D - &lt;a href=&quot;http://localhost:8085&quot; class=&quot;urlextern&quot; title=&quot;http://localhost:8085&quot;&gt;http://localhost:8085&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; これで、200 OKが返って来れば良い&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Proxyを作成する&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; nginx.confに以下を追加する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=18&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;nginx.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;....
  server {
    listen 80;
#    modsecurity on;
#    modsecurity_rules_file /usr/local/etc/nginx/modsec/main.conf;
    location / {
      proxy_pass http://localhost:8085;
      proxy_set_header Host $host;
    }
  }
....&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 正しく返答が返ってくることを確認&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;service nginx reload&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; Errorが出ないことを確認する&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;curl -D - &lt;a href=&quot;http://localhost&quot; class=&quot;urlextern&quot; title=&quot;http://localhost&quot;&gt;http://localhost&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; これで、200 OKが返って来れば良い&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; mod_security3の動作確認&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; /usr/local/etc/modsecurity以下で以下の作業を行う&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;cat modsecurity.conf.sample | sed &amp;#039;s/SecRuleEngine DetectionOnly/SecRuleEngine On&amp;#039;/ &amp;gt; modsecurity.conf&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; main.confを作成する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level4&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=19&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;main.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;# Include the recommended configuration
Include /usr/local/etc/nginx/modsec/modsecurity.conf
# A test rule
SecRule ARGS:testparam &amp;quot;@contains test&amp;quot; &amp;quot;id:1000,deny,log,status:403&amp;quot;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; nginx.confの&lt;code&gt;listen 80;&lt;/code&gt;以下のlocationでコメントアウトされているmod_security関連の設定を生かす&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=20&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;nginx.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;....
  server {
    listen 80;
    modsecurity on;
    modsecurity_rules_file /usr/local/etc/nginx/modsec/main.conf;
    location / {
      proxy_pass http://localhost:8085;
      proxy_set_header Host $host;
    }
  }
....&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; nginxでConfigurationを読み込み直す &lt;code&gt;service nginx reload&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 通常の通信は通ることを確認する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;curl -D - &lt;a href=&quot;http://localhost&quot; class=&quot;urlextern&quot; title=&quot;http://localhost&quot;&gt;http://localhost&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; これで、200 OKが返って来れば良い&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; mod_securityがリクエストをDropしたことを確認する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;curl -D - &lt;a href=&quot;http://localhost/foo?testparam=thisisatestofmodsecurity&quot; class=&quot;urlextern&quot; title=&quot;http://localhost/foo?testparam=thisisatestofmodsecurity&quot;&gt;http://localhost/foo?testparam=thisisatestofmodsecurity&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; これで、403 Forbiddenが返って来れば良い&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; signatureのOn/Offの制御&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; 使用しないSignatureをOffにする方法は２つ。Ruleを読み込む前にOffにする方法とRuleを読んだ後にOffにする方法&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Ruleを読み込む前にOffにする&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;# Include the recommended configuration
Include /usr/local/etc/nginx/modsec/modsecurity.conf

# Omit Rule
....
# A test rule
SecRule ARGS:testparam &amp;quot;@contains test&amp;quot; &amp;quot;id:1000,deny,log,status:403&amp;quot;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;curl -D - &lt;a href=&quot;http://localhost/foo?testparam=thisisatestofmodsecurity&quot; class=&quot;urlextern&quot; title=&quot;http://localhost/foo?testparam=thisisatestofmodsecurity&quot;&gt;http://localhost/foo?testparam=thisisatestofmodsecurity&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; これで、200 OKが返って来れば良い&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Ruleを読み込んだ後にOffにする&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;# Include the recommended configuration
Include /usr/local/etc/nginx/modsec/modsecurity.conf

# A test rule
SecRule ARGS:testparam &amp;quot;@contains test&amp;quot; &amp;quot;id:1000,deny,log,status:403&amp;quot;

# Omit Rule
....
&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;curl -D - &lt;a href=&quot;http://localhost/foo?testparam=thisisatestofmodsecurity&quot; class=&quot;urlextern&quot; title=&quot;http://localhost/foo?testparam=thisisatestofmodsecurity&quot;&gt;http://localhost/foo?testparam=thisisatestofmodsecurity&lt;/a&gt;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; これで、200 OKが返って来れば良い&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u307e\u305a\u306f\u7c21\u5358\u306a\u8a66\u9a13&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u307e\u305a\u306f\u7c21\u5358\u306a\u8a66\u9a13&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:17,&amp;quot;secid&amp;quot;:22,&amp;quot;range&amp;quot;:&amp;quot;18701-22492&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit23&quot; id=&quot;owasp_crsを用いたwafの構築&quot;&gt;OWASP CRSを用いたWAFの構築&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
WAFを作成する場合、False Positive(偽陽性)つまり、過検知による「止める必要がない」「止めてはいけない」通信による障害を可能な限り最小限に留めなければならない。そのため、以下のような手段を取ることが多い
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Detect Only モード(以下Monitorモード)でWAFを投入&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; logに現れる各種通信を確認&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; 不要なSignatureを外す、またはSignatureのscoreを落とす&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Dropモードに移行&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
したがって、WAFを構築する場合、最低でも、MonitorModeWAFの設定とDropModeWAFの設定が必要になる。
&lt;/p&gt;

&lt;p&gt;
加えて、検査するサイトにおいて、調整するSignatureが異なることになるので、その部分の差異を取り込めるようにする設定を考える必要がある。
&lt;/p&gt;

&lt;p&gt;
ここでは、Siteごとの調整は、WAFを分離することで行うこととする(for ex. Dokuwiki用WAFとWP用WAFを分離するなど)。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;OWASP CRS\u3092\u7528\u3044\u305fWAF\u306e\u69cb\u7bc9&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;owasp_crs\u3092\u7528\u3044\u305fwaf\u306e\u69cb\u7bc9&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:23,&amp;quot;secid&amp;quot;:23,&amp;quot;range&amp;quot;:&amp;quot;22493-23508&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit24&quot; id=&quot;設定ファイルのディレクトリ構成&quot;&gt;設定ファイルのディレクトリ構成&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
以下に、本設定で採用したDirectory構成、ファイル構成を記載する。
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;/-+
  +-- ...
  +- var -+- ...
  |       +- modsecurity                                               : mod_securityのWork Directory
  |
  +- usr/local -+- ...
                +- waf -+- bin -+- crsupdate.sh                        : CRS update用shell script
                |       +- local-modsecurity-sigs -+- local-setup.conf : local configuration
                |       |                          +- rules/*          : local signatures
                |       |
                |       +- owasp-modsecurity-crs -+- ...
                |                                 +- crs-setup.conf    : OWASP CRS configuration
                |                                 +- rules/*           : OWASP CRS signatures
                +- etc -+- modsecurity/*                               : FreeBSD portsによって作成される
                        +- nginx -+- ...                               : FreeBSD portsによって作成される
                                  +- modsec -+- MM-Base.conf           : MonitorMode用基本設定
                                  |          +- MM0.conf               : MonitorMode WAF#0 設定
                                  |          +- MM0-preLoad.conf       : MonitorMode WAF#0用rule読み込み前設定
                                  |          +- MM0-postLoad.conf      : MonitorMode WAF#0用rule読み込み後設定
                                  |          +- DM-Base.conf           : DropMode用基本設定
                                  |          +- DM0.conf               : DropMode WAF#0 設定
                                  |          +- DM0-preLoad.conf       : DropMode WAF#0用rule読み込み前設定
                                  |          +- DM0-postLoad.conf      : DropMode WAF$0用rule読み込み後設定
                                  +- conf.http                         : http configuration
                                  +- conf.http.d -+- ...               : server/location configuration&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u8a2d\u5b9a\u30d5\u30a1\u30a4\u30eb\u306e\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u69cb\u6210&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:23,&amp;quot;secid&amp;quot;:24,&amp;quot;range&amp;quot;:&amp;quot;23509-25671&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit25&quot; id=&quot;monitormodewaf&quot;&gt;MonitorModeWAF&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;ol&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; まずは、MonitorMode WAFを構築する&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; この設定は、/usr/local/etc/modsecurity/modsecurity.conf.sampleから作成する。&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; modsecurity.conf.sampleをMM-Base.confとしてコピーする&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; 下記patchを当てる&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;# cp /usr/local/etc/modsecurity/modsecurity.conf.sample /usr/local/etc/nginx/modsec/MM-Base.conf
# patch &amp;lt; MM-Base.conf.diff&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=25&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_diff&quot;&gt;MonitorModeBase.conf.diff&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code diff&quot;&gt;# diff -u ../../modsecurity/modsecurity.conf.sample MM-Base.conf
&lt;span class=&quot;re3&quot;&gt;--- ../../modsecurity/modsecurity.conf.sample   2018-11-04 09:12:19.000000000 +0900&lt;/span&gt;
&lt;span class=&quot;re4&quot;&gt;+++ MM-Base.conf        2018-11-14 16:54:42.293424000 +0900&lt;/span&gt;
&lt;span class=&quot;re6&quot;&gt;@@ -35,7 +35,8 @@&lt;/span&gt;
 # to the size of data, with files excluded. You want to keep that value as
 # low as practical.
 #
&lt;span class=&quot;re7&quot;&gt;-SecRequestBodyLimit 13107200&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#SecRequestBodyLimit 13107200&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecRequestBodyLimit 104857600&lt;/span&gt;
 SecRequestBodyNoFilesLimit &lt;span class=&quot;nu0&quot;&gt;131072&lt;/span&gt;
&amp;nbsp;
 # What do do if the request body size is above our configured limit.
&lt;span class=&quot;re6&quot;&gt;@@ -103,7 +104,8 @@&lt;/span&gt;
 # Do keep in mind that enabling this directive does increases both
 # memory consumption and response latency.
 #
&lt;span class=&quot;re7&quot;&gt;-SecResponseBodyAccess On&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#SecResponseBodyAccess On&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecResponseBodyAccess Off&lt;/span&gt;
&amp;nbsp;
 # Which response MIME types do you want to inspect? You should adjust the
 # configuration below to catch documents but avoid static files
&lt;span class=&quot;re6&quot;&gt;@@ -129,13 +131,15 @@&lt;/span&gt;
 # This default setting is chosen due to all systems have /tmp available however,
 # this is less than ideal. It is recommended that you specify a location that&#039;s private.
 #
&lt;span class=&quot;re7&quot;&gt;-SecTmpDir /tmp/&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#SecTmpDir /tmp/&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecTmpDir /var/modsecurity&lt;/span&gt;
&amp;nbsp;
 # The location where ModSecurity will keep its persistent data.  This default setting
 # is chosen due to all systems have /tmp available however, it
 # too should be updated to a place that other users can&#039;t access.
 #
&lt;span class=&quot;re7&quot;&gt;-SecDataDir /tmp/&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#SecDataDir /tmp/&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecDataDir /var/modsecurity&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 # -- File uploads handling configuration -------------------------------------
&lt;span class=&quot;re6&quot;&gt;@@ -174,7 +178,8 @@&lt;/span&gt;
 # trigger a server error &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;determined by a 5xx or 4xx, excluding &lt;span class=&quot;nu0&quot;&gt;404&lt;/span&gt;,
 # level response status codes&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;.
 #
&lt;span class=&quot;re7&quot;&gt;-SecAuditEngine RelevantOnly&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#SecAuditEngine RelevantOnly&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecAuditEngine off&lt;/span&gt;
 SecAuditLogRelevantStatus &amp;quot;^&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;?:&lt;span class=&quot;nu0&quot;&gt;5&lt;/span&gt;|&lt;span class=&quot;nu0&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;?!04&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&amp;quot;
&amp;nbsp;
 # Log everything we know about a transaction.
&lt;span class=&quot;re6&quot;&gt;@@ -184,7 +189,8 @@&lt;/span&gt;
 # assumes that you will use the audit log only ocassionally.
 #
 SecAuditLogType Serial
&lt;span class=&quot;re7&quot;&gt;-SecAuditLog /var/log/modsec_audit.log&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+#SecAuditLog /var/log/modsec_audit.log&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecAuditLog /var/log/nginx/modsec_audit.log&lt;/span&gt;
&amp;nbsp;
 # Specify the path for concurrent audit logging.
 #SecAuditLogStorageDir /opt/modsecurity/var/audit/&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; MonitorMode WAF設定を作成する&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; /usr/local/etc/nginx/modsec/MM.confを作成&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=26&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;MM.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;#
# mod_security3 Monitor Mode WAF Configuration.
#

# ModSecurity configuration for DetectMode.
Include /usr/local/etc/nginx/modsec/MM-Base.conf

# Load signature configuration
Include /usr/local/waf/owasp-modsecurity-crs/crs-setup.conf
Include /usr/local/waf/local-modsecurity-sigs/local-setup.conf

# Preload of omitting signature
Include /usr/local/etc/nginx/modsec/MM-preLoad.conf

# Load Signature Rules.
Include /usr/local/waf/owasp-modsecurity-crs/rules/*.conf
Include /usr/local/waf/local-modsecurity-sigs/rules/*.conf

# Postload of omitting signature
Include /usr/local/etc/nginx/modsec/MM-postLoad.conf&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 以下、MM-(pre|post)Load.confを作成する&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=27&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;MM-preLoad.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;#
# ModSecurity preload configuration.
#
# id: 1000 - 1999 : for OWASP CRS
# id: 2000 - 2999 : Reserve
# id: 3000 - 4999 : for local Sigs

#SecAction &amp;quot;id:&amp;#039;1000&amp;#039;,phase:1,t:none,pass,nolog,ctl:ruleRemoveById=900000&amp;quot;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=28&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;MM-postLoad.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;#
# ModSecurity postload configuration.
#
# id: 5000 - 5999 : for OWASP CRS
# id: 6000 - 6999 : Reserve
# id: 7000 - 8999 : for local Sigs

#SecRuleRemoveById 900000&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
これで、MonitorMode WAFの設定ファイルが完成。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;MonitorModeWAF&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;monitormodewaf&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:24,&amp;quot;secid&amp;quot;:25,&amp;quot;range&amp;quot;:&amp;quot;25672-29596&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit26&quot; id=&quot;dropmodewaf&quot;&gt;DropModeWAF&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;
&lt;ol&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 次にDropMode WAFを構築する。&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; 基本は、MonitorMode WAFの構築と同様に、ファイル名のMMをDMに置き換えて作業する&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; DM-Base.confの以下の行を書き換える&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=29&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_patch&quot;&gt;DM-Base.patch&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code diff&quot;&gt; diff -u MM-Base.conf DM-Base.conf
&lt;span class=&quot;re3&quot;&gt;--- MM-Base.conf        2018-10-26 14:40:57.052583000 +0900&lt;/span&gt;
&lt;span class=&quot;re4&quot;&gt;+++ DM-Base.conf        2018-10-25 16:52:54.400870000 +0900&lt;/span&gt;
&lt;span class=&quot;re6&quot;&gt;@@ -4,7 +4,7 @@&lt;/span&gt;
 # only to start with, because that minimises the chances of post-installation
 # disruption.
 #
&lt;span class=&quot;re7&quot;&gt;-SecRuleEngine DetectionOnly&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecRuleEngine On&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 # -- Request body handling ---------------------------------------------------&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
これで、DropMode WAFの構築も終了。
&lt;/p&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:27,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;wrap_round wrap_info plugin_wrap&quot;&gt;
&lt;p&gt;
なお、実際には、MonitorModeは検出のみだから全Signatureを利用していても性能が劣化する程度で済むことが多いが、DropModeの場合は、preLoadやPostloadの設定で、不要なSignatureをOffにする、もしくは重みつけを0にする必要があることに注意。
&lt;/p&gt;

&lt;p&gt;
preLoadやPostLoadを作成してあるのはそのため。
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:28,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;
&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;DropModeWAF&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;dropmodewaf&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:29,&amp;quot;secid&amp;quot;:26,&amp;quot;range&amp;quot;:&amp;quot;29597-30713&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit29&quot; id=&quot;owasp_crsの設定&quot;&gt;OWASP CRSの設定&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
OWASP CRSの設定は、&lt;code&gt;/usr/local/waf/owasp-modsecurity-crs/crs-setup.conf&lt;/code&gt;によって行う。実際には、このファイルをModSecurityの設定ファイルから読み込んでいる。
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;cp /usr/local/waf/owasp-modsecurity-crs/crs-setup.conf.example /usr/local/waf/owasp-modsecurity-crs/crs-setup.conf&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;patch &amp;lt; crs-setup.conf.diff&lt;/code&gt;&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=30&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_diff&quot;&gt;crs-setup.conf.diff&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code diff&quot;&gt;&lt;span class=&quot;re3&quot;&gt;--- crs-setup.conf.example      2018-10-26 14:05:01.258754000 +0900&lt;/span&gt;
&lt;span class=&quot;re4&quot;&gt;+++ crs-setup.conf      2018-10-26 16:40:14.631386000 +0900&lt;/span&gt;
&lt;span class=&quot;re6&quot;&gt;@@ -563,6 +563,7 @@&lt;/span&gt;
 # Uncomment this rule to use this feature:
 #
 #SecGeoLookupDB util/geo-location/GeoIP.dat
&lt;span class=&quot;re8&quot;&gt;+SecGeoLookupDB /usr/local/share/GeoIP/GeoIP.dat&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 #
&lt;span class=&quot;re6&quot;&gt;@@ -611,15 +612,15 @@&lt;/span&gt;
 #
 # Uncomment this rule to use this feature:
 #
&lt;span class=&quot;re7&quot;&gt;-#SecAction \&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-# &amp;quot;id:900700,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  nolog,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  pass,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  t:none,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  setvar:&#039;tx.dos_burst_time_slice=60&#039;,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  setvar:&#039;tx.dos_counter_threshold=100&#039;,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  setvar:&#039;tx.dos_block_timeout=600&#039;&amp;quot;&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecAction \&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+ &amp;quot;id:900700,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  nolog,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  pass,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  t:none,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  setvar:&#039;tx.dos_burst_time_slice=60&#039;,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  setvar:&#039;tx.dos_counter_threshold=100&#039;,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  setvar:&#039;tx.dos_block_timeout=600&#039;&amp;quot;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 #
&lt;span class=&quot;re6&quot;&gt;@@ -631,13 +632,13 @@&lt;/span&gt;
 #
 # Uncomment this rule to use this feature:
 #
&lt;span class=&quot;re7&quot;&gt;-#SecAction \&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-# &amp;quot;id:900950,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  nolog,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  pass,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  t:none,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  setvar:tx.crs_validate_utf8_encoding=1&amp;quot;&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecAction \&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+ &amp;quot;id:900950,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  nolog,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  pass,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  t:none,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  setvar:tx.crs_validate_utf8_encoding=1&amp;quot;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 #
&lt;span class=&quot;re6&quot;&gt;@@ -670,24 +671,24 @@&lt;/span&gt;
 #
 # Uncomment this rule to use this feature:
 #
&lt;span class=&quot;re7&quot;&gt;-#SecAction \&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-# &amp;quot;id:900960,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  nolog,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  pass,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  t:none,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  setvar:tx.do_reput_block=1&amp;quot;&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecAction \&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+ &amp;quot;id:900960,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  nolog,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  pass,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  t:none,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  setvar:tx.do_reput_block=1&amp;quot;&lt;/span&gt;
 #
 # Uncomment this rule to change the blocking time:
 # Default: &lt;span class=&quot;nu0&quot;&gt;300&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;5&lt;/span&gt; minutes&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
 #
&lt;span class=&quot;re7&quot;&gt;-#SecAction \&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-# &amp;quot;id:900970,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  nolog,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  pass,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  t:none,\&lt;/span&gt;
&lt;span class=&quot;re7&quot;&gt;-#  setvar:tx.reput_block_duration=300&amp;quot;&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+SecAction \&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+ &amp;quot;id:900970,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  phase:1,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  nolog,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  pass,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  t:none,\&lt;/span&gt;
&lt;span class=&quot;re8&quot;&gt;+  setvar:tx.reput_block_duration=300&amp;quot;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
 #&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
これで、設定は完了。なお、個人の趣味が入っているので、設定自体は見直してください。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;OWASP CRS\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;owasp_crs\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:30,&amp;quot;secid&amp;quot;:29,&amp;quot;range&amp;quot;:&amp;quot;30714-32976&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit30&quot; id=&quot;local_signatureの設定&quot;&gt;local signatureの設定&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
local signatureは、ここでは、自作のSignatureを仮定しているが、要するに、自己管理の各種Signatureのことであるとする。
&lt;/p&gt;

&lt;p&gt;
local signatureは、OWASP CRSと管理構造を同じようにすることで、考え方を調整しなくて済むように考えている。
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; local signatureの作成&lt;/div&gt;
&lt;ol&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;mkdir /usr/local/waf/local-modsecurity-sigs&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;mkdir /usr/local/waf/local-modsecurity-sigs/rules&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; local-setup.confを作成&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=31&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;local-setup.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;# ------------------------------------------------------------------------
# ModSecurity local ruleset configuration.
# ------------------------------------------------------------------------

# ID
# 1000-1999: Preload for OWASP CRS
# 2000-3999: Reserve
# 4000-4999: Preload for local Sigs.
# 5000-5999: Preload for OWASP CRS
# 6000-7999: Reserve
# 8000-8999: Preload for local Sigs.
# 10000-10999: local signatures part 1
# 11000-11999: local signatures part 2 (Reserved)
# .....
# 19000-19999: local signatures part 9 (Reserved)

# -- [[ System Requirements ]] -------------------------------------------------
#
# LOCAL SIGNATURES requires ModSecurity version 3.0.0 or above.
# We recommend to always use the newest ModSecurity version.
#
# The order of file inclusion in your webserver configuration should always be:
# 1. modsecurity.conf
# 2. local-setup.conf (this file)
# 3. rules/*.conf (the LOCAL SIGNATURES rule files)
#

# -- [[ WARNINGS ]] -------------------------------------------------
# This signatures are using with OWASP modsecurity CRS.&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level2 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; rules/LocalSignature-10.confを作成&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level3&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=32&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;LocalSignature-10.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;#
# mod_security3 Local signatures #1.
#
# id: 10000-10999

#SecRule ARGS:testparams &amp;quot;@contains test&amp;quot; &amp;quot;id:10000,deny,log,status:403&amp;quot;&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
以上で、local signature関連の設定は終了
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;local signature\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;local_signature\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:31,&amp;quot;secid&amp;quot;:30,&amp;quot;range&amp;quot;:&amp;quot;32977-34869&amp;quot;} --&gt;
&lt;h4 class=&quot;sectionedit31&quot; id=&quot;nginxの設定&quot;&gt;NGINXの設定&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
ここまで準備できたら、NGINXをWAFとして動作させるための設定を投入する。
&lt;/p&gt;
&lt;dl class=&quot;code&quot;&gt;
&lt;dt&gt;&lt;a href=&quot;http://www.seirios.org/seirios/dokuwiki/doku.php?do=export_code&amp;amp;id=networkapp:waf:mod-security&amp;amp;codeblock=33&quot; title=&quot;この部分をダウンロード&quot; class=&quot;mediafile mf_conf&quot;&gt;nginx.conf&lt;/a&gt;&lt;/dt&gt;
&lt;dd&gt;&lt;pre class=&quot;code&quot;&gt;load_module /usr/local/libexec/nginx/ngx_http_geoip_module.so;
load_module /usr/local/libexec/nginx/ndk_http_module.so;        # need fo lua
load_module /usr/local/libexec/nginx/ngx_http_lua_module.so;

user www www;
worker_processes 1;
events {
  use kqueue;
  worker_connections 4096;
  accept_mutex on;
  accept_mutex_delay 500ms;
}

http {
  server {
    listen localhost:8085;
    location / {
      default_type text/plain;
      return 200 &amp;quot;Thank you for requesting ${request_uri}\n&amp;quot;;
    }
  }

  server { # DropMode
    listen 80;
    modsecurity on;
    error_log /var/log/nginx/test.err info;
    location / {
      modsecurity_rules_file /usr/local/etc/nginx/modsec/DM.conf;
      proxy_pass http://localhost:8085;
      proxy_set_header Host $host;
    }
  }
  server { # MonitorMode
    listen 81;
    modsecurity on;
    error_log /var/log/nginx/test.err info;
    location / {
      modsecurity_rules_file /usr/local/etc/nginx/modsec/MM.conf;
      proxy_pass http://localhost:8085;
      proxy_set_header Host $host;
    }
  }

}&lt;/pre&gt;
&lt;/dd&gt;&lt;/dl&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;NGINX\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;nginx\u306e\u8a2d\u5b9a&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:33,&amp;quot;secid&amp;quot;:31,&amp;quot;range&amp;quot;:&amp;quot;34870-36071&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit32&quot; id=&quot;動作検証&quot;&gt;動作検証&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
ここまでの通り設定してきたら、問題なく MonitorMode、DropModeのWAFが動作していることになる。
&lt;/p&gt;

&lt;p&gt;
以下動作検証。
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u52d5\u4f5c\u691c\u8a3c&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u52d5\u4f5c\u691c\u8a3c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:34,&amp;quot;secid&amp;quot;:32,&amp;quot;range&amp;quot;:&amp;quot;36072-36247&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit33&quot; id=&quot;drop_modeの検証&quot;&gt;Drop Modeの検証&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
WAFに接続できる端末で以下を実行する。
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 問題のない通信&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;$ curl -D - http://waf:80
HTTP/1.1 200 OK
Server: nginx/1.15.5
Date: Tue, 30 Oct 2018 06:02:23 GMT
Content-Type: text/plain
Content-Length: 27
Connection: keep-alive

Thank you for requesting /&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Dropすべき通信 1 (local signatures)&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;$ curl -D - http://waf:80/?testparams=test
HTTP/1.1 403 Forbidden
Server: nginx/1.15.5
Date: Tue, 30 Oct 2018 06:02:39 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;403 Forbidden&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;center&amp;gt;&amp;lt;h1&amp;gt;403 Forbidden&amp;lt;/h1&amp;gt;&amp;lt;/center&amp;gt;
&amp;lt;hr&amp;gt;&amp;lt;center&amp;gt;nginx/1.15.5&amp;lt;/center&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Dropすべき通信 2(OWASP CRS)&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;pre class=&quot;code&quot;&gt;$ curl -D - http://waf:80/?union+select
HTTP/1.1 403 Forbidden
Server: nginx/1.15.5
Date: Tue, 30 Oct 2018 06:09:13 GMT
Content-Type: text/html
Content-Length: 153
Connection: keep-alive

&amp;lt;html&amp;gt;
&amp;lt;head&amp;gt;&amp;lt;title&amp;gt;403 Forbidden&amp;lt;/title&amp;gt;&amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
&amp;lt;center&amp;gt;&amp;lt;h1&amp;gt;403 Forbidden&amp;lt;/h1&amp;gt;&amp;lt;/center&amp;gt;
&amp;lt;hr&amp;gt;&amp;lt;center&amp;gt;nginx/1.15.5&amp;lt;/center&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
Drop modeなら、これだけで判断できるが、一応 log を確認しておくこと
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# Local signature 検出分
xxxx/xx/xx xx:xx:xx [info] 3985#100131: *108 ModSecurity: Access denied with code %d (phase 1). Matched &amp;quot;Operator `Contains&amp;#039; with parameter `test&amp;#039; against variable `ARGS:testparams&amp;#039; (Value: `test&amp;#039; ) [file &amp;quot;/usr/local/etc/nginx/modsec/DM.conf&amp;quot;] [line &amp;quot;115&amp;quot;] [id &amp;quot;10000&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;0&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154087989194.699201&amp;quot;] [ref &amp;quot;o0,4v17,4&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?testparams=test HTTP/1.1&amp;quot;, host: &amp;quot;waf&amp;quot;

xxxx/xx/xx 15:11:31 [warn] 3985#100131: *108 [client 192.0.2.254] ModSecurity: Warning. Matched &amp;quot;Operator `Contains&amp;#039; with parameter `test&amp;#039; against variable `ARGS:testparams&amp;#039; (Value: `test&amp;#039; ) [file &amp;quot;/usr/local/etc/nginx/modsec/DM.conf&amp;quot;] [line &amp;quot;115&amp;quot;] [id &amp;quot;10000&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;0&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154087989194.699201&amp;quot;] [ref &amp;quot;o0,4v17,4&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?testparams=test HTTP/1.1&amp;quot;, host: &amp;quot;waf&amp;quot;

# OWASP CRS検出分(union+select)
xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Warning. Matched &amp;quot;Operator `Rx&amp;#039; with parameter `(?i:(?:\s*?(?:exec|execute).*?(?:\W)xp_cmdshell)|(?:[\&amp;quot;&amp;#039;`]\s*?!\s*?[\&amp;quot;&amp;#039;`\w])|(?:from\W+information_schema\W)|(?:(?:(?:current_)?user|database|schema|connection_id)\s*?\([^\)]*?)|(?:[\&amp;quot;&amp;#039;`];?\s*?(?:sele (185 characters omitted)&amp;#039; against variable `ARGS_NAMES:union select&amp;#039; (Value: `union select&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf&amp;quot;] [line &amp;quot;150&amp;quot;] [id &amp;quot;942190&amp;quot;] [rev &amp;quot;2&amp;quot;] [msg &amp;quot;Detects MSSQL code execution and information gathering attempts&amp;quot;] [data &amp;quot;Matched Data: union select found within ARGS_NAMES:union select: union select&amp;quot;] [severity &amp;quot;2&amp;quot;] [ver &amp;quot;OWASP_CRS/3.0.0&amp;quot;] [maturity &amp;quot;9&amp;quot;] [accuracy &amp;quot;8&amp;quot;] [tag &amp;quot;application-multi&amp;quot;] [tag &amp;quot;language-multi&amp;quot;] [tag &amp;quot;platform-multi&amp;quot;] [tag &amp;quot;attack-sqli&amp;quot;] [tag &amp;quot;OWASP_CRS/WEB_ATTACK/SQL_INJECTION&amp;quot;] [tag &amp;quot;WASCTC/WASC-19&amp;quot;] [tag &amp;quot;OWASP_TOP_10/A1&amp;quot;] [tag &amp;quot;OWASP_AppSensor/CIE1&amp;quot;] [tag &amp;quot;PCI/6.5.2&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154087989855.740312&amp;quot;] [ref &amp;quot;o0,12v6,12t:urlDecodeUni&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, host: &amp;quot;waf&amp;quot;

xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Access denied with code %d (phase 2). Matched &amp;quot;Operator `Ge&amp;#039; with parameter `5&amp;#039; against variable `TX:ANOMALY_SCORE&amp;#039; (Value: `5&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf&amp;quot;] [line &amp;quot;36&amp;quot;] [id &amp;quot;949110&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;Inbound Anomaly Score Exceeded (Total Score: 5)&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;2&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [tag &amp;quot;application-multi&amp;quot;] [tag &amp;quot;language-multi&amp;quot;] [tag &amp;quot;platform-multi&amp;quot;] [tag &amp;quot;attack-generic&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154087989855.740312&amp;quot;] [ref &amp;quot;&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, host: &amp;quot;waf&amp;quot;

xxxx/xx/xx xx:xx:xx [warn] 3985#100131: *109 [client 192.0.2.254] ModSecurity: Warning. Matched &amp;quot;Operator `Ge&amp;#039; with parameter `5&amp;#039; against variable `TX:ANOMALY_SCORE&amp;#039; (Value: `5&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf&amp;quot;] [line &amp;quot;36&amp;quot;] [id &amp;quot;949110&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;Inbound Anomaly Score Exceeded (Total Score: 5)&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;2&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154087989855.740312&amp;quot;] [ref &amp;quot;&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, host: &amp;quot;waf&amp;quot;

xxxx/xx/xx xx:xx:xx [info] 3985#100131: *109 ModSecurity: Warning. Matched &amp;quot;Operator `Ge&amp;#039; with parameter `5&amp;#039; against variable `TX:INBOUND_ANOMALY_SCORE&amp;#039; (Value: `5&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/RESPONSE-980-CORRELATION.conf&amp;quot;] [line &amp;quot;61&amp;quot;] [id &amp;quot;980130&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;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&amp;#039;&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;0&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [tag &amp;quot;event-correlation&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154087989855.740312&amp;quot;] [ref &amp;quot;&amp;quot;] while logging request, client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, host: &amp;quot;waf&amp;quot;
&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Drop Mode\u306e\u691c\u8a3c&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;drop_mode\u306e\u691c\u8a3c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:34,&amp;quot;secid&amp;quot;:33,&amp;quot;range&amp;quot;:&amp;quot;36248-41781&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit34&quot; id=&quot;monitor_modeの検証&quot;&gt;Monitor Modeの検証&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Monitor Modeでの動作確認は、HTTPレベルでのやり取りを見ても判断はできない。
そのため、上記と同じ試験を行った上で、logを見て判断する。
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;$ curl -D - http://waf:81
$ curl -D - http://waf:81/?testparams=test
$ curl -D - http://waf:81/?union+select&lt;/pre&gt;

&lt;p&gt;
以下logの例
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;# Local Signature検出分
xxxx/xx/xx xx:xx:xx [info] 95104#100127: *113 ModSecurity: Warning. Matched &amp;quot;Operator `Contains&amp;#039; with parameter `test&amp;#039; against variable `ARGS:testparams&amp;#039; (Value: `test&amp;#039; ) [file &amp;quot;/usr/local/etc/nginx/modsec/MM.conf&amp;quot;] [line &amp;quot;115&amp;quot;] [id &amp;quot;10000&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;0&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;154088069495.032656&amp;quot;] [ref &amp;quot;o0,4v17,4&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?testparams=test HTTP/1.1&amp;quot;, host: &amp;quot;waf:81&amp;quot;

# OWASP CRS検出分(union+select)
xxxx/xx/xx xx:xx:xx [info] 95104#100127: *116 ModSecurity: Warning. Matched &amp;quot;Operator `Rx&amp;#039; with parameter `(?i:(?:\s*?(?:exec|execute).*?(?:\W)xp_cmdshell)|(?:[\&amp;quot;&amp;#039;`]\s*?!\s*?[\&amp;quot;&amp;#039;`\w])|(?:from\W+information_schema\W)|(?:(?:(?:current_)?user|database|schema|connection_id)\s*?\([^\)]*?)|(?:[\&amp;quot;&amp;#039;`];?\s*?(?:sele (185 characters omitted)&amp;#039; against variable `ARGS_NAMES:union select&amp;#039; (Value: `union select&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf&amp;quot;] [line &amp;quot;150&amp;quot;] [id &amp;quot;942190&amp;quot;] [rev &amp;quot;2&amp;quot;] [msg &amp;quot;Detects MSSQL code execution and information gathering attempts&amp;quot;] [data &amp;quot;Matched Data: union select found within ARGS_NAMES:union select: union select&amp;quot;] [severity &amp;quot;2&amp;quot;] [ver &amp;quot;OWASP_CRS/3.0.0&amp;quot;] [maturity &amp;quot;9&amp;quot;] [accuracy &amp;quot;8&amp;quot;] [tag &amp;quot;application-multi&amp;quot;] [tag &amp;quot;language-multi&amp;quot;] [tag &amp;quot;platform-multi&amp;quot;] [tag &amp;quot;attack-sqli&amp;quot;] [tag &amp;quot;OWASP_CRS/WEB_ATTACK/SQL_INJECTION&amp;quot;] [tag &amp;quot;WASCTC/WASC-19&amp;quot;] [tag &amp;quot;OWASP_TOP_10/A1&amp;quot;] [tag &amp;quot;OWASP_AppSensor/CIE1&amp;quot;] [tag &amp;quot;PCI/6.5.2&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;15408806983.603717&amp;quot;] [ref &amp;quot;o0,12v6,12t:urlDecodeUni&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, host: &amp;quot;waf:81&amp;quot;

xxxx/xx/xx xx:xx:xx [info] 95104#100127: *116 ModSecurity: Warning. Matched &amp;quot;Operator `Ge&amp;#039; with parameter `5&amp;#039; against variable `TX:ANOMALY_SCORE&amp;#039; (Value: `5&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/REQUEST-949-BLOCKING-EVALUATION.conf&amp;quot;] [line &amp;quot;36&amp;quot;] [id &amp;quot;949110&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;Inbound Anomaly Score Exceeded (Total Score: 5)&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;2&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [tag &amp;quot;application-multi&amp;quot;] [tag &amp;quot;language-multi&amp;quot;] [tag &amp;quot;platform-multi&amp;quot;] [tag &amp;quot;attack-generic&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;15408806983.603717&amp;quot;] [ref &amp;quot;&amp;quot;], client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, host: &amp;quot;waf:81&amp;quot;

xxxx/xx/xx xx:xx:xx [info] 95104#100127: *116 ModSecurity: Warning. Matched &amp;quot;Operator `Ge&amp;#039; with parameter `5&amp;#039; against variable `TX:INBOUND_ANOMALY_SCORE&amp;#039; (Value: `5&amp;#039; ) [file &amp;quot;/usr/local/waf/owasp-modsecurity-crs/rules/RESPONSE-980-CORRELATION.conf&amp;quot;] [line &amp;quot;61&amp;quot;] [id &amp;quot;980130&amp;quot;] [rev &amp;quot;&amp;quot;] [msg &amp;quot;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&amp;#039;&amp;quot;] [data &amp;quot;&amp;quot;] [severity &amp;quot;0&amp;quot;] [ver &amp;quot;&amp;quot;] [maturity &amp;quot;0&amp;quot;] [accuracy &amp;quot;0&amp;quot;] [tag &amp;quot;event-correlation&amp;quot;] [hostname &amp;quot;192.0.2.254&amp;quot;] [uri &amp;quot;/&amp;quot;] [unique_id &amp;quot;15408806983.603717&amp;quot;] [ref &amp;quot;&amp;quot;] while logging request, client: 192.0.2.254, server: , request: &amp;quot;GET /?union+select HTTP/1.1&amp;quot;, upstream: &amp;quot;http://127.0.0.1:8085/?union+select&amp;quot;, host: &amp;quot;waf:81&amp;quot;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Monitor Mode\u306e\u691c\u8a3c&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;monitor_mode\u306e\u691c\u8a3c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:38,&amp;quot;secid&amp;quot;:34,&amp;quot;range&amp;quot;:&amp;quot;41782-45360&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit35&quot; id=&quot;落ち穂拾い&quot;&gt;落ち穂拾い&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Memo
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;*-Base.conf&lt;/code&gt;内の SecRuleEngine 設定を記述せず、location内に記述したらどうなるか？&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; server Directive内で&lt;code&gt;*-Base.conf&lt;/code&gt;を設定し、location Directive内でSecRuleEngineを書き換える方法はあるか？&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
今後確認しておくこと
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; Project Honey Pot HTTP Blacklist&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.projecthoneypot.org/httpbl.php&quot; class=&quot;urlextern&quot; title=&quot;https://www.projecthoneypot.org/httpbl.php&quot;&gt;https://www.projecthoneypot.org/httpbl.php&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#wiki-SecHttpBlKey&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#wiki-SecHttpBlKey&quot;&gt;https://github.com/SpiderLabs/ModSecurity/wiki/Reference-Manual#wiki-SecHttpBlKey&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; GeoIP Database&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://blog.spiderlabs.com/2010/10/detecting-malice-with-modsecurity-geolocation-data.html&quot; class=&quot;urlextern&quot; title=&quot;http://blog.spiderlabs.com/2010/10/detecting-malice-with-modsecurity-geolocation-data.html&quot;&gt;http://blog.spiderlabs.com/2010/10/detecting-malice-with-modsecurity-geolocation-data.html&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://blog.spiderlabs.com/2010/11/detecting-malice-with-modsecurity-ip-forensics.html&quot; class=&quot;urlextern&quot; title=&quot;http://blog.spiderlabs.com/2010/11/detecting-malice-with-modsecurity-ip-forensics.html&quot;&gt;http://blog.spiderlabs.com/2010/11/detecting-malice-with-modsecurity-ip-forensics.html&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; 国別の無制限Block( &lt;code&gt;Block Countries&lt;/code&gt; on crs-setup.conf)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; DoS防御( &lt;code&gt;Anti-Automation / DoS Protection&lt;/code&gt; on crs-setup.conf)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; UTF-8チェック( &lt;code&gt;Check UTF-8 encoding&lt;/code&gt; on crs-setup.conf)&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; 一般にUTF-8の処理はむしろトラブルを生みやすいので、いつか試験しなければならない&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;\u843d\u3061\u7a42\u62fe\u3044&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;\u843d\u3061\u7a42\u62fe\u3044&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:40,&amp;quot;secid&amp;quot;:35,&amp;quot;range&amp;quot;:&amp;quot;45361-46400&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit36&quot; id=&quot;link集&quot;&gt;Link集&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project&quot; class=&quot;urlextern&quot; title=&quot;https://www.owasp.org/index.php/Category:OWASP_ModSecurity_Core_Rule_Set_Project&quot;&gt;OWASP ModSecurity Core Rule Set Project&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://modsecurity.org&quot; class=&quot;urlextern&quot; title=&quot;https://modsecurity.org&quot;&gt;ModSecurity&lt;/a&gt; mod_securityのページ&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://github.com/SpiderLabs/ModSecurity/wiki#secdebugloglevel&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/SpiderLabs/ModSecurity/wiki#secdebugloglevel&quot;&gt;ModSecurity GitHUB Home&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules_FAQ&quot; class=&quot;urlextern&quot; title=&quot;https://atomicorp.com/wiki/index.php/Atomic_ModSecurity_Rules_FAQ&quot;&gt;Atomic ModSecurity Rules FAQ&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://blog.tokumaru.org/2012/01/&quot; class=&quot;urlextern&quot; title=&quot;https://blog.tokumaru.org/2012/01/&quot;&gt;ModSecurityをソースからビルドしてhashdos対策に活用する&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; ModSecurity version 2系の記事。&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/install-modsecurity2/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/install-modsecurity2/&quot;&gt;ModSecurity2のインストール&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/modsecurity-basic-config/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/modsecurity-basic-config/&quot;&gt;ModSecurityのベーシックルール&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/auditlog/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/auditlog/&quot;&gt;ModSecurityのAuditLog覚え書き&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/sec-rule/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/sec-rule/&quot;&gt;ModSecurityのSecRuleディレクティブ&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/operator/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/operator/&quot;&gt;ModSecurityのオペレータを読み解く&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/disruptive-action/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/disruptive-action/&quot;&gt;ModSecurityの基本アクションを読み解く&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/special-action/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/special-action/&quot;&gt;ModSecurityのスペシャルアクションを読み解く&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/transformation-functions/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/transformation-functions/&quot;&gt;ModSecurityのTransformation functionsを読み解く&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/about-phase/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/about-phase/&quot;&gt;ModSecurityのProcessing Phasesを紐解く&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;http://open-groove.net/modsecurity/defend-brute-force/&quot; class=&quot;urlextern&quot; title=&quot;http://open-groove.net/modsecurity/defend-brute-force/&quot;&gt;ModSecurityでブルートフォース攻撃を防御するには&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1 node&quot;&gt;&lt;div class=&quot;li&quot;&gt; 周辺&lt;/div&gt;
&lt;ul&gt;
&lt;li class=&quot;level2&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;a href=&quot;https://www.imperva.jp/lg/lgw_trial.asp?pid=483&quot; class=&quot;urlextern&quot; title=&quot;https://www.imperva.jp/lg/lgw_trial.asp?pid=483&quot;&gt;Software: WAF Testing Framework&lt;/a&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Link\u96c6&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;link\u96c6&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:40,&amp;quot;secid&amp;quot;:36,&amp;quot;range&amp;quot;:&amp;quot;46401-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 14 Nov 2018 08:00:25 +0000</pubDate>
        </item>
    </channel>
</rss>
