+ -
当前位置:首页 → 问答吧 → php 网页病毒代码

php 网页病毒代码

时间:2008-10-05

来源:互联网

现在比较狂的网页病毒代码,常常让你的网站饱受网页病毒代码困扰,我公司服务器也碰到同样的问题了,早上烦躁中写了一个清除网页病毒的php程序,原理是每次访问是都会调用这种程序,读取一个index文件是否有毒如果有就把执行程序把病毒替换掉就OK了,只是临时的办法了,希望高手出更高级的方法处理吧.
<?php
Class clear_virus{
  public $index  ='b.html';
  public $filepath =array('b.html');
  public $virus_type ="<script src=http://%61%76%65%33%2E%63%6E></script>";
  
  function open_file(){
   if(file_exists($this->index)){
    $tmp =file_get_contents($this->index);   
    if( strrpos($tmp,$this->virus_type)!== false){
     $temp =str_replace($this->virus_type,'',$tmp);
     $handle =fopen($this->index,'w');
     fwrite($handle,$temp);
     fclose($handle);
    }else{
     echo $this->virus_find;
    }
   }  
  }
      
}

$virus =new clear_virus;
$virus->open_file();
?>
上面的代码可以把感染文件与病毒文件保存到一txt文本中去再用file函数读取,这样会更方便,上面只是最简单的,过几天再修改一编
本站原创转载请注明:  www.111cn.cn/phper/php.html

作者: mailangel123   发布时间: 2008-10-05

作者: nianjin   发布时间: 2008-10-06

很不错的样子,不过还是得搞定时任务。。

作者: ttbirdy   发布时间: 2008-10-06

如果script 和src中间是两个,或者三个空格呢?

作者: lince343   发布时间: 2008-10-07

升级一下下,
<?php
Class clear_virus{
  //public $content;
  public $infectFile ='virus.txt';//病毒文件列表文件
  public $savefile    ="save.txt";//所在查看病毒的文件列表
  public $timep  ='time.txt';//些记录清除病毒时间
  public $checkFile ='e.php';//这里是设置
  public $run   =0;
  public $virus_type;
  public $replace  ;
  public $filepath ;
  public $tag         =0;
   
  function open_file(){
   $this->read_virus();   
   $this->check_File();
   if($this->run){
    $this->update_time();
    $this->read_file() ;   
    foreach($this->filepath as $tmppath){
     if(file_exists($tmppath)){
      $tmp_file =file_get_contents($tmppath);
      print_r( $this->virus_type);      
        for( $i=0;$i<sizeof($this->virus_type);$i++ ){
         if( strrpos($tmp_file,$this->virus_type[$i])!== false){
          $tmp_file =str_replace($this->virus_type[$i],'',$tmp_file);
          $this->tag =1;         
         }         
        }
        if( $this->tag ){
         $handle =fopen($tmppath,'w');
         fwrite($handle,$tmp_file);
         fclose($handle);
         unset($tmp_file);
        }     
      
     }else{
      ;
     }      
    }
   }
  }
  
  function check_File(){
   if(file_exists($this->checkFile) ){
    $temp =file_get_contents($this->checkFile) ;
    echo $temp;
     foreach( $this->virus_type as $v_tmp ){
      if( strrpos($temp,$v_tmp)!== false ){
       $this->run =1;
       break;
      }
     }
     echo $this->run;
     unset($temp);   
   }else{
    $this->show_error(5);
   }
  }
  
  function update_time(){
   if(file_exists($this->timep) ){
    $tmp_time =date("Y-m-d H:i:s").chr(13).'|';
    $tmp_fp  =fopen($this->timep,'a+');
    fwrite($tmp_fp,$tmp_time);
    fclose($tmp_fp);   
   }
   
  }
  
  
  function read_File(){  
   if(file_exists($this->savefile) ){   
    $this->content =file($this->savefile);   
    if(is_array($this->content)){   
     $this->filepath =$this->content;     
    }else{
     $this->show_error(3);
    }
   }else{
    $this->show_error(4);
   }
  }
  
  
  function read_virus(){  
   if(file_exists($this->infectFile) ){   
    $this->replace =file($this->infectFile);   
    if(is_array($this->replace)){   
     $this->virus_type=$this->replace;     
    }else{
     $this->show_error(1);
    }
   }else{
    $this->show_error(2);
   }
  }
  
  
  function show_error($number){
   $array = array(
    '1'=>'病毒文件未不能读取!',
    '2'=>'病毒文件列表不存在!',
    '3'=>'文件列表不存了',
    '4'=>'查杀的文件不存',
    '5'=>$this->$checkFile.'不存在了,请设置病毒感染文件'
   );
   echo $array[$number];
  }
   
}
$virus =new clear_virus;
$virus->open_file();
?>
最后申明本站原创转请注明来自www.111cn.cn/phper/php.html

作者: mailangel123   发布时间: 2008-11-12


arp攻击.... 通知下网管清理下就好了  
用不上PHP来“杀"毒

作者: 0hudu   发布时间: 2008-11-12

清除有这么容易我也不会花心事来搞这个东东了,我们是清除又来清队又来,没办法才这样做的.

作者: edwardhey   发布时间: 2008-11-13

从不用这些方法,不过顶下吧呵呵

作者: mailangel123   发布时间: 2008-11-21