如何在无法访问命令行的情况下找到运行的 Apache 版本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/166607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I find the version of Apache running without access to the command line?
提问by Simon
I need to either find a file in which the version is encoded or a way of polling it across the web so it reveals its version. The server is running at a host who will not provide me command line access, although I can browse the install location via FTP.
我需要找到一个版本编码的文件,或者找到一种在网络上轮询它的方式,以便它显示其版本。尽管我可以通过 FTP 浏览安装位置,但服务器运行在不提供命令行访问的主机上。
I have tried HEAD and do not get a version number reported.
我试过 HEAD 并且没有得到版本号报告。
If I try a missing page to get a 404 it is intercepted, and a stock page is returned which has no server information on it. I guess that points to the server being hardened.
如果我尝试丢失的页面来获取 404,它会被拦截,并返回一个没有服务器信息的股票页面。我想这表明服务器被强化了。
Still no closer...
还是没有靠近……
I put a PHP file up as suggested, but I can't browse to it and can't quite figure out the URL path that would load it. In any case I am getting plenty of access denied messages and the same stock 404 page. I am taking some comfort from knowing that the server is quite robustly protected.
我按照建议放置了一个 PHP 文件,但我无法浏览它,也无法弄清楚加载它的 URL 路径。在任何情况下,我都会收到大量拒绝访问的消息和相同的 404 页面。知道服务器受到了相当强大的保护,我感到有些欣慰。
回答by Paul Dixon
The method
方法
Connect to port 80 on the host and send it
连接到主机上的80端口并发送
HEAD / HTTP/1.0
This needs to be followed by carriage-return + line-feed twice
这需要跟回车+换行两次
You'll get back something like this
你会得到这样的东西
HTTP/1.1 200 OK
Date: Fri, 03 Oct 2008 12:39:43 GMT
Server: Apache/2.2.9 (Ubuntu) DAV/2 SVN/1.5.0 PHP/5.2.6-1ubuntu4 with Suhosin-Patch mod_perl/2.0.4 Perl/v5.10.0
Last-Modified: Thu, 02 Aug 2007 20:50:09 GMT
ETag: "438118-197-436bd96872240"
Accept-Ranges: bytes
Content-Length: 407
Connection: close
Content-Type: text/html; charset=UTF-8
You can then extract the apache version from the Server: header
然后,您可以从 Server: 标头中提取 apache 版本
Typical tools you can use
您可以使用的典型工具
You could use the HEAD utility which comes with a full install of Perl's LWPlibrary, e.g.
您可以使用完整安装 Perl 的LWP库附带的 HEAD 实用程序,例如
HEAD http://your.webserver.com/
Or, use the curlutility, e.g.
或者,使用curl实用程序,例如
curl --head http://your.webserver.com/
You could also use a browser extension which lets you view server headers, such as Live HTTP Headersor Firebugfor Firefox, or Fiddlerfor IE
您还可以使用浏览器扩展来查看服务器标头,例如Live HTTP Headers或Firebugfor Firefox,或Fiddlerfor IE
Stuck with Windows?
被 Windows 困住了?
Finally. if you're on Windows, and have nothing else at your disposal, open a command prompt (Start Menu->Run, type "cmd" and press return), and then type this
最后。如果您使用的是 Windows,并且没有任何其他东西可供您使用,请打开命令提示符(开始菜单->运行,键入“cmd”并按回车键),然后键入以下内容
telnet your.webserver.com 80
Then type (carefully, your characters won't be echoed back)
然后输入(小心,你的字符不会被回显)
HEAD / HTTP/1.0
Press return twice and you'll see the server headers.
按回车两次,您将看到服务器标题。
Other methods
其他方法
As mentioned by cfeduke and Veynom, the server may be set to return limited information in the Server: header. Try and upload a PHP script to your host with this in it
正如 cfeduke 和 Veynom 所提到的,服务器可能被设置为在 Server: 标头中返回有限的信息。尝试将 PHP 脚本上传到您的主机上
<?php phpinfo() ?>
Request the page with a web browser and you should see the Apache version reported there.
使用 Web 浏览器请求页面,您应该会看到那里报告的 Apache 版本。
You could also try and use PHPShellto have a poke around, try a command like
/usr/sbin/apache2 -V
回答by crmpicco
httpd -vwill give you the version of Apache running on your server (if you have SSH/shell access).
httpd -v将为您提供在您的服务器上运行的 Apache 版本(如果您有 SSH/shell 访问权限)。
The output should be something like this:
输出应该是这样的:
Server version: Apache/2.2.3
Server built: Oct 20 2011 17:00:12
As has been suggested you can also do apachectl -vwhich will give you the same output, but will be supported by more flavours of Linux.
正如所建议的那样,您也可以这样做apachectl -v,这将为您提供相同的输出,但会得到更多 Linux 版本的支持。
回答by cfeduke
Rarely, a hardened HTTP server is configured to give no server information or misleading server information. In those scenarios if the server has PHP enabled you can add:
很少将强化的 HTTP 服务器配置为不提供服务器信息或误导性的服务器信息。在这些情况下,如果服务器启用了 PHP,您可以添加:
<?php phpinfo(); ?>
in a file and browse to it and look for the
在一个文件中并浏览到它并查找
_SERVER["SERVER_SOFTWARE"]
entry. This is susceptible to the same hardening lack of information/misleading though I would imagine that it's not altered often, because this method first requires access to the machine to create the PHP file.
入口。这很容易受到同样的强化缺乏信息/误导的影响,尽管我认为它不会经常改变,因为这种方法首先需要访问机器来创建 PHP 文件。
回答by Veynom
Warning, some Apache servers do not always send their version number when using HEAD, like in this case:
警告,一些 Apache 服务器在使用 HEAD 时并不总是发送它们的版本号,比如在这种情况下:
HTTP/1.1 200 OK
Date: Fri, 03 Oct 2008 13:09:45 GMT
Server: Apache
X-Powered-By: PHP/5.2.6RC4-pl0-gentoo
Set-Cookie: PHPSESSID=a97a60f86539b5502ad1109f6759585c; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Connection: close
Content-Type: text/html
Connection to host lost.
If PHP is installed then indeed, just use the php info command:
如果确实安装了 PHP,则只需使用 php info 命令:
<?php phpinfo(); ?>
回答by mmacaulay
The level of version information given out by an Apache server can be configured by the ServerTokens setting in its configuration.
Apache 服务器发出的版本信息级别可以通过其配置中的 ServerTokens 设置进行配置。
I believe there is also a setting that controls whether the version appears in server error pages, although I can't remember what it is off the top of my head. If you don't have direct access to the server, and the server administrator is competent and doesn't want you to know the version they're running... I think you may be SOL.
我相信还有一个设置可以控制版本是否出现在服务器错误页面中,尽管我不记得它是什么。如果您没有直接访问服务器的权限,并且服务器管理员有能力并且不希望您知道他们正在运行的版本......我想您可能是SOL。
回答by Steve g
Telnet to the host at port 80.
Telnet 到主机的 80 端口。
Type:
类型:
get / http1.1
::enter::
::enter::
It is kind of an HTTP request, but it's not valid so the 500 error it gives you will probably give you the information you want. The blank lines at the end are important otherwise it will just seem to hang.
它是一种 HTTP 请求,但它无效,因此它给您的 500 错误可能会为您提供所需的信息。最后的空行很重要,否则它似乎会挂起。
回答by Jonathan Mueller
If they have error pages enabled, you can go to a non-existent page and look at the bottom of the 404 page.
如果他们启用了错误页面,您可以转到不存在的页面并查看 404 页面的底部。
回答by Oli
In the default installation, call a page that doesn't exist and you get an error with the version at the end:
在默认安装中,调用一个不存在的页面,最后会出现版本错误:
Object not found!
The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
If you think this is a server error, please contact the webmaster.
Error 404
localhost
10/03/08 14:41:45
Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5
未找到对象!
在此服务器上找不到请求的 URL。如果您手动输入了 URL,请检查您的拼写并重试。
如果您认为这是服务器错误,请联系网站管理员。
错误 404
本地主机
10/03/08 14:41:45
Apache/2.2.8 (Win32) DAV/2 mod_ssl/2.2.8 OpenSSL/0.9.8g mod_autoindex_color PHP/5.2.5
回答by Eduardo
Your best option is through PHP: All version requests from the client side cannot be trusted since your Apache could be configured with ServerTokens Prod and ServerSignature Off. See: http://www.petefreitag.com/item/419.cfm
您最好的选择是通过 PHP:无法信任来自客户端的所有版本请求,因为您的 Apache 可以使用 ServerTokens Prod 和 ServerSignature Off 进行配置。见:http: //www.petefreitag.com/item/419.cfm
回答by Martin Zeitler
Simply use something like the following - the string should be there already:
只需使用类似以下内容 - 字符串应该已经存在:
<?php
if(isset($_SERVER['SERVER_SOFTWARE'])){
echo $_SERVER['SERVER_SOFTWARE'];
}
?>

