web server避免一些不必要的麻烦,可以把apache和php的版本信息不显示
隐藏 Apache 版本信息
/etc/apache2/apache2.conf 或 /etc/httpd/conf/httpd.conf
ServerTokens ProductOnly
ServerSignature Off
重启 apache
现在 http 头里面只看到:
Server: Apache
=====================
nginx
#vi nginx.conf
在http 加上 server_tokens off;
如下:
http {
……省略配置
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
tcp_nodelay on;
server_tokens off;
…….省略配置
}
=======================
隐藏 PHP 版本
php.ini
expose_php On
改成
expose_php Off
重启apache后,php版本在http头中隐藏了。
详解 :
为了防止某些别有用心的家伙窥视我们的服务器,应该做些什么.
我们来看一下相关的2个参数,分别为ServerTokens和ServerSignature,通过控制这2个阀门应该就能起到一些作用,比如我们可以在配置文件中这么写:
ServerTokens Prod
ServerSignature Off
ServerTokens
用 于控制服务器是否相应来自客户端的请求,向客户端输出服务器系统类型或内置模块等重要的系统信息。在主配置文件中提供全局控制默认阀值为"Full" (ServerTokens Full),所以,如果你的Linux发行版本没有更改过这个阀值的话,所有与你的系统有关的敏感信息都会向全世界公开。比如RHEL会将该阀值更改 为"ServerTokens OS",而Debian依然使用默认的"Full"阀值
以apache-2.0.55为例,阀值可以设定为以下某项(后面为相对应的Banner Header):
Prod >>> Server: Apache
Major >>> Server: Apache/2
Minor >>> Server: Apache/2.0
Minimal >>> Server: Apache/2.0.55
OS >>> Server: Apache/2.0.55 (Debian)
Full (or not specified) default >>> Server: Apache/2.0.55 (Debian) PHP/5.1.2-1+b1 mod_ssl/2.0.55 OpenSSL/0.9.8b
ServerSignature
控制由系统生成的页面(错误信息,mod_proxy ftp directory listing等等)的页脚中如何显示信息。
可在全局设置文件中控制,或是通过.htaccess文件控制
默认为"off"(ServerSignature Off),有些Linux发行版本可能会打开这个阀门,比如Debian在默认的虚拟主机上默认将这个阀门设置为开放
全局阀门的阀值会被虚拟主机或目录单位的配置文件中的阀值所覆盖,所以,必须确保这样的事情不应该发生
可用的阀值为下面所示:
Off (default): 不输出任何页脚信息 (如同Apache1.2以及更旧版本,用于迷惑)
On:输出一行关于版本号以及处于运行中的虚拟主机的ServerName (2.0.44之后的版本,由ServerTokens负责是否输出版本号)
EMail: 创建一个发送给ServerAdmin的"mailto"
注意*上述关于如何设置2个阀门从而尽量减少敏感信息泄露的方法,并不会使你的服务器真的更安全,如果你现在使用的版本比较旧,请务必尽快将系统升级,降低被蠕虫攻击的风险。
隐藏server信息
cd /usr/local/src/nginx-0.5.35/src/core/
[root@zyatt core]# cat nginx.h
/*
* Copyright (C) Igor Sysoev
*/
#ifndef _NGINX_H_INCLUDED_
#define _NGINX_H_INCLUDED_
#define NGINX_VERSION "1.0"
#define NGINX_VER "LPKWS/" NGINX_VERSION
#define NGINX_VAR "LPKWS"
#define NGX_OLDPID_EXT ".oldbin"
#endif /* _NGINX_H_INCLUDED_ */
测试效果
C:\curl-7.18.0>curl.exe -I 211.100.11.122/info.php
HTTP/1.1 200 OK
Server: LPKWS/1.0
Date: Tue, 11 Mar 2008 04:53:02 GMT
Content-Type: text/html
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/5.2.4
还有更彻底的编译安装
修改src/core/nginx.h
#define NGINX_VERSION "1.0.5"
#define NGINX_VER "nginx/" NGINX_VERSION
#define NGINX_VAR "NGINX"
修改src/http/ngx_http_header_filter_module.c48-49
static char ngx_http_server_string[] = "Server: nginx" CRLF;
static char ngx_http_server_full_string[] = "Server: nginx" CRLF;
修改src/http/ngx_http_special_response.c
staticu_char ngx_http_error_tail[]="<hr><center>nginx</center>"CRLF
"</body>"CRLF
"</html>"CRLF
;
嘿嘿,接下来就编译安装吧!不过修改源码后还有1个地方要修改哦,Nginx的FastCGI配置文件fastcgi.conf
fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
常用Web Server版本名称:
Microsoft-IIS
GWS或GFE
Apache
Lighttpd
1. Lighttpd 1.4.20
src/response.c:108 改为:
buffer_append_string_len(b, CONST_STR_LEN("Server: jufukeji"));
输出 Header:
HTTP/1.1 404 Not Found
Content-Type: text/html
Content-Length: 345
Date: Mon, 12 Jan 2009 13:54:02 GMT
Server: jufukeji
2. Nginx 0.7.30
src/http/ngx_http_header_filter_module.c:48-49 改为:
static char ngx_http_server_string[] = "Server: jufukeji" CRLF;
static char ngx_http_server_full_string[] = "Server: jufukeji" CRLF;
输出 Header:
HTTP/1.1 200 OK
Server: jufukeji
Date: Mon, 12 Jan 2009 14:01:10 GMT
Content-Type: text/html
Content-Length: 151
Last-Modified: Mon, 12 Jan 2009 14:00:56 GMT
Connection: keep-alive
Accept-Ranges: bytes
3. Cherokee 0.11.6
cherokee/version.c:93 添加:
ret = cherokee_buffer_add_str (buf, "jufukeji");
return ret;
输出 Header:
HTTP/1.1 200 OK
Connection: Keep-Alive
Keep-Alive: timeout=15
Date: Mon, 12 Jan 2009 14:54:39 GMT
Server: jufukeji
ETag: 496b54af=703
Last-Modified: Mon, 12 Jan 2009 14:33:19 GMT
Content-Type: text/html
Content-Length: 1795
4. Apache 2.2.11
server/core.c:2784 添加:
ap_add_version_component(pconf, "jufukeji");
return;
输出 Header:
HTTP/1.1 200 OK
Date: Mon, 12 Jan 2009 14:28:10 GMT
Server: jufukeji
Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT
ETag: "1920edd-2c-3e9564c23b600"
Accept-Ranges: bytes
Content-Length: 44
Content-Type: text/html
5. Squid 3.0 STABLE 11
src/globals.cc:58 改为:
const char *const full_appname_string = "jufukeji";
输出 Header:
HTTP/1.0 400 Bad Request
Server: jufukeji
Mime-Version: 1.0
Date: Mon, 12 Jan 2009 15:25:15 GMT
Content-Type: text/html
Content-Length: 1553
Expires: Mon, 12 Jan 2009 15:25:15 GMT
X-Squid-Error: ERR_INVALID_URL 0
X-Cache: MISS from 'cache.hutuworm.org'
Via: 1.0 'cache.hutuworm.org' (jufukeji)
Proxy-Connection: close
6. Tomcat 6.0.18
java/org/apache/coyote/http11/Constants.java:56 和 java/org/apache/coyote/ajp/Constants.java:236 均改为:
ByteChunk.convertToBytes("Server: jufukeji" + CRLF);
输出 Header:
HTTP/1.1 200 OK
Server: jufukeji
ETag: W/"7857-1216684872000"
Last-Modified: Tue, 22 Jul 2008 00:01:12 GMT
Content-Type: text/html
Content-Length: 7857
Date: Mon, 12 Jan 2009 16:30:44 GMT
7. JBoss 5.0.0 GA
a. tomcat/src/resources/web.xml:40 改为
jufukeji
b. 下载 JBoss Web Server 2.1.1.GA srctar (http://www.jboss.org/jbossweb/downloads/jboss-web/)
java/org/apache/coyote/http11/Constants.java:56 和 java/org/apache/coyote/ajp/Constants.java:236 均改为:
ByteChunk.convertToBytes("Server: jufukeji" + CRLF);
将编译所得 jbossweb.jar 覆盖 JBoss 编译输出文件:
JBOSS_SRC/build/output/jboss-5.0.0.GA/server/all/deploy/jbossweb.sar/jbossweb.jar
JBOSS_SRC/build/output/jboss-5.0.0.GA/server/standard/deploy/jbossweb.sar/jbossweb.jar
JBOSS_SRC/build/output/jboss-5.0.0.GA/server/default/deploy/jbossweb.sar/jbossweb.jar
JBOSS_SRC/build/output/jboss-5.0.0.GA/server/web/deploy/jbossweb.sar/jbossweb.jar
输出 Header:
HTTP/1.1 200 OK
Server: jufukeji
X-Powered-By: jufukeji
Accept-Ranges: bytes
ETag: W/"1581-1231842222000"
Last-Modified: Tue, 13 Jan 2009 10:23:42 GMT
Content-Type: text/html
Content-Length: 1581
Date: Tue, 13 Jan 2009 10:30:42 GM