Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

隱藏 PHP 版本資訊:修改 expose_php 參數防範資訊洩露

編輯:Linux 教學

風險背景

預設 expose_php = On 會在 HTTP 回應標頭洩露 PHP 版本:

HTTP/1.1 200 OK
Server: nginx
X-Powered-By: PHP/7.0.10
Content-Type: text/html; charset=UTF-8

攻擊者可針對特定版本漏洞發起精準攻擊。

修正步驟

  1. 編輯 PHP 設定檔:vi /etc/php.ini(或 /etc/php.d/security.ini)
  2. 找到 expose_php 設為 Off:
    expose_php = Off
  3. 重啟 Web 服務:systemctl restart httpd 或 systemctl restart php-fpm

驗證生效

curl -I https://example.com/
# 確認不再出現 X-Powered-By 標頭

補充:同步隱藏 Web 伺服器版本

Apache

# /etc/httpd/conf/httpd.conf
ServerTokens Prod
ServerSignature Off

Nginx

# /etc/nginx/nginx.conf (http 區塊)
server_tokens off;

最佳實踐建議

  • 將 expose_php、ServerTokens、server_tokens 納入基線檢查清單
  • 部署自動化腳本驗證標頭資訊
  • 定期掃描外部暴露服務,確認無版本洩露
Copyright © Windows教程網 All Rights Reserved