Someone has managed to pass an undefined HTTP_HOST
server variable to my application script, triggering a series of errors. I am quite perturbed but am unable to replicate this behaviour. My httpd server uses name-based virtual hosting with the following parameters:
ServerName example.com:80
UseCanonicalName On
<VirtualHost *:80>
ServerName example.com
ServerAlias ftp.example.com service.example.com
ErrorDocument 404 /error/404.html.var
...
</VirtualHost>
<VirtualHost *:80>
ServerName notfound.example.com
ServerAlias *
RedirectMatch 404 ^/(?!error)
ErrorDocument 404 /error/404.html.var
</VirtualHost>
I tried to replicate the request using wget with the following:
wget -dS --header='Host: ' http://example.com/?x0a/x04/x0a/x04/x06/x08/x09/...
--2014-07-30 03:00:00-- http://example.com/?x0a/x04/x0a/x04/x06/x08/x09/...
Connecting to example.com:80... connected.
---request begin---
GET / HTTP/1.1
Accept: */*
Host:
Connection: Keep-Alive
---request end---
...
HTTP request sent, awaiting response...
---response begin--
HTTP/1.1 404 Not Found
Date: Wed, 29 Jul 2014 03:00:00 GMT
Server: Apache
Accept-Ranges: bytes
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8
Content-Language: en
---response end---
...
2014-07-29 03:00:00 ERROR 404: Not Found.
And as expectedly, a 404 not found error is delivered. I wonder how anyone can trigger a 200 success with an undefined HTTP_HOST. Does ServerAlias in Apache rely on HTTP_HOST at all? Or could this be a server bug that someone is trying to exploit?
UPDATE:
This is the output from httpd -S
:
VirtualHost configuration:
*:80 is a NameVirtualHost
default server example.com (/etc/httpd/conf/httpd.conf:410)
port 80 namevhost example.com (/etc/httpd/conf/httpd.conf:410)
alias localhost
alias xxx.xxx.xxx.xxx
alias ftp.example.com
alias service.example.com
port 80 namevhost notfound.example.com (/etc/httpd/conf/httpd.conf:491)
wild alias *
ServerRoot: "/etc/httpd"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/etc/httpd/logs/error_log"
Mutex default: dir="/run/httpd/" mechanism=default
Mutex rewrite-map: using_defaults
Mutex ssl-stapling: using_defaults
Mutex proxy: using_defaults
Mutex ssl-cache: using_defaults
PidFile: "/run/httpd/httpd.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="apache" id=48 not_used
Group: name="apache" id=48 not_used