php专区

 首页 > php专区 > PHP应用 > php类库 > php网页病毒清除办法 - php类库

php网页病毒清除办法 - php类库

分享到:
【字体:
导读:
          你的网页是不是经常被无故的在php,asp,html,js 等文件后台加上一些木马地址呢?我以前有个站就是这样,所以一恨之下写了这段代码,文章虽然有一点浪费资源了,但是总比我们手动清除要好吧...

php网页病毒清除办法

你的网页是不是经常被无故的在php,asp,html,js 等文件后台加上一些木马地址呢?我以前有个站就是这样,所以一恨之下写了这段代码,文章虽然有一点浪费资源了,但是总比我们手动清除要好吧,下面我为讲讲程序的清除病毒的原理吧.

首先们要读取 $checkFile 文件这个文章是判断一个文章 是否被感染了,如果是就会执行$savafile变量里面的txt文件路径的所有文件,进行按你infecFile病毒列表清除一次.

  1.  Class clear_virus{ 
  2.   //public $content; 
  3.   public $infectFile ='virus.txt';//病毒文件列表文件 
  4.   public $savefile    ="save.txt";//所在查看病毒的文件列表 
  5.   public $timep  ='time.txt';//些记录清除病毒时间 
  6.   public $checkFile ='e.php';//这里是设置 
  7.   public $run   =0; 
  8.   public $virus_type
  9.   public $replace  ; 
  10.   public $filepath ;  
  11.   public $tag         =0;  
  12.     
  13.   function open_file(){ 
  14.    $this->read_virus();    
  15.    $this->check_File(); 
  16.    if($this->run){  
  17.     $this->update_time();  
  18.     $this->read_file() ;     
  19.     foreach($this->filepath as $tmppath){ 
  20.      if(file_exists($tmppath)){ 
  21.       $tmp_file =file_get_contents($tmppath);  
  22.       print_r( $this->virus_type);       
  23.         for$i=0;$i$this->virus_type);$i++ ){ 
  24.          ifstrrpos($tmp_file,$this->virus_type[$i])!== false){ 
  25.           $tmp_file =str_replace($this->virus_type[$i],'',$tmp_file); 
  26.           $this->tag =1;           
  27.          }          
  28.         } 
  29.         if$this->tag ){ 
  30.          $handle =fopen($tmppath,'w'); 
  31.          fwrite($handle,$tmp_file); 
  32.          fclose($handle); 
  33.          unset($tmp_file);  
  34.         }      
  35.        
  36.      }else
  37.       ; 
  38.      }       
  39.     }  
  40.    } 
  41.   } 
  42.    
  43.   function check_File(){ 
  44.    if(file_exists($this->checkFile) ){ 
  45.     $temp =file_get_contents($this->checkFile) ; 
  46.     echo $temp
  47.      foreach$this->virus_type as $v_tmp ){ 
  48.       ifstrrpos($temp,$v_tmp)!== false ){ 
  49.        $this->run =1; 
  50.        break
  51.       } 
  52.      } 
  53.      echo $this->run; 
  54.      unset($temp);     
  55.    }else
  56.     $this->show_error(5); 
  57.    } 
  58.   } 
  59.    
  60.   function update_time(){ 
  61.    if(file_exists($this->timep) ){ 
  62.     $tmp_time =date("Y-m-d H:i:s").chr(13).'|'
  63.     $tmp_fp  =fopen($this->timep,'a+'); 
  64.     fwrite($tmp_fp,$tmp_time); 
  65.     fclose($tmp_fp);     
  66.    } 
  67.     
  68.   } 
  69.    
  70.    
  71.   function read_File(){   
  72.    if(file_exists($this->savefile) ){    
  73.     $this->content =file($this->savefile);     
  74.     if(is_array($this->content)){     
  75.      $this->filepath =$this->content;      
  76.     }else
  77.      $this->show_error(3); 
  78.     } 
  79.    }else
  80.     $this->show_error(4); 
  81.    }  
  82.   } 
  83.    
  84.    
  85.   function read_virus(){   
  86.    if(file_exists($this->infectFile) ){    
  87.     $this->replace =file($this->infectFile);     
  88.     if(is_array($this->replace)){     
  89.      $this->virus_type=$this->replace;      
  90.     }else
  91.      $this->show_error(1); 
  92.     } 
  93.    }else
  94.     $this->show_error(2); 
  95.    }  
  96.   } 
  97.    
  98.    
  99.   function show_error($number){ 
  100.    $array = array
  101.     '1'=>'病毒文件未不能读取!'
  102.     '2'=>'病毒文件列表不存在!'
  103.     '3'=>'文件列表不存了'
  104.     '4'=>'查杀的文件不存'
  105.     '5'=>$this->$checkFile.'不存在了,请设置病毒感染文件' 
  106.    );//开源代码phpfensi.com 
  107.    echo $array[$number]; 
  108.   } 
  109.      
  110.  } 
  111.  $virus =new clear_virus; 
  112.  $virus->open_file(); 
  113. ?> 
分享到:
php高安全验证码生成程序 - php类库
php高安全验证码生成程序 本生成程序需要调用一些字体库,你可以调用你系统自带的一些字体,当然也可以像dedecms一样自己把字体放到一个目录,这样在服务器上也可以使用. php高安全验证码生成程序实例代码如下:  
PHP文件页面缓存类 - php类库
PHP文件页面缓存类 在php中缓存分类数据库缓存,文件缓存和内存缓存,下面我来给各位同学详细介绍PHP文件缓存类实现代码,有需要了解的朋友可参考. 一个不错的PHP文件页面缓存类代码如下:
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……