您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

转 :php 网站挂马检查

2025/6/25 15:02:24发布14次查看
php后门木马常用的函数大致上可分为四种类型:
1. 执行系统命令: system, passthru, shell_exec, exec, popen, proc_open
2. 代码执行与加密: eval, assert, call_user_func,base64_decode, gzinflate, gzuncompress, gzdecode, str_rot13
3. 文件包含与生成: require, require_once, include, include_once, file_get_contents, file_put_contents, fputs, fwrite
4. .htaccess: sethandler, auto_prepend_file, auto_append_file

想找一个 关键词是“hellow word” 在哪些文件中有,我们用grep命令
grep –color -i -r -n “hellow word”  /data/www/
这样就能搜索出来 文件中包含关键词的文件
–color是关键词标红
-i是不区分大小写
-r是包含子目录的搜索
-d skip忽略子目录
可以用以上命令查找网站项目里的带有挂马的文件

.两个查后门的实用linux命令:
find /data/web/website/ -iname *.php -mtime -35 找出/data/web/website/目录下 35分钟前新建的php
find /data/web/website/ -name “*.php” | xargs grep “eval($_post[” 找出/data/web/website/ 里面源码包含eval($_post[的php文件

例如
注入漏洞eval(base64_decode
grep –color -i -r -n “eval”  /data/www/   找出来对比以前正常的代码,看是否正常。然后用stat查看这个木马文件的修改时间,最后去寻找web日志,找出木马从哪里进来的
五:
实用查找php木马命令:
查找php木马
# find ./ -name *.php |xargs egrep phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|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_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate) | awk -f: '{print $1}' | sort | uniq
1
2
3
4
# find ./ -name *.php |xargs egrep phpspy|c99sh|milw0rm|eval\(gunerpress|eval\(base64_decoolcode|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_decoolcode|eval\(base64_decoolcode|spider_bc|gzinflate) | awk -f: '{print $1}' | sort | uniq
查找最近一天被修改的php文件
#   find -mtime -1 -type f -name \*.php
1
#   find -mtime -1 -type f -name \*.php
修改网站的权限
# find -type f -name \*.php -exec chmod 444 {} \; # find ./ -type d -exec chmod 555{} \;
1
2
# find -type f -name \*.php -exec chmod 444 {} \;
# find ./ -type d -exec chmod 555{} \;
假设最后更新是10天前我们可以查找10天内生成的可以php文件:
find /var/www/ -name “*.php” -mtime -10
也可以通过关键字的形式查找 常见的木马常用代码函数 eval,shell_exec,passthru,popen,system
#find /var/www/ -name “*.php” |xargs grep “eval” |more #find /var/www/ -name “*.php” |xargs grep “shell_exec” |more #find /var/www/ -name “*.php” |xargs grep “passthru” |more
1
2
3
#find /var/www/ -name “*.php” |xargs grep “eval” |more
#find /var/www/ -name “*.php” |xargs grep “shell_exec” |more
#find /var/www/ -name “*.php” |xargs grep “passthru” |more
还有查看access.log 当然前提是你网站的所有php文件不是很多的情况下
一句话查找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
1
2
3
4
# 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
查找最近一天被修改的php文件
# find -mtime -1 -type f -name *.php

以下其实是多余的操作了其实,但是还是有值得看的地方
检查代码。
肯定不是一个文件一个文件的检查,linxu有强悍的命令
grep ‘eval’ * -r 全盘搜索当前目录所有文件(包含子目录)中带有eval的文件,这条可以快速查找到被挂马的文件。
关于eval,请自行google一句话php代码。
2,查看日志。
不到这个时候不知道日志的可贵啊。
还是以grep命令为主。
思路:负责的站点是linux,只开了2个端口,一个22和80,外部的执行命令是由从80端口进来,selinux报httpd访问/boot文件,确认被挂马。而所有的命令执行必须post提交给执行的文件。所以,查找日志中所有的post记录。
cat access_log_20120823.log | grep ‘post’ | grep -v ‘反向查找’ | less,通过grep -v排除正常post,egrep也支持正则,但是太复杂了,看懂不知道怎么运用。
(这里不建议用cat,用tail可以追加一个文件来看)
这可以防患于未然,防止不知道哪天又被人黑进来了。每天看一眼日志。
3,对于网页目录,只给apache用户rx权限,不要给w权限,目录设置要加上rx,不要给w,个别文件除外。所以,配合2使用,linux下可以快速过滤刷选出来不规则的post请求。
综合1,2其实就可以快速查找被黑的页面,被修改的文件替换干净的代码。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product