版本号隐藏

一般情况下,软件的漏洞信息和特定版本是相关的,因此,软件的版本号对攻击者来说是很有价值的。

在默认情况下,Apache Httpd 系统会把Apache版本模块都显示出来(http返回头信息)。如果列举目录的话,会显示域名信息,服务器版本号,操作系统类型等。

隐藏Apache版本号的方法是修改Apache的配置文件:

vim /etc/httpd/conf/httpd.conf

返回客户端头信息:

[root@ithomer conf]# curl –head 127.0.0.1
HTTP/1.1 200 OK
Date: Thu, 22 Jan 2015 15:39:00 GMT
Server: Apache/2.2.26 (CentOS)
X-Powered-By: PHP/5.5.9
Vary: Cookie,Accept-Encoding,User-Agent
X-Pingback: http://blog.mimvp.com/xmlrpc.php
Cache-Control: max-age=600
Expires: Thu, 22 Jan 2015 15:49:00 GMT
Content-Type: text/html; charset=UTF-8

上面头信息中,会显示服务器类型和版本(Apache/2.2.26),以及操作系统(CentOS)

修改 ServerTokens

修改 ServerTokens OS 为 ServerTokens productonly

重启 Apache : /etc/init.d/httpd restart

再次返回头信息如下:

[root@ithomer conf]# curl –head 127.0.0.1
HTTP/1.1 200 OK
Date: Thu, 22 Jan 2015 15:40:53 GMT
Server: Apache
X-Powered-By: PHP/5.5.9
Vary: Cookie,Accept-Encoding,User-Agent
X-Pingback: http://blog.mimvp.com/xmlrpc.php
Cache-Control: max-age=600
Expires: Thu, 22 Jan 2015 15:50:53 GMT
Content-Type: text/html; charset=UTF-8

同时修改 ServerTokens  Prod 和 ServerSignature 为off 返回结果

[root@ithomer conf]# curl –head 127.0.0.1
HTTP/1.1 200 OK
Date: Thu, 22 Jan 2015 16:23:07 GMT
Server: Apache
Vary: Cookie,Accept-Encoding,User-Agent
X-Pingback: http://blog.mimvp.com/xmlrpc.php
Cache-Control: max-age=600
Expires: Thu, 22 Jan 2015 16:33:07 GMT
Content-Type: text/html; charset=UTF-8

到这里,我们还可以改变apache的版本,这就要修改apache的源代码了

在apache的源码包中找到ap_release.h将
#define AP_SERVER_BASEPRODUCT “Apache”
修改为
#define AP_SERVER_BASEPRODUCT “Microsoft-IIS/5.0”
或者
#define AP_SERVER_BASEPRODUCT “Microsoft-IIS/6.0”

然后找到os/unix下的os.h文件,将其
#define PLATFORM “Unix”
修改为
#define PLATFORM “Win32“
然后重新编译,安装apache


最后修改 vim /etc/httpd/conf/httpd.conf 配置文件,添加两行
ServerTokens Prod               // Prod 同 ProductOnly
ServerSignature Off
在发送头请求,头信息就都被偷天换日了
从这点来说,php也是一样,同样可以通过这种方式改变一些系统信息。

附:

ServerSignature 三个选项,分别是 On | Off | EMail
ServerTokens 的取值如下,其分别隐藏信息依次增加

ProductOnly  :  Server: Apache

Major             :  Server: Apache/2

Minor             :  Server: Apache/2.2

Minimal         :  Server: Apache/2.2.26

OS                 :  Server: Apache/2.2.26 (CentOS)

Full                :  Server: Apache/2.2.26 (CentOS) DAV/2 PHP/5.5.9 SVN/1.6.11 mod_perl/2.0.4 Perl/v5.10.1

推荐: ServerTokens ProductOnly

下面对php的配置文件php.ini进行配置,默认情况下 expose_php = On

修改步骤:

vim /etc/php.ini

expose_php = On
将其改为
expose_php = Off

重启Apache: /etc/init.d/httpd restart

获取头信息:

[root@ithomer conf]# curl –head 127.0.0.1
HTTP/1.1 200 OK
Date: Thu, 22 Jan 2015 16:15:48 GMT
Server: Apache
Vary: Cookie,Accept-Encoding,User-Agent
X-Pingback: http://blog.mimvp.com/xmlrpc.php
Cache-Control: max-age=600
Expires: Thu, 22 Jan 2015 16:25:48 GMT
Content-Type: text/html; charset=UTF-8

发现上面php版本信息(X-Powered-By: PHP/5.5.9)已经隐藏了

附上

修改Tomcat 服务器名称的头信息

修改Tomcat配置文件:

vim /opt/apache-tomcat-7.0.54/conf/server.xml

添加下面红色一行:

    <Connector port=”8280″ protocol=”HTTP/1.1″
               connectionTimeout=”20000″
               redirectPort=”8443″ 
               server=”MIServer” />

查看Tomcat头信息:

[root@ithomer conf]# curl –head 127.0.0.1:8280
HTTP/1.1 200 OK
Content-Type: text/html;charset=ISO-8859-1
Transfer-Encoding: chunked
Date: Thu, 22 Jan 2015 16:30:20 GMT
Server: MIServer

发现上面Tomcat服务器名称已经修改为了 Server: MIServer

隐藏 Nexus 服务器的头信息

Nexus 默认运行在Jetty下,并且在头信息中曝露了版本号,如下:
[root@ithomer apache-tomcat-7.0.54]# curl –head 127.0.0.1:8081
HTTP/1.1 404 Not Found
Date: Fri, 23 Jan 2015 01:51:06 GMT
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 1267
Server: Jetty(8.1.11.v20130520)

由于Nexus服务运行在Jetty框架内,因此需要修改Jetty服务配置文件

修改jetty.xml配置文件 :

vim /opt/nexus-2.11.0/nexus-2.11.0-02/conf/jetty.xml

修改 sendServerVersion 值由 true 为 false(不发送服务器版本信息),如下:

  <Set name=”stopAtShutdown”>true</Set>
  <Set name=”sendServerVersion”>false</Set>
  <Set name=”sendDateHeader”>true</Set>
  <Set name=”gracefulShutdown”>1000</Set>

重启Nexus服务:

/opt/nexus-2.11.0/nexus-2.11.0-02/bin/nexus restart

查看Nexus头信息:

[root@ithomer apache-tomcat-7.0.54]# curl –head 127.0.0.1:8081
HTTP/1.1 404 Not Found
Date: Fri, 23 Jan 2015 02:13:53 GMT
Cache-Control: must-revalidate,no-cache,no-store
Content-Type: text/html;charset=ISO-8859-1
Content-Length: 1267

修改完重启Nexus后,发现服务器版本信息 Server: Jetty(8.1.11.v20130520),已被隐藏了
原文:http://blog.mimvp.com/2015/02/hide-the-apache-server-version-number-and-system/

猜你喜欢

转载自blog.csdn.net/shardy0/article/details/88947846