
Gixy-Next v0.7.1
Gixy-Next:NGINX 配置安全扫描器与性能检查器
Gixy-Next:用于安全审计的 NGINX 配置安全扫描器
概述
Gixy-Next(Gixy)是一款开源的 NGINX 配置安全扫描器与加固工具,可对 nginx.conf 进行静态分析,在配置进入生产环境之前检测出安全配置错误、加固缺口以及常见的性能陷阱。它是 Yandex 的 Gixy 的一个积极维护的分支。Gixy-Next 的源代码可在 GitHub 上获取。
Gixy-Next 也可以在浏览器中此页面运行。无需下载;你可以在网站上扫描你的配置(在本地运行,使用 WebAssembly)。
快速开始
Gixy-Next(gixy 或 gixy-next 命令行工具)发布在 PyPI 上。你可以使用 pip 或 uv 安装它:
# pip
pip3 install gixy-next
# uv
uv pip install gixy-next
然后你可以运行它:
# gixy defaults to reading /etc/nginx/nginx.conf
gixy
# But you can also specify a path to the configuration
gixy /opt/nginx.conf
你也可以将 NGINX 配置导出为单个转储文件(参见 nginx -T Live Configuration Dump):
# Dumps the full NGINX configuration into a single file (including all includes)
nginx -T > ./nginx-dump.conf
# Scan the dump elsewhere (or via stdin):
gixy ./nginx-dump.conf
# or
cat ./nginx-dump.conf | gixy -
基于 Web 的扫描器
无需在本地下载并运行 Gixy-Next,你可以使用此网页在 Web 浏览器中扫描配置(在本地通过 WebAssembly 运行)。
使用 Docker 扫描
Gixy-Next 以 Docker 镜像形式提供,可从 Docker Hub 或 GitHub Registry 获取。
通过将本地配置文件挂载到容器中来扫描该文件:
# Use Github Registry
docker run --pull=always --rm -v "$PWD/nginx.conf:/nginx.conf:ro" ghcr.io/megamansec/gixy-next /nginx.conf
# Or Docker Hub
docker run --pull=always --rm -v "$PWD/nginx.conf:/nginx.conf:ro" megamansec/gixy-next /nginx.conf
扫描 NGINX 实时配置转储:
# Dumps the full NGINX configuration into a single file (including all includes)
nginx -T > ./nginx-dump.conf
# Use Github Registry
docker run --pull=always --rm -v "$PWD/nginx-dump.conf:/nginx-dump.conf:ro" ghcr.io/megamansec/gixy-next /nginx-dump.conf
# Or Docker Hub
docker run --pull=always --rm -v "$PWD/nginx-dump.conf:/nginx-dump.conf:ro" megamansec/gixy-next /nginx-dump.conf
从标准输入扫描:
# Use Github Registry
nginx -T | docker run --pull=always --rm -i ghcr.io/megamansec/gixy-next gixy-next -
# Or Docker Hub
nginx -T | docker run --pull=always --rm -i megamansec/gixy-next gixy-next -
功能概述
Gixy-Next 能够检测 nginx.conf 及所包含配置文件中的各类 NGINX 安全与性能配置错误。支持以下插件:
- [add_header_content_type] 通过 add_header 设置 Content-Type
- [add_header_multiline] 多行响应头
- [add_header_redefinition] 通过 "add_header" 指令重定义响应头
- [alias_traversal] 因 alias 配置错误导致的路径遍历
- [allow_without_deny] 指定了 allow 但未指定 deny
- [default_server_flag] 缺少 default_server 标志
- [error_log_off]
error_log设置为off - [filesystem_root_exposure] 将文件系统根目录用作文档根目录
- [hash_without_default] hash 块中缺少 default
- [host_spoofing] 请求的 Host 头伪造
- [http2_misdirected_request] 缺少 HTTP/2 错误定向请求防护
- [http_splitting] HTTP 响应拆分
- [if_is_evil] 在 location 上下文中使用 if 是危险的
- [invalid_regex] 无效的正则捕获组
- [low_keepalive_requests]
keepalive_requests值过低 - [missing_worker_processes] 缺少
worker_processes - [mixed_case_variable] 大小写混合的变量引用
- [origins] referer/origin 头验证问题
- [overlapping_captures] rewrite 重定向/参数上下文中捕获组重叠
- [proxy_buffering_off] 禁用
proxy_buffering - [proxy_pass_normalized]
proxy_pass可能向上游发送非预期路径 - [proxy_set_header_redefinition] 通过 "proxy_set_header" 指令重定义代理请求头
- [quic_bpf_reuseport] 重载后 QUIC 连接被静默丢弃
- [regex_redos] 正则表达式拒绝服务(ReDoS)
- [resolver_external] 使用外部 DNS 名称服务器
- [return_bypasses_allow_deny] return 指令绕过 allow/deny 限制
- [ssl_ecdh_curve] 后量子组导致 NGINX 在旧版 OpenSSL 上无法启动
- [ssl_stapling_letsencrypt] OCSP stapling 对 Let's Encrypt 证书不起作用
- [ssl_stapling_without_resolver] 没有 resolver 时 OCSP stapling 会静默失败
- [ssrf] 服务端请求伪造
- [stale_dns_cache] proxy_pass 中使用了过时/陈旧的缓存 DNS 记录
- [status_page_exposed] 确保 status_page 未对外暴露
- [try_files_is_evil_too] 未启用 open_file_cache 时
try_files指令是危险的 - [unanchored_regex] 未锚定的正则表达式
- [unnamed_groups] rewrite 查询字符串中的未命名捕获组
- [valid_referers] valid_referers 中的 none/blocked
- [version_disclosure] 为 server_tokens 使用不安全的取值
- [worker_rlimit_nofile_vs_connections]
worker_rlimit_nofile必须至少是worker_connections的两倍
有未检测到的情况?请在 GitHub 上提交一个 issue,说明缺少了什么!
用法(标志)
gixy 默认从 /etc/nginx/nginx.conf 读取系统的 NGINX 配置。你也可以通过将其传递给 gixy 来指定位置:
# Analyze the configuration in /opt/nginx.conf
gixy /opt/nginx.conf
你可以使用 --tests 运行一个针对性的检查子集:
# Only run these checks
gixy --tests http_splitting,ssrf,version_disclosure
或者使用 --skips 跳过一些嘈杂的检查:
# Run everything except these checks
gixy --skips low_keepalive_requests,worker_rlimit_nofile_vs_connections
要仅报告某一严重级别或更高级别的问题,请使用可叠加的 -l 标志:
# -l for LOW severity issues and higher, -ll for MEDIUM and higher, and -lll for only HIGH severity issues
gixy -ll
默认情况下,gixy 的输出为 ANSI 彩色格式;建议在兼容的终端中查看。你可以使用 --format(-f)标志并指定 text 值来获得无彩色输出:
$ gixy -f text
==================== Results ===================
Problem: [http_splitting] Possible HTTP-Splitting vulnerability.
Description: Using variables that can contain "\n" may lead to http injection.
Additional info: https://gixy.io/plugins/http_splitting/
Reason: At least variable "$action" can contain "\n"
Pseudo config:
include /etc/nginx/sites/default.conf;
server {
location ~ /v1/((?<action>[^.]*)\.json)?$ {
add_header X-Action $action;
}
}
==================== Summary ===================
Total issues:
Informational: 0
Low: 0
Medium: 0
High: 1
你也可以使用 -f json 来获取可复现、机器可读的 JSON 输出:
