在什么情况下,Apache允许不匹配的HTTP_HOST通过?

有人设法将未定义的HTTP_HOST服务器variables传递给我的应用程序脚本,从而触发一系列错误。 我很困扰,但无法复制这种行为。 我的httpd服务器使用以下参数使用基于名称的虚拟主机:

 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> 

我试图使用wget复制请求与以下内容:

 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. 

如预期的那样,404未find错误被传递。 我不知道如何能有一个未定义的HTTP_HOST触发200成功。 Apache中的ServerAlias是否完全依赖HTTP_HOST? 或者这可能是某人试图利用的服务器错误?

更新:

这是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 

是的,ServerAlias与HTTP_HOSTvariables完全一致(更准确地说,与Host: http头一样,也会被映射到HTTP_HOST )。

如果没有Host: http头,并且request_uri也包含一个http主机(即GET http://example.com/path/to HTTP/1.1 ),它也将被用作HTTP_HOST。 这只发生在代理服务器的情况下。

你的例子是坏的,主机:不能包含一个url,只有一个主机名。 如果有人给这里一个url(可能是一个坏的HTTP工具),它将被解释为一个无效/不存在的主机名,这是你的情况发生。

实际上:虽然我们可以find并分析Apache Web服务器(公共)源代码的相关部分,但是我不认为需要这么艰难的事情。 最好的办法就是用自己的apache和一些telnet 127.0.0.1 80或类似的命令来玩。 给不同的GET / URL,主机:头到你的虚拟主机的Apache,看看会发生什么。 当我需要debugging虚拟主机的Apacheconfiguration时,这是我做了很多次。 一个基于telnet的http查询minimalexample在这里:

 $ telnet 127.0.0.1 80 GET /test/url.html HTTP/1.1 Host: myapache.mydomain.com Connection: close (me: until this you need to type in, don't forget the multiple enter at the end) 200 HTTP/1.1 OK (<- me: from here is coming the reply of the server!) Content-type: html/html <html> ... </html>