共计 1714 个字符,预计需要花费 5 分钟才能阅读完成。
Gixy 是一款用来分析 Nginx 配置文件的工具。Gixy 的主要目标是防止安全配置错误,并自动进行缺陷检测。
Gixy 特性
- 找出服务器端请求伪造。
- 验证 HTTP 拆分。
- 验证 referrer/origin 问题。
- 验证是否正确通过 add_header 指令重新定义 Response Headers。
- 验证请求的主机头是否伪造。
- 验证 valid_referers 是否为空。
- 验证是否存在多行主机头。
Gixy 安装
Gixy 是一个 Python 开发的应用,目前支持的 Python 版本是 2.7 和 3.5+。
安装步骤非常简单,直接使用 pip 安装即可:
$ pip install gixy
如果你的系统比较老,自带 Python 版本比较低。可参考「使用 pyenv 搭建 python 虚拟环境」或者「如何在 CentOS 上启用软件集 Software Collections(SCL)」升级 Python 版本。
Gixy 使用
Gixy 默认会检查 /etc/nginx/nginx.conf 配置文件。
$ gixy
也可以指定 NGINX 配置文件所在的位置。
$ gixy /usr/local/nginx/conf/nginx.conf | |
==================== Results =================== | |
No issues found. | |
==================== Summary =================== | |
Total issues: | |
Unspecified: 0 | |
Low: 0 Medium: 0 | |
High: 0 |
来看一个 http 折分配置有问题的示例,修改 Nginx 配置:
server { | |
… | |
location ~ /v1/((?<action>[^.]*)/.json)?$ {add_header X-Action $action;} | |
… | |
} |
再次运行 Gixy 检查配置。
$ gixy /usr/local/nginx/conf/nginx.conf | |
==================== Results =================== | |
>> Problem: [http_splitting] Possible HTTP-Splitting vulnerability. | |
Description: Using variables that can contain“/n”may lead to http injection. | |
Additional info: https://github.com/yandex/gixy/blob/master/docs/en/plugins/httpsplitting.md | |
Reason: At least variable“$action”can contain“/n”Pseudo config: | |
server { | |
server_name localhost mike.hi-linux.com; | |
location ~ /v1/((?<action>[^.]*)/.json)?$ {add_header X-Action $action;} | |
} | |
==================== Summary =================== | |
Total issues: | |
Unspecified: 0 | |
Low: 0 | |
Medium: 0 | |
High: 1 |
从结果可以看出检测到了一个问题,指出问题类型为 http_splitting。原因是 $action 变量中可以含有换行符。这就是 HTTP 响应头拆分漏洞,通过 CRLFZ 注入实现攻击。
如果你要暂时忽略某类错误检查,可以使用 –skips 参数:
$ gixy –skips http_splitting /usr/local/nginx/conf/nginx.conf | |
==================== Results =================== | |
No issues found. | |
==================== Summary =================== | |
Total issues: | |
Unspecified: 0 | |
Low: 0 | |
Medium: 0 | |
High: 0 |
更多使用方法可以参考 gixy –help 命令。
正文完
星哥玩云-微信公众号
