编译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
相关推荐
JoySSLLian1 天前
手把手教你安装免费SSL证书(附宝塔/Nginx/Apache配置教程)
网络·人工智能·网络协议·tcp/ip·nginx·apache·ssl
一分半心动1 天前
宝塔面板lnmp架构,tp6框架网站伪静态
nginx·php
全栈工程师修炼指南1 天前
Nginx | stream 四层反向代理:SSL、PREREAD 阶段模块指令浅析与实践
运维·网络·网络协议·nginx·ssl
脏脏a2 天前
告别物理出勤:Nginx 搭配 cpolar 实现远程开发无缝协作
运维·nginx
Dxy12393102162 天前
413 Request Entity Too Large 原因与解决方案
nginx
CYpdpjRnUE2 天前
光储一体机仿真模型搭建之旅
nginx
AI_56782 天前
Postman接口测试提速技巧:批量请求+智能断言实践
测试工具·lua·postman
Volunteer Technology2 天前
FastDFS+Nginx
运维·nginx
qinyia2 天前
**使用AI助手在智慧运维中快速定位并修复服务异常:以Nginx配置错误导致502错误为例**
linux·运维·服务器·数据库·mysql·nginx·自动化
404Clukay2 天前
Windows Server 配置 Let‘s Encrypt 免费 HTTPS 证书(WACS + Nginx 自动化方案)
windows·nginx·https