检测php网站是否已经被攻破

from :http://www.gregfreeman.org/2013/how-to-tell-if-your-php-site-has-been-compromised/

http://drops.wooyun.org/web/2718

0x01 查看访问日志
PREMOVED - - [01/Mar/2013:06:16:48 -0600] "POST/uploads/monthly_10_2012/view.php HTTP/1.1" 200 36 "-" "Mozilla/5.0"
IPREMOVED - - [01/Mar/2013:06:12:58 -0600] "POST/public/style_images/master/profile/blog.php HTTP/1.1" 200 36 "-" "Mozilla/5.0"

nginx默认记录的日志格式为:
access_log logs/access.log
access_log logs/access.log combined;

nginx默认记录日志的位置为:
nginx安装目录/log/

0x02 查找含有恶意php代码的文件

2.1 查找最近发生变化的php文件
find . -type f -name '*.php' -mtime -7
-type f 表示搜索正常的一般文件 -mtime -7 表示7*24小时内修改的文件

2.2 查找文件中是否存在疑似代码
find . -type f -name '*.php' | xargs grep -l "eval *(" --color
(*代表任意个空格)

find . -type f -name '*.php' | xargs grep -l "base64_decode *(" --color
find . -type f -name '*.php' | xargs grep -l "gzinflate *(" --color
find . -type f -name '*.php' | xargs grep -l "eval *(str_rot13 *(base64_decode *(" --color

0x03 比较代码文件
diff -r wordpress-clean/ wordpress-compromised/ -x wp-content
上面的例子是比较wordpress-clean/ 和wordpress-comprised/两个目录,并且目录里面的wp-content/子目录不比较

0x04 搜寻可写的目录
看这个目录里面是否有可疑文件,如下脚本查找权限为777的目录是否存在php文件
search_dir=$(pwd)
writable_dirs=$(find $search_dir -type d -perm 0777)
for dir in $writable_dirs
do
#echo $dir
find $dir -type f -name '*.php'
done

黑客经常在jpg文件中插入php代码,因此在查询这些目录的时候也要查询jpg文件:
find wp-content/uploads -type f -iname '*.jpg' | xargs grep -i php
注意:-iname 表示文件名不区分大小写 grep -i 也表示不区分大小写

0x05 检测iframe标签
grep -i '

0x06 查找数据库中是否存在敏感字符串
包括%base64_%、%eval(%<等上面提到的一些关键词

0x07 检查.htaccess文件
是否包含了auto_prepend_file和auto_append_file,使用如下命令
find . -type f -name '\.htaccess' | xargs grep -i auto_prepend_file
find . -type f -name '\.htaccess' | xargs grep -i auto_append_file

posted on 2016-04-14 13:59  lly001  阅读(137)  评论(0编辑  收藏  举报

导航