木馬查殺是運維長期堅持的核心工作。六大技術專區構建Linux主機纵深免疫體系:
location ~* \.php$ { deny all; }path_info漏洞:if ($request_filename ~* (.*)\.php) { set $php_url $1; } if (!-e $php_url.php) { return 404; }server_tokens off;find -type f -name "*.php" -exec chmod 444 {} \;
find -type d -exec chmod 555 {} \;
# 排除上傳/緩存目錄
# 禁用chmod函數防攻擊者修改屬性寫入
disable_functions = dl,eval,exec,passthru,system,popen,shell_exec,proc_open,proc_terminate, curl_exec,curl_multi_exec,show_source,touch,escapeshellcmd,escapeshellarg
skip-networking或bind-address=127.0.0.1SELECT/INSERT/UPDATE/DELETE,拒絕DROP/ALTER/GRANT/FILE# Webshell特徵掃描 grep -r --include="*.php" '[^a-z]eval($_POST' . > webshell.txt grep -r --include="*.php" 'file_put_contents(.*$_POST\[.*\])' . > webshell.txt # 近期異常文件 find -mtime -2 -type f -name "*.php" # 注意:attacker可用touch竄改mtime,故touch必禁
Linux安全非一次配置,而是「基線+監控+響應+演練」的持續工程實踐。