微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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;
#}
}    

  效果

 

 

 

 

 

 

  

 希望大家互相学习.

   

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐