萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

Linux find + xargs 快速掃描 Webshell 後門特徵碼:實戰指令與特徵庫整理

網站被掛馬、植入 Webshell 後,find 配合 xargs grep 能在幾秒內掃出可疑檔案。本文提供**即用型指令模板**,並整理涵蓋 `eval`、`base64_decode`、`assert`、一句話木馬、資料庫操作、.htaccess 竄改等 50+ 高頻特徵碼,可直接貼上執行。

Webshell 掃描流程圖

核心掃描模板

# 掃描 wwwroot 目錄下所有 .php,搜尋關鍵字,結果存檔
find wwwroot/ -type f -name '*.php' | xargs grep -l "關鍵字" > suspicious.txt
  • -l:僅輸出檔案名(不顯示匹配行),適合後續人工審核。
  • -i:忽略大小寫(建議加上)。
  • -r:`grep -r` 可直接遞歸,**無需 find**,單指令更簡潔:
grep -ril "關鍵字" wwwroot/ > suspicious.txt

實戰:分類特徵碼掃描並分檔存證

# 1. 核心危險函數
grep -ril "eval(" wwwroot/ > wwwroot/eval.txt
grep -ril "assert(" wwwroot/ > wwwroot/assert.txt
grep -ril "system(" wwwroot/ > wwwroot/system.txt
grep -ril "passthru(" wwwroot/ > wwwroot/passthru.txt
grep -ril "shell_exec(" wwwroot/ > wwwroot/shell_exec.txt
grep -ril "exec(" wwwroot/ > wwwroot/exec.txt
grep -ril "popen(" wwwroot/ > wwwroot/popen.txt
grep -ril "proc_open" wwwroot/ > wwwroot/proc_open.txt

# 2. 編碼/加密後門
grep -ril "base64_decode(" wwwroot/ > wwwroot/base64_decode.txt
grep -ril "gzinflate(" wwwroot/ > wwwroot/gzinflate.txt
grep -ril "gzuncompress(" wwwroot/ > wwwroot/gzuncompress.txt
grep -ril "gzdecode(" wwwroot/ > wwwroot/gzdecode.txt

# 3. 一句話木馬特徵
grep -ril 'eval($_' wwwroot/ > wwwroot/eval_post.txt
grep -ril 'assert($_' wwwroot/ > wwwroot/assert_post.txt
grep -ril '$_POST\[' wwwroot/ > wwwroot/post_array.txt
grep -ril '$_GET\[' wwwroot/ > wwwroot/get_array.txt
grep -ril '$_REQUEST\[' wwwroot/ > wwwroot/request_array.txt
grep -ril '$_COOKIE\[' wwwroot/ > wwwroot/cookie_array.txt

# 4. 檔案寫入/上傳後門
grep -ril "file_put_contents(" wwwroot/ > wwwroot/file_put_contents.txt
grep -ril "fwrite(" wwwroot/ > wwwroot/fwrite.txt
grep -ril "fputs(" wwwroot/ > wwwroot/fputs.txt

# 5. .htaccess 竄改
grep -ril "SetHandler application/x-httpd-php" wwwroot/ > wwwroot/htaccess.txt
grep -ril "auto_prepend_file" wwwroot/ > wwwroot/prepend.txt
grep -ril "auto_append_file" wwwroot/ > wwwroot/append.txt

# 6. 已知 Webshell 簽名
grep -ril "c99shell" wwwroot/ > wwwroot/c99.txt
grep -ril "r57shell" wwwroot/ > wwwroot/r57.txt
grep -ril "webshell" wwwroot/ > wwwroot/webshell.txt
grep -ril "phpspy" wwwroot/ > wwwroot/phpspy.txt

高頻特徵碼分類速查表(可直接複製建立掃描腳本)

分類特徵碼關鍵字
代碼執行eval(, assert(, system(, passthru(, shell_exec(, exec(, popen(, proc_open(, pcntl_exec(
編碼解碼base64_decode(, gzinflate(, gzuncompress(, gzdecode(, str_rot13(, rawurldecode(
一句話木馬eval($_POST, assert($_POST, $_POST[, $_GET[, $_REQUEST[, $_COOKIE[, call_user_func(, array_map(, filter_var(
檔案操作file_put_contents(, fwrite(, fputs(, fopen(, copy(, move_uploaded_file(
資料庫高危load_file(, into outfile, into dumpfile, UDF, create function
已知馬簽名c99shell, r57shell, phpspy, b374k, WSO, webshell, c100, tiny, mini
.htaccessSetHandler application/x-httpd-php, auto_prepend_file, auto_append_file, php_value, php_flag

後續處理建議

  1. 人工複核:自動掃描會有誤報(如框架合法使用 `base64_decode`),需逐檔確認。
  2. 時間戳關聯:`stat 可疑檔案` 對比入侵時間窗口。
  3. 清理與加固:刪除惡意檔、修補漏洞、修改所有密鑰、部署 WAF/RASP、啟用 `open_basedir`/`disable_functions`。
  4. 建立基線:定期對比 `find wwwroot -type f -name '*.php' | sort` 檔案清單,發現新增/異動檔案即時告警。

結語

`grep -ril` 是應急響應的核武器。將上述特徵碼整理為腳本 `scan_webshell.sh` 納入巡檢體系,**定期掃描、異動告警、快速溯源**,將損失降至最低。

copyright © 萬盛學電腦網 all rights reserved