编译nginx-1.28.0支持lua语法

文章目录

  • [需求:漏洞扫描发现某POST请求的接口存在【NoSQL 注入】,需要通过nginx代理服务时,拦截非正常参数请求](#需求:漏洞扫描发现某POST请求的接口存在【NoSQL 注入】,需要通过nginx代理服务时,拦截非正常参数请求)
  • [1. 解决思路](#1. 解决思路)
  • [2. 存在的问题](#2. 存在的问题)

需求:漏洞扫描发现某POST请求的接口存在【NoSQL 注入】,需要通过nginx代理服务时,拦截非正常参数请求

1. 解决思路

sql 复制代码
  location /t1 {
            # 仅处理POST请求,非POST正常转发
             access_by_lua_block {
            -- 只处理POST请求
            if ngx.req.get_method() == "POST" then
                ngx.req.read_body()  -- 读取请求体
                local body_data = ngx.req.get_body_data()

                -- 如果请求体较大被存入临时文件,从文件读取
                if not body_data then
                    local file_name = ngx.req.get_body_file()
                    if file_name then
                        local file = io.open(file_name, "r")
                        if file then
                            body_data = file:read("*a")
                            file:close()
                        end
                    end
                end

                -- 判断是否包含"$t"参数
                if body_data and string.find(body_data, "%$") then
                    ngx.exit(404)  -- 直接返回404
                end
                    -- ngx.exit(200)  -- 直接返回404
                -- 不包含则继续正常处理(返回200)
            end
        }
        //proxy_pass xxx; #正常转发请求
   }

2. 存在的问题

  1. 直接使用最新的openresty, 则编译后,nginx版本为1.27.1.2 ,可能存在nginx其他漏洞

  2. 使用最新版原生nginx,则编译后可能不支持 lua语法,需要额外处理相关依赖和参数

  3. 总结:通过openresty解决lua依赖问题,然后编译最新版原生nginx,即可

bash 复制代码
 #以下是opensty 执行./configure 后默认的编译参数,原生nginx编译直接粘贴过来修改对应路径即可
[root@test002 nginx]# /usr/local/nginx-1.28/sbin/nginx -V
nginx version: nginx/1.28.0
built by gcc 7.3.0 (GCC) 
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx-1.28 --with-cc-opt='-O2 -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2' --add-module=../ngx_devel_kit-0.3.3 --add-module=../openresty-1.27.1.2/build/echo-nginx-module-0.63 --add-module=../openresty-1.27.1.2/build/xss-nginx-module-0.06 --add-module=../openresty-1.27.1.2/build/ngx_coolkit-0.2 --add-module=../openresty-1.27.1.2/build/set-misc-nginx-module-0.33 --add-module=../openresty-1.27.1.2/build/form-input-nginx-module-0.12 --add-module=../openresty-1.27.1.2/build/encrypted-session-nginx-module-0.09 --add-module=../openresty-1.27.1.2/build/srcache-nginx-module-0.33 --add-module=../openresty-1.27.1.2/build/ngx_lua-0.10.28 --add-module=../openresty-1.27.1.2/build/ngx_lua_upstream-0.07 --add-module=../openresty-1.27.1.2/build/headers-more-nginx-module-0.37 --add-module=../openresty-1.27.1.2/build/array-var-nginx-module-0.06 --add-module=../openresty-1.27.1.2/build/memc-nginx-module-0.20 --add-module=../openresty-1.27.1.2/build/rds-json-nginx-module-0.17 --add-module=../openresty-1.27.1.2/build/rds-csv-nginx-module-0.09 --add-module=../openresty-1.27.1.2/build/ngx_stream_lua-0.0.16 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-z,relro -Wl,-z,now' --user=nginx --group=nginx --with-http_stub_status_module --with-http_realip_module --with-http_v2_module --with-http_ssl_module --with-http_dav_module --with-stream --with-stream_ssl_module --with-http_gzip_static_module --with-mail --with-http_sub_module --with-stream --with-stream_ssl_preread_module
相关推荐
姜鱼问生9 小时前
每次开机手动检查 6 样东西?我写了个 2 秒自检脚本
运维·网络·nginx·docker·容器
xixingzhe21 天前
Nginx 看懂请求耗时瓶颈
服务器·前端·nginx
北风toto2 天前
Windows 下用 OpenSSL 生成 SSL 密钥并配置 Nginx 教程
windows·nginx·ssl
卜锦元2 天前
Docker Compose 部署 Nginx 1.30.6 完整指南
nginx·docker·容器
小小龙学IT2 天前
Nginx 开源 Web 服务器与反向代理深度解
前端·nginx·开源
Coisinier2 天前
docker命令管理镜像及容器
linux·运维·nginx·docker·容器·操作系统
2301_32241428042 天前
基于web的校园失物招领管理系统59695-计算机毕设 原创(免费领源码+部署教程+开发环境)
mysql·nginx·php·apache·thinkphp·phpstudy·wampserver
flytalei3 天前
从YAML到Nginx服务访问:动手理解 Kubernetes Pod、Deployment 与 Service
运维·nginx·kubernetes
开开心心_Every3 天前
黄金价格软件国内外价格实时监控超方便
运维·服务器·游戏·智能手机·pdf·lua·perl