forked from yandex/gixy
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new plugin to detect Nginx version disclosure and enhance add_hea…
…der_redefinition Introduced a new plugin that checks if the Nginx version is being disclosed which is a security vulnerability. At the same time, the previous "add_header_redefinition" plugin has been enhanced to check if any secure headers were dropped. Severity level of this issue is now determined based on whether a secure header was dropped or not.
- Loading branch information
1 parent
65e612a
commit 3bfcda4
Showing
16 changed files
with
292 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
|
||
mkdocs: | ||
configuration: mkdocs.yml | ||
|
||
python: | ||
version: 3.7 | ||
install: | ||
- requirements: docs/requirements.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# [version_disclosure] Disclosure of version information | ||
|
||
## Problem | ||
|
||
Nginx version disclosure. | ||
|
||
## Description | ||
|
||
Nginx version disclosure is a security vulnerability that allows an attacker to obtain information about the version of Nginx running on the server. | ||
|
||
## Recommendation | ||
|
||
Disable version disclosure by adding the following directive to your `nginx.conf`: | ||
|
||
```nginx | ||
server_tokens off; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
GIXY | ||
==== | ||
[![Mozilla Public License 2.0](https://img.shields.io/github/license/dvershinin/gixy.svg?style=flat-square)](https://github.com/dvershinin/gixy/blob/master/LICENSE) | ||
[![Python tests](https://github.com/dvershinin/gixy/actions/workflows/pythonpackage.yml/badge.svg)](https://github.com/dvershinin/gixy/actions/workflows/pythonpackage.yml) | ||
[![Your feedback is greatly appreciated](https://img.shields.io/maintenance/yes/2023.svg?style=flat-square)](https://github.com/dvershinin/gixy/issues/new) | ||
[![GitHub issues](https://img.shields.io/github/issues/dvershinin/gixy.svg?style=flat-square)](https://github.com/dvershinin/gixy/issues) | ||
[![GitHub pull requests](https://img.shields.io/github/issues-pr/dvershinin/gixy.svg?style=flat-square)](https://github.com/dvershinin/gixy/pulls) | ||
|
||
# Overview | ||
<img align="right" width="192" height="192" src="logo.png"> | ||
|
||
Gixy is a tool to analyze Nginx configuration. | ||
The main goal of Gixy is to prevent security misconfiguration and automate flaw detection. | ||
|
||
Currently supported Python versions are 2.7, 3.6, 3.7, 3.8 and 3.9. | ||
|
||
Disclaimer: Gixy is well tested only on GNU/Linux, other OSs may have some issues. | ||
|
||
# What it can do | ||
Right now Gixy can find: | ||
|
||
* [[ssrf] Server Side Request Forgery](en/plugins/ssrf.md) | ||
* [[http_splitting] HTTP Splitting](en/plugins/httpsplitting.md) | ||
* [[origins] Problems with referrer/origin validation](en/plugins/origins.md) | ||
* [[add_header_redefinition] Redefining of response headers by "add_header" directive](en/plugins/addheaderredefinition.md) | ||
* [[host_spoofing] Request's Host header forgery](en/plugins/hostspoofing.md) | ||
* [[valid_referers] none in valid_referers](en/plugins/validreferers.md) | ||
* [[add_header_multiline] Multiline response headers](en/plugins/addheadermultiline.md) | ||
* [[alias_traversal] Path traversal via misconfigured alias](en/plugins/aliastraversal.md) | ||
* [[if_is_evil] If is evil when used in location context](en/plugins/if_is_evil.md) | ||
* [[allow_without_deny] Allow specified without deny](en/plugins/allow_without_deny.md) | ||
* [[add_header_content_type] Setting Content-Type via add_header](en/plugins/add_header_content_type.md) | ||
* [[resolver_external] Using external DNS nameservers](https://blog.zorinaq.com/nginx-resolver-vulns/) | ||
* [[version_disclosure] Using external DNS nameservers](en/plugins/version_disclosure.md) | ||
|
||
You can find things that Gixy is learning to detect at [Issues labeled with "new plugin"](https://github.com/dvershinin/gixy/issues?q=is%3Aissue+is%3Aopen+label%3A%22new+plugin%22) | ||
|
||
# Installation | ||
|
||
## CentOS/RHEL and other RPM-based systems | ||
|
||
```bash | ||
yum -y install https://extras.getpagespeed.com/release-latest.rpm | ||
yum -y install gixy | ||
``` | ||
### Other systems | ||
|
||
Gixy is distributed on [PyPI](https://pypi.python.org/pypi/gixy-ng). The best way to install it is with pip: | ||
|
||
```bash | ||
pip install gixy-ng | ||
``` | ||
|
||
Run Gixy and check results: | ||
```bash | ||
gixy | ||
``` | ||
|
||
# Usage | ||
|
||
By default, Gixy will try to analyze Nginx configuration placed in `/etc/nginx/nginx.conf`. | ||
|
||
But you can always specify needed path: | ||
``` | ||
$ gixy /etc/nginx/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/dvershinin/gixy/blob/master/docs/ru/plugins/httpsplitting.md | ||
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: | ||
Unspecified: 0 | ||
Low: 0 | ||
Medium: 0 | ||
High: 1 | ||
``` | ||
|
||
Or skip some tests: | ||
``` | ||
$ gixy --skips http_splitting /etc/nginx/nginx.conf | ||
==================== Results =================== | ||
No issues found. | ||
==================== Summary =================== | ||
Total issues: | ||
Unspecified: 0 | ||
Low: 0 | ||
Medium: 0 | ||
High: 0 | ||
``` | ||
|
||
Or something else, you can find all other `gixy` arguments with the help command: `gixy --help` | ||
|
||
You can also make `gixy` use pipes (stdin), like so: | ||
|
||
```bash | ||
echo "resolver 1.1.1.1;" | gixy - | ||
``` | ||
|
||
## Docker usage | ||
|
||
Gixy is available as a Docker image [from the Docker hub](https://hub.docker.com/r/getpagespeed/gixy/). To | ||
use it, mount the configuration that you want to analyse as a volume and provide the path to the | ||
configuration file when running the Gixy image. | ||
``` | ||
$ docker run --rm -v `pwd`/nginx.conf:/etc/nginx/conf/nginx.conf getpagespeed/gixy /etc/nginx/conf/nginx.conf | ||
``` | ||
|
||
If you have an image that already contains your nginx configuration, you can share the configuration | ||
with the Gixy container as a volume. | ||
``` | ||
$ docker run --rm --name nginx -d -v /etc/nginx | ||
nginx:alpinef68f2833e986ae69c0a5375f9980dc7a70684a6c233a9535c2a837189f14e905 | ||
$ docker run --rm --volumes-from nginx dvershinin/gixy /etc/nginx/nginx.conf | ||
==================== Results =================== | ||
No issues found. | ||
==================== Summary =================== | ||
Total issues: | ||
Unspecified: 0 | ||
Low: 0 | ||
Medium: 0 | ||
High: 0 | ||
``` | ||
|
||
# Contributing | ||
Contributions to Gixy are always welcome! You can help us in different ways: | ||
* Open an issue with suggestions for improvements and errors you're facing; | ||
* Fork this repository and submit a pull request; | ||
* Improve the documentation. | ||
|
||
Code guidelines: | ||
* Python code style should follow [pep8](https://www.python.org/dev/peps/pep-0008/) standards whenever possible; | ||
* Pull requests with new plugins must have unit tests for it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
mkdocs | ||
mkdocs-material | ||
markdown-include | ||
pymdown-extensions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import gixy | ||
from gixy.plugins.plugin import Plugin | ||
|
||
|
||
class version_disclosure(Plugin): | ||
""" | ||
Syntax for the directive: resolver 127.0.0.1 [::1]:5353 valid=30s; | ||
This comment has been minimized.
Sorry, something went wrong.
LeviPesin
|
||
""" | ||
summary = 'Do not use external nameservers for "resolver"' | ||
severity = gixy.severity.HIGH | ||
description = 'Using external nameservers allows someone to send spoofed DNS replies to poison the resolver ' \ | ||
'cache, causing NGINX to proxy HTTP requests to an arbitrary upstream server.' | ||
help_url = 'https://blog.zorinaq.com/nginx-resolver-vulns/' | ||
directives = ['server_tokens'] | ||
|
||
def audit(self, directive): | ||
if directive.args[0] in ['on', 'build']: | ||
self.add_issue( | ||
severity=gixy.severity.HIGH, | ||
directive=[directive, directive.parent], | ||
reason="User server_tokens off to hide nginx version" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
site_name: Gixy docs | ||
site_description: "Automatic documentation from sources, for Gixy." | ||
site_url: https://gixy.getpagespeed.com/ | ||
repo_url: https://github.com/dvershinin/gixy | ||
theme: | ||
name: "material" | ||
palette: | ||
scheme: slate | ||
primary: teal | ||
accent: purple | ||
features: | ||
- navigation.expand | ||
plugins: | ||
- search | ||
nav: | ||
- Overview: index.md | ||
- Plugins: | ||
- Server Side Request Forgery: en/plugins/ssrf.md | ||
- HTTP Splitting: en/plugins/httpsplitting.md | ||
- Problems with referrer/origin validation: en/plugins/origins.md | ||
- Redefining of response headers by "add_header" directive: en/plugins/addheaderredefinition.md | ||
- Request's Host header forgery: en/plugins/hostspoofing.md | ||
- none in valid_referers: en/plugins/validreferers.md | ||
- Multiline response headers: en/plugins/addheadermultiline.md | ||
- Path traversal via misconfigured alias: en/plugins/aliastraversal.md | ||
- If is evil when used in location context: en/plugins/if_is_evil.md | ||
- Allow specified without deny: en/plugins/allow_without_deny.md | ||
- Setting Content-Type via add_header: en/plugins/add_header_content_type.md | ||
- Using external DNS nameservers: https://blog.zorinaq.com/nginx-resolver-vulns/ | ||
- Version Disclosure: en/plugins/version_disclosure.md | ||
- 'Blog': 'https://www.getpagespeed.com/posts' | ||
markdown_extensions: | ||
- admonition | ||
- markdown_include.include | ||
- pymdownx.emoji | ||
- pymdownx.magiclink | ||
- pymdownx.superfences | ||
- pymdownx.tabbed | ||
- pymdownx.tasklist | ||
- pymdownx.snippets: | ||
check_paths: true | ||
- toc: | ||
permalink: "¤" | ||
extra: | ||
generator: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"severity": "MEDIUM" | ||
} | ||
"severity": ["LOW", "MEDIUM"] | ||
} |
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
tests/plugins/simply/version_disclosure/server_tokens_off_fp.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server_tokens off; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
server_tokens on; |
version_disclosure
is missing from this list here for some reason?