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

Linux Shell 指令掃描 PHP Webshell 木馬完整清單:特徵匹配、近期異動檔案、權限收斂

編輯:關於 Linux

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

PHP 木馬掃描流程示意圖

1. 單行特徵全盤掃描

# 綜合特徵掃描,結果去重排序
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

2. 排查近 24 小時被修改的 PHP 檔案

find /var/www -mtime -1 -type f -name "*.php"
# 正常業務極少修改靜態頁,異動即為可疑

3. 收斂檔案與目錄權限 (最小權限原則)

# 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

4. 常見單句後門特徵

# 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

5. php.ini 禁用高危函數

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

持續防護建議

  • 部署 WAF (ModSecurity + OWASP CRS) 攔截惡意請求
  • 啟用 inotifywait 或 auditd 即時監控關鍵目錄檔案變更
  • 定期比對 git status 或 rpm -Va 發現未授權變更
  • 上傳功能嚴格驗證 MIME、副檔名、內容掃描、儲存於非執行目錄
Copyright © Windows教程網 All Rights Reserved