编译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
相关推荐
s_daqing20 小时前
ubuntu(arm)使用nginx安装静态服务器
服务器·nginx·ubuntu
物有本木20 小时前
httpsok-v2.0.8发布-支持IIS证书自动续签
nginx·ssl
Volunteer Technology21 小时前
Nginx部署静态项目
运维·服务器·nginx
摇滚侠1 天前
尚硅谷 Nginx 教程(亿级流量 Nginx 架构设计),基本使用,笔记 6-42
java·笔记·nginx
衫水1 天前
Ubuntu 系统部署 Vue/Vite 应用到 Nginx
vue.js·nginx·ubuntu
资料库011 天前
LVS、Nginx、HAProxy核心区别是什么?
运维·nginx·lvs
移幻漂流1 天前
Lua的现状与机遇:技术生态全景及高潜力领域分析
junit·单元测试·lua
我发在否1 天前
OpenResty > Lua断点调试
vscode·lua·断点·openresty·luapanda
Filotimo_2 天前
Nginx 的概念
运维·nginx
大雨淅淅2 天前
【开发工具】Postman从入门到精通:环境搭建与使用全攻略
开发语言·lua