nginx用のWeb Application Firewallであるnaxsiを導入してみました。
カスタムrpmを作って、naxsi-coreを入れてみました。
nginx最新版のソースRPMをまずインストール。
rpm -ivh nginx-1.4.1-1.el6.ngx.src.rpm
次に、naxsiのソースを展開。
zcat naxsi-core-0.49.tgz | tar xvf -
nginxのSPECファイルを編集。
vi nginx.spec
–with-debugがないconfigureの引数に「–add-module=/root/naxsi-core/naxsi_src」を追加します。
./configure \
--prefix=%{_sysconfdir}/nginx \
--sbin-path=%{_sbindir}/nginx \
--conf-path=%{_sysconfdir}/nginx/nginx.conf \
--error-log-path=%{_localstatedir}/log/nginx/error.log \
--http-log-path=%{_localstatedir}/log/nginx/access.log \
--pid-path=%{_localstatedir}/run/nginx.pid \
--lock-path=%{_localstatedir}/run/nginx.lock \
--http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp \
--http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp \
--user=%{nginx_user} \
--group=%{nginx_group} \
--with-http_spdy_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--add-module=/root/naxsi-core/naxsi_src \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-cc-opt="%{optflags} $(pcre-config --cflags)" \
$*
rpmbuildをして、生成したrpmをインストール。
naxsi_core.rulesをインクルード。
vi /etc/nginx/nginx.conf
http {
include /etc/nginx/mime.types;
include /etc/nginx/naxsi_core.rules;
</pre> LearningMode; #Enables learning mode SecRulesEnabled; #SecRulesDisabled; DeniedUrl "/RequestDenied"; include "/tmp/naxsi_rules.tmp"; ## check rules CheckRule "$SQL >= 8" BLOCK; CheckRule "$RFI >= 8" BLOCK; CheckRule "$TRAVERSAL >= 4" BLOCK; CheckRule "$EVADE >= 4" BLOCK; CheckRule "$XSS >= 8" BLOCK; <pre>
vi /etc/nginx/conf.d/default.conf
</pre>
server {
listen 80;
server_name totalsolution.biz;
#charset koi8-r;
access_log /var/log/nginx/totalsolution.biz.access.log ltsv;
error_log /var/log/nginx/totalsolution.biz.error.log;
location / {
include /etc/nginx/test.rules;
<pre>
最後に、nginxを再起動して終了。
error_logに以下のようにnaxsiのログが書き出されれば成功。
</pre> 2013/09/07 08:19:46 [error] 25875#0: *6319 NAXSI_FMT: ip=123.218.123.177&server=xxx.js&learnin g=1&total_processed=1490&total_blocked=366&zone0=HEADERS&id0=1005&var_name0=cookie &zone1=HEADERS&id1=1010&var_name1=cookie&zone2=HEADERS&id2=1011&var_name2=cookie&z one3=HEADERS&id3=1315&var_name3=cookie, client: 123.218.123.177, server: totalsolu tion.biz, request: "GET /cms/wp-content/plugins/wp-slimstat/wp-slimstat.js HTTP/1. 1", host: "www.totalsolution.biz", referrer: "http://www.totalsolution.biz/cms/wp- login.php"