openresty用naxsi防xss、SQL注入

下载naxsi

wget https://github.com/nbs-system/naxsi/archive/untagged-afabfc163946baa8036f.tar.gz
tar zxvf untagged-afabfc163946baa8036f.tar.gz
mv naxsi-untagged-afabfc163946baa8036f/ naxsi

编译openresty加上--add-module

./configure --prefix=/usr/local/openresty --with-http_stub_status_module --with-http_gzip_static_module --with-luajit --add-module=/usr/local/naxsi/naxsi_src

将核心规则复制到openresty的conf中

cp /usr/local/naxsi/naxsi_config/naxsi_core.rules /usr/local/openresty/nginx/conf/

自定义一个规则文件

vi /usr/local/openresty/nginx/conf/mySite.rules

内容为

#开启 naxsi
SecRulesEnabled;
#定义阻止请求的位置
DeniedUrl "/RequestDenied";
#CheckRules, 确定 naxsi 何时采取行动
CheckRule "$SQL >= 8" BLOCK;
CheckRule "$RFI >= 8" BLOCK;
CheckRule "$TRAVERSAL >= 4" BLOCK;
CheckRule "$EVADE >= 4" BLOCK;
CheckRule "$XSS >= 8" BLOCK;

编辑opernresty的主配置文件

vi /usr/local/openresty/nginx/conf/nginx.conf
http {
    include       mime.types;
    include       naxsi_core.rules;
    default_type  text/html;

    sendfile        on;

    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            include mySite.rules;
            root   html;
            index  index.html index.htm;
        }

        location /test {
          include mySite.rules;
          content_by_lua_file /usr/local/lua/test.lua;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        
        #定义naxsi.rules中DeniedUrl返回的代码
        location /RequestDenied {
            return 403;
        }
        
        error_page  403  /403.html;
        location = /403.html {
            root   html;
        }
    }

}

 

转载于:https://www.cnblogs.com/xiaofengfree/p/10272877.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值