PHP Webshell 通常植入 eval、base64_decode、gzuncompress 等特徵函數。本文提供五大掃描策略:單行特徵掃描、近期修改檔案排查、檔案權限收斂、常見單句後門特徵、禁用高危函數,並給出具體 grep/find 指令可直接執行。

# 綜合特徵掃描,結果去重排序
find . -name "*.php" -type f -print0 | xargs -0 egrep "(phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decode|eval\(base64_decode|spider_bc|gzinflate)" | awk -F: '{print $1}' | sort -u
# 輸出至檔案供離線分析
find . -name "*.php" | xargs egrep "phpspy|c99sh|milw0rm|eval\(gzuncompress\(base64_decode|eval\(base64_decode|spider_bc" > /tmp/php.txt
grep -r --include=*.php '[^a-z]eval($_POST' . > /tmp/eval.txt
grep -r --include=*.php 'file_put_contents(.*$_POST\[.*\])' . > /tmp/file_put_contents.txt
find /var/www -mtime -1 -type f -name "*.php"
# 正常業務極少修改靜態頁,異動即為可疑
# PHP 檔案唯讀 (444)
find /var/www -type f -name "*.php" -exec chmod 444 {} \;
# 目錄僅可進入/列表 (555)
find /var/www -type d -exec chmod 555 {} \;
# 上傳目錄單獨設定寫入權限 (755 或 775)
chmod 755 /var/www/uploads
# eval($_POST['x']) 類
grep -r --include=*.php '[^a-z]eval($_POST' . > grep.txt
# file_put_contents 寫入後門
grep -r --include=*.php 'file_put_contents(.*$_POST\[.*\])' . > grep.txt
# 更多變體:assert、create_function、preg_replace /e、include $_GET/POST
disable_functions = exec,system,shell_exec,passthru,proc_open,proc_get_status,popen,pclose,pcntl_exec,assert,create_function,eval,preg_replace,include,require,file_put_contents,fopen,fwrite,fsockopen,curl_exec,curl_multi_exec,ld,dl,apache_setenv,apache_getenv,apache_note,apache_child_terminate,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
git status 或 rpm -Va 發現未授權變更Linux showmount 指令詳解:查詢 NFS 伺服器匯出與掛載資訊
Linux 終端機熱鍵大師鍵:自訂鍵盤快捷鍵綁定任意指令,效率翻倍
CentOS 5.5 无法识别 Atheros AR8151 网卡:下载编译 atl1e 驱动解决
CentOS wget 進度條多行顯示亂碼修復:locale 翻譯錯誤導致換行、msgunfmt/msgfmt 修正 .mo 檔案
Linux 硬碟直啟 ISO 映像:GRUB2 循環掛載啟動 Ubuntu/CentOS Live 系統完整教學
使用 Nagios + Python 監控 MogileFS 儲存節點:自動偵測離線節點並告警