一般情況下,軟體的漏洞資訊和特定版本是相關的,是以,軟體的版本号對攻擊者來說是很有價值的。
在預設情況下,Apache Httpd 系統會把Apache版本子產品都顯示出來(http傳回頭資訊)。如果列舉目錄的話,會顯示域名資訊,伺服器版本号,作業系統類型等。
隐藏Apache版本号的方法是修改Apache的配置檔案:
vim /etc/httpd/conf/httpd.conf
傳回用戶端頭資訊:
[[email protected] 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
再次傳回頭資訊如下:
[[email protected] 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 傳回結果
[[email protected] 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
擷取頭資訊:
[[email protected] 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頭資訊:
[[email protected] 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下,并且在頭資訊中曝露了版本号,如下:
[[email protected] 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頭資訊:
[[email protected] 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/