作为站长和运维人员必须要面临站点可能被黑的可能。而在linux下,可以通过简间的语句查找并纠出这些害群之马。下面以php站为例 。php站里的上传的木马一般也都是.php文件 。同其他的网页语言一样,直接可以通过文本工具查看内容。一般的php木马里面都包含特点的关键词或关键语句。
1、查找一句话PHP木马:
# find ./ -name "*.php" |xargs egrep "phpspy|c99sh|milw0rm|eval(gunerpress|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 ./ -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 | uniq
2、查找最近一天被修改的PHP文件
一般站点里的页面文件都很少更改,当然动态临时生成的除外。而那些一般不会变的页面目录里的文件如果被修改了,可大可能是被人做了手脚。
# find -mtime -1 -type f -name *.php
3、只给读权限或执行权限,避免被修改
# find -type f -name *.php -exec chmod 444 {} ;
# find ./ -type d -exec chmod 555{} ;
4、禁用不常用函数
将用不到的权限又比较大的php函数在php.ini文件里禁掉。修改方法如下:disable_functions = system,exec,shell_exec …………