文章目录
- [需求:漏洞扫描发现某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. 存在的问题
-
直接使用最新的openresty, 则编译后,nginx版本为1.27.1.2 ,可能存在nginx其他漏洞

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

-
总结:通过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