歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Apache服務器隱藏版本號和系統

Apache服務器隱藏版本號和系統

日期:2017/2/27 15:55:24   编辑:Linux教程

一般情況下,軟件的漏洞信息和特定版本是相關的,因此,軟件的版本號對攻擊者來說是很有價值的。

在默認情況下,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/

Copyright © Linux教程網 All Rights Reserved