linux查找webshell

独自等待 2017年5月12日02:46:38评论496 views字数 1917阅读6分23秒阅读模式

首先认识一下小马,一般大马容易暴露,骇客都会留一手,把小马加入正常PHP文件里面

//密码为a,使用中国菜刀连接

隐藏很深的小马

fputs(fopen(chr(46).chr(47).chr(97)……省略

解码:

其中chr括号里面的数字是美国信息交换标准代码,缩写:ASCII 可以找一份对照表对应一下

比如

46 就是 .
47 就是 /
32 就是 空格

也可以echo chr(46)解出来


WINDOWS下的应该有很多日志分析和查杀工具(比如D盾等),那么,LINUX下如何查找WEBSHELL呢?

find /www/ -name "*.php" |xargs egrep 'assert|phpspy|c99sh|milw0rm|eval|\(gunerpress|\(base64_decoolcode|spider_bc|shell_exec|passthru|\(\$\_\POST\[|eval \(str_rot13|\.chr\(|\$\{\"\_P|eval\(\$\_R|file_put_contents\(\.\*\$\_|base64_decode'

然后就手工查看,写入计划任务啦。

只查小马的可以

grep -r --include=*.php  '[^a-z]eval($_POST' . > post.txt
grep -r --include=*.php  '[^a-z]eval($_REQUEST' . > REQUEST.txt

查出来了,重要的是要分析日志,查看入侵源头。

防范:

禁用危险函数,整理权限,防止权限过大

disable_functions = exec,scandir,shell_exec,phpinfo,eval,passthru,system,chroot,chgrp,chown,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,fsocket

在网上找了一份用PHP查找WEBSHELL的东东,适用数据量小及少

https://github.com/emposha/PHP-Shell-Detector

git 下来 只需要2个文件

shelldetect.php //默认帐号密码 admin protect

shelldetect.db

如果你有什么好的建议,感谢你的分享:)

20130826更新

小马的变种很多,经常会绕过我们的检查,此时,最好能做把文件进行对比。

比如,网上找的这个PHP一句话


下面提供自己写的比较简单的检查脚本,思路是对比目录有更新的PHP文件进行匹配。

#!/bin/bash
# 先RSYNC干净的,再执行此脚本最好
Date=`date +%Y%m%d_%H:%M`
src=/www/www.a.com/
dest=/www/www.a.com.bk/
log_tmp1=/root/sh/webshell_php.log
log_result=/root/sh/webshell_result.log
which egrep
if [ $? -ne 0 ];then
echo "Not Found egrep,exit"
exit 0
fi
rsync -av --include="*/" --include="*.php" --exclude="*" $src $dest|grep -i php > $log_tmp1
for diff in `cat $log_tmp1`
  do
     egrep 'assert|phpspy|c99sh|milw0rm|eval|\(gunerpress|\(base64_decoolcode|spider_bc|shell_exec|passthru|\(\$\_\POST\[|eval \(str_rot13|\.chr\(|\$\{\"\_P|eval\(\$\_R|file_put_contents\(\.\*\$\_|base64_decode|\@preg_replace' "$dest""$diff"
  if [ $? -eq 0 ];then
     echo "===========================" >> $log_result
     echo "$Date" >> $log_result
     echo "$dest$diff is Dangerous" >> $log_result
   fi
done

原文地址:http://my.oschina.net/longquan/blog/155905



from www.waitalone.cn.thanks for it.

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
独自等待
  • 本文由 发表于 2017年5月12日02:46:38
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   linux查找webshellhttps://cn-sec.com/archives/50415.html

发表评论

匿名网友 填写信息