zoukankan      html  css  js  c++  java
  • nginx 对于post,get参数访问做xss,sql注入过滤

    现在很多基于百度的nginx 防止sql注入都是get方式,如果post就没有了.

    坑点:

    1.$query_string  获取get请求的数据

    2.$request_body 获取post请求的数据,但是这里如果对$request_body进行校验,则为空!!!!!!!!!!  所以这个方式不可行.

    3.在网上找到,通过另外一种方式来获取请求数据.openresty.下面就来说一说如何操作.

    1.环境:

        1.1 操作系统  windows 10

        1.2 http://openresty.org/en/download.html 下载可以获取请求参数基于windows下的nginx(模块自带nginx)

        

    2.编写  nginx.conf 配置文件(./openresty-1.19.3.1-win64/conf/nginx.conf)

       

     下面是原文

    server {
        #nginx 监听端口
        listen 80;
        #nginx 服务名称
        server_name localhost;
    
        #charset koi8-r;
    
        #access_log logs/host.access.log main;
    
        location / {
    #root html;
    #index index.html index.htm;
    
        default_type text/html;
    #打开 lua 允许使用这种方式来获取请求数据
        lua_need_request_body on;
        access_by_lua_block {
    #获取 post请求数据
            local body = ngx.var.request_body
    #获取 get请求数据
            local query = ngx.var.query_string
    #正则表达式
            local regex = "(.*?((select)|(from)|(count)|(delete)|(update)|(drop)|(truncate)).*?){1,}"
    #匹配post参数
            local m,err = ngx.re.match(body, regex)
    #匹配get参数
            local n,err = ngx.re.match(query, regex)
    #做get或者post校验
            if m then
                #返回数据 (二选一)
                ngx.say('{"code": 999,"msg": "传参异常","ok": false,"runningTime": "0ms"}')
                #返回页面
                #ngx.exit(404)
            end
        }
    #设置日志
    access_log logs/host.access.log json_log;
    #转换应用服务ip和端口
    proxy_pass http://127.0.0.1:8081;
    }
    
    location / {
    root html;
    index index.html index.htm;
    }
    
    #error_page 404 /404.html;
    
    # redirect server error pages to the static page /50x.html
    #
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ .php$ {
    # proxy_pass http://127.0.0.1;
    #}
    
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ .php$ {
    # root html;
    # fastcgi_pass 127.0.0.1:9000;
    # fastcgi_index index.php;
    # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
    # include fastcgi_params;
    #}
    
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /.ht {
    # deny all;
    #}
    }    
    

      效果:

     

      

     希望大家互相学习.

       

  • 相关阅读:
    XCode5中新建工程后强制使用了ARC,如何去掉?
    面向对象程序的设计原则--Head First 设计模式笔记
    ios控件自定义指引
    iOS UITableViewDelegate && UITableViewDataSource 执行顺序
    awakeFromNib方法和viewDidLoad方法区别
    ios 视图的旋转及应用
    线段树模板 (刘汝佳)
    poj 3468
    hdu 2829(四边形优化 && 枚举最后一个放炸弹的地方)
    poj 3517(约瑟夫环问题)
  • 原文地址:https://www.cnblogs.com/zf-crazy/p/14168780.html
Copyright © 2011-2022 走看看